refactor(recipe): unify the two topological-sort paths (#1466) - #1728
Conversation
Extract buildDependencyGraph, the shared enabled-filtering, external-satisfaction, and in-degree/dependents construction, so TopologicalSort and ComponentRefsTopologicalLevels become thin wrappers over one graph builder instead of two parallel Kahn implementations. No behavior change: the flat sort keeps its globally-re-sorted FIFO order and the level grouping keeps its BFS tiers, so DeploymentOrder and every deployer's output stay byte-identical. The cross-check test TestRecipeMetadataSpecTopologicalLevelsMatchesSort passes unchanged. This removes the duplication that forced the enabled-filtering fix in Signed-off-by: Brian Lockwood <lockwobr@gmail.com> #1465 to be written twice.
Recipe evidence checkNo leaf overlays affected by this PR. This gate is warning-only and never blocks merge. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefactored dependency-graph construction in Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Coverage Report ✅
Coverage BadgeNo Go source files changed in this PR. |
Summary
Unify the two topological-sort implementations in
pkg/recipe/metadata.gobehind one shared graph builder, soTopologicalSortandComponentRefsTopologicalLevelsstop duplicating Kahn's algorithm and its enabled-filtering logic.Motivation / Context
TopologicalSort(flatDeploymentOrder) andComponentRefsTopologicalLevels(level-grouped, consumed by the helmfile deployer) each build the dependency graph, apply enabled-filtering, and detect cycles independently. That duplication forced theoverrides: {enabled: false}fix in #1465 to be written twice. This extracts the shared work intobuildDependencyGraph; the two functions become thin wrappers over it.Fixes: #1466
Related: #1465
Type of Change
Component(s) Affected
pkg/recipe)Implementation Notes
buildDependencyGraph(refs)returns(inDegree, dependents, enabledCount)and centralizes enabled-filtering,edgeSatisfiedExternally, and in-degree/dependents construction.TopologicalSortuses a globally re-sorted FIFO queue whose flat order can interleave levels alphabetically (e.g.[a, b, z]), which is not the same as flattening the levels ([a, z, b]). Deriving the flat order from the levels would changeDeploymentOrderand churn every deployer's output. Both traversals are preserved exactly; only the graph build is shared.TestRecipeMetadataSpecTopologicalLevelsMatchesSortpasses unchanged.Testing
All
TopologicalSort/TopologicalLevels/MatchesSortsubtests pass; every deployer golden is unchanged (ordering preserved).Risk Assessment
Rollout notes: N/A. No functional, API, or output change.
Checklist
make testwith-race)make lint)git commit -S)