feat: handoff, design graph, single-component slice and drift (WEB-03)
Extend the Design public API for delivery consumers: - handoff/handoff_relative_to derive deterministic Markdown from the model only: design id, source digests, component tree, separated visual containment and non-visual dependency graph, per-component source links, responsibility/visual notes from safe content blocks, inputs, events, scenarios, interactions, dependencies, acceptance and an explicit prototype/not-implemented boundary. Source links are recomputed relative to the output directory when requested. - graph() separates visual containment edges from dependency edges and reports dependency cycle groups (load still rejects cycles for coordination). - slice() selects one loaded component and its visual subtree as an independent Design with only the used sources (single-component delivery). - drift(previous,current) reports added/removed/changed components and changed source digests; design_id() is a deterministic identity for drift checks. - Non-visual dependency targets are loaded as definitions so the graph is explicit even when the dependency is not placed in the visual tree; a cycle on that path reports web.dependency.cycle. - Six new real-CLI tests cover deterministic handoff, relative links, drift, slicing, graph separation and the unchanged negative contract. Refs cflmy/marqdo-web-design#2, cflmy/marqdo#6
This commit was merged in pull request #7.
This commit is contained in:
1 parent
2f18dede85
commit
8cd72b87b6
2 files changed
+507
-47
No files matched your search
+144
-12
@@ -3,7 +3,10 @@
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use marqdo_web_design::{handoff, load, statistics, Error, LoadConfig};
|
||||
use marqdo_web_design::{
|
||||
design_id, drift, graph, handoff, handoff_relative_to, load, slice, statistics, Error,
|
||||
LoadConfig,
|
||||
};
|
||||
|
||||
static UNIQUE: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
@@ -356,10 +359,13 @@ fn loads_full_leaf_contract_inputs_events_scenarios_interactions_dependencies()
|
||||
assert_eq!(a.dependencies[0].target, "components/b.mq.md#乙");
|
||||
assert!(a.acceptance.as_ref().unwrap().text.contains("模拟保存"));
|
||||
let text = handoff(&design);
|
||||
assert!(text.contains("scenario `empty` (initial)"));
|
||||
assert!(text.contains("transition `empty` --模拟保存--> `done`"));
|
||||
assert!(text.contains("dependency `components/b.mq.md#乙`"));
|
||||
assert!(text.contains("acceptance:"));
|
||||
assert!(text.contains("Scenarios:"));
|
||||
assert!(text.contains("`empty` (initial)"));
|
||||
assert!(text.contains("Interactions:"));
|
||||
assert!(text.contains("--模拟保存--> `done`"));
|
||||
assert!(text.contains("Dependencies:"));
|
||||
assert!(text.contains("`components/b.mq.md#乙`: 提交后展示详情"));
|
||||
assert!(text.contains("Acceptance:"));
|
||||
}
|
||||
|
||||
fn leaf_project(sections: &str) -> TempProject {
|
||||
@@ -456,15 +462,11 @@ fn rejects_invalid_inputs_dependencies_and_acceptance() {
|
||||
);
|
||||
|
||||
let unknown = leaf_project(
|
||||
"### 依赖\n\n| 组件 | 原因 |\n| --- | --- |\n| [目标](target.mq.md#目标) | 需要 |\n",
|
||||
);
|
||||
unknown.write(
|
||||
"target.mq.md",
|
||||
"# 目标页面\n\n## @knowledge 目标\n\n### 内容\n\nx\n",
|
||||
"### 依赖\n\n| 组件 | 原因 |\n| --- | --- |\n| [目标](missing.mq.md#目标) | 需要 |\n",
|
||||
);
|
||||
assert_eq!(
|
||||
design_code(load(&unknown.config("a.mq.md", "甲")).unwrap_err()),
|
||||
"web.dependency.unknown"
|
||||
"web.dependency.target"
|
||||
);
|
||||
|
||||
let empty = leaf_project("### 验收\n\n \n");
|
||||
@@ -550,7 +552,8 @@ fn projects_safe_content_blocks_for_components_and_scenarios() {
|
||||
.iter()
|
||||
.all(|scene| !scene.content_blocks.is_empty()));
|
||||
let text = handoff(&design);
|
||||
assert!(text.contains("scenario `only`"));
|
||||
assert!(text.contains("Scenarios:"));
|
||||
assert!(text.contains("`only`"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -668,3 +671,132 @@ fn resolves_outside_scope_links_that_stay_inside_the_explicit_root() {
|
||||
"shared/b.mq.md#乙"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handoff_is_deterministic_and_contains_graph_sources_and_contracts() {
|
||||
let project = TempProject::new();
|
||||
project.write(
|
||||
"index.mq.md",
|
||||
"# 页面\n\n## @knowledge 工作台\n\n### 内容\n\n页面职责。\n\n### 组件\n\n| 行 | 槽 | 组件 | 宽度 |\n| --- | --- | --- | --- |\n| 1 | a | [A](a.mq.md#甲) | auto |\n| 1 | b | [B](b.mq.md#乙) | auto |\n",
|
||||
);
|
||||
project.write(
|
||||
"a.mq.md",
|
||||
"# A 组件\n\n## @knowledge 甲\n\n### 输入\n\n| 名称 | 类型 | 说明 |\n| --- | --- | --- |\n| x | Text | 输入 |\n\n### 场景\n\n| 状态 | 内容 | 初始 |\n| --- | --- | --- |\n| only | [样例](states.mq.md#空状态) | true |\n\n### 依赖\n\n| 组件 | 原因 |\n| --- | --- |\n| [B](b.mq.md#乙) | 组合交付 |\n\n### 验收\n\n- A 可见。\n",
|
||||
);
|
||||
project.write(
|
||||
"b.mq.md",
|
||||
"# B 组件\n\n## @knowledge 乙\n\n### 内容\n\nB 正文。\n",
|
||||
);
|
||||
project.write("states.mq.md", STATES);
|
||||
let design = load(&project.config("index.mq.md", "工作台")).expect("load");
|
||||
let first = handoff(&design);
|
||||
assert_eq!(first, handoff(&design));
|
||||
assert_eq!(
|
||||
first,
|
||||
handoff(&load(&project.config("index.mq.md", "工作台")).expect("reload"))
|
||||
);
|
||||
assert!(first.contains("design id:"));
|
||||
assert!(first.contains("## Sources"));
|
||||
assert!(first.contains("## Design graph"));
|
||||
assert!(first.contains("Visual containment:"));
|
||||
assert!(first.contains("Non-visual dependencies:"));
|
||||
assert!(first.contains("--a-->"));
|
||||
assert!(first.contains("`a.mq.md#甲`"));
|
||||
assert!(first.contains("Inputs:"));
|
||||
assert!(first.contains("Scenarios:"));
|
||||
assert!(first.contains("Acceptance:"));
|
||||
assert!(first.contains("未实现/边界"));
|
||||
assert!(first.contains("sha256:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handoff_relative_to_recomputes_source_links_for_another_directory() {
|
||||
let project = basic_project();
|
||||
let design = load(&project.config("index.mq.md", "工作台")).expect("load");
|
||||
let out_dir = project.path.join("deliver/out");
|
||||
std::fs::create_dir_all(&out_dir).unwrap();
|
||||
let text = handoff_relative_to(&design, &out_dir);
|
||||
assert!(!text.contains(&format!("({}", project.path.display())));
|
||||
assert!(text.contains("../../components/leaf.mq.md#叶子"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drift_reports_changed_components_and_sources_only() {
|
||||
let project = basic_project();
|
||||
let before = load(&project.config("index.mq.md", "工作台")).expect("load v1");
|
||||
let before_id = design_id(&before);
|
||||
project.write(
|
||||
"components/nav.mq.md",
|
||||
"# 导航组件\n\n## @knowledge 导航\n\n### 内容\n\n更新后的导航正文。\n\n### 组件\n\n| 行 | 槽 | 组件 | 宽度 |\n| --- | --- | --- | --- |\n| 1 | leaf | [叶子](leaf.mq.md#叶子) | auto |\n",
|
||||
);
|
||||
let after = load(&project.config("index.mq.md", "工作台")).expect("load v2");
|
||||
assert_ne!(before_id, design_id(&after));
|
||||
let report = drift(&before, &after);
|
||||
assert!(!report.unchanged);
|
||||
assert_eq!(report.changed_components, vec!["components/nav.mq.md#导航"]);
|
||||
assert_eq!(report.changed_sources, vec!["components/nav.mq.md"]);
|
||||
assert!(!report
|
||||
.changed_components
|
||||
.contains(&"components/leaf.mq.md#叶子".to_string()));
|
||||
assert!(drift(&after, &after).unchanged);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slice_keeps_only_the_visual_subtree_and_its_sources() {
|
||||
let project = basic_project();
|
||||
let design = load(&project.config("index.mq.md", "工作台")).expect("load");
|
||||
let sliced = slice(&design, "components/nav.mq.md#导航").expect("slice");
|
||||
assert_eq!(sliced.root, "components/nav.mq.md#导航");
|
||||
assert_eq!(
|
||||
sliced.definitions.keys().cloned().collect::<Vec<_>>(),
|
||||
vec!["components/leaf.mq.md#叶子", "components/nav.mq.md#导航"]
|
||||
);
|
||||
let ids: Vec<&str> = sliced
|
||||
.instances
|
||||
.iter()
|
||||
.map(|item| item.id.as_str())
|
||||
.collect();
|
||||
assert_eq!(ids, vec!["root", "root/leaf"]);
|
||||
let sources: Vec<&str> = sliced
|
||||
.sources
|
||||
.iter()
|
||||
.map(|item| item.path.as_str())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
sources,
|
||||
vec!["components/leaf.mq.md", "components/nav.mq.md"]
|
||||
);
|
||||
assert!(slice(&design, "missing").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graph_separates_visual_containment_from_design_dependencies() {
|
||||
let project = TempProject::new();
|
||||
project.write(
|
||||
"index.mq.md",
|
||||
"# 页面\n\n## @knowledge 工作台\n\n### 组件\n\n| 行 | 槽 | 组件 | 宽度 |\n| --- | --- | --- | --- |\n| 1 | a | [A](a.mq.md#甲) | auto |\n",
|
||||
);
|
||||
project.write(
|
||||
"a.mq.md",
|
||||
"# A 组件\n\n## @knowledge 甲\n\n### 依赖\n\n| 组件 | 原因 |\n| --- | --- |\n| [B](b.mq.md#乙) | 共享合同 |\n",
|
||||
);
|
||||
project.write(
|
||||
"b.mq.md",
|
||||
"# B 组件\n\n## @knowledge 乙\n\n### 内容\n\nB。\n",
|
||||
);
|
||||
let design = load(&project.config("index.mq.md", "工作台")).expect("load");
|
||||
let graph = graph(&design);
|
||||
assert!(graph
|
||||
.visual_edges
|
||||
.iter()
|
||||
.any(|(parent, child, slot)| parent == "index.mq.md#工作台"
|
||||
&& child == "a.mq.md#甲"
|
||||
&& slot == "a"));
|
||||
assert!(graph
|
||||
.dependency_edges
|
||||
.iter()
|
||||
.any(|(from, to, reason)| from == "a.mq.md#甲"
|
||||
&& to == "b.mq.md#乙"
|
||||
&& reason == "共享合同"));
|
||||
assert!(graph.dependency_cycles.is_empty());
|
||||
}
|
||||
Reference in new issue
Block a user