Files
silo-server/internal/metadata/refresh_followup_test.go
807384f4af fix(metadata): record post-refresh stale IDs against the canonical item (#38)
processInternal cleared and re-recorded stale provider IDs against
req.ContentID after mergeAndPersist. But mergeAndPersist can canonicalize
the item into an existing one (provider-ID dedup), deleting req.ContentID
and returning a different result.ContentID. In that case the post-merge
DeleteByContentID/Upsert targeted the now-deleted source: the upsert hit
the stale_media_ids content_id foreign key and the still-404ing providers
were never recorded on the surviving canonical item — so the same providers
get re-attempted (and re-404) on every subsequent refresh.

Target the canonical ID (result.ContentID, falling back to req.ContentID)
for the stale-ID follow-up via refreshFollowUpContentID, matching what the
adjacent refresh-debt sync already uses. The block stays guarded on
provider404s != nil (allocated only when req.ContentID was set) so a
content-id-less refresh that canonicalizes into an existing item does not
clear that item's stale rows without re-recording any. Unit-tested for the
nil/empty/canonicalized cases.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 09:30:26 -04:00

23 lines
985 B
Go

package metadata
import "testing"
func TestRefreshFollowUpContentID(t *testing.T) {
// After a refresh, follow-up writes (stale-ID clear/record, debt sync) must
// target the canonical content ID the item was persisted/merged into, not
// the requested ID — which may have been deleted when the item was
// canonicalized into an existing one during mergeAndPersist.
if got := refreshFollowUpContentID("req", nil); got != "req" {
t.Fatalf("nil result: got %q, want %q", got, "req")
}
if got := refreshFollowUpContentID("req", &ProcessResult{ContentID: ""}); got != "req" {
t.Fatalf("empty result id: got %q, want %q", got, "req")
}
if got := refreshFollowUpContentID("req", &ProcessResult{ContentID: " "}); got != "req" {
t.Fatalf("blank result id: got %q, want %q", got, "req")
}
if got := refreshFollowUpContentID("req", &ProcessResult{ContentID: "canonical"}); got != "canonical" {
t.Fatalf("canonicalized result id: got %q, want %q", got, "canonical")
}
}