use std::path::PathBuf;
use std::process::Command;
fn workspace_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.and_then(|p| p.parent())
.expect("workspace root")
.to_path_buf()
}
fn xpile_bin() -> PathBuf {
PathBuf::from(env!("CARGO_BIN_EXE_xpile"))
}
#[test]
fn attestations_finds_c_py_int_arith_in_live_roadmap() {
let root = workspace_root();
let roadmap = root.join("docs/roadmaps/roadmap.yaml");
let contracts = root.join("contracts");
if !roadmap.is_file() {
eprintln!(
"warning: skipping XPILE-QUORUM-005 — {} missing",
roadmap.display()
);
return;
}
let out = Command::new(xpile_bin())
.args([
"attestations",
"--json",
"--roadmap",
roadmap.to_str().unwrap(),
"--contracts-dir",
contracts.to_str().unwrap(),
])
.output()
.expect("run xpile attestations");
assert!(
out.status.success(),
"xpile attestations failed:\n stderr: {}",
String::from_utf8_lossy(&out.stderr)
);
let stdout = String::from_utf8_lossy(&out.stdout);
let id_marker = "\"id\":\"C-PY-INT-ARITH\"";
let idx = stdout
.find(id_marker)
.unwrap_or_else(|| panic!("expected C-PY-INT-ARITH entry in attestations JSON:\n{stdout}"));
let tail = &stdout[idx..];
let count_marker = "\"mention_count\":";
let cidx = tail
.find(count_marker)
.expect("expected mention_count in entry");
let after = &tail[cidx + count_marker.len()..];
let end = after.find([',', '}']).expect("expected delimiter");
let count: u64 = after[..end]
.trim()
.parse()
.expect("mention_count must be an integer");
assert!(
count >= 1,
"expected ≥1 attestation for C-PY-INT-ARITH; the contract appears in titles for \
multiple shipped PRs (PMAT-002 / 011 / 017 / 019 / 029 / 030). Got {count}. \
Either the scanner regressed or the roadmap was rewritten."
);
}
#[test]
fn attestations_text_output_runs_cleanly() {
let root = workspace_root();
let roadmap = root.join("docs/roadmaps/roadmap.yaml");
let contracts = root.join("contracts");
if !roadmap.is_file() {
return;
}
let out = Command::new(xpile_bin())
.args([
"attestations",
"--roadmap",
roadmap.to_str().unwrap(),
"--contracts-dir",
contracts.to_str().unwrap(),
])
.output()
.expect("run xpile attestations");
assert!(
out.status.success(),
"text-mode xpile attestations failed:\n stderr: {}",
String::from_utf8_lossy(&out.stderr)
);
let stdout = String::from_utf8_lossy(&out.stdout);
for needle in &[
"XPILE-QUORUM-005",
"contract ID(s) from contracts/",
"stratum: Extrinsic",
] {
assert!(
stdout.contains(needle),
"text-mode attestations output missing landmark `{needle}`:\n{stdout}"
);
}
}