fix: close release-gate defects in platform cfg, strict launch, and semantics
WHY - macOS/Windows failed to compile because `cfg!` left `linux::probe()` in the type-checked branch (E0433). - GitHub-hosted Linux can pass the strict probe and then fail the real launch with EAGAIN; the CLI test treated the inspect snapshot as a permanent promise. - The security matrix shared process-id-based scratch paths, so parallel `cargo test --workspace` made its own tests clobber each other. - Condition paragraphs silently ignored executable `Strong`/`Emph`, and condition parse spans included the code-span backticks. - The corpus had no native power/control-flow/inert fixtures and no independent generic Tool consumers. WHAT - Dispatch strict detection through `#[cfg]` functions; add a non-Linux compile/fail-closed regression test. - Split `linux::run` into an injectable probe/spawn seam; test probe-OK -> launch-EAGAIN returns LaunchFailed and never executes unrestricted. - Make the Linux CLI contract accept only (a) successful isolated run or (b) non-zero, diagnosed, fail-closed refusal with no project stdout. - Give each security test a unique project/outside path and compile the helper once. - Reject executable roles in a condition paragraph; map condition expressions from the literal bytes inside the backticks. - Add 10 AST, 8 semantic, 4 compile-negative and 2 runtime-negative fixtures for power, branch/loop conditions, source spans, inert prose/code fences and error boundaries. - Add `sample-view`/`sample-knowledge`/`sample-proof` independent Tool v1 packages and an end-to-end Analysis/Trace consumer test. - Add a locked path-dependency content-tamper test. TESTS - cargo fmt --all -- --check - cargo clippy --workspace --all-targets -- -D warnings - cargo test --workspace --locked - G-C VM lane (separate evidence commit/run) CI_URL - none from this host: the checkout has a Gitee remote and no GitHub credentials. Windows/macOS CI remains UNVERIFIED. BREAKING_CHANGE - An executable node in a list-item condition paragraph is now a hard `markdown.invalid_construct` error instead of being silently ignored. SECURITY_SCOPE - strict remains fail-closed; no downgrade, no new capability, L2 still rejected. G-C still requires the dedicated self-hosted lane for CI-signed evidence.
This commit is contained in:
1 parent
c9f01aa8fb
commit
d05f36fd26
65 files changed
+2134
-87
No files matched your search
@@ -350,21 +350,77 @@ fn strict_mode_enforces_isolation_or_refuses_closed() {
|
||||
let hello = root.join("examples").join("hello.mq.md");
|
||||
let output = cli(&root, &["run", hello.to_str().unwrap(), "--mode", "strict"]);
|
||||
if strict_is_available(&root) {
|
||||
assert_exit(&output, 0, "strict mode must succeed when the gate passes");
|
||||
assert_eq!(stdout_text(&output), "你好,Marqdo\n");
|
||||
// External execution surfaces are rejected at the strict L1 boundary.
|
||||
let foreign = cli(
|
||||
&root,
|
||||
&[
|
||||
"run",
|
||||
hello.to_str().unwrap(),
|
||||
"--mode",
|
||||
"strict",
|
||||
"--allow-foreign",
|
||||
],
|
||||
if output.status.success() {
|
||||
assert_eq!(stdout_text(&output), "你好,Marqdo\n");
|
||||
// External execution surfaces are rejected at the strict L1 boundary.
|
||||
let foreign = cli(
|
||||
&root,
|
||||
&[
|
||||
"run",
|
||||
hello.to_str().unwrap(),
|
||||
"--mode",
|
||||
"strict",
|
||||
"--allow-foreign",
|
||||
],
|
||||
);
|
||||
assert_exit(&foreign, 2, "strict must reject foreign grants");
|
||||
assert!(stderr_text(&foreign).contains("strict mode currently supports"));
|
||||
return;
|
||||
}
|
||||
|
||||
// The snapshot from `inspect --platform` is not a permanent promise:
|
||||
// the host can lose namespace capability or resources between the
|
||||
// probe and the real launch. GitHub-hosted runners have produced
|
||||
// `bwrap: Creating new namespace failed: Resource temporarily
|
||||
// unavailable` here. The only acceptable outcome is a fail-closed
|
||||
// refusal: non-zero exit, diagnostic, and no project output.
|
||||
assert_exit(
|
||||
&output,
|
||||
1,
|
||||
"strict launch failure must fail closed, not fall back",
|
||||
);
|
||||
assert_exit(&foreign, 2, "strict must reject foreign grants");
|
||||
assert!(stderr_text(&foreign).contains("strict mode currently supports"));
|
||||
let stderr = stderr_text(&output);
|
||||
assert!(!stderr.is_empty(), "strict failure had no diagnostic");
|
||||
assert!(
|
||||
stderr.contains("strict isolation failed")
|
||||
|| stderr.contains("refusing to run in strict mode")
|
||||
|| stderr.contains("bubblewrap")
|
||||
|| stderr.contains("bwrap"),
|
||||
"strict failure diagnostic does not identify isolation: {stderr}"
|
||||
);
|
||||
assert!(
|
||||
stderr.contains("namespace")
|
||||
|| stderr.contains("Resource temporarily unavailable")
|
||||
|| stderr.contains("os error 11"),
|
||||
"strict failure diagnostic does not identify the launch failure: {stderr}"
|
||||
);
|
||||
assert!(
|
||||
stdout_text(&output).is_empty(),
|
||||
"project output appeared although strict launch failed: {}",
|
||||
stdout_text(&output)
|
||||
);
|
||||
|
||||
let json = cli(
|
||||
&root,
|
||||
&["run", hello.to_str().unwrap(), "--mode", "strict", "--json"],
|
||||
);
|
||||
if json.status.success() {
|
||||
let value = json_stdout(&json);
|
||||
assert_eq!(value["success"], true);
|
||||
assert_eq!(value["value"]["type"], "none");
|
||||
} else {
|
||||
assert_exit(
|
||||
&json,
|
||||
1,
|
||||
"strict launch failure keeps exit code 1 in JSON mode",
|
||||
);
|
||||
let value = json_stdout(&json);
|
||||
assert_eq!(value["success"], false);
|
||||
assert!(value["error"]
|
||||
.as_str()
|
||||
.expect("error string")
|
||||
.contains("strict"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
assert_exit(
|
||||
@@ -989,3 +1045,61 @@ fn check_never_spawns_a_foreign_kernel() {
|
||||
"run did not execute the provider; the no-execution assertion is vacuous"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn power_branch_loop_and_inert_code_end_to_end() {
|
||||
let dir = TempDir::new("power");
|
||||
dir.write(
|
||||
"branch.mq.md",
|
||||
"## main\n\n**n = 2**\n\n1. `n ** 2 == 4`,正确分支。\n\n > print(\"乘方正确\")\n\n2. `n ** 2 != 4`,另一分支。\n\n > print(\"乘方错误\")\n",
|
||||
);
|
||||
let branch = cli(dir.path(), &["run", "branch.mq.md", "--json"]);
|
||||
assert_exit(&branch, 0, "power branch run");
|
||||
let value = json_stdout(&branch);
|
||||
assert_eq!(value["success"], true);
|
||||
assert_eq!(value["stdout"], "乘方正确\n");
|
||||
assert_eq!(value["value"]["type"], "unit");
|
||||
|
||||
dir.write(
|
||||
"loop.mq.md",
|
||||
"## main\n\n**n = 0**\n\n**limit = 100**\n\n- `n ** 2 < limit`\n\n **n = n + 1**\n\n*n*\n",
|
||||
);
|
||||
let looped = cli(dir.path(), &["run", "loop.mq.md", "--json"]);
|
||||
assert_exit(&looped, 0, "power loop run");
|
||||
let value = json_stdout(&looped);
|
||||
assert_eq!(value["value"]["type"], "int");
|
||||
assert_eq!(value["value"]["decimal"], "10");
|
||||
|
||||
// A code fence containing power syntax is an inert value: it produces no
|
||||
// diagnostics and never changes the returned value.
|
||||
dir.write(
|
||||
"inert.mq.md",
|
||||
"## main\n\n```text\n**n = 2 ** 3**\n```\n\n正文里的 `2 ** 3` 不执行。\n\n**x = 1**\n\n*x*\n",
|
||||
);
|
||||
let inert = cli(dir.path(), &["run", "inert.mq.md", "--json"]);
|
||||
assert_exit(&inert, 0, "inert code run");
|
||||
let value = json_stdout(&inert);
|
||||
assert_eq!(value["value"]["decimal"], "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn condition_parse_diagnostic_points_inside_the_code_span() {
|
||||
let dir = TempDir::new("condition-span");
|
||||
let source = "## main\n\n**n = 2**\n\n1. `n ** 2 ==`\n\n > print(1)\n";
|
||||
dir.write("bad.mq.md", source);
|
||||
let output = cli(dir.path(), &["check", "bad.mq.md", "--json"]);
|
||||
assert_exit(&output, 1, "condition parse error");
|
||||
let value = json_stdout(&output);
|
||||
let diagnostic = value["diagnostics"]
|
||||
.as_array()
|
||||
.expect("diagnostics array")
|
||||
.iter()
|
||||
.find(|diagnostic| diagnostic["code"] == "expr.parse")
|
||||
.expect("expr.parse diagnostic");
|
||||
assert_eq!(diagnostic["line"], 5);
|
||||
// 1-based column 14 is the closing backtick: the empty end-of-input span
|
||||
// must not be shifted by the delimiter.
|
||||
assert_eq!(diagnostic["column"], 14);
|
||||
let line = source.lines().nth(4).expect("line 5");
|
||||
assert_eq!(&line[13..14], "`");
|
||||
}
|
||||
@@ -349,3 +349,61 @@ fn deleted_lock_edge_fails_check_and_run() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tampered_path_dependency_content_is_rejected_by_locked_sync() {
|
||||
let dir = TempDir::new("path-tamper");
|
||||
let root = dir.path();
|
||||
write(
|
||||
&root.join("marqdo.yaml"),
|
||||
"project:\n name: root\n version: 0.1.0\ndependencies:\n dep:\n path: ./dep\n",
|
||||
);
|
||||
write(
|
||||
&root.join("dep/marqdo.yaml"),
|
||||
"project:\n name: dep\n version: 0.1.0\n",
|
||||
);
|
||||
write(&root.join("dep/index.mq.md"), "## value\n\n*1*\n");
|
||||
write(
|
||||
&root.join("index.mq.md"),
|
||||
"---\nimport:\n dep: \"@dep\"\n---\n\n## main\n\n*1*\n",
|
||||
);
|
||||
assert_eq!(cli(root, &["lock"]).status.code(), Some(0));
|
||||
let lock_before = std::fs::read(root.join("marqdo.lock")).unwrap();
|
||||
assert_eq!(cli(root, &["sync", "--locked"]).status.code(), Some(0));
|
||||
let env_before = std::fs::read(root.join(".marqdo/env/env.json")).unwrap();
|
||||
|
||||
// Content change after the lock is a tamper/staleness signal. `run` and
|
||||
// `check` must never silently accept it, re-lock, or materialize a new
|
||||
// environment.
|
||||
write(&root.join("dep/index.mq.md"), "## value\n\n*2*\n");
|
||||
for args in [
|
||||
vec!["sync", "--locked"],
|
||||
vec!["run", "index.mq.md"],
|
||||
vec!["check", "index.mq.md"],
|
||||
] {
|
||||
let output = cli(root, &args);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(1),
|
||||
"{args:?}: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(
|
||||
stderr.contains("out of date")
|
||||
|| stderr.contains("digest")
|
||||
|| stderr.contains("integrity"),
|
||||
"{args:?}: {stderr}"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
std::fs::read(root.join("marqdo.lock")).unwrap(),
|
||||
lock_before,
|
||||
"a failed locked operation must not rewrite the lock"
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read(root.join(".marqdo/env/env.json")).unwrap(),
|
||||
env_before,
|
||||
"a failed locked operation must not replace the materialized environment"
|
||||
);
|
||||
}
|
||||
@@ -110,6 +110,134 @@ fn stdout(output: &Output) -> String {
|
||||
String::from_utf8_lossy(&output.stdout).to_string()
|
||||
}
|
||||
|
||||
fn repo_root() -> PathBuf {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.expect("crates/cli has a parent")
|
||||
.parent()
|
||||
.expect("crates has a parent")
|
||||
.to_path_buf()
|
||||
}
|
||||
|
||||
/// Compile one of the checked-in independent consumer samples and package it
|
||||
/// as a Tool Protocol v1 bundle. Sources live in `examples/tool-samples/` so
|
||||
/// they are reviewable software, not hidden test strings.
|
||||
fn write_sample_from_source(dir: &Path, command: &str) -> PathBuf {
|
||||
let root = repo_root();
|
||||
let source = root.join(format!("examples/tool-samples/{command}/src/main.rs"));
|
||||
let package = dir.join(format!("{command}-pkg"));
|
||||
std::fs::create_dir_all(package.join("bin")).unwrap();
|
||||
let entry = package
|
||||
.join("bin")
|
||||
.join(format!("{command}{}", std::env::consts::EXE_SUFFIX));
|
||||
let status = Command::new("rustc")
|
||||
.args(["--edition", "2021", "-o"])
|
||||
.arg(&entry)
|
||||
.arg(&source)
|
||||
.status()
|
||||
.expect("run rustc for the sample tool");
|
||||
assert!(status.success(), "rustc failed for {command}");
|
||||
let entrypoint = format!("bin/{command}{}", std::env::consts::EXE_SUFFIX);
|
||||
let manifest = package.join("tool.json");
|
||||
std::fs::write(
|
||||
&manifest,
|
||||
format!(
|
||||
r#"{{"schema":"marqdo.cli-tool","schema_version":1,"name":"demo.{command}","version":"0.1.0","command":"{command}","entrypoint":"{entrypoint}","compatibility":{{"marqdo":">=0.1,<1","analysis":[2],"trace":[2]}}}}"#
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
manifest
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn independent_sample_tools_consume_public_analysis_and_trace() {
|
||||
let dir = TempDir::new("samples");
|
||||
let home = dir.path().join("home");
|
||||
let analysis = dir.path().join("analysis.json");
|
||||
let trace = dir.path().join("trace.json");
|
||||
let root = repo_root();
|
||||
|
||||
let check = Command::new(binary())
|
||||
.args([
|
||||
"check",
|
||||
"examples/multi-module/index.mq.md",
|
||||
"--refs",
|
||||
"--emit",
|
||||
])
|
||||
.arg(&analysis)
|
||||
.current_dir(&root)
|
||||
.output()
|
||||
.expect("run check");
|
||||
assert!(check.status.success(), "check failed: {}", stderr(&check));
|
||||
let run = Command::new(binary())
|
||||
.args(["run", "examples/multi-module/index.mq.md", "--trace-file"])
|
||||
.arg(&trace)
|
||||
.current_dir(&root)
|
||||
.output()
|
||||
.expect("run");
|
||||
assert!(run.status.success(), "run failed: {}", stderr(&run));
|
||||
|
||||
// None of these names exists in the CLI: dispatch must come from the
|
||||
// installed generic tool registry.
|
||||
for command in ["sample-view", "sample-knowledge", "sample-proof"] {
|
||||
let unknown = cli(&home, &[command]);
|
||||
assert_eq!(unknown.status.code(), Some(2), "{command} must be unknown");
|
||||
assert!(stderr(&unknown).contains("unknown command"));
|
||||
let manifest = write_sample_from_source(dir.path(), command);
|
||||
let install = cli(&home, &["tool", "install", manifest.to_str().unwrap()]);
|
||||
assert_eq!(
|
||||
install.status.code(),
|
||||
Some(0),
|
||||
"{command}: {}",
|
||||
stderr(&install)
|
||||
);
|
||||
}
|
||||
|
||||
let view = cli(
|
||||
&home,
|
||||
&["sample-view", "--analysis", analysis.to_str().unwrap()],
|
||||
);
|
||||
assert_eq!(view.status.code(), Some(0), "{}", stderr(&view));
|
||||
let text = stdout(&view);
|
||||
assert!(
|
||||
text.contains("sample-view schema=marqdo.analysis version=2"),
|
||||
"{text}"
|
||||
);
|
||||
assert!(text.contains("modules="), "{text}");
|
||||
|
||||
let knowledge = cli(
|
||||
&home,
|
||||
&["sample-knowledge", "--trace", trace.to_str().unwrap()],
|
||||
);
|
||||
assert_eq!(knowledge.status.code(), Some(0), "{}", stderr(&knowledge));
|
||||
let text = stdout(&knowledge);
|
||||
assert!(
|
||||
text.contains("sample-knowledge schema=marqdo.trace version=2"),
|
||||
"{text}"
|
||||
);
|
||||
assert!(text.contains("status=ok"), "{text}");
|
||||
|
||||
let proof = cli(
|
||||
&home,
|
||||
&[
|
||||
"sample-proof",
|
||||
"--analysis",
|
||||
analysis.to_str().unwrap(),
|
||||
"--trace",
|
||||
trace.to_str().unwrap(),
|
||||
],
|
||||
);
|
||||
assert_eq!(proof.status.code(), Some(0), "{}", stderr(&proof));
|
||||
let text = stdout(&proof);
|
||||
assert!(text.contains("sample-proof bound=true"), "{text}");
|
||||
assert!(text.contains("digest=sha256:"), "{text}");
|
||||
|
||||
for command in ["sample-view", "sample-knowledge", "sample-proof"] {
|
||||
let removed = cli(&home, &["tool", "remove", command]);
|
||||
assert_eq!(removed.status.code(), Some(0), "{}", stderr(&removed));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn install_dispatch_list_remove_without_core_knowledge_of_the_name() {
|
||||
let dir = TempDir::new("roundtrip");
|
||||
|
||||
Reference in new issue
Block a user