Plans 013 and 014, the album page that prompted them, and the smaller fixes they turned up. Changelog, largest first. ## The local library is shaped like files, not like MusicBrainz `audio_files` carries its own tags and points at `albums` and `artists`; `file_genres` is the one real many-to-many. `recordings`, `release_group_recordings`, `artist_credit`, `artist_credit_artist`, `recording_genres`, `release_groups` and `release_to_rg` are gone from the local side, and with them a six-way join in every read, a `MIN(release_group_id)` subquery in eleven queries and a first-credited-artist subquery in nine. Measured on a real 25,966-file library, every many-to-many that model expressed was 1:1 in the data. - Ownership is a file. `GetFilePathsByRecordingMBIDs`, `LibraryMBIDIndex.CheckMBIDs`, `collectLibraryEntities` and `pruneStaleLocalCrossReferences` all join `audio_files`, so the 812 orphaned recordings, 216 release groups and 260 artists that library carried are now structurally impossible. - One projection: every track query selects from the `track_metadata` view, one row type, one mapper. Nine hand-rolled copies had drifted far enough to report different years on different screens. - `library_id = 0` means every library, so each list query exists once instead of scoped and unscoped with a branch at every call site. - No migration chain. `sql/schemas/` is the one description of the shape; `sql/migrations/`, `applyMigrations` and `schema_migrations` are squashed away, along with the drift between them that had sqlc generating against a stale schema. - `database.InsertTestTrack` is the one test seeder; twenty test files had been assembling the old FK chain each in its own order. ## The catalog stores its ids as bytes `explore_index`'s three 36-char MBID columns and its entity-type text are 16 raw bytes and a small integer. The table and its six indexes go 780 MB to 405 MB on a real 2,052,200-row catalog, which is why a fresh install is ~0.6 GB rather than ~1.0 GB. - `backend/explore/mbid.go` is the only place the encoding is known; everything above it speaks dashed strings. - `CHECK(length(mbid) = 16)` makes a stringly write fail at the insert rather than silently returning no rows, since SQLite does not coerce between TEXT and BLOB. - The importer asks the artifact what encoding it carries and converts on the way in, so the artifact already published keeps working and no format bump is needed. - `indexRowColumns`/`scanIndexRow` replace four copies of a 22-column list, and `TestStoredEncodingRoundTrips` sweeps every read path. ## An album page that says how much of the album is yours - One question, asked once: is there a file. `filePaths` is filled by a single batched lookup when the tracklist settles, and the badge, the Play count, the dimmed rows and every menu item read it — replacing four claims of decreasing confidence that could show a green tick on an album whose every action did nothing. - Play, Play 7 of 12, or no play button at all. - `total_tracks` on `explore_index` (~2 bytes over 400,677 release groups) and on `audio_files` from tags that have always carried it: a complete MBID-matched album now makes no catalog call at all, where it used to spend the most expensive request the app makes. - A merged cluster shows the running order the most releases agree on, and the version list marks the release you own rather than standing a synthetic entry in for it. - `AlbumReleasesFailed`: a slow fetch is no longer reported as a failed one by a 12-second timer. - Rows not in the library are dimmed in place (with `aria-disabled`) instead of the owned ones wearing a green tick and a legend. ## Caches and cover art get ceilings - Only the three tiers of a cover are stored; the full-resolution copy nothing rendered was 1,134 MB of a 1.4 GB covers directory. - One artist portrait is downloaded and the rest are remembered as URLs — 4.1 GB of a 5.3 GB cache was candidates no code path reads. - `browsedArtBudget` and `httpCacheBudget` bound what an age cannot: the same install held art for 5,770 artists in a 1,301-artist library. - `OrphanedArtistImagesJob` joined a bare MBID onto a sharded directory, so it deleted the rows that were the only record of the files it left behind. `explore.ArtistImageDir` is that layout's one definition now. ## The autotag queue asks whether there is work `tagging_items` was a row per album folder, not a queue, and no query read the `tag_status` column that held the answer. The four queue queries ask the files, which matters most where it is least visible: `startPrefetch` was scoring every album in a tagged library against MusicBrainz. ## Phantom playlist tracks resolve in place An M3U8 imported before its files leaves phantom rows; they now match by path and fall back to position, keep their place in the playlist when resolved, and pair best-first so two phantoms cannot claim the same file. ## Playing a track plays the list it is in Double-click, and Play on a single row's menu, queue the list as displayed with `startIndex` on that row — the album page and the track list used to queue one track and discard the album around it. A multi-row selection still plays exactly itself. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AfVYUVExXsx1nSWrXN8mAh
286 lines
10 KiB
TypeScript
286 lines
10 KiB
TypeScript
import { test, expect } from '../support/fixtures.js';
|
|
import type { Page } from '@playwright/test';
|
|
|
|
/**
|
|
* Plan 007 phase 6 (`H-23`): Explore starts the conversation.
|
|
*
|
|
* It was a search box over a 1.1 M-row local catalog and a sentence
|
|
* telling the user to type into it — the only view in the app that
|
|
* answers "what exists" rather than "what have I got", and it would not
|
|
* begin.
|
|
*
|
|
* Two worlds, and both are asserted rather than one assertion loose
|
|
* enough to pass in either. A developer machine downloads the real
|
|
* catalog artifact on launch and gets a million rows; **CI points
|
|
* `YJ_CORE_INDEX_URL` at a dead address**, so the app there has an
|
|
* empty index — which is also every user's first run.
|
|
*
|
|
* The empty world is the interesting one and it is where the specs used
|
|
* to *skip*, which is no signal at all. So this suite stages its own
|
|
* catalog through `/__test/sql` when there is none, the way the perf
|
|
* harness builds the playlists the bulk seed does not have. That works
|
|
* only because the page asks the database whether a catalog exists
|
|
* rather than consulting a flag set at startup — the first two versions
|
|
* of that gate were cached, and rows staged afterwards were invisible
|
|
* to both.
|
|
*/
|
|
test.describe('Explore before anyone has typed', () => {
|
|
test.beforeEach(async ({ app }) => {
|
|
// Idempotent, so running it per test costs one count query when a
|
|
// catalog is already there — which is every developer machine.
|
|
await stageCatalogIfEmpty(app);
|
|
|
|
await app.getByTestId('nav-explore').click();
|
|
await expect(app.getByTestId('main-content')).toHaveAttribute(
|
|
'data-active-view',
|
|
'explore',
|
|
);
|
|
|
|
// The view being on screen is not the shelves being on it: they
|
|
// are fetched when it activates. Reading them a moment too early
|
|
// gives an empty list, which is also what a broken page gives.
|
|
await expect.poll(() => shelfHeadings(app)).not.toHaveLength(0);
|
|
});
|
|
|
|
test('says something without being typed into', async ({ app }) => {
|
|
const view = app.locator('explore-view');
|
|
|
|
// Shelves, on `backend/home`'s terms: a reason per row, and the
|
|
// sentence that says so beside it. That there are any at all is
|
|
// asserted in beforeEach.
|
|
const reasons = await app.evaluate(
|
|
() =>
|
|
[
|
|
...(document
|
|
.querySelector('explore-view')
|
|
?.shadowRoot?.querySelectorAll('.section-reason') ?? []),
|
|
].length,
|
|
);
|
|
|
|
expect(reasons).toBeGreaterThan(0);
|
|
|
|
// And the page it replaced is gone.
|
|
await expect(view).not.toContainText('Search to discover');
|
|
});
|
|
|
|
test('a shelf card opens the page it is about', async ({ app }) => {
|
|
// The cards route through what already existed — no new detail
|
|
// page was invented for this.
|
|
await clickCard(app, '.album-card');
|
|
await expect(app.getByTestId('main-content')).toHaveAttribute(
|
|
'data-active-view',
|
|
'explore-album-details',
|
|
);
|
|
|
|
await app.getByTestId('nav-explore').click();
|
|
|
|
await clickCard(app, '.artist-card');
|
|
await expect(app.getByTestId('main-content')).toHaveAttribute(
|
|
'data-active-view',
|
|
'explore-artist-details',
|
|
);
|
|
});
|
|
|
|
test('clearing a search comes back to the shelves', async ({ app }) => {
|
|
const before = await shelfHeadings(app);
|
|
|
|
// What the search finds is not this spec's business and differs
|
|
// between the two worlds — a real catalog answers `Artists /
|
|
// Albums / Tracks`, a staged one answers nothing at all. What has
|
|
// to be true in both is that the shelves get out of the way…
|
|
await type(app, 'nirvana');
|
|
await expect.poll(() => shelfHeadings(app)).not.toEqual(before);
|
|
|
|
// …and that they are what the page comes back to when the query is
|
|
// cleared, rather than a mode you have to leave.
|
|
await type(app, '');
|
|
await expect.poll(() => shelfHeadings(app)).toEqual(before);
|
|
});
|
|
|
|
test('two shelves are not the same shelf twice', async ({ app }) => {
|
|
// Ordered by raw listen count, the catalog's top albums are one act
|
|
// and its members and the artists row underneath was the same
|
|
// people — a duplication no id comparison can see, because the two
|
|
// rows hold different entity types.
|
|
const names = await app.evaluate(() => {
|
|
const root = document.querySelector('explore-view')?.shadowRoot;
|
|
const text = (sel: string) =>
|
|
[...(root?.querySelectorAll(sel) ?? [])].map((e) =>
|
|
(e.textContent ?? '').trim(),
|
|
);
|
|
|
|
return {
|
|
albumArtists: text('.album-card .album-artist'),
|
|
artists: text('.artist-card .artist-name'),
|
|
};
|
|
});
|
|
|
|
// One album per artist, and no artist in both rows.
|
|
expect(new Set(names.albumArtists).size).toBe(names.albumArtists.length);
|
|
|
|
for (const artist of names.artists) {
|
|
expect(names.albumArtists).not.toContain(artist);
|
|
}
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Give the app a catalog if it has none, so the empty-index environment
|
|
* still exercises the shelves rather than skipping them.
|
|
*
|
|
* Deliberately shaped: two artists with albums (one of them with
|
|
* three), and a third with none. The three albums are what "one album
|
|
* per artist" can be false about; the third artist is what the artists
|
|
* shelf is made of, because the other two are spent by the albums row
|
|
* above it and correctly skipped — the first version of this fixture
|
|
* had only two, and the artists shelf was rightly omitted, which read
|
|
* as a broken page.
|
|
*/
|
|
async function stageCatalogIfEmpty(app: Page): Promise<void> {
|
|
if ((await catalogRows(app)) > 0) return;
|
|
|
|
// The catalog stores an MBID as its 16 raw bytes and an entity type
|
|
// as a small integer, so a staged row has to be spelled the way the
|
|
// app spells one: a real UUID, converted at the boundary, and a code
|
|
// rather than the word. `'e2e-ar-a'` is 8 characters and fails
|
|
// `CHECK(length(mbid) = 16)` -- which `INSERT OR IGNORE` then
|
|
// swallows, so the staging step looked exactly like a staging step
|
|
// and the page had nothing to draw. That is the same fault this
|
|
// helper's own comment below describes, one layer down.
|
|
const ARTIST = 1;
|
|
const RELEASE_GROUP = 2;
|
|
|
|
const rows = [
|
|
[ARTIST, uuid('ar-a'), 'Staged Alpha', 'Staged Alpha', uuid('ar-a'), 9000],
|
|
[ARTIST, uuid('ar-b'), 'Staged Beta', 'Staged Beta', uuid('ar-b'), 500],
|
|
[ARTIST, uuid('ar-c'), 'Staged Gamma', 'Staged Gamma', uuid('ar-c'), 300],
|
|
[RELEASE_GROUP, uuid('rg-a1'), 'Alpha One', 'Staged Alpha', uuid('ar-a'), 8000],
|
|
[RELEASE_GROUP, uuid('rg-a2'), 'Alpha Two', 'Staged Alpha', uuid('ar-a'), 7000],
|
|
[RELEASE_GROUP, uuid('rg-a3'), 'Alpha Three', 'Staged Alpha', uuid('ar-a'), 6000],
|
|
[RELEASE_GROUP, uuid('rg-b1'), 'Beta One', 'Staged Beta', uuid('ar-b'), 400],
|
|
];
|
|
|
|
for (const row of rows) {
|
|
const result = await app.evaluate(async (args) => {
|
|
const res = await fetch('/__test/sql', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
sql: `INSERT OR IGNORE INTO explore_index
|
|
(entity_type, mbid, title, artist_name, artist_mbid,
|
|
popularity, listener_count, primary_type)
|
|
VALUES (?, unhex(replace(?, '-', '')), ?, ?,
|
|
unhex(replace(?, '-', '')), ?, ?, 'Album')`,
|
|
args: [...args, 10],
|
|
}),
|
|
});
|
|
|
|
return { status: res.status, body: await res.text() };
|
|
}, row);
|
|
|
|
// The first version of this passed six values to seven
|
|
// placeholders and never read the response, so every insert failed
|
|
// and the staging step looked exactly like a staging step. A setup
|
|
// whose failure is not checked is not setup.
|
|
expect(result.status, `staging failed: ${result.body}`).toBe(200);
|
|
|
|
// …and `OR IGNORE` means a 200 is not a write. A CHECK the row
|
|
// violates is *ignored*, not reported, so the count below is the
|
|
// only thing that can tell staging from silence.
|
|
expect(
|
|
(JSON.parse(result.body) as { rowsAffected?: number }).rowsAffected,
|
|
`staged nothing: ${result.body}`,
|
|
).toBe(1);
|
|
}
|
|
|
|
expect(await catalogRows(app)).toBeGreaterThan(0);
|
|
}
|
|
|
|
/**
|
|
* A stable, valid MBID from a short label.
|
|
*
|
|
* The column is `CHECK(length(mbid) = 16)` after `unhex`, so a fixture
|
|
* id has to be a real UUID rather than a readable string -- the same
|
|
* trade the Go fixtures make with `testMBID()`, and for the same
|
|
* reason: a readable id that cannot be stored is not readable, it is
|
|
* absent.
|
|
*/
|
|
function uuid(label: string): string {
|
|
const hex = [...label]
|
|
.map((c) => c.charCodeAt(0).toString(16).padStart(2, '0'))
|
|
.join('')
|
|
.padEnd(32, '0')
|
|
.slice(0, 32);
|
|
|
|
return [
|
|
hex.slice(0, 8),
|
|
hex.slice(8, 12),
|
|
hex.slice(12, 16),
|
|
hex.slice(16, 20),
|
|
hex.slice(20),
|
|
].join('-');
|
|
}
|
|
|
|
/**
|
|
* Whether this environment has a catalog at all. CI has none.
|
|
*
|
|
* `exploreIndex` is deliberately 0-or-1 rather than a row count: a real
|
|
* catalog is ~1.1M rows, and a cold `COUNT(*)` over it took 65 seconds
|
|
* on the first call after a seed was extracted -- which timed out
|
|
* whichever spec ran first and looked like flake.
|
|
*/
|
|
async function catalogRows(app: Page): Promise<number> {
|
|
const health = await app.evaluate(async () => {
|
|
const res = await fetch('/__test/health');
|
|
|
|
return (await res.json()) as { counts?: { exploreIndex?: number } };
|
|
});
|
|
|
|
return health.counts?.exploreIndex ?? 0;
|
|
}
|
|
|
|
async function shelfHeadings(app: Page): Promise<string[]> {
|
|
return app.evaluate(() =>
|
|
[
|
|
...(document
|
|
.querySelector('explore-view')
|
|
?.shadowRoot?.querySelectorAll('.section-header') ?? []),
|
|
].map((h) => (h.textContent ?? '').trim()),
|
|
);
|
|
}
|
|
|
|
async function clickCard(app: Page, selector: string): Promise<void> {
|
|
await expect
|
|
.poll(() =>
|
|
app.evaluate(
|
|
(sel) =>
|
|
document
|
|
.querySelector('explore-view')
|
|
?.shadowRoot?.querySelectorAll(sel).length ?? 0,
|
|
selector,
|
|
),
|
|
)
|
|
.toBeGreaterThan(0);
|
|
|
|
await app.evaluate((sel) => {
|
|
document
|
|
.querySelector('explore-view')
|
|
?.shadowRoot?.querySelector<HTMLElement>(sel)
|
|
?.click();
|
|
}, selector);
|
|
}
|
|
|
|
/** Type into Explore's own search box, and wait out its debounce. */
|
|
async function type(app: Page, query: string): Promise<void> {
|
|
await app.evaluate((q) => {
|
|
const input = document
|
|
.querySelector('explore-view')
|
|
?.shadowRoot?.querySelector<HTMLInputElement>('.search-container input');
|
|
|
|
if (!input) return;
|
|
|
|
input.value = q;
|
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
}, query);
|
|
}
|