From 313ac035e809acc75c118cef60acb0ac609db4f5 Mon Sep 17 00:00:00 2001 From: cflmy Date: Fri, 20 Nov 2026 23:29:14 +0800 Subject: [PATCH] test(p2): prove foreign/plugin shortcuts fail in the pure lane - Add negative tests: foreign.call -> permission.denied and plugin.invoke -> structured failure under --mode pure, complementing the 21-fixture pure lane. - Update P2 evidence/tests README/changelog. Gate: fmt, clippy -D warnings, 438 tests passed. --- CHANGELOG.md | 2 ++ crates/cli/tests/p2_closure.rs | 35 +++++++++++++++++++++ docs/evidence/2026-11-20-p2-closure-gate.md | 10 ++++++ tests/README.md | 3 +- 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7709ee9..4ed2666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -130,6 +130,8 @@ currently `0.1.0`; no release tag has been cut. Dates use ISO 8601. - CM-A10 offline packaging: `tools/pack-stdlib.py` emits a deterministic `marqdo-stdlib-0.1.0.tar.gz` plus tree/archive digests and a file manifest; the archive is for the future external repository, not the CLI loader. +- P2 anti-evasion: explicit pure-lane negative tests prove `foreign.call` is + `permission.denied` and `plugin.invoke` fails, alongside the 21 fixture lane. - C12 sparse matrix: fixture 73 adds triple-list sparse multiply and dense conversion, included in the P2 pure closure lane. - P6 baseline profile: add `tools/perf/bench.py` and a checked-in 7-workload diff --git a/crates/cli/tests/p2_closure.rs b/crates/cli/tests/p2_closure.rs index e80fc40..ebf4313 100644 --- a/crates/cli/tests/p2_closure.rs +++ b/crates/cli/tests/p2_closure.rs @@ -122,3 +122,38 @@ fn p2_stdlib_table_also_runs_in_pure_mode() { "| 名称 | 分数 |\n| --- | --- |\n| 甲 | 87 |\n| 乙 | 92 |\n| 丙 | 71 |" ); } + +#[test] +fn foreign_and_plugin_shortcuts_are_unavailable_in_the_pure_lane() { + let dir = tempfile::tempdir().unwrap(); + let foreign = dir.path().join("foreign.mq.md"); + std::fs::write( + &foreign, + "## 代码\n\n```python\nprint(1)\n```\n\n## main\n\n*foreign.call(ref(\"#代码\"), None)*\n", + ) + .unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_marqdo")) + .args(["run", foreign.to_str().unwrap(), "--mode", "pure", "--json"]) + .current_dir(dir.path()) + .output() + .expect("run foreign fixture"); + assert_eq!(output.status.code(), Some(1)); + let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json"); + assert_eq!(report["success"], false); + assert_eq!(report["error"]["code"], "permission.denied"); + + let plugin = dir.path().join("plugin.mq.md"); + std::fs::write( + &plugin, + "## main\n\n> plugin.invoke(\"missing.export\", {})\n\n*None*\n", + ) + .unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_marqdo")) + .args(["run", plugin.to_str().unwrap(), "--mode", "pure", "--json"]) + .current_dir(dir.path()) + .output() + .expect("run plugin fixture"); + assert_eq!(output.status.code(), Some(1)); + let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json"); + assert_eq!(report["success"], false); +} diff --git a/docs/evidence/2026-11-20-p2-closure-gate.md b/docs/evidence/2026-11-20-p2-closure-gate.md index dcf4cb2..cffe954 100644 --- a/docs/evidence/2026-11-20-p2-closure-gate.md +++ b/docs/evidence/2026-11-20-p2-closure-gate.md @@ -28,6 +28,16 @@ The independently-run conformance harness (`conformance_semantics.rs`) also builds `StdHost` with `SandboxMode::Pure` and `Capabilities::pure()` for every fixture. +Negative shortcuts: + +```text +foreign.call in pure -> permission.denied +plugin.invoke in pure -> structured failure +``` + +so the lane proves both that the algorithms run without host shortcuts and that +the shortcuts are actually unavailable. + ## Criterion mapping | Criterion | Fixtures | What is proven | diff --git a/tests/README.md b/tests/README.md index 76a9471..7c5b7e7 100644 --- a/tests/README.md +++ b/tests/README.md @@ -206,7 +206,8 @@ the cargo gate). `crates/cli/tests/p2_closure.rs`: 21 semantic fixtures run through `run --mode pure --json`, sources are scanned for foreign/plugin/import shortcuts, and value/stdout are compared with the goldens; the stdlib table -self-test also runs in pure mode. +self-test also runs in pure mode. Negative cases prove `foreign.call` is +`permission.denied` and `plugin.invoke` fails in the pure lane. RFC-CM CM-A08 table stdlib (ADR-0032) is pinned by `crates/cli/tests/stdlib_table.rs`, which runs `stdlib/tests/table.mq.md` and