From 566d9e9f789eab65f1669f1d51e0c3a044100960 Mon Sep 17 00:00:00 2001 From: Amal Saidov Date: Mon, 16 Nov 2026 14:18:48 +0700 Subject: [PATCH] Fix artifactSet Diff for duplicate revisions Diff compared each current revision against the updated set with one-directional membership and a length check. When a set holds the same revision more than once, a change that turns a distinct revision into a duplicate kept the length equal and still found every current revision in the updated set, so Diff reported no change. For a GitRepository with multiple includes that resolve to the same revision, that masks an included artifact change and leaves the aggregated artifact stale until another reconcile is triggered. Compare the two sets as multisets of revisions so repeated revisions must appear the same number of times in both. Signed-off-by: Amal Saidov Assisted-by: Claude Code/claude-opus-4-8 --- internal/controller/artifact.go | 18 ++++++++----- internal/controller/artifact_test.go | 40 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/internal/controller/artifact.go b/internal/controller/artifact.go index bebc8d5ae..e386990ee 100644 --- a/internal/controller/artifact.go +++ b/internal/controller/artifact.go @@ -22,20 +22,24 @@ import ( type artifactSet []*meta.Artifact -// Diff returns true if any of the revisions in the artifactSet does not match any of the given artifacts. +// Diff returns true if the revisions in the artifactSet do not match those of +// the given set, regardless of order. A revision that appears more than once +// must appear the same number of times in both sets, otherwise a change in a +// set that holds duplicate revisions goes unnoticed. func (s artifactSet) Diff(set artifactSet) bool { if len(s) != len(set) { return true } -outer: + counts := make(map[string]int, len(set)) + for _, k := range set { + counts[k.Revision]++ + } for _, j := range s { - for _, k := range set { - if k.HasRevision(j.Revision) { - continue outer - } + if counts[j.Revision] == 0 { + return true } - return true + counts[j.Revision]-- } return false } diff --git a/internal/controller/artifact_test.go b/internal/controller/artifact_test.go index d40548c3c..e802641ba 100644 --- a/internal/controller/artifact_test.go +++ b/internal/controller/artifact_test.go @@ -112,6 +112,46 @@ func Test_artifactSet_Diff(t *testing.T) { }, expected: true, }, + { + name: "duplicate revision replaces a distinct one, diff", + current: artifactSet{ + { + Revision: "foo", + }, + { + Revision: "foo", + }, + }, + updated: artifactSet{ + { + Revision: "foo", + }, + { + Revision: "bar", + }, + }, + expected: true, + }, + { + name: "same revisions out of order, no diff", + current: artifactSet{ + { + Revision: "foo", + }, + { + Revision: "bar", + }, + }, + updated: artifactSet{ + { + Revision: "bar", + }, + { + Revision: "foo", + }, + }, + expected: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {