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:
@@ -5,6 +5,8 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"testing"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/secret"
|
||||
)
|
||||
|
||||
type fakeProvider struct {
|
||||
@@ -126,12 +128,12 @@ func TestUpdateProvider_BumpsTheVersionOnlyWhenTheEnabledSetChanges(t *testing.T
|
||||
if !p.configured.Enabled || s.CurrentVersion() != store.version {
|
||||
t.Fatalf("after enable: configured=%v version=%d store=%d", p.configured.Enabled, s.CurrentVersion(), store.version)
|
||||
}
|
||||
// Clearing the key: a key-only change. (An empty key is stored as
|
||||
// NULL without sealing, so the test needs no sealing key.)
|
||||
// Clearing a key that was never set changes nothing a search uses. (An
|
||||
// empty key is stored as NULL without sealing.)
|
||||
key := ""
|
||||
bumped, err = s.UpdateProvider(ctx, "p", UpdatePatch{APIKey: &key})
|
||||
if err != nil || bumped {
|
||||
t.Fatalf("key only: bumped=%v err=%v, want false nil", bumped, err)
|
||||
t.Fatalf("clearing an unset key: bumped=%v err=%v, want false nil", bumped, err)
|
||||
}
|
||||
if _, err := s.UpdateProvider(ctx, "nope", UpdatePatch{}); err != ErrProviderNotFound {
|
||||
t.Fatalf("unknown provider: err=%v, want ErrProviderNotFound", err)
|
||||
@@ -159,3 +161,31 @@ func TestBumpVersionIfProvidersChanged_WritesOnlyOnAChange(t *testing.T) {
|
||||
t.Fatalf("same set: bumped=%v version %d→%d, want no write", bumped, before, store.version)
|
||||
}
|
||||
}
|
||||
|
||||
// A source switched on before its key was entered searched without it, so
|
||||
// the key arriving moves the version and the gaps it left are tried again.
|
||||
// Swapping one key for another doesn't.
|
||||
func TestUpdateProvider_AKeyArrivingOnAnEnabledSourceBumpsTheVersion(t *testing.T) {
|
||||
secret.Install([]byte("providers tests: not a deployment key"))
|
||||
p := &fakeProvider{id: "p"}
|
||||
s, _ := newTestService(t, p)
|
||||
ctx := context.Background()
|
||||
on := true
|
||||
if _, err := s.UpdateProvider(ctx, "p", UpdatePatch{Enabled: &on}); err != nil {
|
||||
t.Fatalf("enable: %v", err)
|
||||
}
|
||||
for _, step := range []struct {
|
||||
key string
|
||||
want bool
|
||||
}{
|
||||
{"first-key", true},
|
||||
{"second-key", false},
|
||||
{"", true},
|
||||
} {
|
||||
key := step.key
|
||||
bumped, err := s.UpdateProvider(ctx, "p", UpdatePatch{APIKey: &key})
|
||||
if err != nil || bumped != step.want {
|
||||
t.Fatalf("key %q: bumped=%v err=%v, want %v", step.key, bumped, err, step.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user