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
@@ -1,11 +1,12 @@
|
||||
//! Unicode/CRLF/duplicate-text span contract (RFC-VIEW-0001 S-04).
|
||||
//! Goldens are emitted by the frozen CLI from the exact fixture bytes.
|
||||
//! Unicode/CRLF/duplicate-text span contract. The only source is the exact
|
||||
//! `modules[].source` carried by the Analysis v3 artifact; all spans are
|
||||
//! half-open UTF-8 byte ranges into it.
|
||||
|
||||
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::model::{anchor_for_span, Navigation, SourceStatus};
|
||||
use marqdo_view::reader::render::{ReaderRenderer, RenderContext};
|
||||
use marqdo_view::reader::source::sha256_hex;
|
||||
use marqdo_view::reader::source::{Project, SafeRelativePath};
|
||||
@@ -14,34 +15,33 @@ fn repo_root() -> std::path::PathBuf {
|
||||
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
}
|
||||
|
||||
fn load(path: &str, golden: &str) -> (String, Vec<u8>, semantic::VerifiedAnalysis) {
|
||||
let root = repo_root();
|
||||
let source = std::fs::read_to_string(root.join(path)).unwrap();
|
||||
let index = marqdo_view::reader::source::SourceIndex::new(&source);
|
||||
let analysis = std::fs::read(root.join(golden)).unwrap();
|
||||
let relative = std::path::Path::new(path)
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
let verified = semantic::verify_analysis(&analysis, &source, &index, &relative).unwrap();
|
||||
(source, analysis, verified)
|
||||
fn load(golden: &str, relative: &str) -> analysis_v3::VerifiedAnalysis {
|
||||
let bytes = std::fs::read(repo_root().join(golden)).unwrap();
|
||||
let verified = analysis_v3::verify_analysis(&bytes, relative, None)
|
||||
.unwrap_or_else(|err| panic!("{golden} does not verify: {err}"));
|
||||
let source = &verified.projection.source;
|
||||
assert_eq!(
|
||||
verified.projection.source_digest,
|
||||
sha256_hex(source.as_bytes())
|
||||
);
|
||||
verified
|
||||
}
|
||||
|
||||
fn render(verified: &semantic::VerifiedAnalysis, source: &str, relative: &str) -> String {
|
||||
let root = repo_root().join("examples/unicode-spans");
|
||||
fn render(verified: &analysis_v3::VerifiedAnalysis, project_dir: &str, relative: &str) -> String {
|
||||
let root = repo_root().join(project_dir);
|
||||
let project = Project::open(&root).unwrap();
|
||||
let entry = SafeRelativePath::parse(relative).unwrap();
|
||||
let document = DocumentModel::parse(source.to_string(), DocumentIdentity::placeholder(&entry));
|
||||
let source = verified.projection.source.clone();
|
||||
let document = DocumentModel::parse(source, DocumentIdentity::placeholder(&entry));
|
||||
let navigation = Navigation::from_project(&project, &ViewConfig::default(), &entry);
|
||||
let model = assemble::build(BuildInput {
|
||||
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,
|
||||
});
|
||||
ReaderRenderer::new()
|
||||
@@ -51,35 +51,25 @@ fn render(verified: &semantic::VerifiedAnalysis, source: &str, relative: &str) -
|
||||
|
||||
#[test]
|
||||
fn unicode_spans_are_exact_and_duplicate_returns_get_distinct_anchors() {
|
||||
let (source, analysis, verified) = load(
|
||||
"examples/unicode-spans/index.mq.md",
|
||||
"tests/golden/analysis-v2/unicode-spans.json",
|
||||
);
|
||||
assert_eq!(
|
||||
verified.projection.source_digest,
|
||||
sha256_hex(source.as_bytes())
|
||||
);
|
||||
let verified = load("tests/golden/analysis-v3/unicode-spans.json", "index.mq.md");
|
||||
let source = verified.projection.source.clone();
|
||||
let function = &verified.projection.functions[0];
|
||||
let returns: Vec<_> = function
|
||||
.flattened_statements()
|
||||
.into_iter()
|
||||
.filter(|statement| statement.kind == semantic::StatementKind::Return)
|
||||
.filter(|statement| statement.kind == analysis_v3::StatementKind::Return)
|
||||
.collect();
|
||||
assert_eq!(returns.len(), 2);
|
||||
let first = returns[0].span;
|
||||
let second = returns[1].span;
|
||||
assert_ne!(first, second);
|
||||
let index = marqdo_view::reader::source::SourceIndex::new(&source);
|
||||
// Core statement spans cover the whole carrier node (including markers).
|
||||
assert_eq!(index.source_text(&source, first), Some("`return 1`"));
|
||||
assert_eq!(index.source_text(&source, second), Some("`return 1`"));
|
||||
// The carrier text is identical, so only spans can distinguish the two.
|
||||
assert_eq!(first.start, source.find("`return 1`").unwrap() as u64);
|
||||
assert_ne!(first.start, second.start);
|
||||
|
||||
let html = render(&verified, &source, "index.mq.md");
|
||||
let statement_ids: Vec<&str> = html.matches("data-source-id=\"").map(|_| "").collect();
|
||||
let _ = statement_ids;
|
||||
let html = render(&verified, "examples/unicode-spans", "index.mq.md");
|
||||
// 3 anchored statements: branch header + two returns.
|
||||
assert_eq!(html.matches("class=\"mq-anchor\"").count(), 3, "{html}");
|
||||
let ids: Vec<&str> = html
|
||||
@@ -91,30 +81,28 @@ fn unicode_spans_are_exact_and_duplicate_returns_get_distinct_anchors() {
|
||||
unique.sort();
|
||||
unique.dedup();
|
||||
assert_eq!(ids.len(), unique.len(), "duplicate source ids: {ids:?}");
|
||||
// Emoji and CJK survive both rendering and source mapping.
|
||||
assert!(html.contains("中文 🙂 标题"));
|
||||
assert!(html.contains("甲🙂"));
|
||||
let _ = analysis;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crlf_source_keeps_exact_digest_and_line_mapping() {
|
||||
let (source, _analysis, verified) = load(
|
||||
"examples/unicode-spans/crlf.mq.md",
|
||||
"tests/golden/analysis-v2/unicode-spans-crlf.json",
|
||||
let verified = load(
|
||||
"tests/golden/analysis-v3/unicode-spans-crlf.json",
|
||||
"crlf.mq.md",
|
||||
);
|
||||
let source = verified.projection.source.clone();
|
||||
assert!(source.contains("\r\n"), "fixture must stay CRLF");
|
||||
assert_eq!(
|
||||
verified.projection.source_digest,
|
||||
sha256_hex(source.as_bytes())
|
||||
);
|
||||
let index = marqdo_view::reader::source::SourceIndex::new(&source);
|
||||
let function = &verified.projection.functions[0];
|
||||
for (_, statement) in verified
|
||||
.projection
|
||||
.all_statements()
|
||||
.into_iter()
|
||||
.filter(|(_, statement)| statement.kind == semantic::StatementKind::Return)
|
||||
.filter(|(_, statement)| statement.kind == analysis_v3::StatementKind::Return)
|
||||
{
|
||||
assert!(
|
||||
index
|
||||
@@ -125,42 +113,20 @@ fn crlf_source_keeps_exact_digest_and_line_mapping() {
|
||||
statement.span
|
||||
);
|
||||
}
|
||||
let html = render(&verified, &source, "crlf.mq.md");
|
||||
let html = render(&verified, "examples/unicode-spans", "crlf.mq.md");
|
||||
assert!(html.contains("CRLF 文档"));
|
||||
// One list item per source line (SourceIndex counts the trailing line too).
|
||||
let source_lines = index.line_count();
|
||||
assert_eq!(html.matches("class=\"mq-line-text\"").count(), source_lines);
|
||||
let _ = function;
|
||||
assert_eq!(
|
||||
html.matches("class=\"mq-line-text\"").count(),
|
||||
index.line_count()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn knowledge_emphasis_never_becomes_an_execution_anchor() {
|
||||
let root = repo_root();
|
||||
let project = Project::open(&root.join("examples/mixed-modes")).unwrap();
|
||||
let project = Project::open(&repo_root().join("examples/mixed-modes")).unwrap();
|
||||
let entry = project.entry().relative.clone();
|
||||
let source = project.read_source_text(&entry).unwrap();
|
||||
let index = marqdo_view::reader::source::SourceIndex::new(&source);
|
||||
let analysis = std::fs::read(root.join("tests/golden/analysis-v2/mixed-modes.json")).unwrap();
|
||||
let verified = semantic::verify_analysis(&analysis, &source, &index, entry.as_str()).unwrap();
|
||||
assert_eq!(
|
||||
verified.projection.source_digest,
|
||||
sha256_hex(source.as_bytes())
|
||||
);
|
||||
let document = DocumentModel::parse(source.clone(), DocumentIdentity::placeholder(&entry));
|
||||
let navigation = Navigation::from_project(&project, &ViewConfig::default(), &entry);
|
||||
let model = assemble::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()),
|
||||
run: None,
|
||||
});
|
||||
let html = ReaderRenderer::new()
|
||||
.render(&model, &RenderContext::live())
|
||||
.html;
|
||||
let verified = load("tests/golden/analysis-v3/mixed-modes.json", entry.as_str());
|
||||
let html = render(&verified, "examples/mixed-modes", entry.as_str());
|
||||
// Exactly the four Exec statements are anchored (branch + assign + 2 returns).
|
||||
assert_eq!(html.matches("class=\"mq-anchor\"").count(), 4, "{html}");
|
||||
let knowledge_bold = "此处加粗是知识内容,不执行。";
|
||||
@@ -173,3 +139,50 @@ fn knowledge_emphasis_never_becomes_an_execution_anchor() {
|
||||
"knowledge emphasis received an execution anchor"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn heading_ui_uses_heading_span_and_section_span_includes_children() {
|
||||
// ADR-0069: heading_span is the heading AST node; the complete span runs
|
||||
// through child sections. A section heading id must be derived from its own
|
||||
// heading span, so adding a child never moves it.
|
||||
let verified = load("tests/golden/analysis-v3/control-flow.json", "index.mq.md");
|
||||
let projection = &verified.projection;
|
||||
let mut sections_with_children = 0;
|
||||
for unit in &projection.units {
|
||||
let Some(heading) = unit.heading_span else {
|
||||
assert_eq!(unit.kind, analysis_v3::UnitKind::Root);
|
||||
continue;
|
||||
};
|
||||
assert!(unit.span.contains(heading));
|
||||
let anchor = anchor_for_span(heading.start, heading.end);
|
||||
// A heading id is derived from the heading itself, not the section body.
|
||||
assert_ne!(
|
||||
anchor,
|
||||
anchor_for_span(unit.span.start, unit.span.end),
|
||||
"unit {:?} used the complete section span as its heading id",
|
||||
unit.id
|
||||
);
|
||||
if projection
|
||||
.units
|
||||
.iter()
|
||||
.any(|child| child.parent_id.as_deref() == Some(unit.id.as_str()))
|
||||
{
|
||||
sections_with_children += 1;
|
||||
assert!(
|
||||
unit.span.end > heading.end,
|
||||
"section {:?} complete span does not include its children",
|
||||
unit.id
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
sections_with_children > 0,
|
||||
"fixture needs a section with children"
|
||||
);
|
||||
let html = render(&verified, "examples/control-flow", "index.mq.md");
|
||||
let function_anchor = anchor_for_span(
|
||||
projection.functions[0].heading_span.start,
|
||||
projection.functions[0].heading_span.end,
|
||||
);
|
||||
assert!(html.contains(&format!("id=\"{function_anchor}\"")));
|
||||
}
|
||||
Reference in new issue
Block a user