Files
minstrel/internal/api/admin_status_test.go
T
bvandeusenandClaude Opus 5.5 55c7497ca7
release / go (push) Successful in 1m54s
release / web (push) Failing after 5s
release / integration (push) Failing after 3m44s
release / govulncheck (push) Successful in 20s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 19s
release / android (push) Canceled after 2m37s
feat: Minstrel stops acquiring music and drops Discover
Minstrel is now a viewer of the library it is pointed at. Finding,
downloading and filing music moves out of it.

Removed from the server:
- the request flow (requests, approval, auto-approve) and the wanted list,
  follows, release profiles and release blocks;
- searching indexers, the download clients, the importer, the album
  lifecycle and missing-file re-acquisition;
- the catalogue's discography, search and art (the MusicBrainz release and
  track-list cache stays, for the duplicate resolver);
- Discover: its suggestions of artists not in the library, snoozes, the
  candidate-artist tag enrichment and its tuning scope;
- writes to acquisition tables from moving the library folder and from
  merging duplicates, the want-list join on Suspect sources, the sealing of
  acquisition credentials, and the release-group lookup only
  re-acquisition used.

Settling a wrong-slot duplicate no longer sets the release aside: the
copies go and their slots show as missing until a good copy is in the
library.

Removed from the web: Admin > Acquisition and Requests, /requests,
/discover, Follow on the artist page, the auto-approve toggle, and the
Collection's wanted-list tabs. The Collection is now the library's health:
an overview, Reports, Duplicates, Suspect sources and Missing files. The
README and docs no longer describe getting music.

The tables stay for now; a later migration drops them. The request
notification kinds and the Android screens are still to go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 20:51:14 -05:00

90 lines
2.9 KiB
Go

package api
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/jackc/pgx/v5/pgtype"
"git.fabledsword.com/bvandeusen/minstrel/internal/buildinfo"
"git.fabledsword.com/bvandeusen/minstrel/internal/logging"
)
// openPlay records a play by user of track that started ago and has not
// ended.
func openPlay(t *testing.T, h *handlers, user, track pgtype.UUID, ago string) {
t.Helper()
ctx := context.Background()
var session pgtype.UUID
if err := h.pool.QueryRow(ctx,
`INSERT INTO play_sessions (user_id, started_at, last_event_at) VALUES ($1, now(), now()) RETURNING id`,
user).Scan(&session); err != nil {
t.Fatalf("session: %v", err)
}
if _, err := h.pool.Exec(ctx,
`INSERT INTO play_events (user_id, track_id, session_id, started_at, client_id)
VALUES ($1, $2, $3, now() - $4::interval, 'web')`, user, track, session, ago); err != nil {
t.Fatalf("play: %v", err)
}
}
// The Overview's status: a play still inside its track's length is
// listening now; one long past it, never closed by its client, is not.
func TestAdminStatus_ListeningAndServer(t *testing.T) {
h, pool := testHandlers(t)
truncateLibrary(t, pool)
admin := seedUser(t, pool, "admin", "pw", true)
fresh, _ := seedTrackOnDisk(t, h, "statusfresh") // 30 s long
stale, _ := seedTrackOnDisk(t, h, "statusstale")
openPlay(t, h, admin.ID, fresh.ID, "10 seconds")
openPlay(t, h, admin.ID, stale.ID, "1 hour")
req := withUser(httptest.NewRequest(http.MethodGet, "/api/admin/status", nil), admin)
w := httptest.NewRecorder()
h.handleGetAdminStatus(w, req)
if w.Code != http.StatusOK {
t.Fatalf("status %d: %s", w.Code, w.Body.String())
}
var got adminStatusView
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
t.Fatalf("decode: %v", err)
}
var sawFresh, sawStale bool
for _, p := range got.Listening.Now {
switch p.TrackID {
case uuidToString(fresh.ID):
sawFresh = true
if p.Username != admin.Username || p.Client != "web" || p.Title != "AdmQ Track statusfresh" {
t.Errorf("listening row = %+v", p)
}
case uuidToString(stale.ID):
sawStale = true
}
}
if !sawFresh || sawStale {
t.Errorf("listening now: fresh %v (want true), stale %v (want false)", sawFresh, sawStale)
}
if got.Listening.PlaysDay < 2 || got.Listening.LastPlayAt == nil {
t.Errorf("last day: plays %d, last %v", got.Listening.PlaysDay, got.Listening.LastPlayAt)
}
if got.Library.Tracks != 2 || got.Library.Albums != 2 || got.Library.Bytes != 10 {
t.Errorf("library = %+v, want 2 tracks, 2 albums, 10 bytes", got.Library)
}
if got.Library.Disks == nil {
t.Error("lists must be [], never null")
}
if got.Server.Version != buildinfo.Version || got.Server.StartedAt == "" || got.Server.Migration < 92 {
t.Errorf("server = %+v", got.Server)
}
if _, total := logging.Errors.Snapshot(); got.Server.ErrorCount != total {
t.Errorf("error count = %d, ring says %d", got.Server.ErrorCount, total)
}
}