fix(library): a file back at a waiting track's path brings it back at once
release / go (push) Successful in 1m40s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m50s
release / android (push) Successful in 4m29s
release / Build signed APK (push) Successful in 4m45s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 42s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 1m40s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m50s
release / android (push) Successful in 4m29s
release / Build signed APK (push) Successful in 4m45s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 42s
release / Verify release artifacts (tag releases only) (push) Skipped
The watcher scans single files and never reconciles, and a file restored with its old mtime takes the unchanged skip, so a track whose file came back at the same path waited in Needs a file for the next full scan. The scan now clears the mark when the path it reads belongs to a waiting track, and tells clients it plays again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db"
|
||||
@@ -485,3 +486,65 @@ func TestScanner_SameTitledAlbumsOfTwoGroupsAreTwoAlbums_Integration(t *testing.
|
||||
t.Errorf("after the re-read, albums by group = %v, want the green track on its own album", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestScanFiles_ClearsTheMarkWhenAFileReturnsToItsPath_Integration: a file
|
||||
// put back at the path of a track waiting for one (an admin removed it, or it
|
||||
// went missing) brings the track back as soon as the watcher scans it, even
|
||||
// with its old mtime, which takes the unchanged-file skip. The track keeps its
|
||||
// id, and clients are told it plays again.
|
||||
func TestScanFiles_ClearsTheMarkWhenAFileReturnsToItsPath_Integration(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
ctx := context.Background()
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
|
||||
root := t.TempDir()
|
||||
path := filepath.Join(root, "Artist R/Album R/03 - Returning.mp3")
|
||||
writeTestMP3(t, path, map[string]string{
|
||||
"TIT2": "Returning", "TPE1": "Artist R", "TALB": "Album R", "TRCK": "3",
|
||||
})
|
||||
scanner := New(pool, logger, []string{root}, nil)
|
||||
if _, err := scanner.ScanFiles(ctx, []string{path}); err != nil {
|
||||
t.Fatalf("first scan: %v", err)
|
||||
}
|
||||
q := dbq.New(pool)
|
||||
before, err := q.GetTrackByPath(ctx, path)
|
||||
if err != nil {
|
||||
t.Fatalf("track not indexed: %v", err)
|
||||
}
|
||||
|
||||
// Removed from Reports: the row waits, and the file is back unchanged.
|
||||
if _, err := q.MarkTracksRemoved(ctx, dbq.MarkTracksRemovedParams{
|
||||
Reason: string(RemovedForReport), Ids: []pgtype.UUID{before.ID},
|
||||
}); err != nil {
|
||||
t.Fatalf("mark removed: %v", err)
|
||||
}
|
||||
var changesBefore int
|
||||
if err := pool.QueryRow(ctx, "SELECT count(*) FROM library_changes").Scan(&changesBefore); err != nil {
|
||||
t.Fatalf("count changes: %v", err)
|
||||
}
|
||||
|
||||
if _, err := scanner.ScanFiles(ctx, []string{path}); err != nil {
|
||||
t.Fatalf("watcher scan: %v", err)
|
||||
}
|
||||
|
||||
after, err := q.GetTrackByID(ctx, before.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("track gone: %v", err)
|
||||
}
|
||||
if after.MissingSince.Valid {
|
||||
t.Errorf("track still waits for a file it has: missing_since=%v", after.MissingSince.Time)
|
||||
}
|
||||
if after.RemovedReason != nil {
|
||||
t.Errorf("removed_reason = %q, want none once the file is back", *after.RemovedReason)
|
||||
}
|
||||
if after.FilePath != path {
|
||||
t.Errorf("file_path = %q, want %q", after.FilePath, path)
|
||||
}
|
||||
var changesAfter int
|
||||
if err := pool.QueryRow(ctx, "SELECT count(*) FROM library_changes").Scan(&changesAfter); err != nil {
|
||||
t.Fatalf("count changes: %v", err)
|
||||
}
|
||||
if changesAfter <= changesBefore {
|
||||
t.Error("no library change logged, so clients would still show the track as unplayable")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user