feat: migrate View 0.3.0 to marqdo 3.0.0-rc.4 contracts
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
Replace the retired rc.2 Analysis v2/Trace v2/Execution Events v1 stack with the
single current contract family:
- Analysis v3 (ADR-0069 public boundary): one check --emit artifact carries the
exact source, Markdown AST, heading scopes (heading_span + complete span),
anchors, state-bearing references, calls, resources and diagnostics; the old
revision-3 shape is rejected with a rebuild hint.
- Observation v1: one run/call --output jsonl stream (+ atomic
--observation-file snapshot) decoded by one decoder and projected into the
reader/SSE/export layers; stale/malformed/truncated/incomplete never render
as success.
- CLI Tool revision 1: requires {api_revision:1, analysis:3, observation:1},
product range >=3.0.0-rc.3,<4.0.0, only MARQDO_BIN and
MARQDO_API_REVISION are consumed.
- Remove compatibility branches, retired flags/env vars and duplicate decoders;
re-record Analysis v3 and Observation v1 fixtures; rewrite contract,
integration and security tests (173 passing locally).
- Add check-no-legacy/check-docs/check-observation gates, rc.4 pins in the
CI pipelines, 0.3.0 Tool bundle and evidence manifest support.
See issues #4, #5 and #6; acceptance baseline is CLI source
452e9a32bd9e40dba427d4180691c58bab74449e, archive
9c3f166b5e5b8840d39d10019074e4e1c42432fc23e26c69670e64fdcf4e15d8.
This commit is contained in:
1 parent
7b34199c96
commit
340ecb035f
108 files changed
+13928
-6461
No files matched your search
+397
-112
@@ -1,5 +1,5 @@
|
||||
//! Contract tests against a real fake-core executable: argv shape, exit codes,
|
||||
//! stderr handling, temp artifacts and process-tree cleanup.
|
||||
//! stderr handling, temp artifacts and the current Analysis v3 revision.
|
||||
//!
|
||||
//! The fake core is a shell script, not a mocked Rust trait, so everything at
|
||||
//! the process boundary is exercised for real.
|
||||
@@ -7,7 +7,9 @@
|
||||
use crate::common;
|
||||
|
||||
use common::{minimal_analysis, sha256_hex, FakeCore, TempProject};
|
||||
use marqdo_view::core_client::{CheckOptions, CheckResponse, CoreClient, RunOptions};
|
||||
use marqdo_view::core_client::{
|
||||
build_call_args, build_run_args, CheckOptions, CheckResponse, CoreClient, RunOptions,
|
||||
};
|
||||
use marqdo_view::reader::source::Project;
|
||||
|
||||
fn fixture(name: &str) -> (TempProject, FakeCore) {
|
||||
@@ -17,11 +19,15 @@ fn fixture(name: &str) -> (TempProject, FakeCore) {
|
||||
(project, core)
|
||||
}
|
||||
|
||||
fn project_source(project: &TempProject) -> String {
|
||||
std::fs::read_to_string(project.path("index.mq.md")).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_returns_exact_analysis_bytes_and_digest() {
|
||||
let (project, core) = fixture("check_ok");
|
||||
let source = std::fs::read(project.path("index.mq.md")).unwrap();
|
||||
let analysis = minimal_analysis("index.mq.md", &sha256_hex(&source), 2);
|
||||
let source = project_source(&project);
|
||||
let analysis = minimal_analysis("index.mq.md", &source, 3);
|
||||
core.set_analysis(&analysis);
|
||||
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
@@ -42,15 +48,18 @@ fn check_returns_exact_analysis_bytes_and_digest() {
|
||||
let args = core.last_args();
|
||||
assert_eq!(args[0], "check");
|
||||
assert!(args.contains(&"--emit".to_string()));
|
||||
// No `--refs` unless requested.
|
||||
assert!(!args.contains(&"--refs".to_string()));
|
||||
// The retired Analysis v2 selector and trace flags never appear.
|
||||
for retired in ["--trace-file", "--event-stream"] {
|
||||
assert!(!args.contains(&retired.to_string()), "retired {retired}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_refs_is_forwarded_as_a_stricter_flag() {
|
||||
let (project, core) = fixture("check_refs");
|
||||
let source = std::fs::read(project.path("index.mq.md")).unwrap();
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", &sha256_hex(&source), 2));
|
||||
let source = project_source(&project);
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", &source, 3));
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
@@ -85,107 +94,105 @@ fn check_failure_preserves_core_stderr_and_code() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_returns_json_and_raw_trace() {
|
||||
let (project, core) = fixture("run_ok");
|
||||
core.set_run(
|
||||
0,
|
||||
r#"{"command":"run","success":true,"stdout":"ok","stderr":"","trace":[]}"#,
|
||||
Some(r#"{"schema":"marqdo.trace","schema_version":2,"events":[]}"#),
|
||||
fn run_and_call_argv_use_the_current_observation_flags_only() {
|
||||
let args = build_run_args(
|
||||
std::path::Path::new("/p/index.mq.md"),
|
||||
std::path::Path::new("/t/observation.json"),
|
||||
&RunOptions::default(),
|
||||
);
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let output = client
|
||||
.run(&project, &entry, &RunOptions::default())
|
||||
.unwrap();
|
||||
assert_eq!(output.exit_code, 0);
|
||||
assert_eq!(output.json["success"], true);
|
||||
let trace = output.trace_bytes.expect("trace bytes");
|
||||
assert_eq!(output.trace_sha256.unwrap(), sha256_hex(&trace));
|
||||
// Mode is always explicit; pure is the View default.
|
||||
let args = core.last_args();
|
||||
assert!(args.contains(&"--mode".to_string()));
|
||||
let mode_index = args.iter().position(|a| a == "--mode").unwrap();
|
||||
assert_eq!(args[mode_index + 1], "pure");
|
||||
assert!(args.contains(&"--json".to_string()));
|
||||
assert!(args.contains(&"--trace-file".to_string()));
|
||||
let text: Vec<String> = args
|
||||
.iter()
|
||||
.map(|arg| arg.to_string_lossy().to_string())
|
||||
.collect();
|
||||
assert_eq!(text[0], "run");
|
||||
assert!(text.contains(&"--mode".to_string()));
|
||||
assert!(text.contains(&"pure".to_string()));
|
||||
assert!(text.contains(&"--output".to_string()));
|
||||
assert!(text.contains(&"jsonl".to_string()));
|
||||
assert!(text.contains(&"--observation-file".to_string()));
|
||||
assert!(text.contains(&"--observe-max-events".to_string()));
|
||||
assert!(text.contains(&"--observe-max-bytes".to_string()));
|
||||
assert!(text.contains(&"--observe-max-value-bytes".to_string()));
|
||||
for retired in [
|
||||
"--json",
|
||||
"--trace-file",
|
||||
"--event-stream",
|
||||
"--trace-max-events",
|
||||
"--trace-max-bytes",
|
||||
"--trace-max-value-bytes",
|
||||
] {
|
||||
assert!(
|
||||
!text.contains(&retired.to_string()),
|
||||
"retired flag {retired}"
|
||||
);
|
||||
}
|
||||
assert!(!text
|
||||
.iter()
|
||||
.any(|token| token.contains(';') || token.contains('|') || token.contains('&')));
|
||||
|
||||
let args = build_call_args(
|
||||
std::path::Path::new("/p/index.mq.md"),
|
||||
"demo.calculate",
|
||||
&[("n".to_string(), "3".to_string())],
|
||||
std::path::Path::new("/t/observation.json"),
|
||||
&RunOptions::default(),
|
||||
);
|
||||
let text: Vec<String> = args
|
||||
.iter()
|
||||
.map(|arg| arg.to_string_lossy().to_string())
|
||||
.collect();
|
||||
assert_eq!(text[0], "call");
|
||||
assert!(text.contains(&"--arg".to_string()));
|
||||
assert!(text.contains(&"n=3".to_string()));
|
||||
assert!(text.contains(&"--observation-file".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_without_trace_file_reports_no_trace() {
|
||||
let (project, core) = fixture("run_no_trace");
|
||||
core.set_run(
|
||||
0,
|
||||
r#"{"command":"run","success":true,"stdout":"","stderr":"","trace":[]}"#,
|
||||
None,
|
||||
);
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let output = client
|
||||
.run(&project, &entry, &RunOptions::default())
|
||||
.unwrap();
|
||||
assert!(output.trace_bytes.is_none());
|
||||
assert!(output.trace_sha256.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_invalid_json_is_a_protocol_io_error() {
|
||||
let (project, core) = fixture("run_bad_json");
|
||||
core.set_run(0, "this is not json", None);
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let err = client
|
||||
.run(&project, &entry, &RunOptions::default())
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.io");
|
||||
assert!(err.to_string().contains("exactly one JSON"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timeout_kills_the_process_group_and_reports_timeout() {
|
||||
let (project, core) = fixture("run_timeout");
|
||||
core.set_sleep_seconds(5);
|
||||
core.set_run(0, r#"{"command":"run","success":true}"#, None);
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let started = std::time::Instant::now();
|
||||
let err = client
|
||||
.run(
|
||||
&project,
|
||||
&entry,
|
||||
&RunOptions {
|
||||
view_timeout: Some(std::time::Duration::from_millis(300)),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap_err();
|
||||
let elapsed = started.elapsed();
|
||||
assert_eq!(err.code(), "view.core_timeout");
|
||||
assert!(
|
||||
elapsed < std::time::Duration::from_secs(3),
|
||||
"timeout took {elapsed:?}"
|
||||
fn default_run_does_not_request_variable_or_parameter_values() {
|
||||
let args = build_run_args(
|
||||
std::path::Path::new("/p/index.mq.md"),
|
||||
std::path::Path::new("/t/observation.json"),
|
||||
&RunOptions::default(),
|
||||
);
|
||||
let text: Vec<String> = args
|
||||
.iter()
|
||||
.map(|arg| arg.to_string_lossy().to_string())
|
||||
.collect();
|
||||
// Budgets are explicit, but no value name is selected by default.
|
||||
for flag in [
|
||||
"--observe-variable",
|
||||
"--observe-parameter",
|
||||
"--observe-text-values",
|
||||
] {
|
||||
assert!(!text.contains(&flag.to_string()), "default {flag}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incompatible_product_version_is_rejected_before_any_work() {
|
||||
let (project, core) = fixture("version_old");
|
||||
core.set_version("marqdo 2.9.1\n");
|
||||
let (_project, core) = fixture("version_old");
|
||||
core.set_version("marqdo 3.0.0-rc.2\n");
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let err = client.negotiate().unwrap_err();
|
||||
assert_eq!(err.code(), "view.protocol_incompatible");
|
||||
assert_eq!(err.exit_code(), 2);
|
||||
// Only `--version` was invoked; no check/run happened.
|
||||
assert_eq!(core.last_args(), vec!["--version".to_string()]);
|
||||
let _ = project;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn current_rc_version_is_accepted() {
|
||||
let (_project, core) = fixture("version_rc4");
|
||||
core.set_version("marqdo 3.0.0-rc.4\n");
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
assert_eq!(
|
||||
client.negotiate().unwrap().version.to_string(),
|
||||
"3.0.0-rc.4"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_emit_after_success_is_an_analysis_failure() {
|
||||
// Fake core exits 0 but writes nothing: never accept a phantom analysis.
|
||||
let (project, core) = fixture("check_no_emit");
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
@@ -196,11 +203,6 @@ fn missing_emit_after_success_is_an_analysis_failure() {
|
||||
assert_eq!(err.code(), "view.analysis_failed");
|
||||
}
|
||||
|
||||
fn expect_check_ok(response: CheckResponse) -> marqdo_view::core_client::CheckOutput {
|
||||
assert!(response.success, "check failed: {:?}", response.diagnostics);
|
||||
response.analysis.expect("analysis on success")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_check_normalizes_diagnostics_without_absolute_paths() {
|
||||
let (project, core) = fixture("check_diagnostics");
|
||||
@@ -218,44 +220,152 @@ fn failed_check_normalizes_diagnostics_without_absolute_paths() {
|
||||
assert_eq!(response.diagnostics.len(), 1);
|
||||
assert_eq!(response.diagnostics[0].code, "sem.unclosed_control");
|
||||
assert_eq!(response.diagnostics[0].line, Some(5));
|
||||
// The raw absolute `file` field is not part of the normalized type at all.
|
||||
let rendered = serde_json::to_string(&response.diagnostics).unwrap();
|
||||
assert!(!rendered.contains("/home/secret"), "{rendered}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_verify_end_to_end_against_fake_core() {
|
||||
let (project, core) = fixture("verify_cli");
|
||||
let source = std::fs::read(project.path("index.mq.md")).unwrap();
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", &sha256_hex(&source), 2));
|
||||
fn analysis_v2_revision_is_a_hard_protocol_error() {
|
||||
let (project, core) = fixture("analysis_v2");
|
||||
let source = project_source(&project);
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", &source, 2));
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let check = expect_check_ok(
|
||||
client
|
||||
.check(&project, &entry, &CheckOptions::default())
|
||||
.unwrap(),
|
||||
);
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
&check.analysis_bytes,
|
||||
entry.as_str(),
|
||||
Some(&source),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.protocol_incompatible");
|
||||
assert_eq!(err.exit_code(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retired_revision_3_shape_is_rejected_with_a_rebuild_hint() {
|
||||
let (project, core) = fixture("analysis_old_shape");
|
||||
let source = project_source(&project);
|
||||
let mut analysis: serde_json::Value =
|
||||
serde_json::from_str(&minimal_analysis("index.mq.md", &source, 3)).unwrap();
|
||||
// An old same-revision artifact has no source/document/anchors/entry id.
|
||||
let module = analysis["modules"][0].as_object_mut().unwrap();
|
||||
module.remove("source");
|
||||
module.remove("document");
|
||||
module.remove("anchors");
|
||||
analysis["project"]
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.remove("entry_module_id");
|
||||
core.set_analysis(&analysis.to_string());
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let check = expect_check_ok(
|
||||
client
|
||||
.check(&project, &entry, &CheckOptions::default())
|
||||
.unwrap(),
|
||||
);
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
&check.analysis_bytes,
|
||||
entry.as_str(),
|
||||
Some(&source),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.protocol_incompatible");
|
||||
assert!(err.to_string().contains("revision 3"), "{err}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_digest_mismatch_is_not_silently_accepted() {
|
||||
let (project, core) = fixture("analysis_digest_mismatch");
|
||||
let source = project_source(&project);
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", "# another document\n", 3));
|
||||
let client = CoreClient::with_bin(&core.script).unwrap();
|
||||
let project = Project::open(&project.path("index.mq.md")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let check = expect_check_ok(
|
||||
client
|
||||
.check(&project, &entry, &CheckOptions::default())
|
||||
.unwrap(),
|
||||
);
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
&check.analysis_bytes,
|
||||
entry.as_str(),
|
||||
Some(&source),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.source_mismatch");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_api_revision_environment_is_an_exact_expectation() {
|
||||
// Pure validation: no process-global environment mutation (which would race
|
||||
// with tests running in parallel).
|
||||
use marqdo_view::protocol::tool_v1;
|
||||
assert!(tool_v1::validate_api_revision_env(None).is_ok());
|
||||
assert!(tool_v1::validate_api_revision_env(Some("1")).is_ok());
|
||||
let err = tool_v1::validate_api_revision_env(Some("2")).unwrap_err();
|
||||
assert_eq!(err.code(), "view.protocol_incompatible");
|
||||
assert!(tool_v1::validate_api_revision_env(Some("nope")).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn installed_tool_api_revision_is_enforced_at_the_process_boundary() {
|
||||
let (project, core) = fixture("api_revision_cli");
|
||||
core.set_analysis(&minimal_analysis(
|
||||
"index.mq.md",
|
||||
&project_source(&project),
|
||||
3,
|
||||
));
|
||||
let script = core.script.to_str().unwrap().to_string();
|
||||
let dir = project.dir.to_str().unwrap().to_string();
|
||||
let output = common::run_view(
|
||||
&["verify", "index.mq.md", "--marqdo-bin", &script],
|
||||
std::path::Path::new(&dir),
|
||||
&[
|
||||
("MARQDO_BIN", None),
|
||||
("MARQDO_TOOL_PROTOCOL", None),
|
||||
("MARQDO_PROTOCOL_ANALYSIS", None),
|
||||
("MARQDO_PROTOCOL_TRACE", None),
|
||||
],
|
||||
&[("MARQDO_BIN", None), ("MARQDO_API_REVISION", Some("2"))],
|
||||
);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert_eq!(output.status.code(), Some(2), "stderr: {stderr}");
|
||||
assert!(
|
||||
stderr.contains("view.protocol_incompatible"),
|
||||
"stderr: {stderr}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_verify_end_to_end_against_fake_core() {
|
||||
let (project, core) = fixture("verify_cli");
|
||||
let source = project_source(&project);
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", &source, 3));
|
||||
let script = core.script.to_str().unwrap().to_string();
|
||||
let dir = project.dir.to_str().unwrap().to_string();
|
||||
let output = common::run_view(
|
||||
&["verify", "index.mq.md", "--marqdo-bin", &script],
|
||||
std::path::Path::new(&dir),
|
||||
&[("MARQDO_BIN", None), ("MARQDO_API_REVISION", None)],
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert_eq!(output.status.code(), Some(0), "stderr: {stderr}");
|
||||
assert!(stdout.contains("result: PASS"), "{stdout}");
|
||||
assert!(stdout.contains("marqdo 3.0.0-beta.1"), "{stdout}");
|
||||
assert!(stdout.contains("marqdo 3.0.0-rc.4"), "{stdout}");
|
||||
assert!(!stdout.contains(&dir), "absolute path leaked: {stdout}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_verify_rejects_schema_v4_and_digest_mismatch() {
|
||||
fn cli_verify_rejects_schema_v2_and_digest_mismatch() {
|
||||
let (project, core) = fixture("verify_negative");
|
||||
let source = std::fs::read(project.path("index.mq.md")).unwrap();
|
||||
let source = project_source(&project);
|
||||
let script = core.script.to_str().unwrap().to_string();
|
||||
let dir = project.dir.to_str().unwrap().to_string();
|
||||
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", &sha256_hex(&source), 4));
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", &source, 2));
|
||||
let output = common::run_view(
|
||||
&["verify", "index.mq.md", "--marqdo-bin", &script],
|
||||
std::path::Path::new(&dir),
|
||||
@@ -264,12 +374,187 @@ fn cli_verify_rejects_schema_v4_and_digest_mismatch() {
|
||||
assert_eq!(output.status.code(), Some(2));
|
||||
assert!(String::from_utf8_lossy(&output.stderr).contains("view.protocol_incompatible"));
|
||||
|
||||
core.set_analysis(&minimal_analysis("index.mq.md", &"0".repeat(64), 2));
|
||||
// A different, internally consistent document: the exact artifact does not
|
||||
// bind to the checked source. This is a source-mismatch, not a silent retry.
|
||||
core.set_analysis(&minimal_analysis(
|
||||
"index.mq.md",
|
||||
"# a different but internally consistent document\n",
|
||||
3,
|
||||
));
|
||||
let output = common::run_view(
|
||||
&["verify", "index.mq.md", "--marqdo-bin", &script],
|
||||
std::path::Path::new(&dir),
|
||||
&[("MARQDO_BIN", None)],
|
||||
);
|
||||
assert_eq!(output.status.code(), Some(1));
|
||||
assert!(String::from_utf8_lossy(&output.stderr).contains("view.source_mismatch"));
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(1),
|
||||
"stderr: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
assert!(
|
||||
String::from_utf8_lossy(&output.stderr).contains("view.source_mismatch"),
|
||||
"stderr: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
|
||||
// A forged source_digest is an internal artifact inconsistency.
|
||||
let mut analysis: serde_json::Value =
|
||||
serde_json::from_str(&minimal_analysis("index.mq.md", &source, 3)).unwrap();
|
||||
analysis["modules"][0]["source_digest"] = serde_json::json!("0".repeat(64));
|
||||
core.set_analysis(&analysis.to_string());
|
||||
let output = common::run_view(
|
||||
&["verify", "index.mq.md", "--marqdo-bin", &script],
|
||||
std::path::Path::new(&dir),
|
||||
&[("MARQDO_BIN", None)],
|
||||
);
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(1),
|
||||
"stderr: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
assert!(
|
||||
String::from_utf8_lossy(&output.stderr).contains("view.analysis_failed"),
|
||||
"stderr: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
|
||||
fn expect_check_ok(response: CheckResponse) -> marqdo_view::core_client::CheckOutput {
|
||||
assert!(response.success, "check failed: {:?}", response.diagnostics);
|
||||
response.analysis.expect("analysis on success")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_analysis_schema_name_or_major_is_rejected() {
|
||||
// N02: an artifact with the wrong schema identity or an unknown major is a
|
||||
// protocol error; there is no guess or fallback decoder.
|
||||
let source = "# @knowledge fixture\n";
|
||||
let mut analysis: serde_json::Value =
|
||||
serde_json::from_str(&minimal_analysis("index.mq.md", source, 3)).unwrap();
|
||||
analysis["schema"] = serde_json::json!("marqdo.analysis.legacy");
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
analysis.to_string().as_bytes(),
|
||||
"index.mq.md",
|
||||
None,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.protocol_incompatible");
|
||||
|
||||
let mut analysis: serde_json::Value =
|
||||
serde_json::from_str(&minimal_analysis("index.mq.md", source, 3)).unwrap();
|
||||
analysis["schema_version"] = serde_json::json!(5);
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
analysis.to_string().as_bytes(),
|
||||
"index.mq.md",
|
||||
None,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.protocol_incompatible");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_required_analysis_fields_are_rejected() {
|
||||
// N03: required fields are not optional; a missing module/document/unit field
|
||||
// must never decode as an empty, successful document.
|
||||
for field in ["modules", "diagnostics"] {
|
||||
let source = "# @knowledge fixture\n";
|
||||
let mut analysis: serde_json::Value =
|
||||
serde_json::from_str(&minimal_analysis("index.mq.md", source, 3)).unwrap();
|
||||
analysis.as_object_mut().unwrap().remove(field);
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
analysis.to_string().as_bytes(),
|
||||
"index.mq.md",
|
||||
None,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.protocol_incompatible", "field {field}");
|
||||
}
|
||||
let source = "# @knowledge fixture\n";
|
||||
let mut analysis: serde_json::Value =
|
||||
serde_json::from_str(&minimal_analysis("index.mq.md", source, 3)).unwrap();
|
||||
analysis["modules"][0]
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.remove("functions");
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
analysis.to_string().as_bytes(),
|
||||
"index.mq.md",
|
||||
None,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.protocol_incompatible");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_module_and_unit_references_are_rejected() {
|
||||
// N08: resolved references, imports, functions and anchors must point at
|
||||
// records that exist in the same artifact.
|
||||
let source = "# @knowledge fixture\n";
|
||||
let base = minimal_analysis("index.mq.md", source, 3);
|
||||
let module_id = serde_json::from_str::<serde_json::Value>(&base).unwrap()["modules"][0]["id"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let mut analysis: serde_json::Value = serde_json::from_str(&base).unwrap();
|
||||
analysis["modules"][0]["references"] = serde_json::json!([{
|
||||
"source": module_id,
|
||||
"source_unit": format!("{module_id}#missing"),
|
||||
"url": "./theory.mq.md",
|
||||
"span": {"start": 0, "end": 1},
|
||||
"state": "resolved",
|
||||
"target_kind": "module",
|
||||
"target_module": module_id,
|
||||
"target_unit": null,
|
||||
"candidate_package_instance_id": "root:fixture@0.1.0",
|
||||
"candidate_path": "theory.mq.md",
|
||||
"fragment": null,
|
||||
"candidates": []
|
||||
}]);
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
analysis.to_string().as_bytes(),
|
||||
"index.mq.md",
|
||||
None,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.analysis_failed");
|
||||
|
||||
let mut analysis: serde_json::Value = serde_json::from_str(&base).unwrap();
|
||||
analysis["modules"][0]["imports"] = serde_json::json!([{
|
||||
"alias": "theory",
|
||||
"target": "./theory.mq.md",
|
||||
"resolved": "root:fixture@0.1.0::theory.mq.md",
|
||||
"span": {"start": 0, "end": 1}
|
||||
}]);
|
||||
let err = marqdo_view::protocol::analysis_v3::verify_analysis(
|
||||
analysis.to_string().as_bytes(),
|
||||
"index.mq.md",
|
||||
None,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err.code(), "view.analysis_failed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strict_mode_run_request_is_rejected_by_view_validation() {
|
||||
// N13: View never passes a `strict` mode to the CLI. The request schema
|
||||
// rejects it before any process starts (no retry with project).
|
||||
let body = serde_json::json!({
|
||||
"document": "index.mq.md",
|
||||
"target": {"kind": "entry"},
|
||||
"analysis_digest": format!("sha256:{}", "0".repeat(64)),
|
||||
"mode": "strict",
|
||||
"grants": {"read": [], "write": []},
|
||||
"client_request_id": "strict-1"
|
||||
})
|
||||
.to_string();
|
||||
let err = marqdo_view::execution::request::validate_request(body.as_bytes()).unwrap_err();
|
||||
assert!(
|
||||
matches!(err.code(), "view.run_invalid" | "view.run_denied"),
|
||||
"strict mode must be refused before spawn, got {}",
|
||||
err.code()
|
||||
);
|
||||
assert_eq!(err.exit_code(), 2);
|
||||
}
|
||||
Reference in new issue
Block a user