analysis: bind to marqdo.analysis rev 3 and extract proof units
- strict DTOs for the current public Analysis contract, digest/span validation - controlled-root CLI invocation with argv-only, timeout and process group kill - proof-unit selection: one Knowledge H2 + direct 证明依赖 H3 + one display goal - dependency list shape validation with 证明依赖 links - real-CLI integration tests for the algebra/vector/arithmetic fixtures
This commit is contained in:
1 parent
ecaf1b756c
commit
3a529b923d
8 files changed
+2672
-1
No files matched your search
@@ -0,0 +1,100 @@
|
||||
//! 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");
|
||||
}
|
||||
Reference in new issue
Block a user