Skip to content

Commit 51a7383

Browse files
fix: make mergeIssueFieldValues output order deterministic
mergeIssueFieldValues built the merged slice by iterating a Go map, which produces non-deterministic ordering and caused a flake in Test_UpdateIssue/partial_update_with_issue_fields_reconciled_by_names (introduced in #2551). Switch to an order-preserving merge: emit incoming entries first in their original order, then any existing entries (in their original order) whose field IDs weren't seen in incoming. Semantics (incoming wins, existing preserved) unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1123344 commit 51a7383

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

pkg/github/issues.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,19 @@ func fetchExistingIssueFieldValues(ctx context.Context, gqlClient *githubv4.Clie
460460

461461
// mergeIssueFieldValues returns a merged slice where incoming values override existing ones
462462
// for the same field ID, and existing fields not present in incoming are preserved.
463+
// Ordering is deterministic: incoming entries first in their original order, followed by any
464+
// existing entries (in their original order) whose field IDs weren't seen in incoming.
463465
func mergeIssueFieldValues(existing, incoming []*github.IssueRequestFieldValue) []*github.IssueRequestFieldValue {
464-
merged := make(map[int64]*github.IssueRequestFieldValue, len(existing)+len(incoming))
465-
for _, v := range existing {
466-
merged[v.FieldID] = v
467-
}
466+
seen := make(map[int64]struct{}, len(incoming))
467+
result := make([]*github.IssueRequestFieldValue, 0, len(existing)+len(incoming))
468468
for _, v := range incoming {
469-
merged[v.FieldID] = v
469+
seen[v.FieldID] = struct{}{}
470+
result = append(result, v)
470471
}
471-
result := make([]*github.IssueRequestFieldValue, 0, len(merged))
472-
for _, v := range merged {
472+
for _, v := range existing {
473+
if _, ok := seen[v.FieldID]; ok {
474+
continue
475+
}
473476
result = append(result, v)
474477
}
475478
return result

0 commit comments

Comments
 (0)