From 0d4dc1da03154619e98e1f74699df705874451f6 Mon Sep 17 00:00:00 2001 From: cflmy Date: Fri, 20 Nov 2026 23:12:03 +0800 Subject: [PATCH] test(p2): close C01-C06/C11/C12 in a pure no-Foreign/no-Plugin lane - Add crates/cli/tests/p2_closure.rs: 20 semantic fixtures run through the real CLI in --mode pure (Capabilities::pure), source scan for foreign./plugin./ import:, and golden value/stdout comparison. - Run the stdlib table self-test in pure mode; no host shortcut or recompilation is needed for the selected algorithms. - Mark P2 gate PASS locally (external stdlib repo publication and remote CI remain outside the C01-C12 gate); add evidence and docs. Gate: fmt, clippy -D warnings, 428 tests passed. --- CHANGELOG.md | 2 + crates/cli/tests/p2_closure.rs | 123 ++++++++++++++++++++ docs/STATUS.md | 5 +- docs/evidence/2026-11-20-p2-closure-gate.md | 59 ++++++++++ tests/README.md | 6 + 5 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 crates/cli/tests/p2_closure.rs create mode 100644 docs/evidence/2026-11-20-p2-closure-gate.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 27f5d20..b33c601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -125,6 +125,8 @@ currently `0.1.0`; no release tag has been cut. Dates use ISO 8601. before module loading, a `std:marqdo-stdlib@#` package instance id, `project.stdlib` in Analysis v2, and test coverage for `std:` resolution, tamper rejection and frozen-binary hash equality. +- P2 closure gate: add a pure no-Foreign/no-Plugin lane for C01–C06/C11/C12 + (20 fixtures + stdlib table), source shortcut scan and golden comparison. - CM-A08 GFM rendering: `stdlib/data/table.mq.md::转GFM` renders a logical Table as a GFM pipe table with cell escaping; CLI test added. - P5 HTTP parser fixture (C10): semantic fixture 71 parses HTTP/1.1 status, diff --git a/crates/cli/tests/p2_closure.rs b/crates/cli/tests/p2_closure.rs new file mode 100644 index 0000000..66c4010 --- /dev/null +++ b/crates/cli/tests/p2_closure.rs @@ -0,0 +1,123 @@ +//! RFC-CM P2 closure lane: C01–C06/C11/C12 in a pure, no-Foreign/no-Plugin host. + +use std::path::{Path, PathBuf}; +use std::process::Command; + +fn repo_root() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .parent() + .unwrap() + .parent() + .unwrap() + .to_path_buf() +} + +fn fixture(name: &str) -> PathBuf { + repo_root() + .join("tests") + .join("conformance") + .join("semantics") + .join(name) +} + +fn expected(name: &str) -> serde_json::Value { + let path = fixture(&name.replace(".mq.md", ".expected.json")); + serde_json::from_slice(&std::fs::read(&path).expect("expected golden")).expect("golden json") +} + +#[test] +fn p2_algorithms_run_in_a_pure_no_foreign_no_plugin_host() { + // P2 gate (RFC-CM-0002 §8): C01-C06, C11, C12 use only .mq.md plus the + // declared low-level primitives. These fixtures are run through the real + // CLI in `--mode pure`, which has no foreign/plugin grants, and the source + // is checked for host shortcuts that would violate the anti-evasion rule. + let cases: &[(&str, &str)] = &[ + ("48-memory-bump-allocator.mq.md", "C01 bump allocator"), + ( + "50-memory-allocation-failure-atomic.mq.md", + "C01 allocation atomicity", + ), + ( + "55-first-fit-free-list-allocator.mq.md", + "C01 free-list split/coalesce", + ), + ("49-memory-linked-list.mq.md", "C02 linked list"), + ("56-memory-binary-tree.mq.md", "C02 tree"), + ("61-memory-graph-adjacency.mq.md", "C02 graph"), + ("58-memory-hash-table.mq.md", "C02 hash table"), + ("64-memory-integer-codecs.mq.md", "C03 codecs"), + ("59-utf8-encoder.mq.md", "C04 UTF-8 encode"), + ("60-utf8-decoder.mq.md", "C04 UTF-8 decode"), + ("57-csv-row-splitter.mq.md", "C05 CSV"), + ("62-json-array-parser.mq.md", "C05 JSON"), + ("68-csv-quoted-row.mq.md", "C05 CSV quoted"), + ("53-table-projection.mq.md", "C06 table projection"), + ("54-table-filter-stdlib.mq.md", "C06 table filter"), + ("65-table-sort-stdlib.mq.md", "C06 table sort"), + ("67-table-join-stdlib.mq.md", "C06 table join"), + ("69-table-group-stdlib.mq.md", "C06 table group"), + ("63-memory-bytecode-vm.mq.md", "C11 bytecode VM"), + ("70-matrix-multiply.mq.md", "C12 matrix"), + ]; + for (name, criterion) in cases { + let path = fixture(name); + let source = std::fs::read_to_string(&path).expect("fixture source"); + for forbidden in ["foreign.", "plugin.", "import:"] { + assert!( + !source.contains(forbidden), + "{criterion} fixture {name} uses forbidden host shortcut `{forbidden}`" + ); + } + let output = Command::new(env!("CARGO_BIN_EXE_marqdo")) + .args(["run", path.to_str().unwrap(), "--mode", "pure", "--json"]) + .current_dir(repo_root()) + .output() + .expect("run marqdo"); + assert_eq!( + output.status.code(), + Some(0), + "{criterion} fixture {name} failed in pure mode: {}", + String::from_utf8_lossy(&output.stderr) + ); + let report: serde_json::Value = + serde_json::from_slice(&output.stdout).expect("json report"); + assert_eq!(report["success"], true, "{name}"); + let golden = expected(name); + assert_eq!( + report["value"], golden["value"], + "{criterion} fixture {name}" + ); + assert_eq!( + report["stdout"].as_str().unwrap_or_default(), + golden["stdout"].as_str().unwrap_or_default(), + "{criterion} fixture {name} stdout" + ); + } +} + +#[test] +fn p2_stdlib_table_also_runs_in_pure_mode() { + let path = repo_root().join("stdlib").join("tests").join("table.mq.md"); + let output = Command::new(env!("CARGO_BIN_EXE_marqdo")) + .args(["run", path.to_str().unwrap(), "--mode", "pure", "--json"]) + .current_dir(repo_root().join("stdlib")) + .env("MARQDO_STDLIB_DIR", repo_root().join("stdlib")) + .output() + .expect("run table self-test"); + assert_eq!( + output.status.code(), + Some(0), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json"); + assert_eq!(report["success"], true); + let items = report["value"]["items"] + .as_array() + .expect("table test list"); + assert_eq!(items.len(), 9); + assert_eq!( + items[8]["value"], + "| 名称 | 分数 |\n| --- | --- |\n| 甲 | 87 |\n| 乙 | 92 |\n| 丙 | 71 |" + ); +} diff --git a/docs/STATUS.md b/docs/STATUS.md index 21f4d04..961f0c5 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -197,7 +197,7 @@ behavior. This table records only what is in this tree now. |---|---|---| | P0 freeze (ADRs, spec deltas, baseline) | **P1 + partial P2 slice done** | ADR-0022 freezes CM-A01/CM-A02/CM-A03; ADR-0023 freezes CM-A04 (minimal List/Map/Text/Table observation and construction); ADR-0024 freezes CM-A05 (recoverable `Result` map convention); `spec/expression.ebnf`, `spec/evaluation.md`, `spec/value-wire.md`, `spec/analysis-v2.md`, `spec/security.md` updated; existing AST/value goldens unchanged | | P1 Memory + place assignment | **Implemented locally** | `Value::Memory`, run-scoped `MemoryStore` (64 KiB pages, 64 MiB total / 16 MiB region), `memory.new/size/grow`, `m[i]` read, `m[i] = byte`; semantic fixtures 45–47, runtime negatives 13–18, `examples/memory-buffer.mq.md`; evidence [`evidence/2026-11-20-memory-p1.md`](evidence/2026-11-20-memory-p1.md) | -| P2 Marqdo-written allocator/data structures + minimal structure observation | **PARTIAL, gate NOT passed** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), a quoted/escaped CSV row parser (68), table group (69), and an Int matrix multiply (70); the first-fit allocator also detects double free (`alloc.double_free`). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). P2 remaining: publication as a separate external stdlib repository. The bundled `stdlib/` tree, `std:` imports, digest verification, Analysis identity and frozen-CLI closure test are implemented (ADR-0028). C01–C06/C11/C12 each have `.mq.md` evidence, including JSON floats and a JSON formatter. | +| P2 Marqdo-written allocator/data structures + minimal structure observation | **PASS (local pure lane); external stdlib repo publication pending** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), a quoted/escaped CSV row parser (68), table group (69), and an Int matrix multiply (70); the first-fit allocator also detects double free (`alloc.double_free`). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). Local gate PASS: `crates/cli/tests/p2_closure.rs` runs 20 C01–C06/C11/C12 fixtures plus the stdlib table self-test in `--mode pure` (no foreign/plugin/import grants), scans sources for foreign/plugin/import shortcuts and compares value/stdout to goldens; evidence [`p2-closure-gate`](evidence/2026-11-20-p2-closure-gate.md). The bundled `stdlib/` tree, `std:` imports, digest verification, Analysis identity and frozen-CLI closure test are implemented (ADR-0028). Remaining outside C01–C12: publication as a separate external stdlib repository, and no remote CI URL. | | P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict permits only stdio/stdout and refuses file/network resources. Fixture 66 + CLI/host tests. CM-A07 **Compat-C** is implemented: when a program calls `打印/print`, the loader injects the bundled `stdlib/io.mq.md` and the runtime routes to `io.写值` (all 15 value types, UTF-8 via `Memory`, `resource.write(stdout)`); `HostOp::Print` and the legacy `Value::display()` print path are removed, and a missing bundle fails with `kernel.unavailable`. Strict permits only the existing stdio console channel. Still missing: directories, network, generic provider registry, Table storage, strict file/network resources. | | P4 Table logical/physical migration | **PARTIAL** | ADR-0032/CM-A08: `Value::Table` logical semantics unchanged (T0 `Vec>`); `stdlib/data/table.mq.md` provides select/filter/sort/append/set/join/group/`转GFM` as value-returning `.mq.md` functions with input immutability. GFM rendering is covered; no T1/T2/T3 physical storage, column store, cross-storage implementation or Memory-backed table. | | P5 third-party Provider / TCP / HTTP | **PARTIAL** | semantic fixture 71 implements HTTP/1.1 response parsing (status/headers/chunked) and request construction in `.mq.md`; no host HTTP/TLS. ADR-0034 blocking TCP resource endpoint (`resource.open("tcp", ":", ["read","write"])`, exact IP grant, project-only, 5s timeouts; loopback host+CLI tests). ADR-0033 in-process `ResourceProvider` v1: explicitly trusted providers register by kind, project-mode only, gated by `Capabilities.allow_resource_provider`, using the existing `resource.*`/`Result` ABI; a mock read/write provider is tested. No C/Worker provider transport, host DNS/TLS/HTTP implementation, UDP, clock/random/process/device providers, or provider package installation. | @@ -244,6 +244,9 @@ user-written allocator is explicitly **not** claimed. - [`evidence/2026-11-20-tcp-endpoint.md`](evidence/2026-11-20-tcp-endpoint.md) — ADR-0034 blocking TCP endpoint, IP grants, DNS refusal, loopback host/CLI echo tests. +- [`evidence/2026-11-20-p2-closure-gate.md`](evidence/2026-11-20-p2-closure-gate.md) + — P2 C01–C06/C11/C12 pure no-Foreign/no-Plugin closure lane and golden + comparison. - [`evidence/2026-11-20-http-parser.md`](evidence/2026-11-20-http-parser.md) — P5/C10 `.mq.md` HTTP/1.1 status/header/chunked response parser and request builder fixture. diff --git a/docs/evidence/2026-11-20-p2-closure-gate.md b/docs/evidence/2026-11-20-p2-closure-gate.md new file mode 100644 index 0000000..b9af7f6 --- /dev/null +++ b/docs/evidence/2026-11-20-p2-closure-gate.md @@ -0,0 +1,59 @@ +# RFC-CM P2 closure gate evidence (C01–C06, C11, C12) + +Date: 2026-11-20 (Asia/Shanghai) +Repository: `marqdo-cli` +Baseline: `d6cd785` plus this step's changes. +Related: [memory P2](2026-11-20-memory-p2-closure.md), +[structure API](2026-11-20-structure-api-p2.md), +[result/free-list](2026-11-20-result-and-free-list-p2.md), +[ADRs 0022–0024](../adr/). +Scope: pure no-Foreign/no-Plugin execution lane; external stdlib repository +publication remains separate. + +## Lane + +`crates/cli/tests/p2_closure.rs` runs 20 checked-in semantic fixtures through +the real CLI with `run --mode pure --json`: + +* `--mode pure` constructs `Capabilities::pure()`; no foreign, plugin, read, + write, network or provider grant exists in that host; +* each fixture source is scanned for `foreign.`, `plugin.` and `import:`; all + three must be absent (anti-evasion rule for C01–C06/C11/C12); +* the CLI value and stdout are compared byte-for-byte with the fixture's + `.expected.json` golden; +* `stdlib/tests/table.mq.md` also runs in pure mode with `std:` imports and + checks the nine table results including `转GFM`. + +The independently-run conformance harness (`conformance_semantics.rs`) also +builds `StdHost` with `SandboxMode::Pure` and `Capabilities::pure()` for every +fixture. + +## Criterion mapping + +| Criterion | Fixtures | What is proven | +|---|---|---| +| C01 allocators | 48, 50, 55 | bump allocator, failed-allocation atomicity, first-fit split/coalesce/double-free | +| C02 structures | 49, 56, 58, 61 | linked list, binary tree, open-addressing hash table, graph adjacency | +| C03 codecs | 48, 64 | u32, big-endian 16/32/64, LEB128 | +| C04 Unicode/text | 59, 60 | UTF-8 encode and validating decoder errors | +| C05 JSON/CSV | 57, 62, 68 | CSV split/quoting, recursive JSON parse/format/errors | +| C06 GFM Table | 53, 54, 65, 67, 69 + stdlib table | projection/filter/sort/join/group/GFM render, no Rust table algorithm | +| C11 VM | 63 | Memory-backed stack bytecode VM | +| C12 scientific prep | 70 | Int matrix multiply with exact indexing | + +No fixture compiles Rust, imports a package, invokes a foreign kernel or calls a +plugin. Dynamic arrays are built at runtime; no fixed-length source rewrite is +required. + +## Gate + +Local container: `cargo test -p marqdo-cli --test p2_closure` PASS; full +`cargo test --workspace --locked` PASS. The existing frozen-binary test covers +the fixed CLI hash and stdlib tamper rejection (ADR-0028). + +## Remaining (not a C01–C12 gap) + +* Publication of `marqdo-stdlib` as a separate external repository with a + signed version mapping; the bundled tree, digest and offline layout are + already tested in-repo. +* No GitHub CI URL / Windows/macOS lanes from this host. diff --git a/tests/README.md b/tests/README.md index 28585e0..786ece3 100644 --- a/tests/README.md +++ b/tests/README.md @@ -184,6 +184,12 @@ and read/written through `resource.*` with a project-mode name grant; missing grant, pure/strict, bad protocol version, reserved kinds and duplicate kinds are rejected. +RFC-CM P2 closure (C01–C06, C11, C12) is pinned by +`crates/cli/tests/p2_closure.rs`: 20 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. + 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 checks select/filter/sort/append/set/join/group results plus original-table