Files
marqdo-cli/crates/cli/tests/p2_closure.rs
T
cflmy 72f57beee0
ci/woodpecker/push/main Pipeline failed
ci/woodpecker/pr/main Pipeline failed
refactor: accept the ecosystem stdlib Bundle and remove the in-repo sources
Phase B of ADR-0070 (issue #11): the CLI no longer owns standard-library
sources. The pin names the accepted ecosystem Bundle (marqdo-stdlib@0.2.0,
root commit + tree/alias digests); tools/ci/fetch_ecosystem_bundle.py
materializes it from the pinned root commit and stdlib gitlinks and verifies
the digests. bundle.py and the test harness require an explicit verified Bundle
for the accepted identity, and runtime discovery has no compile-time source
fallback in any profile.

Delete stdlib/ (modules, self-tests, aliases manifest). Module and domain tests
stay with their component owners; the CLI product lane now verifies the
external Bundle's public surface, std: resolution and official print/打印 alias
routing (tests/product-stdlib). Composition assertions whose owner is the
ecosystem (Table split, print-format equivalence) moved to the root Bundle
acceptance; the generic TCP round-trip stays a CLI test. Spawned-CLI tests name
the verified Bundle explicitly.

CI (Woodpecker + GitHub) materializes the pinned Bundle before product tests,
packaging and performance lanes; packaging and release take --stdlib-dir from
that artifact. Docs, STATUS, ADR-0070 and a Phase B evidence record updated.

Refs cflmy/marqdo#9, cflmy/marqdo-cli#11
2026-11-27 01:04:01 +08:00

162 lines
5.5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! RFC-CM P2 closure lane: C01–C06/C11/C12 in a pure, no-Foreign/no-Plugin host.
#[path = "support/stdlib.rs"]
pub mod stdlib_support;
#[path = "support/observation.rs"]
pub mod observation;
use std::path::{Path, PathBuf};
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"),
("73-sparse-matrix.mq.md", "C12 sparse 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 = stdlib_support::cli_command()
.args([
"run",
path.to_str().unwrap(),
"--mode",
"pure",
"--output",
"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["run"]["status"], "ok", "{name}");
let golden = expected(name);
assert_eq!(
observation::terminal(&report)["value"],
golden["value"],
"{criterion} fixture {name}"
);
assert_eq!(
observation::text(&report, "stdout.chunk"),
golden["stdout"].as_str().unwrap_or_default(),
"{criterion} fixture {name} stdout"
);
}
}
#[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,
"## @knowledge 代码\n\n```python\nprint(1)\n```\n\n## @exec main\n\n`return foreign.call(ref(\"#代码\"), None)`\n",
)
.unwrap();
let output = stdlib_support::cli_command()
.args([
"run",
foreign.to_str().unwrap(),
"--mode",
"pure",
"--output",
"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_ne!(report["run"]["status"], "ok");
assert_eq!(
observation::terminal(&report)["error"]["code"],
"permission.denied"
);
let plugin = dir.path().join("plugin.mq.md");
std::fs::write(
&plugin,
"## @exec main\n\n`plugin.invoke(\"missing.export\", {})`\n\n`return None`\n",
)
.unwrap();
let output = stdlib_support::cli_command()
.args([
"run",
plugin.to_str().unwrap(),
"--mode",
"pure",
"--output",
"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_ne!(report["run"]["status"], "ok");
}