use std::{fs, path::Path};
use assert_cmd::Command;
use predicates::prelude::*;
fn write(path: &Path, contents: &str) {
fs::write(path, contents).unwrap();
}
#[test]
fn commit_msg_gate_accepts_evidenced_claim() {
let temp = tempfile::tempdir().unwrap();
let commit_msg = temp.path().join("COMMIT_EDITMSG");
write(
&commit_msg,
"feat: claim parser\n\nCLAIM: add parser | verified: cargo test | evidence: tests:cargo-test\n",
);
Command::cargo_bin("truth-mirror")
.unwrap()
.args(["gate", "--commit-msg", commit_msg.to_str().unwrap()])
.assert()
.success();
}
#[test]
fn commit_msg_gate_rejects_missing_claim() {
let temp = tempfile::tempdir().unwrap();
let commit_msg = temp.path().join("COMMIT_EDITMSG");
write(&commit_msg, "feat: claim parser\n");
Command::cargo_bin("truth-mirror")
.unwrap()
.args(["gate", "--commit-msg", commit_msg.to_str().unwrap()])
.assert()
.failure()
.stderr(predicate::str::contains("missing CLAIM"));
}
#[test]
fn commit_msg_gate_rejects_completion_without_evidence() {
let temp = tempfile::tempdir().unwrap();
let commit_msg = temp.path().join("COMMIT_EDITMSG");
write(
&commit_msg,
"feat: done parser\n\nCLAIM: complete parser | verified: cargo test\n",
);
Command::cargo_bin("truth-mirror")
.unwrap()
.args(["gate", "--commit-msg", commit_msg.to_str().unwrap()])
.assert()
.failure()
.stderr(predicate::str::contains(
"completion wording lacks evidence",
));
}
#[test]
fn commit_msg_gate_rejects_fake_marker_in_diff_file() {
let temp = tempfile::tempdir().unwrap();
let commit_msg = temp.path().join("COMMIT_EDITMSG");
let diff = temp.path().join("staged.diff");
write(
&commit_msg,
"feat: claim parser\n\nCLAIM: add parser | verified: cargo test | evidence: tests:cargo-test\n",
);
write(
&diff,
"diff --git a/src/lib.rs b/src/lib.rs\n+ TODO-as-done\n",
);
Command::cargo_bin("truth-mirror")
.unwrap()
.args([
"gate",
"--commit-msg",
commit_msg.to_str().unwrap(),
"--diff-file",
diff.to_str().unwrap(),
])
.assert()
.failure()
.stderr(predicate::str::contains("TODO-as-done"));
}