feat(mermaid): spar-mermaid foundation with flowchart emitter (v0.10.x)#220
Merged
Conversation
Adds the new `spar-mermaid` crate (emit-only, library-only) that walks a `SystemInstance` arena and produces a `flowchart TD` Mermaid diagram. Nodes are filtered by ComponentCategory set and max parent-hop depth; ConnectionInstance edges are resolved by subcomponent name lookup and deduplicated. Six unit tests cover the canonical 3-thread/1-processor instance, category filter, depth filter, edge suppression, label format, and ID sanitisation. Registers REQ-MERMAID-001 and TEST-MERMAID-FLOWCHART in the artifact tracker. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ster in workspace.dependencies Aligns spar-mermaid with the per-crate convention used by every other spar-* crate in this repo: - crates/spar-mermaid/Cargo.toml: replace path literal with `spar-hir-def.workspace = true` (matches spar-trace-topology, sysml2, analysis, etc.). - Cargo.toml: register `spar-mermaid` under [workspace.dependencies] so follow-on crates (CLI integration, SysML2 bridge) can depend on it via `spar-mermaid.workspace = true` without re-spelling the path. No behavior change. Build + test still pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
No behavior change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
# Conflicts: # artifacts/requirements.yaml # artifacts/verification.yaml
# Conflicts: # artifacts/requirements.yaml # artifacts/verification.yaml
# Conflicts: # artifacts/requirements.yaml # artifacts/verification.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The current SVG rendering path (via
etch) has known quality pain documented indocs/plans/2026-03-17-rendering-quality-design.md. Mermaid addresses both rendering quality and machine-parseability: rivet renders Mermaid in-place in requirement/test descriptions, and the text output is diff-able and round-trip-testable.Scope — emit only, library only
This PR is the M1 foundation. It adds one new crate with no CLI surface and no renderer dependency.
In this PR:
spar-mermaid(version 0.9.3, workspace edition)emit_flowchart(instance: &SystemInstance, opts: &MermaidOptions) -> String— walks the component arena and emitsflowchart TDMermaidOptionswithcategoriesfilter,max_depthfilter,include_connectionsflagREQ-MERMAID-001+TEST-MERMAID-FLOWCHARTin artifact trackerFollow-on PRs (out of scope here):
classDiagram,requirementDiagram,block-betastateDiagramper SOM (v0.11.0)MWE — sample emitted Mermaid
From the canonical test instance (root system + 3 threads + 1 processor + 2 connections):
flowchart TD cpu["processor: cpu"] root["system: root"] t1["thread: t1"] t2["thread: t2"] t3["thread: t3"] t1 --> t2 t2 --> t3Paste into https://mermaid.live to verify visually.
Design notes
ConnectionEndholdssubcomponent: Option<Name>+feature: Name(not a directComponentInstanceIdx). Endpoint resolution uses case-insensitive name lookup against the owner's children — consistent with AADL §3.1 case-insensitive identifiers.SemanticConnection(which does carry direct idx pairs) is deliberately not used here: those entries are computed post-instantiation from aGlobalScopeand aren't available in manually-constructed test instances. TheConnectionInstancepath is sufficient for foundation emission.SystemInstance::instantiatealready detects circular containment; the emitter trusts that guarantee and documents the assumption.max_depthprovides a natural bound for manually-constructed instances with depth limits set.Checklist
cargo build -p spar-mermaid— cleancargo test -p spar-mermaid— 6/6 passcargo clippy -p spar-mermaid -- -D warnings— cleanrivet validate— REQ-MERMAID-001 + TEST-MERMAID-FLOWCHART present and linked (pre-existing unrelated YAML issue at line 1615 of verification.yaml is not introduced by this PR)🤖 Generated with Claude Code