observation: deliver one execution event sequence to stream and snapshot
This commit is contained in:
1 parent
f83d992c61
commit
404d559b86
97 files changed
+2672
-3128
No files matched your search
@@ -1,5 +1,8 @@
|
||||
//! Public Analysis and Trace black-box contracts (spec/analysis.md,
|
||||
//! spec/trace-v1.md).
|
||||
//! Public Analysis and Observation black-box contracts (spec/analysis.md,
|
||||
//! spec/observation.md).
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Output};
|
||||
@@ -271,7 +274,7 @@ print(1)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trace_v2_budget_truncates_long_loops_without_failing_the_run() {
|
||||
fn snapshot_budget_truncates_long_loops_without_failing_the_run() {
|
||||
let dir = TempDir::new("trace-budget");
|
||||
write(
|
||||
dir.path(),
|
||||
@@ -284,9 +287,9 @@ fn trace_v2_budget_truncates_long_loops_without_failing_the_run() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--trace-file",
|
||||
"--observation-file",
|
||||
trace_path.to_str().unwrap(),
|
||||
"--trace-max-events",
|
||||
"--observe-max-events",
|
||||
"20",
|
||||
],
|
||||
);
|
||||
@@ -298,14 +301,18 @@ fn trace_v2_budget_truncates_long_loops_without_failing_the_run() {
|
||||
);
|
||||
let trace: serde_json::Value =
|
||||
serde_json::from_slice(&std::fs::read(&trace_path).unwrap()).unwrap();
|
||||
assert_eq!(trace["schema_version"], 2);
|
||||
assert_eq!(trace["schema_version"], 1);
|
||||
assert_eq!(trace["run"]["status"], "ok");
|
||||
assert_eq!(trace["limits"]["max_events"], 20);
|
||||
assert_eq!(trace["truncated"]["reason"], "event_budget");
|
||||
assert_eq!(trace["truncated"]["limit"], 20);
|
||||
assert_eq!(
|
||||
trace["events"][0]["payload"]["limits"]["max_observation_events"],
|
||||
20
|
||||
);
|
||||
assert_eq!(trace["capture"]["truncated"]["reason"], "event_budget");
|
||||
assert_eq!(trace["capture"]["truncated"]["limit"], 20);
|
||||
let events = trace["events"].as_array().unwrap();
|
||||
assert!(events.len() <= 21, "events: {}", events.len());
|
||||
assert_eq!(events.last().unwrap()["kind"], "trace.truncated");
|
||||
assert_eq!(events.len(), 24);
|
||||
assert_eq!(events[22]["kind"], "observation.truncated");
|
||||
assert_eq!(events[23]["kind"], "run.completed");
|
||||
let mut previous = None;
|
||||
for event in events {
|
||||
let seq = event["seq"].as_u64().unwrap();
|
||||
@@ -331,7 +338,7 @@ fn failed_check_removes_stale_analysis() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trace_records_calls_effects_and_status_without_secrets() {
|
||||
fn snapshot_records_calls_effects_and_status_without_secrets() {
|
||||
let dir = TempDir::new("trace");
|
||||
write(dir.path(), "index.mq.md", PROGRAM);
|
||||
let trace_path = dir.path().join("trace.json");
|
||||
@@ -340,7 +347,7 @@ fn trace_records_calls_effects_and_status_without_secrets() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--trace-file",
|
||||
"--observation-file",
|
||||
trace_path.to_str().unwrap(),
|
||||
],
|
||||
);
|
||||
@@ -356,15 +363,16 @@ fn trace_records_calls_effects_and_status_without_secrets() {
|
||||
"values must not be recorded"
|
||||
);
|
||||
let trace: serde_json::Value = serde_json::from_str(&text).unwrap();
|
||||
assert_eq!(trace["schema"], "marqdo.trace");
|
||||
assert_eq!(trace["schema_version"], 2);
|
||||
assert_eq!(trace["schema"], "marqdo.observation");
|
||||
assert_eq!(trace["schema_version"], 1);
|
||||
assert_eq!(trace["run"]["status"], "ok");
|
||||
assert_eq!(trace["run"]["entry"], "root:default::index.mq.md::main");
|
||||
assert_eq!(
|
||||
trace["events"][1]["payload"]["entry"],
|
||||
"root:default::index.mq.md::main"
|
||||
);
|
||||
let events = trace["events"].as_array().unwrap();
|
||||
assert!(events
|
||||
.iter()
|
||||
.any(|event| event["kind"] == "call.enter"
|
||||
&& event["module_id"] == "root:default::index.mq.md"));
|
||||
assert!(events.iter().any(|event| event["kind"] == "call.enter"
|
||||
&& event["payload"]["module_id"] == "root:default::index.mq.md"));
|
||||
assert!(events.iter().any(|event| event["kind"] == "effect"));
|
||||
assert!(events.iter().any(|event| event["kind"] == "call.exit"));
|
||||
let mut previous = None;
|
||||
@@ -384,14 +392,18 @@ fn trace_records_calls_effects_and_status_without_secrets() {
|
||||
&[
|
||||
"run",
|
||||
"bad.mq.md",
|
||||
"--trace-file",
|
||||
"--observation-file",
|
||||
error_trace.to_str().unwrap(),
|
||||
],
|
||||
);
|
||||
assert_eq!(output.status.code(), Some(1));
|
||||
let trace: serde_json::Value =
|
||||
serde_json::from_slice(&std::fs::read(&error_trace).unwrap()).unwrap();
|
||||
assert_eq!(trace["run"]["status"], "runtime.division_by_zero");
|
||||
assert_eq!(trace["run"]["status"], "error");
|
||||
assert_eq!(
|
||||
trace["events"].as_array().unwrap().last().unwrap()["payload"]["error"]["code"],
|
||||
"runtime.division_by_zero"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -453,12 +465,13 @@ fn multi_arm_branch_preserves_analysis_and_carrier_positions() {
|
||||
"分类",
|
||||
"--arg",
|
||||
&format!("数值={input}"),
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert!(output.status.success(), "{output:?}");
|
||||
let result: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
|
||||
assert_eq!(result["value"]["decimal"], expected);
|
||||
assert_eq!(observation::terminal(&result)["value"]["decimal"], expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
//! point is to prove that `check` and `run` share one static resolution and
|
||||
//! that the runtime never guesses a plugin from a dotted string prefix.
|
||||
#![cfg(unix)]
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Output};
|
||||
@@ -187,11 +189,11 @@ fn renamed_import_alias_binds_the_module_function() {
|
||||
);
|
||||
let check = cli(&["check", "index.mq.md"], dir.path());
|
||||
assert_eq!(check.status.code(), Some(0), "{}", stderr(&check));
|
||||
let run = cli(&["run", "index.mq.md", "--json"], dir.path());
|
||||
let run = cli(&["run", "index.mq.md", "--output", "json"], dir.path());
|
||||
assert_eq!(run.status.code(), Some(0), "{}", stderr(&run));
|
||||
let json: serde_json::Value = serde_json::from_str(&stdout(&run)).unwrap();
|
||||
assert_eq!(
|
||||
json["value"],
|
||||
observation::terminal(&json)["value"],
|
||||
serde_json::json!({"type": "int", "decimal": "101"})
|
||||
);
|
||||
}
|
||||
@@ -482,11 +484,14 @@ fn local_function_reference_is_a_dynamic_language_call() {
|
||||
&dir.path().join("index.mq.md"),
|
||||
"## @exec 平方\n\n`params(n: Int)`\n\n`return n * n`\n\n## @exec 主\n\n`f = ref(\"#平方\")`\n\n`return f(n=4)`\n",
|
||||
);
|
||||
let run = cli(&["call", "index.mq.md", "主", "--json"], dir.path());
|
||||
let run = cli(
|
||||
&["call", "index.mq.md", "主", "--output", "json"],
|
||||
dir.path(),
|
||||
);
|
||||
assert_eq!(run.status.code(), Some(0), "{}", stderr(&run));
|
||||
let json: serde_json::Value = serde_json::from_str(&stdout(&run)).unwrap();
|
||||
assert_eq!(
|
||||
json["value"],
|
||||
observation::terminal(&json)["value"],
|
||||
serde_json::json!({"type": "int", "decimal": "16"})
|
||||
);
|
||||
}
|
||||
@@ -526,11 +531,11 @@ fn explicit_import_aliases_bind_same_named_functions_independently() {
|
||||
&dir.path().join("index.mq.md"),
|
||||
"---\nimport:\n aa: \"./a.mq.md\"\n bb: \"./b.mq.md\"\n---\n\n## @exec main\n\n`return aa.value() + bb.value()`\n",
|
||||
);
|
||||
let run = cli(&["run", "index.mq.md", "--json"], dir.path());
|
||||
let run = cli(&["run", "index.mq.md", "--output", "json"], dir.path());
|
||||
assert_eq!(run.status.code(), Some(0), "{}", stderr(&run));
|
||||
let json: serde_json::Value = serde_json::from_str(&stdout(&run)).unwrap();
|
||||
assert_eq!(
|
||||
json["value"],
|
||||
observation::terminal(&json)["value"],
|
||||
serde_json::json!({"type": "int", "decimal": "30"})
|
||||
);
|
||||
}
|
||||
@@ -632,7 +637,6 @@ fn check_emit_and_run_share_the_same_static_binding_source() {
|
||||
plugin_dir.path().to_str().unwrap(),
|
||||
"--allow-plugin",
|
||||
"demo.solver",
|
||||
"--json",
|
||||
],
|
||||
dir.path(),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
//! R6 integration examples that do not require an official external repo.
|
||||
#![cfg(unix)]
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output};
|
||||
|
||||
@@ -51,13 +54,13 @@ fn mqmd_stdlib_print_output_matches_builtin_print() {
|
||||
|
||||
#[test]
|
||||
fn addressable_memory_example_runs_through_the_cli() {
|
||||
let output = cli(&["run", "examples/memory-buffer.mq.md", "--json"]);
|
||||
let output = cli(&["run", "examples/memory-buffer.mq.md", "--output", "json"]);
|
||||
assert_eq!(output.status.code(), Some(0), "{}", stderr(&output));
|
||||
let report: serde_json::Value =
|
||||
serde_json::from_slice(&output.stdout).expect("run --json emits JSON");
|
||||
assert_eq!(report["success"], true);
|
||||
assert_eq!(report["value"]["type"], "int");
|
||||
assert_eq!(report["value"]["decimal"], "141");
|
||||
serde_json::from_slice(&output.stdout).expect("run --output json emits a snapshot");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
assert_eq!(observation::terminal(&report)["value"]["type"], "int");
|
||||
assert_eq!(observation::terminal(&report)["value"]["decimal"], "141");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -67,13 +70,17 @@ fn cli_memory_budget_override_fails_closed() {
|
||||
"examples/memory-buffer.mq.md",
|
||||
"--max-memory",
|
||||
"0",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
]);
|
||||
assert_eq!(output.status.code(), Some(1), "{}", stderr(&output));
|
||||
let report: serde_json::Value =
|
||||
serde_json::from_slice(&output.stdout).expect("run --json emits JSON");
|
||||
assert_eq!(report["success"], false);
|
||||
assert_eq!(report["error"]["code"], "resource.exhausted");
|
||||
serde_json::from_slice(&output.stdout).expect("run --output json emits a snapshot");
|
||||
assert_eq!(report["run"]["status"], "error");
|
||||
assert_eq!(
|
||||
observation::terminal(&report)["error"]["code"],
|
||||
"resource.exhausted"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -133,7 +140,12 @@ fn unknown_tool_name_installs_and_dispatches() {
|
||||
|
||||
#[test]
|
||||
fn public_schemas_are_valid_json_and_versioned() {
|
||||
for name in ["analysis", "trace-v1", "cli-tool", "execution-events-v1"] {
|
||||
for name in [
|
||||
"analysis",
|
||||
"observation-event",
|
||||
"cli-tool",
|
||||
"observation-file",
|
||||
] {
|
||||
let path = repo()
|
||||
.join("spec/schemas")
|
||||
.join(format!("{name}.schema.json"));
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
//! C10/P5: a `.mq.md` HTTP client over the TCP resource endpoint.
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::io::{Read, Write};
|
||||
use std::net::TcpListener;
|
||||
use std::path::Path;
|
||||
@@ -89,7 +92,14 @@ import:
|
||||
);
|
||||
std::fs::write(dir.path().join("index.mq.md"), program).unwrap();
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", "index.mq.md", "--allow-net", "127.0.0.1", "--json"])
|
||||
.args([
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--allow-net",
|
||||
"127.0.0.1",
|
||||
"--output",
|
||||
"json",
|
||||
])
|
||||
.current_dir(dir.path())
|
||||
.env(
|
||||
"MARQDO_STDLIB_DIR",
|
||||
@@ -110,8 +120,10 @@ import:
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
);
|
||||
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("list");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["value"], true);
|
||||
assert_eq!(items[2]["decimal"], "200");
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
//! Temporary directories live under the OS temp directory and are removed on
|
||||
//! drop; the repository itself is never modified.
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Output};
|
||||
@@ -253,16 +256,16 @@ fn run_json_embeds_program_stdout() {
|
||||
"print.mq.md",
|
||||
"## @exec main\n\n`打印(\"你好\")`\n\n`打印(42)`\n\n`return None`\n",
|
||||
);
|
||||
let output = cli(dir.path(), &["run", "print.mq.md", "--json"]);
|
||||
assert_exit(&output, 0, "run --json must succeed");
|
||||
let output = cli(dir.path(), &["run", "print.mq.md", "--output", "json"]);
|
||||
assert_exit(&output, 0, "run --output json must succeed");
|
||||
// Exactly one JSON document on stdout: program output is embedded, never
|
||||
// interleaved with the machine-readable envelope.
|
||||
let value = json_stdout(&output);
|
||||
assert_eq!(value["command"], "run");
|
||||
assert_eq!(value["success"], true);
|
||||
assert_eq!(value["stdout"], "你好\n42\n");
|
||||
assert_eq!(value["value"]["type"], "none");
|
||||
assert!(value["trace"].as_array().is_some());
|
||||
assert_eq!(value["schema"], "marqdo.observation");
|
||||
assert_eq!(value["run"]["status"], "ok");
|
||||
assert_eq!(observation::text(&value, "stdout.chunk"), "你好\n42\n");
|
||||
assert_eq!(observation::terminal(&value)["value"]["type"], "none");
|
||||
assert!(value["events"].as_array().is_some());
|
||||
assert!(stderr_text(&output).is_empty());
|
||||
|
||||
// Text mode writes program output only to stdout, no JSON envelope.
|
||||
@@ -297,24 +300,33 @@ fn call_executes_examples_with_typed_arguments() {
|
||||
"数学.阶乘",
|
||||
"--arg",
|
||||
"n=5",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_exit(&output, 0, "call must execute factorial");
|
||||
let value = json_stdout(&output);
|
||||
assert_eq!(value["success"], true);
|
||||
assert_eq!(value["value"]["type"], "int");
|
||||
assert_eq!(value["value"]["decimal"], "120");
|
||||
assert_eq!(value["run"]["status"], "ok");
|
||||
assert_eq!(observation::terminal(&value)["value"]["type"], "int");
|
||||
assert_eq!(observation::terminal(&value)["value"]["decimal"], "120");
|
||||
|
||||
let math = examples.join("math.mq.md");
|
||||
let output = cli(
|
||||
&root,
|
||||
&["call", math.to_str().unwrap(), "计算圆面积", "--json"],
|
||||
&[
|
||||
"call",
|
||||
math.to_str().unwrap(),
|
||||
"计算圆面积",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_exit(&output, 0, "call must execute the math example");
|
||||
let value = json_stdout(&output);
|
||||
assert_eq!(value["value"]["type"], "float");
|
||||
let area = value["value"]["value"].as_f64().expect("float value");
|
||||
assert_eq!(observation::terminal(&value)["value"]["type"], "float");
|
||||
let area = observation::terminal(&value)["value"]["value"]
|
||||
.as_f64()
|
||||
.expect("float value");
|
||||
assert!(
|
||||
(area - std::f64::consts::PI * 16.0).abs() < 1e-12,
|
||||
"area={area}"
|
||||
@@ -323,11 +335,17 @@ fn call_executes_examples_with_typed_arguments() {
|
||||
let references = examples.join("references.mq.md");
|
||||
let output = cli(
|
||||
&root,
|
||||
&["call", references.to_str().unwrap(), "计算作用力", "--json"],
|
||||
&[
|
||||
"call",
|
||||
references.to_str().unwrap(),
|
||||
"计算作用力",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_exit(&output, 0, "call must execute the references example");
|
||||
let value = json_stdout(&output);
|
||||
assert_eq!(value["value"]["decimal"], "6");
|
||||
assert_eq!(observation::terminal(&value)["value"]["decimal"], "6");
|
||||
|
||||
let hello = examples.join("hello.mq.md");
|
||||
let output = cli(&root, &["run", hello.to_str().unwrap()]);
|
||||
@@ -425,7 +443,8 @@ fn strict_mode_enforces_isolation_or_refuses_closed() {
|
||||
assert!(
|
||||
stderr.contains("namespace")
|
||||
|| stderr.contains("Resource temporarily unavailable")
|
||||
|| stderr.contains("os error 11"),
|
||||
|| stderr.contains("os error 11")
|
||||
|| (stderr.contains("bwrap") && stderr.contains("Permission denied")),
|
||||
"strict failure diagnostic does not identify the launch failure: {stderr}"
|
||||
);
|
||||
assert!(
|
||||
@@ -436,12 +455,19 @@ fn strict_mode_enforces_isolation_or_refuses_closed() {
|
||||
|
||||
let json = cli(
|
||||
&root,
|
||||
&["run", hello.to_str().unwrap(), "--mode", "strict", "--json"],
|
||||
&[
|
||||
"run",
|
||||
hello.to_str().unwrap(),
|
||||
"--mode",
|
||||
"strict",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
if json.status.success() {
|
||||
let value = json_stdout(&json);
|
||||
assert_eq!(value["success"], true);
|
||||
assert_eq!(value["value"]["type"], "none");
|
||||
assert_eq!(value["run"]["status"], "ok");
|
||||
assert_eq!(observation::terminal(&value)["value"]["type"], "none");
|
||||
} else {
|
||||
assert_exit(
|
||||
&json,
|
||||
@@ -449,8 +475,8 @@ fn strict_mode_enforces_isolation_or_refuses_closed() {
|
||||
"strict launch failure keeps exit code 1 in JSON mode",
|
||||
);
|
||||
let value = json_stdout(&json);
|
||||
assert_eq!(value["success"], false);
|
||||
assert!(value["error"]
|
||||
assert_eq!(value["run"]["status"], "rejected");
|
||||
assert!(observation::terminal(&value)["error"]["message"]
|
||||
.as_str()
|
||||
.expect("error string")
|
||||
.contains("strict"));
|
||||
@@ -472,19 +498,26 @@ fn strict_mode_enforces_isolation_or_refuses_closed() {
|
||||
|
||||
let json = cli(
|
||||
&root,
|
||||
&["run", hello.to_str().unwrap(), "--mode", "strict", "--json"],
|
||||
&[
|
||||
"run",
|
||||
hello.to_str().unwrap(),
|
||||
"--mode",
|
||||
"strict",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_exit(&json, 1, "strict refusal keeps exit code 1 in JSON mode");
|
||||
let value = json_stdout(&json);
|
||||
assert_eq!(value["success"], false);
|
||||
assert!(value["error"]
|
||||
assert_eq!(value["run"]["status"], "rejected");
|
||||
assert!(observation::terminal(&value)["error"]["message"]
|
||||
.as_str()
|
||||
.expect("error string")
|
||||
.contains("strict mode"));
|
||||
}
|
||||
|
||||
/// A forged `MARQDO_STRICT_ACTIVE` marker must never be trusted and every
|
||||
/// `--json` refusal must still contain exactly one JSON document. This runs on
|
||||
/// `--output json` refusal must still contain exactly one JSON document. This runs on
|
||||
/// every platform; Linux rejects the marker during identity verification and
|
||||
/// non-Linux builds reject it as unsupported.
|
||||
#[test]
|
||||
@@ -494,15 +527,18 @@ fn forged_strict_marker_is_rejected_with_one_json_document() {
|
||||
let hello = hello.to_str().unwrap();
|
||||
let json = cli_env(
|
||||
&root,
|
||||
&["run", hello, "--mode", "strict", "--json"],
|
||||
&["run", hello, "--mode", "strict", "--output", "json"],
|
||||
"MARQDO_STRICT_ACTIVE",
|
||||
"1",
|
||||
);
|
||||
assert_exit(&json, 1, "forged strict marker must fail closed");
|
||||
let value = json_stdout(&json);
|
||||
assert_eq!(value["command"], "run");
|
||||
assert_eq!(value["success"], false);
|
||||
assert_eq!(value["code"], "strict.identity_invalid");
|
||||
assert_eq!(value["schema"], "marqdo.observation");
|
||||
assert_eq!(value["run"]["status"], "rejected");
|
||||
assert_eq!(
|
||||
observation::terminal(&value)["error"]["code"],
|
||||
"strict.identity_invalid"
|
||||
);
|
||||
|
||||
let human = cli_env(
|
||||
&root,
|
||||
@@ -519,7 +555,7 @@ fn forged_strict_marker_is_rejected_with_one_json_document() {
|
||||
assert!(stderr_text(&human).contains("strict isolation verification failed"));
|
||||
}
|
||||
|
||||
/// CLI usage errors in `--json` mode keep the same one-document contract as
|
||||
/// CLI usage errors in `--output json` mode keep the same one-document contract as
|
||||
/// successful and runtime-failure paths.
|
||||
#[test]
|
||||
fn json_mode_reports_cli_errors_as_one_document() {
|
||||
@@ -527,11 +563,17 @@ fn json_mode_reports_cli_errors_as_one_document() {
|
||||
let hello = root.join("examples").join("hello.mq.md");
|
||||
let hello = hello.to_str().unwrap();
|
||||
|
||||
let mode = cli(&root, &["run", hello, "--mode", "bogus", "--json"]);
|
||||
let mode = cli(
|
||||
&root,
|
||||
&["run", hello, "--mode", "bogus", "--output", "json"],
|
||||
);
|
||||
assert_exit(&mode, 2, "unknown mode");
|
||||
let value = json_stdout(&mode);
|
||||
assert_eq!(value["success"], false);
|
||||
assert_eq!(value["code"], "cli.invalid_mode");
|
||||
assert_eq!(value["run"]["status"], "rejected");
|
||||
assert_eq!(
|
||||
observation::terminal(&value)["error"]["code"],
|
||||
"cli.invalid_mode"
|
||||
);
|
||||
|
||||
let grants = cli(
|
||||
&root,
|
||||
@@ -542,13 +584,17 @@ fn json_mode_reports_cli_errors_as_one_document() {
|
||||
"pure",
|
||||
"--allow-read",
|
||||
"x",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_exit(&grants, 2, "pure mode must reject grants");
|
||||
let value = json_stdout(&grants);
|
||||
assert_eq!(value["success"], false);
|
||||
assert_eq!(value["code"], "cli.invalid_grants");
|
||||
assert_eq!(value["run"]["status"], "rejected");
|
||||
assert_eq!(
|
||||
observation::terminal(&value)["error"]["code"],
|
||||
"cli.invalid_grants"
|
||||
);
|
||||
|
||||
let strict = cli(
|
||||
&root,
|
||||
@@ -558,13 +604,17 @@ fn json_mode_reports_cli_errors_as_one_document() {
|
||||
"--mode",
|
||||
"strict",
|
||||
"--allow-foreign",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_exit(&strict, 2, "strict L1 must reject foreign grants");
|
||||
let value = json_stdout(&strict);
|
||||
assert_eq!(value["success"], false);
|
||||
assert_eq!(value["code"], "strict.unsupported_grant");
|
||||
assert_eq!(value["run"]["status"], "rejected");
|
||||
assert_eq!(
|
||||
observation::terminal(&value)["error"]["code"],
|
||||
"strict.unsupported_grant"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -923,11 +973,11 @@ fn runtime_error_in_imported_module_reports_that_module() {
|
||||
"## @exec boom\n\n说明文字。\n\n`x = 1 / 0`\n\n`return x`\n",
|
||||
);
|
||||
|
||||
let output = cli(dir.path(), &["run", "index.mq.md", "--json"]);
|
||||
let output = cli(dir.path(), &["run", "index.mq.md", "--output", "json"]);
|
||||
assert_exit(&output, 1, "division by zero is a runtime error");
|
||||
let value: serde_json::Value =
|
||||
serde_json::from_str(&stdout_text(&output)).expect("run --json emits JSON");
|
||||
let error = &value["error"];
|
||||
serde_json::from_str(&stdout_text(&output)).expect("run --output json emits JSON");
|
||||
let error = &observation::terminal(&value)["error"];
|
||||
assert_eq!(error["code"], "runtime.division_by_zero");
|
||||
assert!(
|
||||
error["module_id"]
|
||||
@@ -1171,22 +1221,22 @@ fn power_branch_loop_and_inert_code_end_to_end() {
|
||||
"branch.mq.md",
|
||||
"## @exec main\n\n`n = 2`\n\n`if n ** 2 == 4`\n\n`print(\"乘方正确\")`\n\n`else`\n\n`if n ** 2 != 4`\n\n`print(\"乘方错误\")`\n\n`end`\n\n`end`\n",
|
||||
);
|
||||
let branch = cli(dir.path(), &["run", "branch.mq.md", "--json"]);
|
||||
let branch = cli(dir.path(), &["run", "branch.mq.md", "--output", "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");
|
||||
assert_eq!(value["run"]["status"], "ok");
|
||||
assert_eq!(observation::text(&value, "stdout.chunk"), "乘方正确\n");
|
||||
assert_eq!(observation::terminal(&value)["value"]["type"], "unit");
|
||||
|
||||
dir.write(
|
||||
"loop.mq.md",
|
||||
"## @exec main\n\n`n = 0`\n\n`limit = 100`\n\n`while n ** 2 < limit`\n\n`n = n + 1`\n\n`end`\n\n`return n`\n",
|
||||
);
|
||||
let looped = cli(dir.path(), &["run", "loop.mq.md", "--json"]);
|
||||
let looped = cli(dir.path(), &["run", "loop.mq.md", "--output", "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");
|
||||
assert_eq!(observation::terminal(&value)["value"]["type"], "int");
|
||||
assert_eq!(observation::terminal(&value)["value"]["decimal"], "10");
|
||||
|
||||
// A code fence containing power syntax is an inert value: it produces no
|
||||
// diagnostics and never changes the returned value.
|
||||
@@ -1194,10 +1244,10 @@ fn power_branch_loop_and_inert_code_end_to_end() {
|
||||
"inert.mq.md",
|
||||
"## @exec main\n\n```text\n**n = 2 ** 3**\n```\n\n`x = 1`\n\n`return x`\n\n### @knowledge 说明\n\n正文里的 `2 ** 3` 不执行。\n",
|
||||
);
|
||||
let inert = cli(dir.path(), &["run", "inert.mq.md", "--json"]);
|
||||
let inert = cli(dir.path(), &["run", "inert.mq.md", "--output", "json"]);
|
||||
assert_exit(&inert, 0, "inert code run");
|
||||
let value = json_stdout(&inert);
|
||||
assert_eq!(value["value"]["decimal"], "1");
|
||||
assert_eq!(observation::terminal(&value)["value"]["decimal"], "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Black-box Execution Events v1 contract tests (RFC-OBS-0001).
|
||||
//! Black-box Observation contract tests.
|
||||
//!
|
||||
//! These drive the real `marqdo` binary (`CARGO_BIN_EXE_marqdo`) and parse the
|
||||
//! stdout line stream exactly like an external consumer. They cover the P0
|
||||
//! envelope/lifecycle/byte-fidelity contract and the P1 frame/value policy,
|
||||
//! plus trace coexistence, truncation, live delivery and a broken pipe.
|
||||
//! plus snapshot equivalence, truncation, live delivery and a broken pipe.
|
||||
|
||||
use std::fs;
|
||||
use std::io::{BufRead, BufReader, Read};
|
||||
@@ -124,7 +124,7 @@ fn assert_envelope(events: &[Value]) {
|
||||
assert!(!events.is_empty());
|
||||
let first = &events[0];
|
||||
assert_eq!(first["kind"], "stream.opened");
|
||||
assert_eq!(first["schema"], "marqdo.execution-events");
|
||||
assert_eq!(first["schema"], "marqdo.observation");
|
||||
assert_eq!(first["schema_version"], 1);
|
||||
assert_eq!(first["seq"], 0);
|
||||
let run_id = first["run_id"].as_str().unwrap().to_string();
|
||||
@@ -174,15 +174,16 @@ fn checked_in_fixtures_validate_against_the_public_schema() {
|
||||
eprintln!("python3 + jsonschema unavailable; schema consumer skipped");
|
||||
return;
|
||||
}
|
||||
let fixtures = repo_root().join("tests/consumers/fixtures/execution-events");
|
||||
let consumer = repo_root().join("tests/consumers/execution_events_consumer.py");
|
||||
let fixtures = repo_root().join("tests/consumers/fixtures/observation");
|
||||
let consumer = repo_root().join("tests/consumers/observation_consumer.py");
|
||||
for name in ["minimal.jsonl", "full.jsonl"] {
|
||||
let path = fixtures.join("valid").join(name);
|
||||
let output = Command::new("python3")
|
||||
.arg(&consumer)
|
||||
.arg("--validate-schema")
|
||||
.arg(&path)
|
||||
.output()
|
||||
.expect("run execution events consumer");
|
||||
.expect("run observation consumer");
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"valid fixture {name} rejected: {}",
|
||||
@@ -193,9 +194,10 @@ fn checked_in_fixtures_validate_against_the_public_schema() {
|
||||
let path = entry.unwrap().path();
|
||||
let output = Command::new("python3")
|
||||
.arg(&consumer)
|
||||
.arg("--validate-schema")
|
||||
.arg(&path)
|
||||
.output()
|
||||
.expect("run execution events consumer");
|
||||
.expect("run observation consumer");
|
||||
assert!(
|
||||
!output.status.success(),
|
||||
"invalid fixture {} was accepted",
|
||||
@@ -208,7 +210,7 @@ fn checked_in_fixtures_validate_against_the_public_schema() {
|
||||
fn structure_fixture_attributes_repeated_recursive_frames() {
|
||||
let dir = TempDir::new("structure");
|
||||
let source = fs::read_to_string(
|
||||
repo_root().join("tests/consumers/fixtures/execution-events/structure.mq.md"),
|
||||
repo_root().join("tests/consumers/fixtures/observation/structure.mq.md"),
|
||||
)
|
||||
.unwrap();
|
||||
dir.write("index.mq.md", &source);
|
||||
@@ -217,7 +219,7 @@ fn structure_fixture_attributes_repeated_recursive_frames() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--observe-max-events",
|
||||
"1000",
|
||||
@@ -287,7 +289,7 @@ fn native_plugin_is_fail_closed_in_event_mode() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--plugin",
|
||||
plugin_dir.join("plugin.yaml").to_str().unwrap(),
|
||||
@@ -302,7 +304,7 @@ fn native_plugin_is_fail_closed_in_event_mode() {
|
||||
assert_eq!(terminal["kind"], "run.rejected");
|
||||
assert_eq!(
|
||||
terminal["payload"]["error"]["code"],
|
||||
"ext.event_stream_unsupported_native_plugin"
|
||||
"ext.observation_unsupported_native_plugin"
|
||||
);
|
||||
assert!(
|
||||
events_of(&events, "run.started").is_empty(),
|
||||
@@ -311,8 +313,8 @@ fn native_plugin_is_fail_closed_in_event_mode() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn observed_values_never_enter_trace_v2() {
|
||||
let dir = TempDir::new("trace-redaction");
|
||||
fn selected_values_apply_equally_to_stream_and_private_snapshot() {
|
||||
let dir = TempDir::new("capture-consent");
|
||||
dir.write(
|
||||
"index.mq.md",
|
||||
"## @exec main\n\n`secret_token = \"DO_NOT_LEAK_SENTINEL_1\"`\n\n`visible_count = 42`\n\n`return visible_count`\n",
|
||||
@@ -323,12 +325,12 @@ fn observed_values_never_enter_trace_v2() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--observe-variable",
|
||||
"secret_token",
|
||||
"--observe-text-values",
|
||||
"--trace-file",
|
||||
"--observation-file",
|
||||
trace_path.to_str().unwrap(),
|
||||
],
|
||||
);
|
||||
@@ -337,24 +339,32 @@ fn observed_values_never_enter_trace_v2() {
|
||||
String::from_utf8_lossy(&output.stdout).contains("DO_NOT_LEAK_SENTINEL_1"),
|
||||
"the explicit event consent publishes the selected value in the stream"
|
||||
);
|
||||
let trace = fs::read(&trace_path).unwrap();
|
||||
assert!(
|
||||
!String::from_utf8_lossy(&trace).contains("DO_NOT_LEAK_SENTINEL_1"),
|
||||
"Trace v2 must not gain observed values"
|
||||
let snapshot_bytes = fs::read(&trace_path).unwrap();
|
||||
let snapshot: Value = serde_json::from_slice(&snapshot_bytes).unwrap();
|
||||
assert_eq!(
|
||||
snapshot["events"],
|
||||
serde_json::json!(parse_events(&output.stdout))
|
||||
);
|
||||
let trace: Value = serde_json::from_slice(&trace).unwrap();
|
||||
assert_eq!(trace["schema"], "marqdo.trace");
|
||||
assert_eq!(trace["schema_version"], 2);
|
||||
assert_eq!(
|
||||
snapshot["capture"]["selected_variables"],
|
||||
serde_json::json!(["secret_token"])
|
||||
);
|
||||
assert!(String::from_utf8_lossy(&snapshot_bytes).contains("DO_NOT_LEAK_SENTINEL_1"));
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
assert_eq!(
|
||||
fs::metadata(&trace_path).unwrap().permissions().mode() & 0o777,
|
||||
0o600
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_stream_is_pure_jsonl_and_reconstructs_program_output() {
|
||||
let dir = TempDir::new("basic");
|
||||
dir.write("index.mq.md", BASIC);
|
||||
let output = cli(
|
||||
dir.path(),
|
||||
&["run", "index.mq.md", "--event-stream", "jsonl"],
|
||||
);
|
||||
let output = cli(dir.path(), &["run", "index.mq.md", "--output", "jsonl"]);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(0),
|
||||
@@ -382,27 +392,27 @@ fn basic_stream_is_pure_jsonl_and_reconstructs_program_output() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_stream_rejects_mixed_json_and_static_commands() {
|
||||
fn retired_run_options_and_static_observation_are_rejected() {
|
||||
let dir = TempDir::new("reject");
|
||||
dir.write("index.mq.md", BASIC);
|
||||
let mixed = cli(
|
||||
dir.path(),
|
||||
&["run", "index.mq.md", "--event-stream", "jsonl", "--json"],
|
||||
);
|
||||
assert_eq!(mixed.status.code(), Some(2));
|
||||
assert!(mixed.stdout.is_empty(), "no mixed stdout");
|
||||
assert!(String::from_utf8_lossy(&mixed.stderr).contains("--json"));
|
||||
|
||||
for args in [
|
||||
vec!["--json"],
|
||||
vec!["--event-stream", "jsonl"],
|
||||
vec!["--trace-file", "retired.json"],
|
||||
vec!["--trace"],
|
||||
vec!["--output", "jsonl", "--output", "json"],
|
||||
vec!["--observe-variable", "n"],
|
||||
] {
|
||||
let mut command = vec!["run", "index.mq.md"];
|
||||
command.extend(args);
|
||||
let rejected = cli(dir.path(), &command);
|
||||
assert_eq!(rejected.status.code(), Some(2));
|
||||
assert!(rejected.stdout.is_empty(), "{command:?} must not execute");
|
||||
}
|
||||
assert!(!dir.path().join("retired.json").exists());
|
||||
for command in ["check", "inspect"] {
|
||||
let rejected = cli(
|
||||
dir.path(),
|
||||
&[command, "index.mq.md", "--event-stream", "jsonl"],
|
||||
);
|
||||
assert_eq!(
|
||||
rejected.status.code(),
|
||||
Some(2),
|
||||
"{command} must reject the option"
|
||||
);
|
||||
let rejected = cli(dir.path(), &[command, "index.mq.md", "--output", "jsonl"]);
|
||||
assert_eq!(rejected.status.code(), Some(2));
|
||||
assert!(rejected.stdout.is_empty(), "{command} must not execute");
|
||||
}
|
||||
}
|
||||
@@ -411,10 +421,7 @@ fn event_stream_rejects_mixed_json_and_static_commands() {
|
||||
fn prepare_and_runtime_failures_have_defined_terminals() {
|
||||
let dir = TempDir::new("failures");
|
||||
dir.write("broken.mq.md", "## @exec main\n\n`if true`\n\n`return 1`\n");
|
||||
let rejected = cli(
|
||||
dir.path(),
|
||||
&["run", "broken.mq.md", "--event-stream", "jsonl"],
|
||||
);
|
||||
let rejected = cli(dir.path(), &["run", "broken.mq.md", "--output", "jsonl"]);
|
||||
assert_eq!(rejected.status.code(), Some(1));
|
||||
let events = parse_events(&rejected.stdout);
|
||||
assert_envelope(&events);
|
||||
@@ -429,10 +436,7 @@ fn prepare_and_runtime_failures_have_defined_terminals() {
|
||||
"runtime.mq.md",
|
||||
"## @exec main\n\n`x = 1 / 0`\n\n`return x`\n",
|
||||
);
|
||||
let failed = cli(
|
||||
dir.path(),
|
||||
&["run", "runtime.mq.md", "--event-stream", "jsonl"],
|
||||
);
|
||||
let failed = cli(dir.path(), &["run", "runtime.mq.md", "--output", "jsonl"]);
|
||||
assert_eq!(failed.status.code(), Some(1));
|
||||
let events = parse_events(&failed.stdout);
|
||||
assert_envelope(&events);
|
||||
@@ -455,10 +459,7 @@ fn value_observation_is_exact_and_requires_text_consent() {
|
||||
"## @exec main\n\n`secret_token = \"DO_NOT_LEAK_SENTINEL_1\"`\n\n`visible_count = 42`\n\n`return visible_count`\n",
|
||||
);
|
||||
// Default: metadata only; no value, no sentinel anywhere.
|
||||
let default = cli(
|
||||
dir.path(),
|
||||
&["run", "index.mq.md", "--event-stream", "jsonl"],
|
||||
);
|
||||
let default = cli(dir.path(), &["run", "index.mq.md", "--output", "jsonl"]);
|
||||
assert_eq!(default.status.code(), Some(0));
|
||||
assert!(!String::from_utf8_lossy(&default.stdout).contains("DO_NOT_LEAK_SENTINEL_1"));
|
||||
for event in events_of(&parse_events(&default.stdout), "variable.assigned") {
|
||||
@@ -471,7 +472,7 @@ fn value_observation_is_exact_and_requires_text_consent() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--observe-variable",
|
||||
"visible_count",
|
||||
@@ -498,7 +499,7 @@ fn value_observation_is_exact_and_requires_text_consent() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--observe-variable",
|
||||
"secret_token",
|
||||
@@ -519,7 +520,7 @@ fn value_observation_is_exact_and_requires_text_consent() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--observe-variable",
|
||||
"secret_token",
|
||||
@@ -554,10 +555,7 @@ fn binary_and_multibyte_output_is_byte_exact() {
|
||||
"{}",
|
||||
String::from_utf8_lossy(&normal.stderr)
|
||||
);
|
||||
let streamed = cli(
|
||||
dir.path(),
|
||||
&["run", "index.mq.md", "--event-stream", "jsonl"],
|
||||
);
|
||||
let streamed = cli(dir.path(), &["run", "index.mq.md", "--output", "jsonl"]);
|
||||
assert_eq!(streamed.status.code(), Some(0));
|
||||
let events = parse_events(&streamed.stdout);
|
||||
let chunks = chunk_bytes(&events, "stdout.chunk");
|
||||
@@ -570,37 +568,50 @@ fn binary_and_multibyte_output_is_byte_exact() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trace_file_coexists_and_shares_the_run_identity() {
|
||||
let dir = TempDir::new("trace");
|
||||
fn stream_and_snapshot_share_every_event_from_one_run() {
|
||||
let dir = TempDir::new("destinations");
|
||||
dir.write("index.mq.md", BASIC);
|
||||
let trace_path = dir.path().join("trace.json");
|
||||
let output = cli(
|
||||
dir.path(),
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--trace-file",
|
||||
trace_path.to_str().unwrap(),
|
||||
"--observation-file",
|
||||
"run.json",
|
||||
],
|
||||
);
|
||||
assert_eq!(output.status.code(), Some(0));
|
||||
assert!(output.status.success(), "{output:?}");
|
||||
let events = parse_events(&output.stdout);
|
||||
assert_envelope(&events);
|
||||
let trace: Value = serde_json::from_slice(&fs::read(&trace_path).unwrap()).unwrap();
|
||||
assert_eq!(trace["schema"], "marqdo.trace");
|
||||
assert_eq!(trace["schema_version"], 2);
|
||||
assert_eq!(trace["run"]["id"], events[0]["run_id"]);
|
||||
let started = events_of(&events, "run.started")[0];
|
||||
let snapshot: Value =
|
||||
serde_json::from_slice(&fs::read(dir.path().join("run.json")).unwrap()).unwrap();
|
||||
assert_eq!(snapshot["schema"], "marqdo.observation");
|
||||
assert_eq!(snapshot["schema_version"], 1);
|
||||
assert_eq!(snapshot["run"]["id"], events[0]["run_id"]);
|
||||
assert_eq!(snapshot["run"]["source"], events[1]["payload"]["source"]);
|
||||
assert_eq!(snapshot["events"], serde_json::json!(events));
|
||||
|
||||
let second = cli(
|
||||
dir.path(),
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--output",
|
||||
"json",
|
||||
"--observation-file",
|
||||
"run.json",
|
||||
],
|
||||
);
|
||||
assert!(second.status.success(), "{second:?}");
|
||||
assert_eq!(
|
||||
started["payload"]["source"]["analysis_digest"],
|
||||
trace["source"]["analysis_digest"]
|
||||
);
|
||||
assert!(
|
||||
events_of(&events, "run.completed").len() == 1,
|
||||
"trace writing does not suppress the terminal event"
|
||||
second.stdout,
|
||||
fs::read(dir.path().join("run.json")).unwrap()
|
||||
);
|
||||
let second: Value = serde_json::from_slice(&second.stdout).unwrap();
|
||||
assert_ne!(second["run"]["id"], snapshot["run"]["id"]);
|
||||
assert_eq!(second["run"]["status"], "ok");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -612,7 +623,7 @@ fn structural_budget_truncates_without_losing_critical_events() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--observe-max-events",
|
||||
"5",
|
||||
@@ -637,7 +648,7 @@ fn output_budget_still_fails_the_run_and_emits_no_chunk() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--max-output",
|
||||
"3",
|
||||
@@ -663,7 +674,7 @@ fn live_chunks_arrive_while_the_program_is_still_running() {
|
||||
.args([
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--observe-max-events",
|
||||
"20",
|
||||
@@ -716,7 +727,7 @@ fn broken_pipe_makes_the_run_fail_instead_of_running_forever() {
|
||||
.args([
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--observe-max-events",
|
||||
"10",
|
||||
@@ -811,9 +822,9 @@ fn loop_transfers_are_ordered_structural_events_with_source_spans() {
|
||||
"index.mq.md",
|
||||
"--mode",
|
||||
"pure",
|
||||
"--event-stream",
|
||||
"--output",
|
||||
"jsonl",
|
||||
"--trace-file",
|
||||
"--observation-file",
|
||||
"trace.json",
|
||||
],
|
||||
);
|
||||
@@ -823,9 +834,9 @@ fn loop_transfers_are_ordered_structural_events_with_source_spans() {
|
||||
assert_eq!(events.last().unwrap()["kind"], "run.completed");
|
||||
let trace: Value =
|
||||
serde_json::from_slice(&fs::read(dir.path().join("trace.json")).unwrap()).unwrap();
|
||||
assert_eq!(trace["schema_version"], 2);
|
||||
assert_eq!(trace["schema_version"], 1);
|
||||
assert_eq!(
|
||||
trace["source"]["analysis_digest"],
|
||||
trace["run"]["source"]["analysis_digest"],
|
||||
format!("sha256:{:x}", Sha256::digest(analysis_bytes))
|
||||
);
|
||||
|
||||
@@ -850,7 +861,7 @@ fn loop_transfers_are_ordered_structural_events_with_source_spans() {
|
||||
];
|
||||
assert_eq!(kinds(&events), expected);
|
||||
let trace_events = trace["events"].as_array().unwrap();
|
||||
assert_eq!(kinds(trace_events), expected);
|
||||
assert_eq!(trace_events, &events);
|
||||
let frame = &events_of(&events, "call.enter")[0]["payload"]["frame_id"];
|
||||
for (index, keyword) in ["continue", "break"].iter().enumerate() {
|
||||
let kind = format!("control.{keyword}");
|
||||
@@ -862,10 +873,6 @@ fn loop_transfers_are_ordered_structural_events_with_source_spans() {
|
||||
assert_eq!(payload["module_id"], module["id"]);
|
||||
assert_eq!(payload["span"], span);
|
||||
assert_eq!(payload.as_object().unwrap().len(), 3);
|
||||
let event = &events_of(trace_events, &kind)[0];
|
||||
assert_eq!(event["module_id"], module["id"]);
|
||||
assert_eq!(event["span"], span);
|
||||
assert!(event["detail"].is_null());
|
||||
let statement = &branch["arms"][index]["body"][0];
|
||||
assert_eq!(statement["kind"], *keyword);
|
||||
assert_eq!(statement["span"], span);
|
||||
@@ -1,5 +1,8 @@
|
||||
//! RFC-CM P2 closure lane: C01–C06/C11/C12 in a pure, no-Foreign/no-Plugin host.
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
@@ -70,7 +73,14 @@ fn p2_algorithms_run_in_a_pure_no_foreign_no_plugin_host() {
|
||||
);
|
||||
}
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", path.to_str().unwrap(), "--mode", "pure", "--json"])
|
||||
.args([
|
||||
"run",
|
||||
path.to_str().unwrap(),
|
||||
"--mode",
|
||||
"pure",
|
||||
"--output",
|
||||
"json",
|
||||
])
|
||||
.current_dir(repo_root())
|
||||
.output()
|
||||
.expect("run marqdo");
|
||||
@@ -82,14 +92,15 @@ fn p2_algorithms_run_in_a_pure_no_foreign_no_plugin_host() {
|
||||
);
|
||||
let report: serde_json::Value =
|
||||
serde_json::from_slice(&output.stdout).expect("json report");
|
||||
assert_eq!(report["success"], true, "{name}");
|
||||
assert_eq!(report["run"]["status"], "ok", "{name}");
|
||||
let golden = expected(name);
|
||||
assert_eq!(
|
||||
report["value"], golden["value"],
|
||||
observation::terminal(&report)["value"],
|
||||
golden["value"],
|
||||
"{criterion} fixture {name}"
|
||||
);
|
||||
assert_eq!(
|
||||
report["stdout"].as_str().unwrap_or_default(),
|
||||
observation::text(&report, "stdout.chunk"),
|
||||
golden["stdout"].as_str().unwrap_or_default(),
|
||||
"{criterion} fixture {name} stdout"
|
||||
);
|
||||
@@ -100,7 +111,14 @@ fn p2_algorithms_run_in_a_pure_no_foreign_no_plugin_host() {
|
||||
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"])
|
||||
.args([
|
||||
"run",
|
||||
path.to_str().unwrap(),
|
||||
"--mode",
|
||||
"pure",
|
||||
"--output",
|
||||
"json",
|
||||
])
|
||||
.current_dir(repo_root().join("stdlib"))
|
||||
.env("MARQDO_STDLIB_DIR", repo_root().join("stdlib"))
|
||||
.output()
|
||||
@@ -112,8 +130,8 @@ fn p2_stdlib_table_also_runs_in_pure_mode() {
|
||||
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"]
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("table test list");
|
||||
assert_eq!(items.len(), 9);
|
||||
@@ -133,14 +151,24 @@ fn foreign_and_plugin_shortcuts_are_unavailable_in_the_pure_lane() {
|
||||
)
|
||||
.unwrap();
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", foreign.to_str().unwrap(), "--mode", "pure", "--json"])
|
||||
.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_eq!(report["success"], false);
|
||||
assert_eq!(report["error"]["code"], "permission.denied");
|
||||
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(
|
||||
@@ -149,11 +177,18 @@ fn foreign_and_plugin_shortcuts_are_unavailable_in_the_pure_lane() {
|
||||
)
|
||||
.unwrap();
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", plugin.to_str().unwrap(), "--mode", "pure", "--json"])
|
||||
.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_eq!(report["success"], false);
|
||||
assert_ne!(report["run"]["status"], "ok");
|
||||
}
|
||||
@@ -52,7 +52,7 @@ fn print_is_routed_through_the_stdlib_and_not_hostop_print() {
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--trace-file",
|
||||
"--observation-file",
|
||||
trace.to_str().unwrap(),
|
||||
],
|
||||
);
|
||||
@@ -69,7 +69,7 @@ fn print_is_routed_through_the_stdlib_and_not_hostop_print() {
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter_map(|event| event["operation"].as_str())
|
||||
.filter_map(|event| event["payload"]["operation"].as_str())
|
||||
.collect();
|
||||
assert!(
|
||||
operations.contains(&"resource.write"),
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
//! Other platforms must keep this file compiling but run no provider
|
||||
//! assertions; the CLI itself fails closed with `ext.platform_unsupported`.
|
||||
#![cfg(all(target_os = "linux", target_arch = "x86_64"))]
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -417,17 +419,14 @@ fn json_of(output: &Output) -> serde_json::Value {
|
||||
}
|
||||
|
||||
fn error_code(report: &serde_json::Value) -> String {
|
||||
report
|
||||
.get("error")
|
||||
.and_then(|error| error.get("code"))
|
||||
.or_else(|| report.get("code"))
|
||||
.and_then(|code| code.as_str())
|
||||
.unwrap_or("<missing error code>")
|
||||
observation::terminal(report)["error"]["code"]
|
||||
.as_str()
|
||||
.expect("terminal error code")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn map_field<'a>(report: &'a serde_json::Value, name: &str) -> &'a serde_json::Value {
|
||||
&report["value"]["entries"][name]
|
||||
&observation::terminal(report)["value"]["entries"][name]
|
||||
}
|
||||
|
||||
fn cc_available() -> bool {
|
||||
@@ -469,7 +468,8 @@ fn prov_01_authorized_v2_worker_reads_five_bytes() {
|
||||
manifest.to_str().expect("utf-8 manifest path"),
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -480,7 +480,7 @@ fn prov_01_authorized_v2_worker_reads_five_bytes() {
|
||||
"run failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
assert!(report["success"].as_bool().unwrap_or(false));
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
assert_eq!(map_field(&report, "count")["decimal"], "5");
|
||||
assert!(map_field(&report, "eof")["value"]
|
||||
.as_bool()
|
||||
@@ -490,13 +490,14 @@ fn prov_01_authorized_v2_worker_reads_five_bytes() {
|
||||
.unwrap_or(false));
|
||||
// `hello` is in the Memory region the provider filled on the first byte.
|
||||
assert_eq!(map_field(&report, "data")["decimal"], "104");
|
||||
assert_eq!(report["stdout"], "");
|
||||
assert_eq!(observation::text(&report, "stdout.chunk"), "");
|
||||
// The Host recorded the real resource effect (not a synthetic success).
|
||||
let trace = report["trace"].as_array().expect("trace array");
|
||||
let trace = report["events"].as_array().expect("trace array");
|
||||
assert!(
|
||||
trace
|
||||
.iter()
|
||||
.any(|entry| entry["op"] == "resource.open" && entry["result"] == "ok"),
|
||||
.any(|entry| entry["payload"]["operation"] == "resource.open"
|
||||
&& entry["payload"]["result_code"] == "ok"),
|
||||
"missing resource.open trace: {trace:?}"
|
||||
);
|
||||
let marks = marker_text(&marker);
|
||||
@@ -534,13 +535,14 @@ fn prov_02_without_grant_is_permission_denied_and_never_starts_the_worker() {
|
||||
"index.mq.md",
|
||||
"--provider",
|
||||
manifest.to_str().expect("utf-8 manifest path"),
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
assert_eq!(output.status.code(), Some(1));
|
||||
let report = json_of(&output);
|
||||
assert!(!report["success"].as_bool().unwrap_or(true));
|
||||
assert_eq!(report["run"]["status"], "rejected");
|
||||
assert_eq!(error_code(&report), "permission.denied");
|
||||
assert!(
|
||||
!marker.exists(),
|
||||
@@ -562,7 +564,8 @@ fn prov_03_grant_without_manifest_is_never_discovered() {
|
||||
"index.mq.md",
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -603,7 +606,8 @@ fn prov_04_duplicate_kind_across_providers_is_rejected_before_spawn() {
|
||||
"demo.one",
|
||||
"--allow-provider",
|
||||
"demo.two",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -636,7 +640,8 @@ fn prov_05_one_provider_serves_two_non_reserved_kinds() {
|
||||
manifest.to_str().expect("utf-8 manifest path"),
|
||||
"--allow-provider",
|
||||
"demo.multi",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -647,7 +652,9 @@ fn prov_05_one_provider_serves_two_non_reserved_kinds() {
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let report = json_of(&output);
|
||||
let items = report["value"]["items"].as_array().expect("list result");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list result");
|
||||
assert_eq!(items[0]["decimal"], "5");
|
||||
assert_eq!(items[1]["decimal"], "2");
|
||||
assert!(items[2]["value"].as_bool().unwrap_or(false));
|
||||
@@ -691,7 +698,8 @@ fn prov_06_reserved_core_kinds_are_rejected() {
|
||||
manifest.to_str().expect("utf-8 manifest path"),
|
||||
"--allow-provider",
|
||||
"demo.reserved",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -734,7 +742,8 @@ fn prov_07_digest_symlink_and_traversal_fail_before_spawn() {
|
||||
digest_manifest.to_str().expect("utf-8 path"),
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -772,7 +781,8 @@ fn prov_07_digest_symlink_and_traversal_fail_before_spawn() {
|
||||
symlink_manifest.to_str().expect("utf-8 path"),
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -803,7 +813,8 @@ fn prov_07_digest_symlink_and_traversal_fail_before_spawn() {
|
||||
traversal_manifest.to_str().expect("utf-8 path"),
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -838,7 +849,8 @@ fn prov_08_missing_current_target_is_no_matching_artifact() {
|
||||
manifest.to_str().expect("utf-8 path"),
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -873,7 +885,8 @@ fn prov_09_v1_manifest_is_unsupported_without_migration() {
|
||||
manifest.to_str().expect("utf-8 path"),
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -910,7 +923,8 @@ fn prov_10_pure_and_strict_preflight_refuse_provider_flags() {
|
||||
manifest_arg,
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -932,7 +946,8 @@ fn prov_10_pure_and_strict_preflight_refuse_provider_flags() {
|
||||
manifest_arg,
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -953,7 +968,8 @@ fn prov_10_pure_and_strict_preflight_refuse_provider_flags() {
|
||||
manifest_arg,
|
||||
"--allow-provider",
|
||||
"*",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
&marker,
|
||||
);
|
||||
@@ -992,7 +1008,8 @@ fn prov_13_missing_sibling_helper_is_worker_unavailable_without_path_fallback()
|
||||
manifest.to_str().expect("utf-8 path"),
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
])
|
||||
.current_dir(fixture.path())
|
||||
.env("PATH", path)
|
||||
@@ -1007,7 +1024,9 @@ fn prov_13_missing_sibling_helper_is_worker_unavailable_without_path_fallback()
|
||||
);
|
||||
let report = json_of(&output);
|
||||
assert_eq!(error_code(&report), "ext.worker_unavailable");
|
||||
let message = report["error"]["message"].as_str().unwrap_or_default();
|
||||
let message = observation::terminal(&report)["error"]["message"]
|
||||
.as_str()
|
||||
.unwrap_or_default();
|
||||
assert!(
|
||||
message.contains("marqdo-provider-worker") && message.contains("missing"),
|
||||
"{message}"
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
//! End-to-end resource stream tests through the CLI.
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Output, Stdio};
|
||||
@@ -80,7 +83,14 @@ fn project_file_stream_reads_chunks_into_memory() {
|
||||
write_file(&dir.path().join("index.mq.md"), READER);
|
||||
let output = cli(
|
||||
dir.path(),
|
||||
&["run", "index.mq.md", "--allow-read", "data.txt", "--json"],
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--allow-read",
|
||||
"data.txt",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
@@ -89,8 +99,8 @@ fn project_file_stream_reads_chunks_into_memory() {
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output");
|
||||
assert_eq!(report["success"], true);
|
||||
let values: Vec<&serde_json::Value> = report["value"]["items"]
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let values: Vec<&serde_json::Value> = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list result")
|
||||
.iter()
|
||||
@@ -148,7 +158,8 @@ fn project_file_stream_writes_on_close_then_reads_back() {
|
||||
"out.bin",
|
||||
"--allow-read",
|
||||
"out.bin",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -158,8 +169,10 @@ fn project_file_stream_writes_on_close_then_reads_back() {
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output");
|
||||
assert_eq!(report["success"], true);
|
||||
let values = report["value"]["items"].as_array().expect("list result");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let values = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list result");
|
||||
assert_eq!(values[0]["decimal"], "3");
|
||||
assert_eq!(values[1]["value"], true);
|
||||
assert_eq!(values[2]["decimal"], "3");
|
||||
@@ -224,7 +237,8 @@ fn file_copy_is_written_in_mqmd_through_chunked_streams() {
|
||||
"data.txt",
|
||||
"--allow-write",
|
||||
"out.bin",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -234,8 +248,10 @@ fn file_copy_is_written_in_mqmd_through_chunked_streams() {
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output");
|
||||
assert_eq!(report["success"], true);
|
||||
let values = report["value"]["items"].as_array().expect("list result");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let values = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list result");
|
||||
assert_eq!(values[0]["decimal"], "6");
|
||||
assert_eq!(values[1]["value"], true);
|
||||
assert_eq!(values[2]["value"], true);
|
||||
@@ -287,7 +303,14 @@ fn tcp_stream_round_trips_through_mqmd_with_a_network_grant() {
|
||||
write_file(&dir.path().join("index.mq.md"), &program);
|
||||
let output = cli(
|
||||
dir.path(),
|
||||
&["run", "index.mq.md", "--allow-net", "127.0.0.1", "--json"],
|
||||
&[
|
||||
"run",
|
||||
"index.mq.md",
|
||||
"--allow-net",
|
||||
"127.0.0.1",
|
||||
"--output",
|
||||
"json",
|
||||
],
|
||||
);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
@@ -296,8 +319,10 @@ fn tcp_stream_round_trips_through_mqmd_with_a_network_grant() {
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output");
|
||||
assert_eq!(report["success"], true);
|
||||
let values = report["value"]["items"].as_array().expect("list");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let values = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(values[0]["decimal"], "4");
|
||||
assert_eq!(values[1]["decimal"], "4");
|
||||
for (index, expected) in ["112", "105", "110", "103"].into_iter().enumerate() {
|
||||
@@ -312,11 +337,14 @@ fn file_stream_requires_a_read_grant() {
|
||||
let dir = TempDir::new("file-denied");
|
||||
write_file(&dir.path().join("data.txt"), "abcdef");
|
||||
write_file(&dir.path().join("index.mq.md"), READER);
|
||||
let output = cli(dir.path(), &["run", "index.mq.md", "--json"]);
|
||||
let output = cli(dir.path(), &["run", "index.mq.md", "--output", "json"]);
|
||||
assert_eq!(output.status.code(), Some(1));
|
||||
let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output");
|
||||
assert_eq!(report["success"], false);
|
||||
assert_eq!(report["error"]["code"], "permission.denied");
|
||||
assert_ne!(report["run"]["status"], "ok");
|
||||
assert_eq!(
|
||||
observation::terminal(&report)["error"]["code"],
|
||||
"permission.denied"
|
||||
);
|
||||
}
|
||||
|
||||
const STDIN_READER: &str = r#"## @exec main
|
||||
@@ -338,7 +366,11 @@ const STDIN_READER: &str = r#"## @exec main
|
||||
fn piped_stdin_is_chunked_and_reaches_eof() {
|
||||
let dir = TempDir::new("stdin");
|
||||
write_file(&dir.path().join("index.mq.md"), STDIN_READER);
|
||||
let output = cli_with_stdin(dir.path(), &["run", "index.mq.md", "--json"], b"abcd");
|
||||
let output = cli_with_stdin(
|
||||
dir.path(),
|
||||
&["run", "index.mq.md", "--output", "json"],
|
||||
b"abcd",
|
||||
);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(0),
|
||||
@@ -346,8 +378,10 @@ fn piped_stdin_is_chunked_and_reaches_eof() {
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output");
|
||||
assert_eq!(report["success"], true);
|
||||
let values = report["value"]["items"].as_array().expect("list result");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let values = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list result");
|
||||
assert_eq!(values[0]["decimal"], "2");
|
||||
assert_eq!(values[1]["value"], false);
|
||||
assert_eq!(values[2]["decimal"], "2");
|
||||
@@ -393,7 +427,7 @@ const STDERR_WRITER: &str = r#"## @exec main
|
||||
fn program_stderr_is_separate_from_stdout_and_diagnostics() {
|
||||
let dir = TempDir::new("stderr");
|
||||
write_file(&dir.path().join("index.mq.md"), STDERR_WRITER);
|
||||
let output = cli(dir.path(), &["run", "index.mq.md", "--json"]);
|
||||
let output = cli(dir.path(), &["run", "index.mq.md", "--output", "json"]);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(0),
|
||||
@@ -401,10 +435,12 @@ fn program_stderr_is_separate_from_stdout_and_diagnostics() {
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output");
|
||||
assert_eq!(report["success"], true);
|
||||
assert_eq!(report["stdout"], "out");
|
||||
assert_eq!(report["stderr"], "err");
|
||||
let values = report["value"]["items"].as_array().expect("list result");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
assert_eq!(observation::text(&report, "stdout.chunk"), "out");
|
||||
assert_eq!(observation::text(&report, "stderr.chunk"), "err");
|
||||
let values = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list result");
|
||||
assert_eq!(values[0]["decimal"], "3");
|
||||
assert_eq!(values[1]["decimal"], "3");
|
||||
assert_eq!(values[2]["value"], true);
|
||||
@@ -433,7 +469,11 @@ import:
|
||||
fn stdlib_console_reads_lines_and_reports_eof() {
|
||||
let dir = TempDir::new("console");
|
||||
write_file(&dir.path().join("index.mq.md"), CONSOLE_READER);
|
||||
let output = cli_with_stdin(dir.path(), &["run", "index.mq.md", "--json"], b"one\ntwo\n");
|
||||
let output = cli_with_stdin(
|
||||
dir.path(),
|
||||
&["run", "index.mq.md", "--output", "json"],
|
||||
b"one\ntwo\n",
|
||||
);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(0),
|
||||
@@ -441,9 +481,11 @@ fn stdlib_console_reads_lines_and_reports_eof() {
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let report: serde_json::Value = serde_json::from_slice(&output.stdout).expect("json output");
|
||||
assert_eq!(report["success"], true);
|
||||
assert_eq!(report["stdout"], "one|two\n");
|
||||
let values = report["value"]["items"].as_array().expect("list result");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
assert_eq!(observation::text(&report, "stdout.chunk"), "one|two\n");
|
||||
let values = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list result");
|
||||
assert_eq!(values[0]["value"], true);
|
||||
assert_eq!(values[1]["value"], true);
|
||||
assert_eq!(values[2]["value"], false);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
//! CM-A08/P5 stdlib HTTP framing module tests.
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -15,7 +18,7 @@ fn repo_root() -> std::path::PathBuf {
|
||||
#[test]
|
||||
fn stdlib_http_parses_chunked_responses_and_builds_requests() {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", "tests/http.mq.md", "--json"])
|
||||
.args(["run", "tests/http.mq.md", "--output", "json"])
|
||||
.current_dir(repo_root().join("stdlib"))
|
||||
.env("MARQDO_STDLIB_DIR", repo_root().join("stdlib"))
|
||||
.output()
|
||||
@@ -27,8 +30,10 @@ fn stdlib_http_parses_chunked_responses_and_builds_requests() {
|
||||
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("list");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["decimal"], "200");
|
||||
assert_eq!(items[1]["value"], "OK");
|
||||
assert_eq!(items[2]["value"], "text/plain");
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
//! user import path (`std:` + the verified bundle), not through a conformance
|
||||
//! fixture or a Rust shortcut.
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
@@ -130,7 +133,7 @@ fn run_product_test(file: &TestFile) -> serde_json::Value {
|
||||
.args(["run"])
|
||||
.arg(stdlib_dir().join("tests").join(&file.name))
|
||||
.args(file.args.iter())
|
||||
.args(["--json"])
|
||||
.args(["--output", "json"])
|
||||
.current_dir(stdlib_dir())
|
||||
.env("MARQDO_STDLIB_DIR", stdlib_dir())
|
||||
.envs(
|
||||
@@ -196,9 +199,10 @@ fn the_whole_bundled_library_runs_through_std_imports() {
|
||||
for file in product_tests() {
|
||||
let _guard = lock_fs(&file.name);
|
||||
let report = run_product_test(&file);
|
||||
assert_eq!(report["success"], true, "{}", file.name);
|
||||
assert_eq!(report["run"]["status"], "ok", "{}", file.name);
|
||||
assert_eq!(
|
||||
report["stdout"], file.stdout,
|
||||
observation::text(&report, "stdout.chunk"),
|
||||
file.stdout,
|
||||
"{} wrote unexpected stdout",
|
||||
file.name
|
||||
);
|
||||
@@ -214,7 +218,9 @@ fn fs_test_exercises_the_file_operation_surface() {
|
||||
.find(|file| file.name == "fs.mq.md")
|
||||
.expect("fs test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["decimal"], "7");
|
||||
assert_eq!(items[2]["value"], true);
|
||||
@@ -244,7 +250,9 @@ fn json_test_parses_and_formats_nested_values() {
|
||||
.find(|file| file.name == "json.mq.md")
|
||||
.expect("json test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["decimal"], "1");
|
||||
assert_eq!(items[2]["value"], "说\"好");
|
||||
@@ -269,7 +277,9 @@ fn csv_test_parses_and_formats_quoted_rows() {
|
||||
.find(|file| file.name == "csv.mq.md")
|
||||
.expect("csv test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
let row = items[0]["items"].as_array().expect("row");
|
||||
assert_eq!(row.len(), 3);
|
||||
assert_eq!(row[0]["value"], "甲");
|
||||
@@ -298,7 +308,9 @@ fn path_test_joins_and_normalizes_project_paths() {
|
||||
.find(|file| file.name == "path.mq.md")
|
||||
.expect("path test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], "a/b/c");
|
||||
assert_eq!(items[1]["value"], "c.txt");
|
||||
assert_eq!(items[2]["value"], "a/b");
|
||||
@@ -318,7 +330,9 @@ fn regex_test_matches_anchors_classes_and_search() {
|
||||
.find(|file| file.name == "regex.mq.md")
|
||||
.expect("regex test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["value"], false);
|
||||
assert_eq!(items[2]["value"], true);
|
||||
@@ -347,7 +361,9 @@ fn datetime_test_formats_and_parses_utc_instants() {
|
||||
.find(|file| file.name == "datetime.mq.md")
|
||||
.expect("datetime test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], "1970-01-01T00:00:00Z");
|
||||
assert_eq!(items[1]["value"], "2023-11-14T22:13:20.123Z");
|
||||
assert_eq!(items[2]["decimal"], "0");
|
||||
@@ -365,7 +381,9 @@ fn clock_test_reports_project_mode_unix_millis() {
|
||||
.find(|file| file.name == "clock.mq.md")
|
||||
.expect("clock test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["value"], "Int");
|
||||
assert_eq!(items[2]["value"], true);
|
||||
@@ -379,7 +397,9 @@ fn env_test_reads_only_granted_names() {
|
||||
.find(|file| file.name == "env.mq.md")
|
||||
.expect("env test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["value"], true);
|
||||
assert_eq!(items[2]["value"], true);
|
||||
@@ -396,7 +416,9 @@ fn process_test_runs_an_explicitly_granted_program() {
|
||||
.find(|file| file.name == "process.mq.md")
|
||||
.expect("process test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["decimal"], "0");
|
||||
let expected = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
@@ -420,7 +442,9 @@ fn random_test_reads_bounded_entropy() {
|
||||
.find(|file| file.name == "random.mq.md")
|
||||
.expect("random test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["decimal"], "16");
|
||||
assert_eq!(items[2]["value"], true);
|
||||
@@ -436,7 +460,9 @@ fn compress_test_round_trips_gzip_text() {
|
||||
.find(|file| file.name == "compress.mq.md")
|
||||
.expect("compress test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["value"], true);
|
||||
assert_eq!(items[1]["value"], true);
|
||||
assert_eq!(items[2]["value"], true);
|
||||
@@ -451,7 +477,9 @@ fn format_test_pins_value_semantics_and_handle_observation() {
|
||||
.find(|file| file.name == "format.mq.md")
|
||||
.expect("format test"),
|
||||
);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items[0]["decimal"], "3");
|
||||
assert_eq!(items[1]["value"], "[\"文本\", 2, 1.5]");
|
||||
assert_eq!(items[2]["value"], "{a: 1}");
|
||||
@@ -473,12 +501,30 @@ fn text_and_utf8_tests_agree_on_the_byte_encoding() {
|
||||
.find(|file| file.name == "utf8.mq.md")
|
||||
.expect("utf8 test"),
|
||||
);
|
||||
assert_eq!(text["value"]["items"][0]["decimal"], "2");
|
||||
assert_eq!(text["value"]["items"][1]["decimal"], "195");
|
||||
assert_eq!(text["value"]["items"][2]["decimal"], "169");
|
||||
assert_eq!(utf8["value"]["items"][0]["decimal"], "2");
|
||||
assert_eq!(utf8["value"]["items"][1]["value"], "é");
|
||||
assert_eq!(utf8["value"]["items"][2]["value"], false);
|
||||
assert_eq!(
|
||||
observation::terminal(&text)["value"]["items"][0]["decimal"],
|
||||
"2"
|
||||
);
|
||||
assert_eq!(
|
||||
observation::terminal(&text)["value"]["items"][1]["decimal"],
|
||||
"195"
|
||||
);
|
||||
assert_eq!(
|
||||
observation::terminal(&text)["value"]["items"][2]["decimal"],
|
||||
"169"
|
||||
);
|
||||
assert_eq!(
|
||||
observation::terminal(&utf8)["value"]["items"][0]["decimal"],
|
||||
"2"
|
||||
);
|
||||
assert_eq!(
|
||||
observation::terminal(&utf8)["value"]["items"][1]["value"],
|
||||
"é"
|
||||
);
|
||||
assert_eq!(
|
||||
observation::terminal(&utf8)["value"]["items"][2]["value"],
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -489,8 +535,14 @@ fn stream_and_console_use_the_resource_endpoints() {
|
||||
.find(|file| file.name == "stream.mq.md")
|
||||
.expect("stream test"),
|
||||
);
|
||||
assert_eq!(stream["value"]["items"][0]["value"], true);
|
||||
assert_eq!(stream["value"]["items"][1]["decimal"], "7");
|
||||
assert_eq!(
|
||||
observation::terminal(&stream)["value"]["items"][0]["value"],
|
||||
true
|
||||
);
|
||||
assert_eq!(
|
||||
observation::terminal(&stream)["value"]["items"][1]["decimal"],
|
||||
"7"
|
||||
);
|
||||
|
||||
let console = run_product_test(
|
||||
product_tests()
|
||||
@@ -498,14 +550,21 @@ fn stream_and_console_use_the_resource_endpoints() {
|
||||
.find(|file| file.name == "console.mq.md")
|
||||
.expect("console test"),
|
||||
);
|
||||
assert_eq!(console["value"]["items"][0]["value"], true);
|
||||
assert_eq!(console["value"]["items"][1]["value"], "hello");
|
||||
assert_eq!(
|
||||
observation::terminal(&console)["value"]["items"][0]["value"],
|
||||
true
|
||||
);
|
||||
assert_eq!(
|
||||
observation::terminal(&console)["value"]["items"][1]["value"],
|
||||
"hello"
|
||||
);
|
||||
assert!(
|
||||
console["trace"]
|
||||
console["events"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|event| event["op"] == "resource.read" || event["op"] == "resource.open"),
|
||||
.any(|event| event["payload"]["operation"] == "resource.read"
|
||||
|| event["payload"]["operation"] == "resource.open"),
|
||||
"console test did not go through a resource endpoint"
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
//! CM-A08 table stdlib module tests.
|
||||
|
||||
#[path = "support/observation.rs"]
|
||||
pub mod observation;
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -14,7 +17,7 @@ fn repo_root() -> std::path::PathBuf {
|
||||
|
||||
fn run_table_self_test() -> serde_json::Value {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["run", "tests/table.mq.md", "--json"])
|
||||
.args(["run", "tests/table.mq.md", "--output", "json"])
|
||||
.current_dir(repo_root().join("stdlib"))
|
||||
.env("MARQDO_STDLIB_DIR", repo_root().join("stdlib"))
|
||||
.output()
|
||||
@@ -35,8 +38,10 @@ fn rows(value: &serde_json::Value) -> &Vec<serde_json::Value> {
|
||||
#[test]
|
||||
fn stdlib_table_algorithms_rebuild_without_mutating_inputs() {
|
||||
let report = run_table_self_test();
|
||||
assert_eq!(report["success"], true);
|
||||
let items = report["value"]["items"].as_array().expect("list");
|
||||
assert_eq!(report["run"]["status"], "ok");
|
||||
let items = observation::terminal(&report)["value"]["items"]
|
||||
.as_array()
|
||||
.expect("list");
|
||||
assert_eq!(items.len(), 9);
|
||||
|
||||
assert_eq!(items[0]["header"], serde_json::json!(["分数"]));
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//! Helpers for black-box tests that inspect values or committed program bytes.
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
pub fn terminal(snapshot: &Value) -> &Value {
|
||||
assert_eq!(snapshot["schema"], "marqdo.observation");
|
||||
let event = snapshot["events"].as_array().unwrap().last().unwrap();
|
||||
assert!(matches!(
|
||||
event["kind"].as_str(),
|
||||
Some("run.completed" | "run.failed" | "run.rejected")
|
||||
));
|
||||
&event["payload"]
|
||||
}
|
||||
|
||||
pub fn text(snapshot: &Value, channel: &str) -> String {
|
||||
let bytes = snapshot["events"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|event| event["kind"] == channel)
|
||||
.flat_map(|event| {
|
||||
let payload = &event["payload"];
|
||||
let bytes = base64_decode(payload["data_base64"].as_str().unwrap());
|
||||
assert_eq!(payload["byte_count"], bytes.len());
|
||||
bytes
|
||||
})
|
||||
.collect();
|
||||
String::from_utf8(bytes).unwrap()
|
||||
}
|
||||
|
||||
fn base64_decode(text: &str) -> Vec<u8> {
|
||||
const ALPHABET: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
let mut out = Vec::new();
|
||||
let bytes: Vec<u8> = text
|
||||
.bytes()
|
||||
.filter(|byte| *byte != b'=')
|
||||
.map(|byte| {
|
||||
ALPHABET
|
||||
.iter()
|
||||
.position(|item| *item == byte)
|
||||
.unwrap_or_else(|| panic!("invalid base64 byte {byte}")) as u8
|
||||
})
|
||||
.collect();
|
||||
for chunk in bytes.chunks(4) {
|
||||
let mut triple = 0u32;
|
||||
for (index, byte) in chunk.iter().enumerate() {
|
||||
triple |= u32::from(*byte) << (18 - 6 * index);
|
||||
}
|
||||
out.push((triple >> 16) as u8);
|
||||
if chunk.len() > 2 {
|
||||
out.push((triple >> 8) as u8);
|
||||
}
|
||||
if chunk.len() > 3 {
|
||||
out.push(triple as u8);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -8,6 +8,8 @@ use std::process::{Command, Output};
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use sha2::Digest;
|
||||
|
||||
static COUNTER: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
struct TempDir(PathBuf);
|
||||
@@ -137,20 +139,18 @@ fn write_sample_from_source(dir: &Path, command: &str) -> PathBuf {
|
||||
.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}","requires":{{"api_revision":1,"analysis":3,"observation":1}}}}"#
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let template = root.join(format!("examples/tool-samples/{command}/tool.json"));
|
||||
let mut document: serde_json::Value =
|
||||
serde_json::from_slice(&std::fs::read(template).unwrap()).unwrap();
|
||||
document["entrypoint"] =
|
||||
serde_json::json!(format!("bin/{command}{}", std::env::consts::EXE_SUFFIX));
|
||||
std::fs::write(&manifest, document.to_string()).unwrap();
|
||||
manifest
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn independent_sample_tools_consume_public_analysis_and_trace() {
|
||||
fn independent_sample_tools_consume_public_analysis_and_observation() {
|
||||
let dir = TempDir::new("samples");
|
||||
let home = dir.path().join("home");
|
||||
let analysis = dir.path().join("analysis.json");
|
||||
@@ -170,7 +170,11 @@ fn independent_sample_tools_consume_public_analysis_and_trace() {
|
||||
.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"])
|
||||
.args([
|
||||
"run",
|
||||
"examples/multi-module/index.mq.md",
|
||||
"--observation-file",
|
||||
])
|
||||
.arg(&trace)
|
||||
.current_dir(&root)
|
||||
.output()
|
||||
@@ -207,15 +211,15 @@ fn independent_sample_tools_consume_public_analysis_and_trace() {
|
||||
|
||||
let knowledge = cli(
|
||||
&home,
|
||||
&["sample-knowledge", "--trace", trace.to_str().unwrap()],
|
||||
&["sample-knowledge", "--analysis", analysis.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.contains("sample-knowledge schema=marqdo.analysis version=3"),
|
||||
"{text}"
|
||||
);
|
||||
assert!(text.contains("status=ok"), "{text}");
|
||||
assert!(text.contains("reference_sets="), "{text}");
|
||||
|
||||
let proof = cli(
|
||||
&home,
|
||||
@@ -223,14 +227,20 @@ fn independent_sample_tools_consume_public_analysis_and_trace() {
|
||||
"sample-proof",
|
||||
"--analysis",
|
||||
analysis.to_str().unwrap(),
|
||||
"--trace",
|
||||
"--observation",
|
||||
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}");
|
||||
let digest = format!(
|
||||
"sha256:{:x}",
|
||||
sha2::Sha256::digest(std::fs::read(&analysis).unwrap())
|
||||
);
|
||||
assert!(
|
||||
text.contains(&format!("sample-proof claimed_digest={digest}")),
|
||||
"{text}"
|
||||
);
|
||||
|
||||
for command in ["sample-view", "sample-knowledge", "sample-proof"] {
|
||||
let removed = cli(&home, &["tool", "remove", command]);
|
||||
|
||||
Reference in new issue
Block a user