feat(web): every Collection queue can remove the file and keep the track
release / web (push) Failing after 1m28s
release / go (push) Successful in 1m53s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 4m16s
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 2m13s
release / android (push) Canceled after 2m59s

Reports offers "Remove the file" ahead of "Remove from library": the
bad file goes and the track waits in Needs a file, with its likes and
plays, for a good copy. Suspect sources gets "Remove this file", and the
Duplicates wrong-slot action and its route are named for what they do
(remove-files). Their toasts and copy name Needs a file.

Missing files becomes Needs a file in the rail, the Collection header and
the Overview counts. Each track says why it waits and who removed it, and
can be forgotten one at a time or by folder; the list exports as a CSV or
copies to the clipboard. The empty state says how a track gets there and
how it leaves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 18:47:36 -05:00
co-authored by Claude Opus 5.5
parent 492eb2fb9a
commit bcd9e422a5
19 changed files with 461 additions and 139 deletions
@@ -1,16 +1,23 @@
import { afterEach, describe, expect, test, vi } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import { fireEvent, render, screen, waitFor, within } from '@testing-library/svelte';
import { mockQuery } from '../../../test-utils/query';
import type { AdminMissingResponse } from '#lib/api/types.js';
import type { AdminMissingResponse, AdminMissingTrack } from '#lib/api/types.js';
vi.mock('#lib/api/admin.js', () => ({ createMissingFilesQuery: vi.fn() }));
vi.mock('#lib/api/admin.js', () => ({
createMissingFilesQuery: vi.fn(),
forgetMissingTracks: vi.fn().mockResolvedValue({ forgotten: 1 }),
MISSING_FILES_CSV_URL: '/api/admin/library/missing.csv'
}));
import MissingPage from './+page.svelte';
import { createMissingFilesQuery } from '#lib/api/admin.js';
import { createMissingFilesQuery, forgetMissingTracks } from '#lib/api/admin.js';
const DAY = 24 * 3_600_000;
function track(title: string, opts: { lastPlayed?: string | null } = {}) {
function track(
title: string,
opts: { lastPlayed?: string | null; removedFor?: AdminMissingTrack['removed_for']; removedBy?: string } = {}
): AdminMissingTrack {
return {
track_id: `t-${title}`,
title,
@@ -20,6 +27,12 @@ function track(title: string, opts: { lastPlayed?: string | null } = {}) {
album_title: 'Minutes to Midnight',
file_path: `/music/Linkin Park/Minutes to Midnight/${title}.flac`,
duration_sec: 185,
disc_number: 1,
track_number: 1,
recording_mbid: null,
release_group_mbid: null,
removed_for: opts.removedFor ?? null,
removed_by: opts.removedBy ?? null,
missing_since: new Date(Date.now() - 3 * DAY).toISOString(),
last_played_at: opts.lastPlayed === undefined ? null : opts.lastPlayed
};
@@ -35,7 +48,7 @@ const response: AdminMissingResponse = {
missing_since: new Date(Date.now() - 3 * DAY).toISOString(),
tracks: [
track('Given Up', { lastPlayed: new Date(Date.now() - 2 * DAY).toISOString() }),
track('Bleed It Out')
track('Bleed It Out', { removedFor: 'report', removedBy: 'alice' })
]
},
{
@@ -68,10 +81,10 @@ describe('/collection/missing', () => {
expect(screen.getByTestId('missing-count-pill').textContent?.trim()).toBe('3');
});
test('a group states how many tracks and how long gone', () => {
test('a group states how many tracks and how long they have waited', () => {
renderWith(response);
expect(screen.getByText(/2 tracks · gone 3d ago/)).toBeTruthy();
expect(screen.getByText(/1 track · gone 9d ago/)).toBeTruthy();
expect(screen.getByText(/2 tracks · 3d ago/)).toBeTruthy();
expect(screen.getByText(/1 track · 9d ago/)).toBeTruthy();
});
// The deciding fact for whether a missing file is worth chasing.
@@ -96,35 +109,65 @@ describe('/collection/missing', () => {
// An operator who has never seen this page should not have to guess what
// would put a row here.
test('the empty state explains what missing means', () => {
test('the empty state says how a track gets here and how it leaves', () => {
renderWith({ total: 0, limit: 50, offset: 0, groups: [] });
expect(screen.getByText(/every track's file is where it should be/i)).toBeTruthy();
expect(screen.getByText(/can't find its file/i)).toBeTruthy();
expect(screen.getByText(/every track has its file/i)).toBeTruthy();
expect(screen.getByText(/removed from one of the collection's queues/i)).toBeTruthy();
expect(screen.getByText(/when a good copy is in the library/i)).toBeTruthy();
expect(screen.queryByTestId('missing-count-pill')).toBeNull();
});
test('shows a loading line while pending', () => {
renderWith(undefined, { isPending: true });
expect(screen.getByText(/checking what's missing/i)).toBeTruthy();
expect(screen.getByText(/reading the list/i)).toBeTruthy();
});
test('shows an error line when the query fails', () => {
renderWith(undefined, { isError: true });
expect(screen.getByText(/couldn't load the missing files/i)).toBeTruthy();
expect(screen.getByText(/couldn't load the list/i)).toBeTruthy();
});
// Paging only appears when it can do something: a single page of results
// should not render dead Previous/Next buttons.
test('no pager when everything fits on one page', () => {
renderWith(response);
expect(screen.queryByLabelText('Missing files pages')).toBeNull();
expect(screen.queryByLabelText('Needs a file pages')).toBeNull();
});
test('pager appears when the server reports more than this page holds', () => {
renderWith({ ...response, total: 120 });
expect(screen.getByLabelText('Missing files pages')).toBeTruthy();
expect(screen.getByLabelText('Needs a file pages')).toBeTruthy();
expect(screen.getByText('1–3 of 120')).toBeTruthy();
expect(screen.getByRole('button', { name: 'Previous' })).toHaveProperty('disabled', true);
expect(screen.getByRole('button', { name: 'Next' })).toHaveProperty('disabled', false);
});
test('each track says why it waits', () => {
renderWith(response);
const why = screen.getAllByTestId('missing-track-why').map((e) => e.textContent ?? '');
expect(why[0]).toMatch(/file went missing from disk/i);
expect(why[1]).toMatch(/file removed from a report by alice/i);
});
test('Forget asks first, then forgets the one track', async () => {
renderWith(response);
await fireEvent.click(screen.getByRole('button', { name: 'Forget Given Up' }));
expect(forgetMissingTracks).not.toHaveBeenCalled();
await fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: /confirm forget/i }));
await waitFor(() => expect(forgetMissingTracks).toHaveBeenCalledWith(['t-Given Up']));
});
test('Forget all takes the whole folder', async () => {
renderWith(response);
await fireEvent.click(
screen.getByRole('button', { name: 'Forget the 2 tracks in /music/Linkin Park/Minutes to Midnight' })
);
await fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: /confirm forget/i }));
await waitFor(() => expect(forgetMissingTracks).toHaveBeenCalledWith(['t-Given Up', 't-Bleed It Out']));
});
test('Export CSV links to the whole list', () => {
renderWith(response);
expect(screen.getByRole('link', { name: /export csv/i })).toHaveAttribute('href', '/api/admin/library/missing.csv');
});
});