fix(providers): saving a key for an enabled source tries the gaps again (#8102)

A source that needs a key, such as Last.fm, answers "not found" without
one, and the enricher settles each row it tried that way at the current
version. Switching Last.fm on before entering its key settled every gap
without it, and saving the key didn't move the version, so Last.fm never
came back to them. The sources signature now marks each enabled source
that has a key, so a key arriving or leaving moves the version. Replacing
one key with another still doesn't.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 23:50:29 -05:00
co-authored by Claude Opus 5.5
parent 3a7081be19
commit f3997b657c
5 changed files with 115 additions and 56 deletions
+26 -20
View File
@@ -151,7 +151,7 @@ func TestAdminUpdateCoverSource_FlippingEnabledBumpsVersion(t *testing.T) {
}
}
func TestAdminUpdateCoverSource_KeyOnlyDoesNotBump(t *testing.T) {
func TestAdminUpdateCoverSource_ReplacingAKeyDoesNotBump(t *testing.T) {
if os.Getenv("MINSTREL_TEST_DATABASE_URL") == "" {
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
}
@@ -163,26 +163,32 @@ func TestAdminUpdateCoverSource_KeyOnlyDoesNotBump(t *testing.T) {
h, _ := testHandlersWithCoverSettings(t)
admin := seedUser(t, h.pool, "cskey", "pw", true)
newKey := "newkey"
body, _ := json.Marshal(updateProviderSourceReq{APIKey: &newKey})
req := httptest.NewRequest(http.MethodPatch, "/api/admin/cover-sources/key-prov", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req = withUser(req, admin)
rec := httptest.NewRecorder()
newAdminCoverSourcesRouter(h).ServeHTTP(rec, req)
// The first key on an enabled source moves the version (it searched
// without one until now); replacing that key with another doesn't.
for i, step := range []struct {
key string
wantBumped bool
}{{"firstkey", true}, {"newkey", false}} {
body, _ := json.Marshal(updateProviderSourceReq{APIKey: &step.key})
req := httptest.NewRequest(http.MethodPatch, "/api/admin/cover-sources/key-prov", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req = withUser(req, admin)
rec := httptest.NewRecorder()
newAdminCoverSourcesRouter(h).ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want 200; body=%s", rec.Code, rec.Body.String())
}
var resp updateProviderSourceResp
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode: %v", err)
}
if resp.VersionBumped {
t.Error("version_bumped = true, want false for key-only change")
}
if !resp.APIKeySet {
t.Error("api_key_set = false, want true after setting key")
if rec.Code != http.StatusOK {
t.Fatalf("step %d: status = %d, want 200; body=%s", i, rec.Code, rec.Body.String())
}
var resp updateProviderSourceResp
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode: %v", err)
}
if resp.VersionBumped != step.wantBumped {
t.Errorf("key %q: version_bumped = %v, want %v", step.key, resp.VersionBumped, step.wantBumped)
}
if !resp.APIKeySet {
t.Error("api_key_set = false, want true after setting key")
}
}
}
+26 -20
View File
@@ -134,7 +134,7 @@ func TestAdminUpdateTagSource_FlippingEnabledBumpsVersion(t *testing.T) {
}
}
func TestAdminUpdateTagSource_KeyOnlyDoesNotBump(t *testing.T) {
func TestAdminUpdateTagSource_ReplacingAKeyDoesNotBump(t *testing.T) {
if os.Getenv("MINSTREL_TEST_DATABASE_URL") == "" {
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
}
@@ -145,26 +145,32 @@ func TestAdminUpdateTagSource_KeyOnlyDoesNotBump(t *testing.T) {
h := testHandlersWithTagSettings(t)
admin := seedUser(t, h.pool, "tskey", "pw", true)
newKey := "newkey"
body, _ := json.Marshal(updateProviderSourceReq{APIKey: &newKey})
req := httptest.NewRequest(http.MethodPatch, "/api/admin/tag-sources/key-tag", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req = withUser(req, admin)
rec := httptest.NewRecorder()
newAdminTagSourcesRouter(h).ServeHTTP(rec, req)
// The first key on an enabled source moves the version (it searched
// without one until now); replacing that key with another doesn't.
for i, step := range []struct {
key string
wantBumped bool
}{{"firstkey", true}, {"newkey", false}} {
body, _ := json.Marshal(updateProviderSourceReq{APIKey: &step.key})
req := httptest.NewRequest(http.MethodPatch, "/api/admin/tag-sources/key-tag", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req = withUser(req, admin)
rec := httptest.NewRecorder()
newAdminTagSourcesRouter(h).ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want 200; body=%s", rec.Code, rec.Body.String())
}
var resp updateProviderSourceResp
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode: %v", err)
}
if resp.VersionBumped {
t.Error("version_bumped = true, want false for key-only change")
}
if !resp.APIKeySet {
t.Error("api_key_set = false, want true after setting key")
if rec.Code != http.StatusOK {
t.Fatalf("step %d: status = %d, want 200; body=%s", i, rec.Code, rec.Body.String())
}
var resp updateProviderSourceResp
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode: %v", err)
}
if resp.VersionBumped != step.wantBumped {
t.Errorf("key %q: version_bumped = %v, want %v", step.key, resp.VersionBumped, step.wantBumped)
}
if !resp.APIKeySet {
t.Error("api_key_set = false, want true after setting key")
}
}
}