feat(graph): add dot format, file output, and step-wave overlay - #58
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58 +/- ##
==========================================
+ Coverage 92.97% 93.59% +0.62%
==========================================
Files 27 29 +2
Lines 1565 1687 +122
==========================================
+ Hits 1455 1579 +124
+ Misses 107 105 -2
Partials 3 3
🚀 New features to boost your workflow:
|
Owner
Author
|
🎉 This PR is included in version 1.32.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Closes #28.
keepup graphgains--format mermaid|dot,--output <file>, a step-mode wave overlay, and annotations for conditional and cacheable groups.It was also drawing the wrong picture
While mapping the work I found
cmd/graph.gore-derived the topology withconfig.ExtractRefsinstead of usinginternal/plan. The scheduler'sbuildDAGEdgesalso adds edges fromwhen:references — so the diagram omitted dependencies the scheduler enforces.On
config-dag-when.yml, wheredeployis gated on{{ eq (output "test") "pass" }}:The fix is the design: the model is built from
plan.Build— the same plan the engine schedules — so the picture cannot drift from what runs. That also hands overWavesfor free, which is why the step overlay is small rather than new machinery.Step mode was silent about ordering
Step mode is the default, and its waves were invisible: four sequential steps rendered as four floating nodes, reading as "these are independent".
Formats
mermaid(default) renders natively in GitHub markdown.dotcovers everything else:SVG is deliberately not a format we emit. Generating it means either shelling out to a
dotbinary we cannot assume exists or pulling in a Go layout engine — both at odds with "a single binary, no runtime". Piping to Graphviz costs users one extra command and keeps the binary unchanged.Visual language
The two annotations are orthogonal, so a group can be both:
[(…)]in mermaid,shape=cylinderin dot) for groups declaringcache:classDefin mermaid andstyle=dashedin dotIn dag mode
when:belongs to the group, so the node is dashed. In step mode it belongs to the step, so the wave box is dashed and its label saysstep 2 (conditional).Group descriptions are still rendered, as before.
A bug the tests caught
The first dot implementation emitted clusters with no edges between them. Graphviz lays unconnected clusters out side by side — which reads as parallelism, the exact thing the overlay exists to fix. It now emits
compound=trueplusltail/lheadbarrier edges so the wave order is real in dot too, matching mermaid's-.->.Structure
A new
internal/graphleaf package holds the model and both renderers;cmd/graph.godrops to flag wiring and shrinks by roughly half. This keeps rendering testable without cobra and matches howcmd/stays thin elsewhere.nodeIDmoved there asident, and its test moved with it.Golden examples
internal/graph/test-resources/holds two realistic configs and the exact output each produces in both formats. They are tests and documentation at once — readingstep.mermaidshows what a wave overlay looks like without running anything. Regenerate withgo test ./internal/graph -update, and review the diff: these files are the reference for what a keepup diagram should look like, not a snapshot of whatever the renderer happens to emit.Writing them surfaced one more bug. A group named
endrendered as:endbegins a line as both a node declaration and the subgraph terminator — ambiguous by construction. Mermaid identifiers now get a suffix when they collide with a keyword (end,graph,subgraph,class,classDef,style,click,linkStyle), while the label keeps the real name. Dot needs no equivalent since it quotes node names.Verification
gofmt,go vet,golangci-lint, andgo test -race ./...all clean.Tests cover: the
when:-derived edge, conditional and cacheable marking, wave construction including a conditional step, step data edges, both renderers in both modes, format rejection, file output and-for stdout, an unwritable path, flag completion, and determinism of model and output (a regenerated diagram must not produce a spurious diff).Also driven through the built binary: both formats,
--outputto a file with stdout left empty, and--format <TAB>completing tomermaid/dot.Rendered for real
Every golden was put through the actual renderers, not just the grammar:
step.dot,dag.dotstep.mermaid,dag.mermaid@mermaid-js/mermaid-cliThe dag PNG confirms the fix visually:
build(cylinder) →test→deploy(dashed) →notify, with thetest → deployedge — the one that was missing — drawn. The step PNG shows three stacked wave boxes, step 3 dashed, andbuild → packagecrossing from wave 1 to wave 3. The barrier edges carrystroke-dasharrayin the SVG, so they read as ordering rather than data flow.The
endbug is confirmed real, not theoretical. Feeding Mermaid the pre-fix output:Mermaid takes
endas the keyword and chokes on the[. The post-fix output (end_["end"]) renders cleanly.Aside
Writing the step-mode tests surfaced that a step-mode group may only reference outputs from earlier steps — my first fixture violated it and the loader caught it. Worth knowing: cross-wave data edges always point backwards in wave order.