Skip to content

Sort mermaid graph nodes alphabetically for stable code generation#1869

Merged
pelikhan merged 4 commits intomainfrom
copilot/sort-nodes-by-names
Oct 17, 2025
Merged

Sort mermaid graph nodes alphabetically for stable code generation#1869
pelikhan merged 4 commits intomainfrom
copilot/sort-nodes-by-names

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 17, 2025

Problem

The mermaid graph generation in workflow compilation was using job insertion order, which led to non-deterministic output when jobs were added in different orders. This created unnecessary git diffs when recompiling workflows, making it harder to track meaningful changes.

Solution

Modified the GenerateMermaidGraph() function in pkg/workflow/jobs.go to sort job names alphabetically before generating the graph. This ensures:

  • Deterministic output: Same mermaid graph regardless of job insertion order
  • Stable code generation: Reduces noise in git diffs when workflows are recompiled
  • Predictable behavior: Alphabetical ordering is intuitive and consistent

Example

Before this change, jobs added in the order [zebra, apple, banana] would generate:

graph LR
  zebra["Zebra Job"]
  apple["Apple Job"]
  banana["Banana Job"]
Loading

After this change, the same jobs now generate:

graph LR
  apple["Apple Job"]
  banana["Banana Job"]
  zebra["Zebra Job"]
Loading

Changes

  1. Modified GenerateMermaidGraph() to create a sorted copy of job names using sort.Strings()
  2. Updated node generation to iterate over sorted names
  3. Updated edge generation to iterate over sorted names for consistency
  4. Added test case to verify alphabetical ordering regardless of insertion order

Testing

  • ✅ All existing tests pass
  • ✅ New test case validates alphabetical sorting
  • ✅ All 64 workflow files successfully recompiled with sorted graphs
  • ✅ Build and lint successful
Original prompt

The code that generates the mermaid graph of jobs needs to sort the nodes by names first to stabilize the code generation.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 17, 2025 15:37
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Sort nodes by names for mermaid graph generation Sort mermaid graph nodes alphabetically for stable code generation Oct 17, 2025
Copilot AI requested a review from pelikhan October 17, 2025 15:45
@pelikhan pelikhan marked this pull request as ready for review October 17, 2025 15:47
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants