fix: auto-quote leading-@ flowchart labels + mermaid.parse regression suite - #17
Conversation
Mermaid >= 10.5 lexes '[@' as its edge-ID/shape syntax, so a flowchart node label starting with '@' (e.g. N[@utils/utils -> ...]) fails the whole diagram on GitHub. sanitize.ts now wraps such labels in double quotes inside flowchart/graph blocks; SKILL.md and the templates doc gain the corresponding authoring rule. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add a jsdom-backed mermaid.parse() helper (cli/tests/helpers/mermaid.ts) and a fixture-driven regression suite: valid/ fixtures must parse, invalid/ fixtures must fail and parse again after sanitize(). The leading-@ field incident diagram is stored verbatim as the first fixture pair, and all mermaid blocks in iago/examples, the templates reference, and README are swept on every bun test run. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Greptile SummaryThis PR fixes a Mermaid parse failure on GitHub when a flowchart node label begins with
Confidence Score: 5/5The change is a targeted string rewrite confined to mermaid fence bodies, with no production runtime dependencies added and no changes to the published CLI bundle. The No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["sanitize(src)"] --> B["Match mermaid fences"]
B --> C["rewriteBlock(body)"]
C --> D["Split into lines"]
D --> E["Find first non-blank non-%% line"]
E --> F{"isFlow?"}
F -->|yes| G["LEADING_AT replace: at-bracket to quoted-at-bracket"]
F -->|no| H["MSG.exec: semicolon to comma in sequence labels"]
G --> I["Join lines + return"]
H --> I
Reviews (2): Last reviewed commit: "fix: detect flowchart header past %% com..." | Re-trigger Greptile |
A %% comment or %%{init: ...}%% directive before the flowchart header
made isFlow detection miss, skipping the leading-@ label repair. Skip
%%-prefixed lines when locating the header; document the deliberate
jsdom globalThis install in the test helper.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
What
A posted Iago flowchart failed to render on GitHub. Root cause: a node label starting with
@right after[—N[@utils/utils -> @i18n -> antd locale: not loaded]. Mermaid ≥ 10.5 lexes[@as its edge-ID/shape syntax (got 'LINK_ID'parse error). Mid-label@is fine; only a leading@breaks, and quoting the label fixes it.Changes
iago/scripts/sanitize.ts: new rule — insideflowchart/graphmermaid blocks, unquoted[@…]labels are rewritten to["@…"], mirroring the existing;→,sequence-label repair. Still pure string transform, no deps.cli/tests/helpers/mermaid.ts: jsdom-backedparseMermaid()(realmermaid.parse(), same parser GitHub runs) +extractMermaidBlocks().mermaid/jsdomadded as cli devDependencies only.cli/tests/fixtures/mermaid/{valid,invalid}/: fixture corpus for field rendering incidents — the exact failing diagram is stored verbatim;invalid/must fail parse and parse again aftersanitize(),valid/must parse as-is.cli/tests/mermaid-validation.test.ts: runs the corpus plus a sweep of every mermaid block iniago/examples/*.md,iago/references/mermaid-templates.md, andREADME.md.iago/SKILL.mdandiago/references/mermaid-templates.md(with bad/good pair);CLAUDE.mdcritical rule extended with the incident.Testing
cd cli && bun test— 73 pass, 0 fail (incident fixture fails parse unquoted, parses aftersanitize())cd cli && bun run typecheck— clean🤖 Generated with Claude Code