- document_contract: negative path coverage through the real CLI (selection, shape errors, formula unsupported/invalid, missing/external links, cycles, --unit, upstream static failure, root escape) with exit-code assertions - e2e: algebra, vector composition (declared == used), program model scope, refutation, export+replay, cache reuse, tampered payload rejection - report fixes: declared/used locator consistency, diagnostic-only exit status, unsupported vs invalid formula outcomes - clippy -D warnings and cargo fmt clean; docs/STATUS records pinned identities, executed commands, measured backend limits and known gaps
104 lines
3.5 KiB
Rust
104 lines
3.5 KiB
Rust
//! Real-CLI integration: emitted Analysis revision 3 -> proof unit extraction.
|
|
//!
|
|
//! Requires `MARQDO_BIN` to point at a Marqdo CLI that emits analysis revision 3.
|
|
//! The test is skipped (not silently passed) when the variable is unset, so a
|
|
//! developer without a built CLI still gets a green unit suite; CI must set it.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use marqdo_prove::analysis::AnalysisBackend;
|
|
use marqdo_prove::document::{extract, Extraction};
|
|
|
|
fn cli() -> Option<PathBuf> {
|
|
std::env::var_os("MARQDO_BIN").map(PathBuf::from)
|
|
}
|
|
|
|
fn examples_root() -> PathBuf {
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples")
|
|
}
|
|
|
|
fn work_dir(tag: &str) -> PathBuf {
|
|
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.join(".tmp")
|
|
.join("tests")
|
|
.join(tag);
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
std::fs::create_dir_all(&dir).expect("create work dir");
|
|
dir
|
|
}
|
|
|
|
#[test]
|
|
fn real_cli_extracts_vector_fixture() {
|
|
let Some(bin) = cli() else {
|
|
eprintln!("skipping: MARQDO_BIN is not set");
|
|
return;
|
|
};
|
|
let root = examples_root();
|
|
let backend = AnalysisBackend::new(bin, work_dir("analysis_document")).expect("backend");
|
|
let snapshot = backend
|
|
.load(&root.join("vector.mq.md"), &root)
|
|
.expect("load vector analysis");
|
|
assert_eq!(snapshot.relative_path, "vector.mq.md");
|
|
assert_eq!(snapshot.project.identity_kind, "workspace_snapshot");
|
|
let extracted = extract(snapshot.entry());
|
|
assert_eq!(extracted.len(), 1, "{extracted:?}");
|
|
let Extraction::Unit(unit) = &extracted[0] else {
|
|
panic!("expected proof unit, got {extracted:?}");
|
|
};
|
|
assert_eq!(unit.title, "平方和非负性");
|
|
assert_eq!(
|
|
unit.goal.literal,
|
|
"\\forall x,y\\in\\mathbb{Z},\\quad x^2+y^2\\geq0\n"
|
|
);
|
|
assert_eq!(unit.dependencies.links.len(), 2);
|
|
assert_eq!(unit.dependencies.links[0].text, "整数平方非负性");
|
|
assert_eq!(
|
|
unit.dependencies.links[0].url,
|
|
"algebra.mq.md#整数平方非负性"
|
|
);
|
|
assert!(unit.goal.payload_span.is_some());
|
|
let source = &snapshot.entry().source;
|
|
assert_eq!(
|
|
&source[unit.goal.payload_span.unwrap().start..unit.goal.payload_span.unwrap().end],
|
|
unit.goal.literal
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn real_cli_extracts_algebra_fixture() {
|
|
let Some(bin) = cli() else {
|
|
eprintln!("skipping: MARQDO_BIN is not set");
|
|
return;
|
|
};
|
|
let root = examples_root();
|
|
let backend = AnalysisBackend::new(bin, work_dir("analysis_algebra")).expect("backend");
|
|
let snapshot = backend
|
|
.load(&root.join("algebra.mq.md"), &root)
|
|
.expect("load algebra analysis");
|
|
let extracted = extract(snapshot.entry());
|
|
assert_eq!(extracted.len(), 2, "{extracted:?}");
|
|
for entry in &extracted {
|
|
assert!(matches!(entry, Extraction::Unit(_)), "{entry:?}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn real_cli_extracts_program_model_fixture() {
|
|
let Some(bin) = cli() else {
|
|
eprintln!("skipping: MARQDO_BIN is not set");
|
|
return;
|
|
};
|
|
let root = examples_root();
|
|
let backend = AnalysisBackend::new(bin, work_dir("analysis_arith")).expect("backend");
|
|
let snapshot = backend
|
|
.load(&root.join("arithmetic.mq.md"), &root)
|
|
.expect("load arithmetic analysis");
|
|
let extracted = extract(snapshot.entry());
|
|
assert_eq!(extracted.len(), 1, "{extracted:?}");
|
|
let Extraction::Unit(unit) = &extracted[0] else {
|
|
panic!("expected proof unit, got {extracted:?}");
|
|
};
|
|
assert_eq!(unit.dependencies.links.len(), 2);
|
|
assert_eq!(unit.dependencies.links[0].url, "#square");
|
|
}
|