fix: address code review findings
- Fix artist-ID namespace mismatch in MusicBrainz provider: SyncArtistDiscography now stores the canonical Navidrome artist ID (artist_settings.id) as external_releases.artist_id instead of the MusicBrainz MBID. Previously the MBID was stored, which violated the FK to artist_settings and broke the scanner join (local_albums.artist_id is the Navidrome ID), causing every external release to be falsely reported as missing and the sync insert to fail at runtime. getArtistFilterOptions now also resolves by the Navidrome ID. - Resolve threshold in FindMissingReleases so the exported primitive honors the same zero-means-default contract as ScanArtist/ScanAll. - Remove dead maxLen==0 guard in scanner.Similarity. - Inline trivial buildPath helper; drop unused url import in client.go. - Replace hand-rolled itoa with strconv.Itoa in tests. - Rewrite SyncArtistDiscography tests to seed artist_settings with the Navidrome ID (tests previously seeded the MBID to mask the FK mismatch). - Fix TestFuzzySmoke to exercise the real dependency (fuzzy.LevenshteinDistance / scanner.Similarity) instead of an unused API. - Fix TestAppRun_ScanLogsMissingReleases to run the scan against a live context and assert the missing release is found. - Document cached_at column in Specification.md and note startup scan / required musicbrainz.user_agent in README. - Stop tracking .serena/ tooling config; add it to .gitignore.
This commit is contained in:
@@ -5,15 +5,19 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"naviwatcher/internal/config"
|
||||
"naviwatcher/internal/database"
|
||||
"naviwatcher/internal/scanner"
|
||||
)
|
||||
|
||||
func TestAppRun_ScanLogsMissingReleases(t *testing.T) {
|
||||
// Verify the compute-only run() hook scans monitored artists and returns
|
||||
// nil without starting notifier/web. Uses an in-memory DB with one
|
||||
// monitored artist that has one missing release.
|
||||
// monitored artist that has one missing release (Animals) vs a local album
|
||||
// (The Wall). The context is left live so the scan actually executes; we
|
||||
// cancel shortly after to let run() return cleanly.
|
||||
db, err := database.New(":memory:")
|
||||
if err != nil {
|
||||
t.Fatalf("database.New() error: %v", err)
|
||||
@@ -48,11 +52,30 @@ func TestAppRun_ScanLogsMissingReleases(t *testing.T) {
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel() // cancel immediately so run() exits after scanning
|
||||
defer cancel()
|
||||
|
||||
if err := app.run(ctx); err != nil {
|
||||
// Run the (blocking) hook in a goroutine; cancel after it has had time to
|
||||
// perform the scan so run() returns nil via the ctx.Done() path.
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- app.run(ctx) }()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
cancel()
|
||||
|
||||
if err := <-done; err != nil {
|
||||
t.Fatalf("app.run() returned error: %v", err)
|
||||
}
|
||||
|
||||
// The scan should have found the missing release (Animals) for artist-1.
|
||||
// Use a fresh context for the verification scan since the run context was
|
||||
// cancelled above.
|
||||
missing, err := scanner.ScanAll(context.Background(), db, 0.85)
|
||||
if err != nil {
|
||||
t.Fatalf("ScanAll() error: %v", err)
|
||||
}
|
||||
if len(missing) != 1 || missing[0].RGID != "rg2" {
|
||||
t.Fatalf("expected 1 missing release (rg2/Animals), got %+v", missing)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigIntegration(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user