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
a802f96b6e
109 files changed
+14000
-6461
No files matched your search
+102
-58
@@ -1,47 +1,81 @@
|
||||
//! Rendering contract tests: one renderer, safe Markdown, exact source view,
|
||||
//! verified semantic annotations and Live/Export link differences.
|
||||
//! verified Analysis v3 annotations and Live/Export link differences.
|
||||
|
||||
use marqdo_view::config::ViewConfig;
|
||||
use marqdo_view::protocol::analysis_v2 as semantic;
|
||||
use marqdo_view::reader::assemble::{self as assemble, BuildInput};
|
||||
use marqdo_view::protocol::analysis_v3;
|
||||
use marqdo_view::reader::assemble::{build, BuildInput};
|
||||
use marqdo_view::reader::markdown::{DocumentIdentity, DocumentModel};
|
||||
use marqdo_view::reader::model::{Navigation, SourceStatus};
|
||||
use marqdo_view::reader::render::{ReaderRenderer, RenderContext};
|
||||
use marqdo_view::reader::source::{Project, SafeRelativePath};
|
||||
|
||||
fn example(name: &str) -> (marqdo_view::reader::model::PresentationModel, String) {
|
||||
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("examples")
|
||||
.join(name);
|
||||
let project = Project::open(&root).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let source = project.read_source_text(&entry).unwrap();
|
||||
let document = DocumentModel::parse(source.clone(), DocumentIdentity::placeholder(&entry));
|
||||
let golden_name = name;
|
||||
let golden = std::fs::read(
|
||||
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("tests/golden/analysis-v2")
|
||||
.join(format!("{golden_name}.json")),
|
||||
)
|
||||
.unwrap_or_else(|err| panic!("missing golden for {name}: {err}"));
|
||||
let verified =
|
||||
semantic::verify_analysis(&golden, &source, &document.source_index, entry.as_str())
|
||||
.unwrap_or_else(|err| panic!("golden does not verify for {name}: {err}"));
|
||||
fn repo_root() -> std::path::PathBuf {
|
||||
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
}
|
||||
|
||||
fn example(
|
||||
name: &str,
|
||||
entry: &str,
|
||||
golden: &str,
|
||||
) -> (marqdo_view::reader::model::PresentationModel, String) {
|
||||
let project = Project::open(&repo_root().join("examples").join(name)).unwrap();
|
||||
let analysis = std::fs::read(repo_root().join(golden)).unwrap();
|
||||
let verified = analysis_v3::verify_analysis(&analysis, entry, None)
|
||||
.unwrap_or_else(|err| panic!("golden does not verify for {name}: {err}"));
|
||||
let source = verified.projection.source.clone();
|
||||
assert_eq!(
|
||||
verified.projection.source_digest,
|
||||
marqdo_view::reader::source::sha256_hex(source.as_bytes())
|
||||
);
|
||||
let entry_path = SafeRelativePath::parse(entry).unwrap();
|
||||
let document = DocumentModel::parse(source.clone(), DocumentIdentity::placeholder(&entry_path));
|
||||
let config = ViewConfig::load(project.root()).unwrap_or_default();
|
||||
let navigation = Navigation::from_project(&project, &config, &entry);
|
||||
let model = assemble::build(BuildInput {
|
||||
let navigation = Navigation::from_project(&project, &config, &entry_path);
|
||||
let model = build(BuildInput {
|
||||
document,
|
||||
analysis: Some(&verified),
|
||||
status: SourceStatus::StaticOk,
|
||||
status_note: None,
|
||||
diagnostics: Vec::new(),
|
||||
navigation,
|
||||
core_version: Some("3.0.0-beta.1".to_string()),
|
||||
core_version: Some("3.0.0-rc.4".to_string()),
|
||||
run: None,
|
||||
});
|
||||
(model, source)
|
||||
}
|
||||
|
||||
fn control_flow() -> (marqdo_view::reader::model::PresentationModel, String) {
|
||||
example(
|
||||
"control-flow",
|
||||
"index.mq.md",
|
||||
"tests/golden/analysis-v3/control-flow.json",
|
||||
)
|
||||
}
|
||||
|
||||
fn mixed_modes() -> (marqdo_view::reader::model::PresentationModel, String) {
|
||||
example(
|
||||
"mixed-modes",
|
||||
"index.mq.md",
|
||||
"tests/golden/analysis-v3/mixed-modes.json",
|
||||
)
|
||||
}
|
||||
|
||||
fn tables_math() -> (marqdo_view::reader::model::PresentationModel, String) {
|
||||
example(
|
||||
"tables-math",
|
||||
"index.mq.md",
|
||||
"tests/golden/analysis-v3/tables-math.json",
|
||||
)
|
||||
}
|
||||
|
||||
fn welcome() -> (marqdo_view::reader::model::PresentationModel, String) {
|
||||
example(
|
||||
"welcome",
|
||||
"00-welcome.mq.md",
|
||||
"tests/golden/analysis-v3/welcome.json",
|
||||
)
|
||||
}
|
||||
|
||||
fn render_live(model: &marqdo_view::reader::model::PresentationModel) -> String {
|
||||
ReaderRenderer::new()
|
||||
.render(model, &RenderContext::live())
|
||||
@@ -60,8 +94,7 @@ fn heading_ids(html: &str) -> Vec<String> {
|
||||
let Some(after_tag) = part.split_once(' ') else {
|
||||
continue;
|
||||
};
|
||||
let rest = after_tag.1;
|
||||
if let Some(id_part) = rest.split_once("id=\"") {
|
||||
if let Some(id_part) = after_tag.1.split_once("id=\"") {
|
||||
if let Some((id, _)) = id_part.1.split_once('"') {
|
||||
ids.push(id.to_string());
|
||||
}
|
||||
@@ -72,7 +105,7 @@ fn heading_ids(html: &str) -> Vec<String> {
|
||||
|
||||
#[test]
|
||||
fn page_has_exactly_one_theme_and_one_script() {
|
||||
let (model, _) = example("mixed-modes");
|
||||
let (model, _) = mixed_modes();
|
||||
let html = render_live(&model);
|
||||
assert_eq!(html.matches("<link rel=\"stylesheet\"").count(), 1);
|
||||
assert_eq!(
|
||||
@@ -84,14 +117,13 @@ fn page_has_exactly_one_theme_and_one_script() {
|
||||
assert!(html.contains("Content-Security-Policy"));
|
||||
assert!(html.contains("default-src 'none'"));
|
||||
assert!(html.contains("data-live=\"true\""));
|
||||
// The one source of prose is the Markdown document itself.
|
||||
assert!(html.contains("计算笔记"));
|
||||
assert!(html.contains("静态阅读"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semantic_annotations_come_from_analysis_and_are_unique() {
|
||||
let (model, _) = example("mixed-modes");
|
||||
let (model, _) = mixed_modes();
|
||||
let html = render_live(&model);
|
||||
assert!(html.contains("data-source-status=\"static-ok\""));
|
||||
assert!(html.contains("data-statement-kind=\"return\""));
|
||||
@@ -109,31 +141,29 @@ fn semantic_annotations_come_from_analysis_and_are_unique() {
|
||||
|
||||
#[test]
|
||||
fn tables_math_and_code_are_inert_and_readable() {
|
||||
let (model, source) = example("tables-math");
|
||||
let (model, source) = tables_math();
|
||||
let html = render_live(&model);
|
||||
assert!(html.contains("<table>"));
|
||||
assert!(html.contains("mq-table-wrap"));
|
||||
assert!(html.contains("mq-math-block"));
|
||||
assert!(html.contains("代码围栏永远是惰性资源"));
|
||||
assert!(html.contains("mq-codeblock"));
|
||||
// Inert resources are never executed: no run controls are enabled.
|
||||
assert!(html.contains("data-live=\"true\""));
|
||||
assert!(!html.contains("RUNNING"));
|
||||
// Source is preserved exactly in the textarea (escaped only).
|
||||
assert!(source.contains("```python"));
|
||||
assert!(html.contains("mq-raw-source"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn welcome_hero_only_when_configured() {
|
||||
let (welcome, _) = example("welcome");
|
||||
let (welcome, _) = welcome();
|
||||
let html = render_live(&welcome);
|
||||
assert!(welcome.navigation.welcome);
|
||||
assert!(html.contains("mq-welcome"));
|
||||
assert!(html.contains("WELCOME TO"));
|
||||
assert!(html.contains("代码即文档 · 文档即知识库 · 知识即可执行"));
|
||||
|
||||
let (ordinary, _) = example("tables-math");
|
||||
let (ordinary, _) = tables_math();
|
||||
let html = render_live(&ordinary);
|
||||
assert!(!ordinary.navigation.welcome);
|
||||
assert!(!html.contains("mq-welcome"));
|
||||
@@ -141,25 +171,23 @@ fn welcome_hero_only_when_configured() {
|
||||
|
||||
#[test]
|
||||
fn live_and_static_share_content_but_rewrite_links() {
|
||||
let (model, _) = example("welcome");
|
||||
let (model, _) = welcome();
|
||||
let live = render_live(&model);
|
||||
let static_site = render_static(&model, 0);
|
||||
assert!(live.contains("/file?path=guide.mq.md"));
|
||||
assert!(static_site.contains("pages/guide.mq.md.html"));
|
||||
assert!(!static_site.contains("/file?path="));
|
||||
// Same prose and semantics.
|
||||
for needle in ["欢迎来到 Marqdo", "代码即文档", "mq-document"] {
|
||||
assert!(live.contains(needle));
|
||||
assert!(static_site.contains(needle));
|
||||
assert!(live.contains(needle), "live misses {needle}");
|
||||
assert!(static_site.contains(needle), "static misses {needle}");
|
||||
}
|
||||
// Assets are relative from the site root.
|
||||
assert!(static_site.contains("href=\"assets/reader."));
|
||||
assert!(live.contains("href=\"/assets/reader."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn static_pages_use_parent_relative_assets_and_links() {
|
||||
let (model, _) = example("welcome");
|
||||
let (model, _) = welcome();
|
||||
let html = render_static(&model, 1);
|
||||
assert!(html.contains("href=\"../assets/reader."));
|
||||
assert!(html.contains("../pages/guide.mq.md.html"));
|
||||
@@ -193,17 +221,13 @@ fn malicious_markdown_cannot_inject_markup_or_scripts() {
|
||||
source_sha256: String::new(),
|
||||
},
|
||||
);
|
||||
let project = Project::open(
|
||||
&std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/tables-math"),
|
||||
)
|
||||
.unwrap();
|
||||
let config = ViewConfig::default();
|
||||
let project = Project::open(&repo_root().join("examples/tables-math")).unwrap();
|
||||
let navigation = Navigation::from_project(
|
||||
&project,
|
||||
&config,
|
||||
&ViewConfig::default(),
|
||||
&SafeRelativePath::parse("index.mq.md").unwrap(),
|
||||
);
|
||||
let model = assemble::build(BuildInput {
|
||||
let model = build(BuildInput {
|
||||
document,
|
||||
analysis: None,
|
||||
status: SourceStatus::CoreUnavailable,
|
||||
@@ -219,10 +243,7 @@ fn malicious_markdown_cannot_inject_markup_or_scripts() {
|
||||
assert!(!html.contains("<svg onload"));
|
||||
assert!(!html.contains("href=\"javascript:"));
|
||||
assert!(!html.contains("href=\"data:text/html"));
|
||||
// Ordinary page chrome (logo, dock icons) is allowed, but no tag carries an
|
||||
// attacker-supplied event handler.
|
||||
assert!(!html.contains("onerror=\"") && !html.contains("onload=\""));
|
||||
// The exact source is still available in the source pane, safely escaped.
|
||||
assert!(html.contains("<script>alert"));
|
||||
assert!(html.contains("https://example.com/ok"));
|
||||
assert!(html.contains("已忽略原始 HTML"));
|
||||
@@ -231,29 +252,26 @@ fn malicious_markdown_cannot_inject_markup_or_scripts() {
|
||||
|
||||
#[test]
|
||||
fn rendering_is_deterministic() {
|
||||
let (model, _) = example("control-flow");
|
||||
let first = render_live(&model);
|
||||
let second = render_live(&model);
|
||||
assert_eq!(first, second);
|
||||
let (model, _) = control_flow();
|
||||
assert_eq!(render_live(&model), render_live(&model));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_controls_are_explicitly_unavailable_before_pr04() {
|
||||
let (model, _) = example("control-flow");
|
||||
fn run_controls_are_explicitly_unavailable_before_an_explicit_run() {
|
||||
let (model, _) = control_flow();
|
||||
let html = render_live(&model);
|
||||
assert!(html.contains("data-live=\"true\""));
|
||||
assert!(
|
||||
html.contains("data-disabled=\"true\"") || html.contains("aria-disabled"),
|
||||
"run control must have an explicit disabled marker"
|
||||
);
|
||||
// No fake RUNNING/SUCCEEDED marker on a freshly opened document.
|
||||
assert!(!html.contains("data-run-state=\"running\""));
|
||||
assert!(!html.contains("data-run-state=\"succeeded\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reader_exposes_simple_theme_toggle_and_no_variable_or_memory_tabs() {
|
||||
let (model, _source) = example("welcome");
|
||||
let (model, _) = welcome();
|
||||
let html = render_live(&model);
|
||||
assert!(html.contains("data-theme=\"light\""));
|
||||
assert!(html.contains("data-action=\"theme\""));
|
||||
@@ -261,3 +279,29 @@ fn reader_exposes_simple_theme_toggle_and_no_variable_or_memory_tabs() {
|
||||
assert!(!html.contains("data-action=\"memory\""));
|
||||
assert!(html.contains("data-action=\"unsupported\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn headings_use_heading_span_while_sections_use_the_complete_span() {
|
||||
// ADR-0069: `heading_span` locates the heading node; the complete `span`
|
||||
// includes child sections. The renderer must not use the complete span as the
|
||||
// heading id source (that would shift ids when a section grows).
|
||||
let (model, _) = control_flow();
|
||||
let projection = model.semantic.as_ref().unwrap();
|
||||
for unit in &projection.units {
|
||||
if let Some(heading) = unit.heading_span {
|
||||
if unit.span != heading {
|
||||
assert!(unit.span.contains(heading));
|
||||
}
|
||||
}
|
||||
}
|
||||
let function = &projection.functions[0];
|
||||
let html = render_live(&model);
|
||||
let expected = marqdo_view::reader::model::anchor_for_span(
|
||||
function.heading_span.start,
|
||||
function.heading_span.end,
|
||||
);
|
||||
assert!(
|
||||
html.contains(&format!("id=\"{expected}\"")),
|
||||
"{expected} missing"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user