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.
This commit is contained in:
sam committed 2026-09-03 07:15:36 +10:00
1 parent 11c8121d81
commit 6c1caf2f5c
2 files changed
+17 -3

No files matched your search

+5 -1
View File
@@ -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
+12 -2
View File
@@ -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
}
}