feat: verify safe whitespace fixes before atomic writeback
This commit is contained in:
1 parent
94c36270fa
commit
1f4e120a53
11 files changed
+416
-11
No files matched your search
@@ -120,3 +120,61 @@ fn t30_frozen_core_installs_and_dispatches_lint() {
|
||||
let report: Value = serde_json::from_slice(&output.stdout).unwrap();
|
||||
assert_eq!(report["analysis_status"], "complete");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn safe_fix_previews_then_persists_verified_whitespace_in_a_manifest_project() {
|
||||
if std::env::var_os("MARQDO_BIN").is_none() {
|
||||
return;
|
||||
}
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
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();
|
||||
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);
|
||||
fs::write(&source, &original).unwrap();
|
||||
let fix = |args: &[&str]| {
|
||||
lint()
|
||||
.current_dir(temp.path())
|
||||
.args(["index.mq.md", "--fix", "safe", "--format", "json", "--fail-on", "never"])
|
||||
.args(args)
|
||||
.output()
|
||||
.unwrap()
|
||||
};
|
||||
let preview = fix(&["--dry-run"]);
|
||||
assert!(preview.status.success(), "{:?}", preview);
|
||||
assert!(String::from_utf8_lossy(&preview.stderr).contains("@@"));
|
||||
assert_eq!(fs::read_to_string(&source).unwrap(), original);
|
||||
let applied = fix(&[]);
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn safe_fix_rejects_changes_to_inert_payload_and_unavailable_analysis() {
|
||||
if std::env::var_os("MARQDO_BIN").is_none() {
|
||||
return;
|
||||
}
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let source = temp.path().join("index.mq.md");
|
||||
for (original, code) in [
|
||||
("## @exec example\n\n```text\n \t\n```\n\n*return 1*\n", 1),
|
||||
("## @exec example\n\n`if true`\n\n*return 1*", 2),
|
||||
] {
|
||||
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();
|
||||
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_eq!(fs::read_to_string(&source).unwrap(), original);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user