use assert_cmd::Command;
use predicates::prelude::*;
use tempfile::TempDir;
fn bin() -> Command {
Command::cargo_bin("musts").expect("musts binary not built")
}
#[test]
fn empty_workspace_with_git_anchor_is_clean() {
let dir = TempDir::new().unwrap();
std::fs::create_dir(dir.path().join(".git")).unwrap();
bin()
.arg("--workspace")
.arg(dir.path())
.arg("validate")
.assert()
.success()
.stdout(predicate::str::contains(
"Musts validation clean. No MUSTS.yml files found.",
));
}
#[test]
fn json_clean_shape_matches_contract() {
let dir = TempDir::new().unwrap();
let out = bin()
.arg("--workspace")
.arg(dir.path())
.arg("validate")
.arg("--json")
.assert()
.success();
let stdout = std::str::from_utf8(&out.get_output().stdout).unwrap();
let parsed: serde_json::Value = serde_json::from_str(stdout).expect("valid JSON");
assert_eq!(parsed["protocol_version"], 1);
assert_eq!(parsed["status"], "clean");
assert!(parsed["tasks"].as_array().unwrap().is_empty());
assert!(parsed["ignored_checks"].as_array().unwrap().is_empty());
assert!(parsed["notes"].as_array().unwrap().is_empty());
}
#[test]
fn missing_extension_capability_reports_clearly() {
let dir = TempDir::new().unwrap();
std::fs::write(
dir.path().join("MUSTS.yml"),
"version: 1\nchecks:\n custom-check:\n uses: third-party/lint\n with: {}\n",
)
.unwrap();
bin()
.arg("--workspace")
.arg(dir.path())
.arg("validate")
.assert()
.failure()
.code(2)
.stderr(predicate::str::contains(
"no extension implements capability `third-party/lint`",
))
.stderr(predicate::str::contains("root/custom-check"))
.stderr(predicate::str::contains("MUSTS.yml"));
}
#[test]
fn missing_workspace_reports_workspace_not_found() {
let dir = TempDir::new().unwrap();
let alt = TempDir::new().unwrap();
bin()
.current_dir(alt.path())
.env("HOME", dir.path())
.arg("validate")
.assert()
.failure()
.code(2)
.stderr(predicate::str::contains(
"no .git directory or MUSTS.yml found",
));
}
#[test]
fn broken_workspace_path_canonicalisation() {
bin()
.arg("--workspace")
.arg("/this/path/definitely/does/not/exist")
.arg("validate")
.assert()
.failure()
.code(2)
.stderr(predicate::str::contains(
"could not canonicalise workspace path",
));
}