feat: complete rule evidence and frozen review fixtures
This commit is contained in:
1 parent
1f4e120a53
commit
344ef28870
27 files changed
+1992
-356
No files matched your search
+192
-21
@@ -48,31 +48,66 @@ fn reports_and_exit_codes_distinguish_style_from_unavailable_analysis() {
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(output.stderr.is_empty(), "{:?}", output);
|
||||
(output.status.code().unwrap(), serde_json::from_slice::<Value>(&output.stdout).unwrap())
|
||||
(
|
||||
output.status.code().unwrap(),
|
||||
serde_json::from_slice::<Value>(&output.stdout).unwrap(),
|
||||
)
|
||||
};
|
||||
let (code, result) = report(&[]);
|
||||
assert_eq!(code, 1, "{result}");
|
||||
assert_eq!(result["analysis_status"], "complete");
|
||||
assert_eq!(result["diagnostics"][0]["id"], "MQD-DOC-001");
|
||||
assert!(result["diagnostics"].as_array().unwrap().iter().any(|diagnostic| {
|
||||
diagnostic["id"] == "MQD-DOC-003" && diagnostic["severity"] == "info"
|
||||
}));
|
||||
assert!(result["diagnostics"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|diagnostic| {
|
||||
diagnostic["id"] == "MQD-DOC-003" && diagnostic["severity"] == "info"
|
||||
}));
|
||||
assert_eq!(report(&["--fail-on", "error"]).0, 0);
|
||||
|
||||
fs::write(temp.path().join("marqdo-lint.toml"), r#"
|
||||
fs::write(
|
||||
temp.path().join("marqdo-lint.toml"),
|
||||
r#"
|
||||
[[suppress]]
|
||||
path = "index.mq.md"
|
||||
rule = "MQD-DOC-001"
|
||||
reason = "Fixture for a deliberately short helper"
|
||||
"#).unwrap();
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(report(&[]).0, 0);
|
||||
let config_path = temp.path().join("marqdo-lint.toml");
|
||||
let config = fs::read_to_string(&config_path).unwrap();
|
||||
fs::write(
|
||||
&config_path,
|
||||
format!("{config}\n[rules]\n\"MQD-DOC-003\" = \"warning\"\n"),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(report(&[]).0, 1);
|
||||
|
||||
fs::copy(fixtures().join("golden/invalid-control.mq.md"), source).unwrap();
|
||||
let (code, result) = report(&["--fail-on", "never"]);
|
||||
assert_eq!(code, 2, "{result}");
|
||||
assert_eq!(result["analysis_status"], "analysis_incomplete");
|
||||
assert!(result["metrics"]["narrative_ratio"].is_null());
|
||||
assert!(result["core_output"].as_str().unwrap().contains("sem.unclosed_control"));
|
||||
assert!(result["core_output"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.contains("sem.unclosed_control"));
|
||||
assert!(result["diagnostics"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|d| d["id"] == "MQD-KNOW-001"));
|
||||
let invalid_signature = "## @exec x\n\n- `params(n: Int)`\n\n*return 1*";
|
||||
fs::write(temp.path().join("index.mq.md"), invalid_signature).unwrap();
|
||||
let (code, result) = report(&[]);
|
||||
assert_eq!(code, 2, "{result}");
|
||||
assert!(
|
||||
result["core_output"].as_str().unwrap().contains("params"),
|
||||
"{result}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -82,7 +117,15 @@ fn multi_module_run_reports_each_source_once() {
|
||||
}
|
||||
let output = lint()
|
||||
.current_dir(fixtures().join("multi"))
|
||||
.args(["index.mq.md", "geometry.mq.md", ".", "--format", "json", "--fail-on", "never"])
|
||||
.args([
|
||||
"index.mq.md",
|
||||
"geometry.mq.md",
|
||||
".",
|
||||
"--format",
|
||||
"json",
|
||||
"--fail-on",
|
||||
"never",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(output.status.success(), "{:?}", output);
|
||||
@@ -101,21 +144,38 @@ fn t30_frozen_core_installs_and_dispatches_lint() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let bundle = temp.path().join("bundle");
|
||||
fs::create_dir_all(bundle.join("bin")).unwrap();
|
||||
fs::copy(env!("CARGO_BIN_EXE_marqdo-lint"), bundle.join("bin/marqdo-lint")).unwrap();
|
||||
fs::copy(
|
||||
env!("CARGO_BIN_EXE_marqdo-lint"),
|
||||
bundle.join("bin/marqdo-lint"),
|
||||
)
|
||||
.unwrap();
|
||||
let manifest = bundle.join("tool.json");
|
||||
fs::write(&manifest, include_bytes!("../tool.json")).unwrap();
|
||||
let marqdo = || {
|
||||
let mut command = Command::new(&core);
|
||||
command.env("MARQDO_TOOL_HOME", temp.path().join("registry"))
|
||||
command
|
||||
.env("MARQDO_TOOL_HOME", temp.path().join("registry"))
|
||||
.env_remove("MARQDO_BIN");
|
||||
command
|
||||
};
|
||||
let install = marqdo().args(["tool", "install"]).arg(manifest).output().unwrap();
|
||||
let install = marqdo()
|
||||
.args(["tool", "install"])
|
||||
.arg(manifest)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(install.status.success(), "{:?}", install);
|
||||
let output = marqdo()
|
||||
.current_dir(fixtures().join("golden"))
|
||||
.args(["lint", "branches.mq.md", "--format", "json", "--fail-on", "never"])
|
||||
.output().unwrap();
|
||||
.args([
|
||||
"lint",
|
||||
"branches.mq.md",
|
||||
"--format",
|
||||
"json",
|
||||
"--fail-on",
|
||||
"never",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(output.status.success(), "{:?}", output);
|
||||
let report: Value = serde_json::from_slice(&output.stdout).unwrap();
|
||||
assert_eq!(report["analysis_status"], "complete");
|
||||
@@ -130,7 +190,11 @@ fn safe_fix_previews_then_persists_verified_whitespace_in_a_manifest_project() {
|
||||
let source = temp.path().join("index.mq.md");
|
||||
let multi = fixtures().join("multi");
|
||||
fs::copy(multi.join("marqdo.yaml"), temp.path().join("marqdo.yaml")).unwrap();
|
||||
fs::copy(multi.join("geometry.mq.md"), temp.path().join("geometry.mq.md")).unwrap();
|
||||
fs::copy(
|
||||
multi.join("geometry.mq.md"),
|
||||
temp.path().join("geometry.mq.md"),
|
||||
)
|
||||
.unwrap();
|
||||
let clean = fs::read_to_string(multi.join("index.mq.md")).unwrap();
|
||||
let original = clean.replace("## @exec main\n\n", "## @exec main\n \t\n");
|
||||
assert_ne!(original, clean);
|
||||
@@ -138,7 +202,15 @@ fn safe_fix_previews_then_persists_verified_whitespace_in_a_manifest_project() {
|
||||
let fix = |args: &[&str]| {
|
||||
lint()
|
||||
.current_dir(temp.path())
|
||||
.args(["index.mq.md", "--fix", "safe", "--format", "json", "--fail-on", "never"])
|
||||
.args([
|
||||
"index.mq.md",
|
||||
"--fix",
|
||||
"safe",
|
||||
"--format",
|
||||
"json",
|
||||
"--fail-on",
|
||||
"never",
|
||||
])
|
||||
.args(args)
|
||||
.output()
|
||||
.unwrap()
|
||||
@@ -151,7 +223,11 @@ fn safe_fix_previews_then_persists_verified_whitespace_in_a_manifest_project() {
|
||||
assert!(applied.status.success(), "{:?}", applied);
|
||||
assert_eq!(fs::read_to_string(&source).unwrap(), clean);
|
||||
let repeated = fix(&[]);
|
||||
assert!(repeated.status.success() && repeated.stderr.is_empty(), "{:?}", repeated);
|
||||
assert!(
|
||||
repeated.status.success() && repeated.stderr.is_empty(),
|
||||
"{:?}",
|
||||
repeated
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -168,13 +244,108 @@ fn safe_fix_rejects_changes_to_inert_payload_and_unavailable_analysis() {
|
||||
fs::write(&source, original).unwrap();
|
||||
let output = lint()
|
||||
.current_dir(temp.path())
|
||||
.args(["index.mq.md", "--fix", "safe", "--format", "json", "--fail-on", "never"])
|
||||
.output().unwrap();
|
||||
.args([
|
||||
"index.mq.md",
|
||||
"--fix",
|
||||
"safe",
|
||||
"--format",
|
||||
"json",
|
||||
"--fail-on",
|
||||
"never",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
let report: Value = serde_json::from_slice(&output.stdout).unwrap();
|
||||
assert_eq!(output.status.code(), Some(code), "{report}");
|
||||
assert!(report["diagnostics"].as_array().unwrap().iter().any(|diagnostic| {
|
||||
diagnostic["id"] == "MQD-SAFETY-001"
|
||||
}), "{report}");
|
||||
assert!(
|
||||
report["diagnostics"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|diagnostic| { diagnostic["id"] == "MQD-SAFETY-001" }),
|
||||
"{report}"
|
||||
);
|
||||
assert_eq!(fs::read_to_string(&source).unwrap(), original);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn supplemental_rules_use_bound_calls_and_allow_rich_knowledge() {
|
||||
if std::env::var_os("MARQDO_BIN").is_none() {
|
||||
return;
|
||||
}
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let source = temp.path().join("index.mq.md");
|
||||
let original = "## @exec output\n\n`params(x: Int)`\n\n**打印(x)**\n\n### @knowledge 说明\n\n这一段说明输出用途。\n\n### @exec 结果\n\n`return x`\n";
|
||||
let report = |text: &str| {
|
||||
fs::write(&source, text).unwrap();
|
||||
let result = lint()
|
||||
.current_dir(temp.path())
|
||||
.args(["index.mq.md", "--format", "json", "--fail-on", "never"])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(result.status.success(), "{:?}", result);
|
||||
serde_json::from_slice::<Value>(&result.stdout).unwrap()
|
||||
};
|
||||
let result = report(original);
|
||||
assert_eq!(
|
||||
result["metrics"]["functions"][0]["has_explicit_effects"],
|
||||
true
|
||||
);
|
||||
let has = |result: &Value, id: &str| {
|
||||
result["diagnostics"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|diagnostic| diagnostic["id"] == id)
|
||||
};
|
||||
for id in [
|
||||
"MQD-PROSE-002",
|
||||
"MQD-PARAM-001",
|
||||
"MQD-KNOW-001",
|
||||
"MQD-STYLE-001",
|
||||
] {
|
||||
assert!(has(&result, id), "{id} {result}");
|
||||
}
|
||||
let improved = original
|
||||
.replace(
|
||||
"`params(x: Int)`",
|
||||
"输入 x 使用最小货币单位。\n\n`params(x: Int)`",
|
||||
)
|
||||
.replace("**打印(x)**", "向控制台写入整数以便核对。\n\n**打印(x)**")
|
||||
.replace("这一段说明输出用途。", "这里的**输出**指控制台记录。")
|
||||
.replace("`return x`", "*return x*");
|
||||
let result = report(&improved);
|
||||
for id in [
|
||||
"MQD-PROSE-002",
|
||||
"MQD-PARAM-001",
|
||||
"MQD-KNOW-001",
|
||||
"MQD-STYLE-001",
|
||||
] {
|
||||
assert!(!has(&result, id), "{id} {result}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t16_exec_emphasis_inside_prose_is_not_a_comment() {
|
||||
if std::env::var_os("MARQDO_BIN").is_none() {
|
||||
return;
|
||||
}
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
fs::write(
|
||||
temp.path().join("index.mq.md"),
|
||||
"## @exec 示例\n\n这是 **特别重要** 的处理。\n\n*return 1*\n",
|
||||
)
|
||||
.unwrap();
|
||||
let output = lint()
|
||||
.current_dir(temp.path())
|
||||
.args(["index.mq.md", "--format", "json"])
|
||||
.output()
|
||||
.unwrap();
|
||||
let report: Value = serde_json::from_slice(&output.stdout).unwrap();
|
||||
assert!(report["diagnostics"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|d| d["id"] == "MQD-PROSE-001"));
|
||||
}
|
||||
Reference in new issue
Block a user