feat(library): Missing files says why each track waits, and can forget or export it
release / go (push) Successful in 1m49s
release / web (push) Successful in 1m26s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m29s
release / android (push) Successful in 4m43s
release / Build signed APK (push) Successful in 5m1s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 1m49s
release / web (push) Successful in 1m26s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m29s
release / android (push) Successful in 4m43s
release / Build signed APK (push) Successful in 5m1s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped
- The missing list carries each track's disc and track number, its
recording and release-group MBIDs, the Collection queue its file was
removed from, and the admin who removed it.
- POST /api/admin/library/missing/forget deletes waiting tracks for good,
tidying away an album or artist they leave empty, and writes a
track_forget audit row naming each. It is all or nothing: a track that
has its file again is refused with 409 track_has_file.
- GET /api/admin/library/missing.csv exports every waiting track (artist,
album, disc, track, title, MBIDs, why, since) to hand to whatever finds
music.
- DELETE /api/admin/tracks/{id} is retired. No client called it; its
service becomes tracks.Service.ForgetTracks.
Grimoire #7744 (milestone 635).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/csv"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The export names every waiting track and why it waits, with an empty cell
|
||||
// for an MBID or a position the tags never carried.
|
||||
func TestHandleExportMissingTracks_Integration(t *testing.T) {
|
||||
h, pool := testHandlers(t)
|
||||
truncateLibrary(t, pool)
|
||||
admin := seedUser(t, pool, "export-admin", "pw", true)
|
||||
artist := seedArtist(t, pool, "Boards of Canada")
|
||||
album := seedAlbum(t, pool, artist.ID, "Geogaddi", 2002)
|
||||
gone := seedTrack(t, pool, album.ID, artist.ID, "Music Is Math", 0, 300_000)
|
||||
removed := seedTrack(t, pool, album.ID, artist.ID, "Dawn Chorus", 2, 240_000)
|
||||
seedTrack(t, pool, album.ID, artist.ID, "Julie and Candy", 3, 200_000)
|
||||
ctx := context.Background()
|
||||
if _, err := pool.Exec(ctx, `UPDATE tracks SET missing_since = now() WHERE id = $1`, gone.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := pool.Exec(ctx, `UPDATE tracks SET missing_since = now(), removed_reason = 'report', removed_by = $2,
|
||||
mbid = 'rec-dawn', mbid_source = 'tag' WHERE id = $1`, removed.ID, admin.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
req := withUser(httptest.NewRequest(http.MethodGet, "/api/admin/library/missing.csv", nil), admin)
|
||||
w := httptest.NewRecorder()
|
||||
h.handleExportMissingTracks(w, req)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
rows, err := csv.NewReader(bytes.NewReader(w.Body.Bytes())).ReadAll()
|
||||
if err != nil {
|
||||
t.Fatalf("parse csv: %v", err)
|
||||
}
|
||||
if len(rows) != 3 {
|
||||
t.Fatalf("rows = %v, want a header and the two waiting tracks", rows)
|
||||
}
|
||||
byTitle := map[string][]string{}
|
||||
for _, r := range rows[1:] {
|
||||
byTitle[r[4]] = r
|
||||
}
|
||||
if r := byTitle["Music Is Math"]; r == nil || r[3] != "" || r[5] != "" || r[7] != "missing" {
|
||||
t.Errorf("untagged missing row = %v, want no track number, no mbid, why missing", r)
|
||||
}
|
||||
if r := byTitle["Dawn Chorus"]; r == nil || r[3] != "2" || r[5] != "rec-dawn" || r[7] != "report" {
|
||||
t.Errorf("removed row = %v, want track 2, its mbid, why report", r)
|
||||
}
|
||||
}
|
||||
|
||||
// Forget deletes waiting tracks, all or nothing: a track that has its file
|
||||
// is refused, and nothing in that request goes.
|
||||
func TestHandleForgetMissingTracks_Integration(t *testing.T) {
|
||||
h, pool := testHandlers(t)
|
||||
truncateLibrary(t, pool)
|
||||
admin := seedUser(t, pool, "forget-admin", "pw", true)
|
||||
artist := seedArtist(t, pool, "Autechre")
|
||||
album := seedAlbum(t, pool, artist.ID, "Amber", 1994)
|
||||
waiting := seedTrack(t, pool, album.ID, artist.ID, "Foil", 1, 300_000)
|
||||
present := seedTrack(t, pool, album.ID, artist.ID, "Montreal", 2, 300_000)
|
||||
ctx := context.Background()
|
||||
if _, err := pool.Exec(ctx, `UPDATE tracks SET missing_since = now() WHERE id = $1`, waiting.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
forget := func(ids ...string) int {
|
||||
body := `{"track_ids":[`
|
||||
for i, id := range ids {
|
||||
if i > 0 {
|
||||
body += ","
|
||||
}
|
||||
body += `"` + id + `"`
|
||||
}
|
||||
body += `]}`
|
||||
req := withUser(httptest.NewRequest(http.MethodPost, "/api/admin/library/missing/forget", bytes.NewBufferString(body)), admin)
|
||||
w := httptest.NewRecorder()
|
||||
h.handleForgetMissingTracks(w, req)
|
||||
return w.Code
|
||||
}
|
||||
exists := func(id string) bool {
|
||||
var n int
|
||||
if err := pool.QueryRow(ctx, `SELECT count(*) FROM tracks WHERE id = $1`, id).Scan(&n); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return n == 1
|
||||
}
|
||||
|
||||
if code := forget(uuidToString(waiting.ID), uuidToString(present.ID)); code != http.StatusConflict {
|
||||
t.Fatalf("forgetting a track with its file: status %d, want 409", code)
|
||||
}
|
||||
if !exists(uuidToString(waiting.ID)) || !exists(uuidToString(present.ID)) {
|
||||
t.Fatalf("a refused forget removed a track")
|
||||
}
|
||||
if code := forget(uuidToString(waiting.ID)); code != http.StatusOK {
|
||||
t.Fatalf("forgetting the waiting track: status %d, want 200", code)
|
||||
}
|
||||
if exists(uuidToString(waiting.ID)) {
|
||||
t.Errorf("the forgotten track is still there")
|
||||
}
|
||||
if !exists(uuidToString(present.ID)) {
|
||||
t.Errorf("the album's other track went too")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user