From 6c1caf2f5c1aedf5e47c82d208ff0686733fc712 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 3 Sep 2026 07:15:36 +1000 Subject: [PATCH] fix(eda): make playbook key collision reporting deterministic loadPlaybookFile ranged over the raw YAML map directly, so which key "won" when a file declared two colliding bindings depended on Go's randomized map iteration order -- contradicting the function's own doc comment promise of a reproducible, deterministic collision error. Surfaced as a flaky failure in TestLintReportsLoadErrorAsFinding (internal/app/archieplaybooks), which has two independent collisions in its fixture and asserted on whichever one used to win by chance. Sort the file's keys before checking them, matching the existing sorted-filenames convention for cross-file order. Updated the test's assertion to the now-deterministic outcome ("bug", alphabetically first) with a comment explaining why. --- internal/app/archieplaybooks/lint_test.go | 6 +++++- internal/domain/workflow/routing.go | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/app/archieplaybooks/lint_test.go b/internal/app/archieplaybooks/lint_test.go index 7f7d2b2ba..82762dd45 100644 --- a/internal/app/archieplaybooks/lint_test.go +++ b/internal/app/archieplaybooks/lint_test.go @@ -97,7 +97,11 @@ func TestLintReportsLoadErrorAsFinding(t *testing.T) { t.Fatal("Lint() exit = 0, want non-zero") } joined := strings.Join(result.Findings, "\n") - if !strings.Contains(joined, "security") { + // Both "bug" and "security" collide across the two files; the loader + // sorts a file's keys before checking them (routing.go's + // loadPlaybookFile), so "bug" -- alphabetically first -- is always the + // one reported, deterministically. + if !strings.Contains(joined, "bug") { t.Fatalf("Lint() findings = %q, want the colliding key named", joined) } // Fail-fast like the daemon: one definition failure is reported (the diff --git a/internal/domain/workflow/routing.go b/internal/domain/workflow/routing.go index 029cad786..be439340f 100644 --- a/internal/domain/workflow/routing.go +++ b/internal/domain/workflow/routing.go @@ -161,8 +161,18 @@ func loadPlaybookFile(path string, kw KindWorkflows, lw LabelWorkflows) error { if err := yaml.Unmarshal(data, &raw); err != nil { return fmt.Errorf("parse playbook file %s: %w", path, err) } - for key, value := range raw { - if err := bindPlaybookKey(path, key, value, kw, lw); err != nil { + // Sorted, not range order: LoadPlaybookDirs' doc comment promises a + // reproducible error when a file declares more than one colliding key, + // which a raw map range (Go's iteration order is randomized) cannot + // keep -- the same file could report a different "first" collision on + // every run otherwise. + keys := make([]string, 0, len(raw)) + for key := range raw { + keys = append(keys, key) + } + sort.Strings(keys) + for _, key := range keys { + if err := bindPlaybookKey(path, key, raw[key], kw, lw); err != nil { return err } }