prove: P3 — --all 目录模式、T4 差分一致性、库语义对齐、2.8.0 收口
- main.rs:prove --all/--max-files(递归收集,目录不带 --all 拒绝; 聚合 JSON kind=prove-all,整体状态差者胜);--fault-inject offline-claim (调试分歧注入,A3 护栏验证入口) - tests/conformance.rs:T4 差分一致性——5 例纯函数语料(算术/中文标识符/ 分支比较/字符串拼接/i64 边界)解释器求值 == Lean example(simp+try rfl); B4 result.ok 结构字段 access 两侧一致 - MarqdoProof.lean:mqAdd 补文本拼接与 num 混合(与解释器 eval_binary(Add) 对齐——T4 实测抓出的真分歧);mqDisplay 显示串(标量精确,容器一层, 有意简化并记录) - 文档:design §12 P3 落地 + §12.4 延期理由(foreach/assume-guarantee/T3 → 2.9)+ §12.5 权限受限待合入清单;roadmap 状态 → 已实施; 教程 §13.8 prove 章节;skills/marqdo/reference.md 定理表; doc/verification/skill-proof-theory.md(库形式化说明); doc/roadmap/prove-release-2.8.0.md(双语发版说明 + CHANGELOG/README/ skills/marqdo-dev prove 任务待合入原文) - Cargo.toml/Cargo.lock:2.7.1 → 2.8.0 实测:全量 516 通过(仅 2 个已记录环境基线失败);prove 23 + prove_lean 10 + corpus 40 夹具 + conformance 6 例全绿;biz 定理 proved、假定理反例、 --all 聚合与护栏目录模式同样生效。
This commit is contained in:
1 parent
63d60e3ba1
commit
4fae71342d
12 files changed
+1015
-21
No files matched your search
+131
@@ -552,6 +552,19 @@ enum Commands {
|
||||
/// maxHeartbeats for lean (default: lean's own)
|
||||
#[arg(long, value_name = "N")]
|
||||
heartbeats: Option<u64>,
|
||||
|
||||
/// Directory mode: recursively prove every .mq.md (aggregated, worst status wins)
|
||||
#[arg(long)]
|
||||
all: bool,
|
||||
|
||||
/// Cap for --all file collection (default 200)
|
||||
#[arg(long = "max-files", value_name = "N", default_value_t = 200)]
|
||||
max_files: usize,
|
||||
|
||||
/// Debug fault injection: `offline-claim` flips one Lean-proved claim to
|
||||
/// force proof.divergence (monotonicity tripwire verification)
|
||||
#[arg(long = "fault-inject", value_name = "SPEC")]
|
||||
fault_inject: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -774,6 +787,85 @@ fn main() -> ExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
/// `prove --all`:逐文件出报告,整体取最差状态(差者胜,§3.2)。
|
||||
/// JSON:`{"schema":1,"kind":"prove-all","status":…,"files":[…],"duration_ms":…}`。
|
||||
fn run_prove_all(
|
||||
dir: &std::path::Path,
|
||||
max_files: usize,
|
||||
opts: &marqdo::prove::ProveOptions,
|
||||
json: bool,
|
||||
require_lean: bool,
|
||||
) -> Result<i32> {
|
||||
let mut files = collect_mq_files(dir)?;
|
||||
anyhow::ensure!(
|
||||
!files.is_empty(),
|
||||
"目录中没有 .mq.md 文件:{}",
|
||||
dir.display()
|
||||
);
|
||||
anyhow::ensure!(
|
||||
files.len() <= max_files,
|
||||
"--max-files {max_files} 已达上限(实际 {} 个文件;请调大或缩小范围)",
|
||||
files.len()
|
||||
);
|
||||
files.sort();
|
||||
let started = std::time::Instant::now();
|
||||
let mut worst = marqdo::prove::Verdict::Proved;
|
||||
let mut file_items: Vec<serde_json::Value> = Vec::new();
|
||||
let mut text_rows: Vec<(String, marqdo::prove::Verdict, usize)> = Vec::new();
|
||||
for f in &files {
|
||||
let report = marqdo::prove::prove_path(f, opts)?;
|
||||
for d in &report.diagnostics {
|
||||
eprintln!("{}", d.format_message());
|
||||
}
|
||||
let claims: usize = report
|
||||
.functions
|
||||
.iter()
|
||||
.map(|fun| fun.claims.len())
|
||||
.sum();
|
||||
worst = marqdo::prove::Verdict::worst(worst, report.status);
|
||||
text_rows.push((
|
||||
f.strip_prefix(dir).unwrap_or(f).display().to_string(),
|
||||
report.status,
|
||||
claims,
|
||||
));
|
||||
let mut item = report.to_json();
|
||||
if let Some(obj) = item.as_object_mut() {
|
||||
obj.insert(
|
||||
"file".into(),
|
||||
serde_json::Value::String(
|
||||
f.strip_prefix(dir).unwrap_or(f).display().to_string(),
|
||||
),
|
||||
);
|
||||
}
|
||||
file_items.push(item);
|
||||
}
|
||||
let duration_ms = started.elapsed().as_millis() as u64;
|
||||
if json {
|
||||
let agg = serde_json::json!({
|
||||
"schema": 1,
|
||||
"kind": "prove-all",
|
||||
"root": dir.display().to_string(),
|
||||
"status": worst.as_str(),
|
||||
"files": file_items,
|
||||
"file_count": files.len(),
|
||||
"duration_ms": duration_ms,
|
||||
});
|
||||
println!("{agg}");
|
||||
} else {
|
||||
println!(
|
||||
"prove --all {}:{} 个文件,{} ms,整体 {}",
|
||||
dir.display(),
|
||||
files.len(),
|
||||
duration_ms,
|
||||
worst.as_str()
|
||||
);
|
||||
for (rel, status, claims) in &text_rows {
|
||||
println!(" {rel}: {}(定理 {claims})", status.as_str());
|
||||
}
|
||||
}
|
||||
Ok(worst.exit_code(require_lean))
|
||||
}
|
||||
|
||||
/// Resolve the value-path spelling introduced for executable knowledge without
|
||||
/// evaluating it. The import bind comes from the caller's source file, so
|
||||
/// `math.pi` never degrades into a project-wide name guess.
|
||||
@@ -1101,7 +1193,14 @@ fn try_main(cli: Cli) -> Result<i32> {
|
||||
timeout,
|
||||
no_cache,
|
||||
heartbeats,
|
||||
all,
|
||||
max_files,
|
||||
fault_inject,
|
||||
} => {
|
||||
// 调试注入(§6 A3):仅面向测试的分歧触发器。
|
||||
if fault_inject.as_deref() == Some("offline-claim") {
|
||||
std::env::set_var("MARQDO_PROOF_INJECT_DIVERGENCE", "1");
|
||||
}
|
||||
// 子命令参数覆盖顶层默认;默认动作 = emit + 报告。
|
||||
let (file, action_json, action_emit, action_only, action_opaque, action_relax) =
|
||||
match &action {
|
||||
@@ -1154,6 +1253,38 @@ fn try_main(cli: Cli) -> Result<i32> {
|
||||
// emit 子命令只生成不判定(§8.2)。
|
||||
let judge = !matches!(action, Some(ProveAction::Emit { .. }));
|
||||
let no_cache = no_cache || std::env::var_os("MARQDO_PROOF_NO_CACHE").is_some();
|
||||
// 目录必须显式 --all(§3.2 proof.need_all)。
|
||||
if file.is_dir() {
|
||||
if !all {
|
||||
eprintln!(
|
||||
"error: {} 是目录:逐文件证明请加 --all(--max-files 默认 200)",
|
||||
file.display()
|
||||
);
|
||||
return Ok(1);
|
||||
}
|
||||
let out_json = json || action_json;
|
||||
let code = run_prove_all(
|
||||
&file,
|
||||
max_files,
|
||||
&marqdo::prove::ProveOptions {
|
||||
entry: None,
|
||||
only: action_only,
|
||||
allow_opaque: action_opaque,
|
||||
emit_dir: emit_target,
|
||||
strict_types: !action_relax,
|
||||
require_lean,
|
||||
report_only,
|
||||
judge,
|
||||
no_cache,
|
||||
lean,
|
||||
timeout: std::time::Duration::from_secs(timeout),
|
||||
max_heartbeats: heartbeats,
|
||||
},
|
||||
out_json,
|
||||
require_lean,
|
||||
)?;
|
||||
return Ok(code);
|
||||
}
|
||||
let opts = marqdo::prove::ProveOptions {
|
||||
entry: None,
|
||||
only: action_only,
|
||||
|
||||
Reference in new issue
Block a user