feat(library): removing a bad file keeps its track, waiting for a good copy
release / go (push) Successful in 2m6s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m46s
release / android (push) Successful in 4m47s
release / Build signed APK (push) Successful in 5m38s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 31s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 2m6s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m46s
release / android (push) Successful in 4m47s
release / Build signed APK (push) Successful in 5m38s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 31s
release / Verify release artifacts (tag releases only) (push) Skipped
Reports, Duplicates and Suspect sources now end the same way: the file
goes and the track stays, marked missing with its likes, plays and
playlist places, until a good copy lands in the library and move
adoption or missing-pair folding brings it back.
- library.RemoveFile removes one track's file and marks the track
missing with the queue it was removed from and who removed it
(tracks.removed_reason / removed_by, migration 0104). The duplicate
resolver's wrong-slot removal shares the same marking.
- POST /api/admin/quarantine/{id}/remove-file removes a reported file,
clears the listeners' reports, marks open playback errors deleted and
records removed_file in the Reports history. A wrong-file or
wrong-tags report drops the file's recording MBID.
- POST /api/admin/library/suspect-sources/{id}/remove removes a video
rip's file and its MBID, and writes a suspect_file_remove audit row.
- The removal reason clears with the missing mark when a file returns.
Grimoire #7743 (milestone 635).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -329,6 +329,77 @@ func TestDeleteFile_RemovesFileAndAuditsAffected(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove file keeps the reported track, missing, and settles its reports:
|
||||
// the listeners' rows go, open playback errors read deleted, and the history
|
||||
// says the file was removed. A "wrong file" report drops the file's MBID.
|
||||
func TestRemoveFile_KeepsTheTrackAndSettlesItsReports(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
ctx := context.Background()
|
||||
alice := seedUser(t, pool, "alice")
|
||||
admin := seedUser(t, pool, "admin")
|
||||
q := dbq.New(pool)
|
||||
|
||||
path := filepath.Join(t.TempDir(), "track.mp3")
|
||||
if err := os.WriteFile(path, []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
artist, _ := q.UpsertArtist(ctx, dbq.UpsertArtistParams{Name: "A", SortName: "A"})
|
||||
album, _ := q.UpsertAlbum(ctx, dbq.UpsertAlbumParams{Title: "Al", SortTitle: "Al", ArtistID: artist.ID})
|
||||
mbid := "rec-of-another-song"
|
||||
track, err := q.UpsertTrack(ctx, dbq.UpsertTrackParams{
|
||||
Title: "T", AlbumID: album.ID, ArtistID: artist.ID, Mbid: &mbid,
|
||||
DurationMs: 1000, FilePath: path, FileSize: 1, FileFormat: "mp3",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := pool.Exec(ctx, `UPDATE tracks SET mbid_source = 'tag' WHERE id = $1`, track.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
svc := NewService(pool, "")
|
||||
if _, err := svc.Flag(ctx, alice.ID, track.ID, "wrong_file", ""); err != nil {
|
||||
t.Fatalf("Flag: %v", err)
|
||||
}
|
||||
if _, err := q.InsertPlaybackError(ctx, dbq.InsertPlaybackErrorParams{
|
||||
TrackID: track.ID, UserID: alice.ID, ClientID: "web", Kind: "load_failed",
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
action, err := svc.RemoveFile(ctx, track.ID, admin.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("RemoveFile: %v", err)
|
||||
}
|
||||
if action.Action != dbq.QuarantineActionKindRemovedFile || action.AffectedUsers != 1 {
|
||||
t.Errorf("history = %v for %d users, want removed_file for 1", action.Action, action.AffectedUsers)
|
||||
}
|
||||
if _, err := os.Stat(path); !errors.Is(err, os.ErrNotExist) {
|
||||
t.Errorf("file still exists: %v", err)
|
||||
}
|
||||
got, err := q.GetTrackByID(ctx, track.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("the track went with its file: %v", err)
|
||||
}
|
||||
if !got.MissingSince.Valid || got.RemovedReason == nil || *got.RemovedReason != "report" {
|
||||
t.Errorf("track = missing %v, reason %v; want missing for a report", got.MissingSince.Valid, got.RemovedReason)
|
||||
}
|
||||
if got.Mbid != nil {
|
||||
t.Errorf("mbid = %q, want it dropped for a wrong-file report", *got.Mbid)
|
||||
}
|
||||
if n, _ := q.CountQuarantineForTrack(ctx, track.ID); n != 0 {
|
||||
t.Errorf("%d reports left, want them cleared", n)
|
||||
}
|
||||
var open, deleted int
|
||||
if err := pool.QueryRow(ctx, `SELECT count(*) FILTER (WHERE resolved_at IS NULL),
|
||||
count(*) FILTER (WHERE resolution = 'deleted')
|
||||
FROM playback_errors WHERE track_id = $1`, track.ID).Scan(&open, &deleted); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if open != 0 || deleted != 1 {
|
||||
t.Errorf("playback errors: %d open, %d deleted; want 0 and 1", open, deleted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteFile_TrackNotFound(t *testing.T) {
|
||||
pool := newPool(t)
|
||||
user := seedUser(t, pool, "alice")
|
||||
|
||||
Reference in New Issue
Block a user