feat(harness): agent-drivable dev harness and CI that gates
Build & publish Arch package / arch-package (push) Successful in 2m8s
CI / check (push) Failing after 1m56s
CI / e2e (push) Skipped
Search index maintenance / maintain-index (push) Successful in 13s

A coding agent could develop this repo's Go packages and could not
develop the application: every path to running YellowJacket ended in a
blocking GTK window, so 265 bound methods, 46 events, 33 component
directories and 13 stores had exactly one form of verification
available — `tsc --noEmit`.

The unlock is that `wails dev`'s dev server on :34115 serves the real
frontend with the real generated bindings against the same Go backend a
desktop window attaches to, so a plain Chromium under Xvfb gets a fully
functional app. Four test tiers now exist, cheapest first:

- `make ui-test` — 313 Vitest tests in a real browser in ~2 s, no app,
  no backend, no display. Works because `frontend/wailsjs/` is a pure
  passthrough to `window.go`/`window.runtime`, so faking just those two
  globals runs the real bindings and the real store code.
- `make test` — services in-process, asserting on the payload the
  frontend would receive, via a new `events.Emit` wrapper.
- `make dev-headless` + `playwright-cli` — the real app, driven
  interactively, with an event bridge on `window.__yjEvents` and a
  dev-only control surface at `/__test/`.
- `make e2e` — 19 of those flows frozen as Playwright specs.

`events.Emit(ctx, …)` replaces all 35 direct `runtime.EventsEmit` call
sites: wails' `getEvents` `log.Fatalf`s on any context without its
runtime, so those paths could not run under test and a background
worker could take the app down. Four packages had each hand-rolled the
same guard; nine more guarded on `ctx != nil`, which does not help.
`TestNoDirectRuntimeEmits` fails the build on a new one.

Fixtures are generated, not committed (`make testdata`), and seeds are
built by *running the app* — never by hand-writing config and DB rows,
which would be a second description of a valid YJ_HOME.

`.gitea/workflows/ci.yml` is the first workflow here that tests
anything; the other three only package, so `gitea_ci` reported only
packaging jobs and misled anyone asking whether a push was healthy.
Both jobs were prototyped to green in a bare ubuntu:24.04 container
before the YAML was written, which immediately caught `make lint`
linting three configurations that nothing builds: all three passes
omitted `webkit2_41`, so wails resolved webkit2gtk-4.0 — which Arch
still ships and Ubuntu 24.04 dropped.

Operational instructions live in `.pi/skills/yellowjacket-dev/`,
measured discoveries in `.planning/NOTES.md`, and architecture in
`CLAUDE.md` — split by tense, not by topic, because a topical split
gives every new fact two plausible homes. `make skill-check` fails a
commit if the skill cites a make target that does not exist.
This commit is contained in:
2026-08-10 23:20:42 -04:00
parent 65333857e2
commit 5ca6cad45a
117 changed files with 14585 additions and 262 deletions
+18
View File
@@ -0,0 +1,18 @@
{
"name": "yellowjacket-e2e",
"private": true,
"type": "module",
"version": "0.0.0",
"description": "End-to-end specs driving the real app on the Wails dev server.",
"scripts": {
"test": "playwright test",
"test:headed": "playwright test --headed",
"report": "playwright show-report",
"typecheck": "tsc --noEmit -p tsconfig.json"
},
"devDependencies": {
"@playwright/test": "^1.56.0",
"@types/node": "^26.2.0",
"typescript": "^7.0.2"
}
}
+49
View File
@@ -0,0 +1,49 @@
import { defineConfig, devices } from '@playwright/test';
/**
* These specs drive the *real* application: the Wails dev server on
* :34115 serves the real frontend with real bindings on `window.go`,
* bridged to the same Go backend a desktop window would use. Nothing
* here is mocked.
*
* The app is not started by Playwright. `make dev-headless` daemonises
* (it writes .dev/app.pid and returns), which is the opposite of what
* `webServer` expects to supervise, and starting it per-run would also
* mean rebuilding the frontend per-run. globalSetup checks it is up
* and says exactly what to run if it is not.
*
* WebKit is CI-only: Playwright's Linux WebKit build links Ubuntu 24.04
* libraries that Arch does not provide, so it cannot start on a local
* dev machine. It is the closest available approximation of the
* WebKit2GTK renderer we actually ship, so CI runs it and local runs
* do not.
*/
const PORT = Number(process.env.YJ_E2E_PORT ?? 34115);
export default defineConfig({
testDir: './specs',
globalSetup: './support/global-setup.ts',
// The backend is a single shared process with one SQLite database, so
// parallel workers would fight over the same state.
workers: 1,
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
reporter: process.env.CI ? [['github'], ['html', { open: 'never' }]] : [['list']],
timeout: 30_000,
expect: { timeout: 10_000 },
use: {
baseURL: `http://localhost:${PORT}`,
testIdAttribute: 'data-testid',
viewport: { width: 1440, height: 900 },
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video: process.env.CI ? 'retain-on-failure' : 'off',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
...(process.env.YJ_E2E_WEBKIT
? [{ name: 'webkit', use: { ...devices['Desktop Safari'] } }]
: []),
],
});
+278
View File
@@ -0,0 +1,278 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
devDependencies:
'@playwright/test':
specifier: ^1.56.0
version: 1.62.1
'@types/node':
specifier: ^26.2.0
version: 26.2.0
typescript:
specifier: ^7.0.2
version: 7.0.2
packages:
'@playwright/test@1.62.1':
resolution: {integrity: sha512-DTcUc8qii+cpHvtOwggMtBRMjKZHXYWdw8syRYu2vtzuq4Wxphqq4NfCs5Zt44L6mA8rfDfj+PHnxFc/FeK6mQ==}
engines: {node: '>=20'}
hasBin: true
'@types/node@26.2.0':
resolution: {integrity: sha512-5IviulTZeRNp2vAJ514cc/HUlY5nZ9fCbq9DMyC52BrhFZACo3nI0R7qBxhQmo/d27NFe96ur/b7Wwxklda+kg==}
'@typescript/typescript-aix-ppc64@7.0.2':
resolution: {integrity: sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==}
engines: {node: '>=16.20.0'}
cpu: [ppc64]
os: [aix]
'@typescript/typescript-darwin-arm64@7.0.2':
resolution: {integrity: sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==}
engines: {node: '>=16.20.0'}
cpu: [arm64]
os: [darwin]
'@typescript/typescript-darwin-x64@7.0.2':
resolution: {integrity: sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==}
engines: {node: '>=16.20.0'}
cpu: [x64]
os: [darwin]
'@typescript/typescript-freebsd-arm64@7.0.2':
resolution: {integrity: sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==}
engines: {node: '>=16.20.0'}
cpu: [arm64]
os: [freebsd]
'@typescript/typescript-freebsd-x64@7.0.2':
resolution: {integrity: sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==}
engines: {node: '>=16.20.0'}
cpu: [x64]
os: [freebsd]
'@typescript/typescript-linux-arm64@7.0.2':
resolution: {integrity: sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==}
engines: {node: '>=16.20.0'}
cpu: [arm64]
os: [linux]
'@typescript/typescript-linux-arm@7.0.2':
resolution: {integrity: sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==}
engines: {node: '>=16.20.0'}
cpu: [arm]
os: [linux]
'@typescript/typescript-linux-loong64@7.0.2':
resolution: {integrity: sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==}
engines: {node: '>=16.20.0'}
cpu: [loong64]
os: [linux]
'@typescript/typescript-linux-mips64el@7.0.2':
resolution: {integrity: sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==}
engines: {node: '>=16.20.0'}
cpu: [mips64el]
os: [linux]
'@typescript/typescript-linux-ppc64@7.0.2':
resolution: {integrity: sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==}
engines: {node: '>=16.20.0'}
cpu: [ppc64]
os: [linux]
'@typescript/typescript-linux-riscv64@7.0.2':
resolution: {integrity: sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==}
engines: {node: '>=16.20.0'}
cpu: [riscv64]
os: [linux]
'@typescript/typescript-linux-s390x@7.0.2':
resolution: {integrity: sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==}
engines: {node: '>=16.20.0'}
cpu: [s390x]
os: [linux]
'@typescript/typescript-linux-x64@7.0.2':
resolution: {integrity: sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==}
engines: {node: '>=16.20.0'}
cpu: [x64]
os: [linux]
'@typescript/typescript-netbsd-arm64@7.0.2':
resolution: {integrity: sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==}
engines: {node: '>=16.20.0'}
cpu: [arm64]
os: [netbsd]
'@typescript/typescript-netbsd-x64@7.0.2':
resolution: {integrity: sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==}
engines: {node: '>=16.20.0'}
cpu: [x64]
os: [netbsd]
'@typescript/typescript-openbsd-arm64@7.0.2':
resolution: {integrity: sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==}
engines: {node: '>=16.20.0'}
cpu: [arm64]
os: [openbsd]
'@typescript/typescript-openbsd-x64@7.0.2':
resolution: {integrity: sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==}
engines: {node: '>=16.20.0'}
cpu: [x64]
os: [openbsd]
'@typescript/typescript-sunos-x64@7.0.2':
resolution: {integrity: sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==}
engines: {node: '>=16.20.0'}
cpu: [x64]
os: [sunos]
'@typescript/typescript-win32-arm64@7.0.2':
resolution: {integrity: sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==}
engines: {node: '>=16.20.0'}
cpu: [arm64]
os: [win32]
'@typescript/typescript-win32-x64@7.0.2':
resolution: {integrity: sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==}
engines: {node: '>=16.20.0'}
cpu: [x64]
os: [win32]
fsevents@2.3.2:
resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
os: [darwin]
playwright-core@1.62.1:
resolution: {integrity: sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw==}
engines: {node: '>=20'}
hasBin: true
playwright@1.62.1:
resolution: {integrity: sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg==}
engines: {node: '>=20'}
hasBin: true
typescript@7.0.2:
resolution: {integrity: sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==}
engines: {node: '>=16.20.0'}
hasBin: true
undici-types@8.3.0:
resolution: {integrity: sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==}
snapshots:
'@playwright/test@1.62.1':
dependencies:
playwright: 1.62.1
'@types/node@26.2.0':
dependencies:
undici-types: 8.3.0
'@typescript/typescript-aix-ppc64@7.0.2':
optional: true
'@typescript/typescript-darwin-arm64@7.0.2':
optional: true
'@typescript/typescript-darwin-x64@7.0.2':
optional: true
'@typescript/typescript-freebsd-arm64@7.0.2':
optional: true
'@typescript/typescript-freebsd-x64@7.0.2':
optional: true
'@typescript/typescript-linux-arm64@7.0.2':
optional: true
'@typescript/typescript-linux-arm@7.0.2':
optional: true
'@typescript/typescript-linux-loong64@7.0.2':
optional: true
'@typescript/typescript-linux-mips64el@7.0.2':
optional: true
'@typescript/typescript-linux-ppc64@7.0.2':
optional: true
'@typescript/typescript-linux-riscv64@7.0.2':
optional: true
'@typescript/typescript-linux-s390x@7.0.2':
optional: true
'@typescript/typescript-linux-x64@7.0.2':
optional: true
'@typescript/typescript-netbsd-arm64@7.0.2':
optional: true
'@typescript/typescript-netbsd-x64@7.0.2':
optional: true
'@typescript/typescript-openbsd-arm64@7.0.2':
optional: true
'@typescript/typescript-openbsd-x64@7.0.2':
optional: true
'@typescript/typescript-sunos-x64@7.0.2':
optional: true
'@typescript/typescript-win32-arm64@7.0.2':
optional: true
'@typescript/typescript-win32-x64@7.0.2':
optional: true
fsevents@2.3.2:
optional: true
playwright-core@1.62.1: {}
playwright@1.62.1:
dependencies:
playwright-core: 1.62.1
optionalDependencies:
fsevents: 2.3.2
typescript@7.0.2:
optionalDependencies:
'@typescript/typescript-aix-ppc64': 7.0.2
'@typescript/typescript-darwin-arm64': 7.0.2
'@typescript/typescript-darwin-x64': 7.0.2
'@typescript/typescript-freebsd-arm64': 7.0.2
'@typescript/typescript-freebsd-x64': 7.0.2
'@typescript/typescript-linux-arm': 7.0.2
'@typescript/typescript-linux-arm64': 7.0.2
'@typescript/typescript-linux-loong64': 7.0.2
'@typescript/typescript-linux-mips64el': 7.0.2
'@typescript/typescript-linux-ppc64': 7.0.2
'@typescript/typescript-linux-riscv64': 7.0.2
'@typescript/typescript-linux-s390x': 7.0.2
'@typescript/typescript-linux-x64': 7.0.2
'@typescript/typescript-netbsd-arm64': 7.0.2
'@typescript/typescript-netbsd-x64': 7.0.2
'@typescript/typescript-openbsd-arm64': 7.0.2
'@typescript/typescript-openbsd-x64': 7.0.2
'@typescript/typescript-sunos-x64': 7.0.2
'@typescript/typescript-win32-arm64': 7.0.2
'@typescript/typescript-win32-x64': 7.0.2
undici-types@8.3.0: {}
+89
View File
@@ -0,0 +1,89 @@
import {
test,
expect,
callBinding,
resetEvents,
waitForEvent,
} from '../support/fixtures.js';
/**
* The harness testing itself.
*
* If these fail, every other spec's failure is uninterpretable — a
* missing event could mean a broken feature or a broken recorder, and
* telling those apart afterwards is expensive.
*/
test.describe('harness', () => {
test('the app is the real app, not a mock', async ({ app }) => {
// All 11 bound services land on window.go through the dev server.
const services = await app.evaluate(() => Object.keys(window.go));
expect(services).toEqual(
expect.arrayContaining(['queue', 'player', 'library', 'explore']),
);
const state = await callBinding<{ tracks: unknown[] }>(
app,
'queue.Queue.GetState',
);
expect(state).toHaveProperty('tracks');
});
test('backend events are recorded, in order, with payloads', async ({
app,
}) => {
await resetEvents(app);
await callBinding(app, 'player.Player.SetVolume', [37]);
const ev = await waitForEvent(app, 'VolumeChanged');
expect(ev.data).toEqual([37]);
expect(ev.dir).toBe('in');
});
test('exactly one recorder is installed', async ({ app }) => {
// Listeners registered by one evaluate survive into the next, so a
// recorder that re-registers counts every event twice. This is the
// regression test for that.
await resetEvents(app);
await callBinding(app, 'player.Player.SetVolume', [41]);
await waitForEvent(app, 'VolumeChanged');
const count = await app.evaluate(() =>
window.__yjEvents.count('VolumeChanged'),
);
expect(count).toBe(1);
});
test('a binding called with wrong types fails fast', async ({ app }) => {
// player.UserVolume is an int. Passing a float makes the backend
// log "error parsing arguments" and never fire the callback; without
// a timeout the promise never settles and the spec hangs until the
// suite gives up.
const failure = await app.evaluate(async () => {
try {
await window.__yjEvents.call(
'player.Player.SetVolume',
[0.42],
2_000,
);
return 'settled';
} catch (err) {
return (err as Error).message;
}
});
expect(failure).toContain('did not settle');
});
test('the control surface is mounted and seeded', async ({ testctl }) => {
const health = await testctl.health();
expect(health.ok).toBe(true);
expect(health.libraries.length).toBeGreaterThan(0);
expect(health.counts.tracks).toBeGreaterThan(0);
});
});
+68
View File
@@ -0,0 +1,68 @@
import { test, expect } from '../support/fixtures.js';
/**
* The library views, against the generated fixture library
* (`make testdata`): 31 tracks chosen to cover the cases the app has
* code for — unicode and RTL titles, missing tags, a deliberately
* absurd artist name for truncation, duplicates.
*/
test.describe('library views', () => {
test('lands in the app, not the first-run wizard', async ({ app }) => {
// A fresh YJ_HOME puts <first-run-wizard> over everything and it
// intercepts every pointer event, so "the click did nothing" is the
// symptom of an unseeded sandbox rather than a broken control.
//
// Asserted by clicking rather than by inspecting the wizard element:
// the element is always in the DOM and merely renders nothing once a
// library exists, so its presence proves nothing. Playwright's own
// actionability check fails a covered click with "intercepts pointer
// events", which is exactly the condition worth catching.
await expect(app.getByTestId('track-row').first()).toBeVisible();
await app.getByTestId('nav-artists').click({ timeout: 5_000 });
await expect(app.getByTestId('main-content')).toHaveAttribute(
'data-active-view',
'artists',
);
});
test('renders every fixture track, unicode included', async ({
app,
testctl,
}) => {
const health = await testctl.health();
const rows = app.getByTestId('track-row');
await expect(rows).toHaveCount(health.counts.tracks);
// Non-Latin scripts survive the tag reader, the database and the
// renderer. These titles exist in the fixtures for this reason.
await expect(app.getByText('Привет мир')).toBeVisible();
await expect(app.getByText('さくら')).toBeVisible();
await expect(app.getByText('مرحبا بالعالم')).toBeVisible();
});
test('the sidebar navigates between primary views', async ({ app }) => {
const main = app.getByTestId('main-content');
for (const view of ['artists', 'genres', 'albums', 'playlists', 'tracks']) {
await app.getByTestId(`nav-${view}`).click();
await expect(main).toHaveAttribute('data-active-view', view);
await expect(app.getByTestId(`nav-${view}`)).toHaveAttribute(
'aria-current',
'page',
);
}
});
test('the artists view shows the fixture artists', async ({ app }) => {
await app.getByTestId('nav-artists').click();
await expect(app.getByTestId('main-content')).toHaveAttribute(
'data-active-view',
'artists',
);
await expect(app.getByText('Aurora Fields').first()).toBeVisible();
await expect(app.getByText('Pale Circuit').first()).toBeVisible();
});
});
+114
View File
@@ -0,0 +1,114 @@
import {
test,
expect,
callBinding,
resetEvents,
waitForEvent,
LONG_TRACK,
} from '../support/fixtures.js';
/** The one fixture long enough to still be playing on the next line. */
const longRow = (app: import('@playwright/test').Page) =>
app.getByTestId('track-row').filter({ hasText: LONG_TRACK }).first();
/**
* Playback and the queue, driven through the UI and asserted on the
* events the backend actually emits.
*
* Audio really is initialised here: under `dbus-run-session` + Xvfb the
* PulseAudio socket in /run/user is untouched, so InitSpeaker succeeds
* and these tracks genuinely play. A CI container without /run/user
* needs a null sink; everything except the audio itself still works
* without one.
*/
test.describe('playback', () => {
test.beforeEach(async ({ app }) => {
await callBinding(app, 'queue.Queue.Clear').catch(() => {
/* older builds may not expose Clear; the specs below do not need it */
});
await resetEvents(app);
});
test('double-clicking a track plays it', async ({ app }) => {
await longRow(app).dblclick();
const changed = await waitForEvent(app, 'TrackChanged');
expect(changed.data[0]).toBeTruthy();
// The transport flips to Pause, which is the only place the UI
// states "we are playing" in a way a user can see. `exact` is not
// optional: "Add queue to playlist" also matches /play/i.
await expect(
app.getByRole('button', { name: 'Pause', exact: true }),
).toBeVisible();
await expect(app.getByTestId('now-playing-title')).toContainText(
LONG_TRACK,
);
});
test('the elapsed time advances', async ({ app }) => {
await longRow(app).dblclick();
await waitForEvent(app, 'TrackChanged');
// Not a fixed sleep on a fixed value: assert the observable
// outcome, which is that the clock is no longer at zero.
await expect(app.getByTestId('elapsed-time')).not.toHaveText('--:--');
await expect(app.getByTestId('elapsed-time')).not.toHaveText('00:00', {
timeout: 15_000,
});
});
test('pause and play round-trip through the backend', async ({ app }) => {
await longRow(app).dblclick();
await waitForEvent(app, 'TrackChanged');
await resetEvents(app);
await app.getByRole('button', { name: 'Pause', exact: true }).click();
await waitForEvent(app, 'PlaybackStateChanged');
await expect(
app.getByRole('button', { name: 'Play', exact: true }),
).toBeVisible();
});
test('volume changes are pushed back from Go', async ({ app }) => {
await resetEvents(app);
await callBinding(app, 'player.Player.SetVolume', [55]);
const ev = await waitForEvent(app, 'VolumeChanged');
expect(ev.data).toEqual([55]);
});
});
test.describe('queue', () => {
test('playing a track populates the queue panel', async ({ app }) => {
await resetEvents(app);
await longRow(app).dblclick();
await waitForEvent(app, 'QueueChanged');
await expect(app.getByTestId('queue-row')).toHaveCount(1);
const state = await callBinding<{ tracks: unknown[] }>(
app,
'queue.Queue.GetState',
);
expect(state.tracks).toHaveLength(1);
});
test('shuffle and repeat toggles report their state', async ({ app }) => {
const shuffle = app.getByRole('button', { name: 'Shuffle' });
await resetEvents(app);
await shuffle.click();
await waitForEvent(app, 'QueueModeChanged');
await expect(shuffle).toHaveAttribute('aria-pressed', 'true');
await shuffle.click();
await expect(shuffle).toHaveAttribute('aria-pressed', 'false');
});
});
+68
View File
@@ -0,0 +1,68 @@
import { test, expect, resetEvents, waitForEvent } from '../support/fixtures.js';
/**
* The dev-only control surface (backend/testctl), which exists for the
* things a browser genuinely cannot do.
*/
test.describe('control surface', () => {
test('database snapshot and restore round-trip', async ({ testctl }) => {
// VACUUM INTO copies the whole file and the restore copies every
// row back; on a database carrying an explore catalog that is tens
// of seconds, not the default 30s budget for a whole test.
test.setTimeout(180_000);
const before = (await testctl.health()).counts.tracks;
await testctl.snapshot('e2e-pristine');
await testctl.sql('DELETE FROM audio_files');
expect((await testctl.health()).counts.tracks).toBe(0);
// Restore copies rows rather than files, because the app holds the
// database open across two connection pools and cannot be made to
// reopen it from here.
await testctl.restore('e2e-pristine');
expect((await testctl.health()).counts.tracks).toBe(before);
});
test('a forced backend event reaches the browser', async ({
app,
testctl,
}) => {
// LibraryScanProgress normally only arrives during a real scan.
// Emitting it directly is how a push-driven view gets exercised
// without staging the work that would produce it.
await resetEvents(app);
await testctl.emit('LibraryScanProgress', {
current: 7,
total: 31,
currentFile: 'probe.mp3',
});
const ev = await waitForEvent(app, 'LibraryScanProgress');
expect(ev.data[0]).toMatchObject({ current: 7, total: 31 });
});
test('sql reads return rows, writes return a count', async ({ testctl }) => {
const read = await testctl.sql(
'SELECT COUNT(*) AS n FROM audio_files',
);
expect(read.rows[0].n).toBeGreaterThan(0);
const write = await testctl.sql(
'UPDATE player_state SET volume = volume',
);
expect(write).toHaveProperty('rowsAffected');
});
test('bad input is rejected with a reason, not a bare status', async ({
testctl,
}) => {
await expect(testctl.snapshot('../escape')).rejects.toThrow(/name must/);
await expect(testctl.restore('nope')).rejects.toThrow(/no such snapshot/);
});
});
+172
View File
@@ -0,0 +1,172 @@
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { test as base, expect, type Page } from '@playwright/test';
const here = dirname(fileURLToPath(import.meta.url));
/** The same bridge `playwright-cli` loads, so an exploratory session and
* a committed spec see an identical page. */
const INIT_SCRIPT = resolve(here, '../../.playwright/init-events.js');
/**
* The 90-second fixture track (`cmd/gentestdata`, case `edge-lengths`).
*
* Every other fixture is 26 seconds, which is shorter than the time a
* spec takes to click something — a "pause it" test against one of
* those races the track finishing and fails on a UI that is correct.
*/
export const LONG_TRACK = 'Long Player';
/** Shape of the recorder installed by .playwright/init-events.js. */
export type YjEvent = {
seq: number;
name: string;
data: unknown[];
dir: 'in' | 'out';
t: number;
};
/**
* Await a backend event instead of a timeout.
*
* Half of this app is push-driven, and the events that matter
* (scan progress, job updates, playback state) arrive whenever the
* backend gets to them. `waitForEvent` resolves against events already
* buffered as well as future ones, so there is no race between doing
* the thing and starting to listen.
*/
export async function waitForEvent(
page: Page,
name: string,
opts: { timeoutMs?: number; since?: number } = {},
): Promise<YjEvent> {
return page.evaluate(
([n, o]) => window.__yjEvents.wait(n as string, o as object),
[name, { timeoutMs: 10_000, ...opts }] as const,
) as Promise<YjEvent>;
}
/** Drop the event buffer. Never re-register a recorder: listeners
* survive across evaluate calls and a second recorder double-counts. */
export async function resetEvents(page: Page): Promise<void> {
await page.evaluate(() => void window.__yjEvents.reset());
}
/** name -> count, for asserting on (or debugging) what actually fired. */
export async function eventNames(
page: Page,
): Promise<Record<string, number>> {
return page.evaluate(() => window.__yjEvents.names());
}
/**
* Call a bound Go method with a timeout.
*
* Wrong argument types make the backend log "error parsing arguments"
* and never fire the callback, so an unguarded call hangs until the
* whole spec times out with no clue why. This fails in seconds and
* says where to look.
*/
export async function callBinding<T = unknown>(
page: Page,
path: string,
args: unknown[] = [],
timeoutMs = 10_000,
): Promise<T> {
return page.evaluate(
([p, a, t]) =>
window.__yjEvents.call(p as string, a as unknown[], t as number),
[path, args, timeoutMs] as const,
) as Promise<T>;
}
/** Thin client for the dev-only /__test/ surface (backend/testctl). */
export class TestCtl {
constructor(private readonly baseURL: string) {}
private async req(path: string, init?: RequestInit) {
const res = await fetch(`${this.baseURL}${path}`, {
signal: AbortSignal.timeout(120_000),
...init,
});
const body = await res.json();
if (!res.ok) {
throw new Error(`testctl ${path}: ${body.error ?? res.status}`);
}
return body;
}
health() {
return this.req('/__test/health');
}
snapshot(name: string) {
return this.req(`/__test/db/snapshot?name=${name}`, { method: 'POST' });
}
restore(name: string) {
return this.req(`/__test/db/restore?name=${name}`, { method: 'POST' });
}
emit(name: string, ...data: unknown[]) {
return this.req('/__test/emit', {
method: 'POST',
body: JSON.stringify({ name, data }),
});
}
sql(sql: string, args: unknown[] = []) {
return this.req('/__test/sql', {
method: 'POST',
body: JSON.stringify({ sql, args }),
});
}
}
export const test = base.extend<{ app: Page; testctl: TestCtl }>({
/** A page with the event bridge installed and the app loaded and
* actually talking to the backend — not merely DOM-ready, which is
* earlier and lies. */
app: async ({ page, baseURL }, use) => {
await page.addInitScript({ path: INIT_SCRIPT });
await page.goto(baseURL!);
await page.evaluate(() => window.__yjEvents.ready(20_000));
await use(page);
},
testctl: async ({ baseURL }, use) => {
await use(new TestCtl(baseURL!));
},
});
export { expect };
declare global {
interface Window {
__yjEvents: {
version: number;
seq: number;
log: YjEvent[];
reset(): number;
all(name?: string): YjEvent[];
count(name?: string): number;
last(name?: string): YjEvent | null;
since(seq: number): YjEvent[];
names(): Record<string, number>;
wait(
name: string,
opts?: {
timeoutMs?: number;
since?: number;
match?: (data: unknown[], entry: YjEvent) => boolean;
},
): Promise<YjEvent>;
ready(timeoutMs?: number): Promise<boolean>;
call(path: string, args?: unknown[], timeoutMs?: number): Promise<any>;
};
go: Record<string, Record<string, Record<string, (...a: any[]) => any>>>;
}
}
+62
View File
@@ -0,0 +1,62 @@
import type { FullConfig } from '@playwright/test';
/**
* Fail fast, and fail legibly.
*
* Without this the first spec dies on a connection refused deep inside
* a `page.goto`, which reads like a Playwright problem rather than "you
* forgot to start the app". Checking /__test/health also verifies the
* two things every spec below assumes: that the control surface is
* mounted (dev build + YJ_TESTCTL=1) and that the app is pointed at the
* seeded fixture library rather than someone's real collection.
*/
const HELP = `
The app is not running, or is not a seeded dev build. Start it with:
make testdata # once — generates the fixtures
make sandbox-seed NAME=default # once — builds a seed by running the app
make dev-headless SEED=default # starts in the background and returns
and stop it afterwards with 'make dev-stop'.
`;
export default async function globalSetup(config: FullConfig) {
const baseURL =
config.projects[0]?.use?.baseURL ?? 'http://localhost:34115';
let health: any;
try {
const res = await fetch(`${baseURL}/__test/health`, {
signal: AbortSignal.timeout(5_000),
});
if (!res.ok) throw new Error(`health returned ${res.status}`);
health = await res.json();
} catch (err) {
throw new Error(
`e2e: no healthy backend at ${baseURL} (${String(err)})\n${HELP}`,
);
}
if (!health.libraries?.length) {
throw new Error(
`e2e: backend has no library configured — specs would land on ` +
`the first-run wizard, which intercepts every pointer event.\n${HELP}`,
);
}
const tracks = health.counts?.tracks ?? 0;
if (tracks < 1) {
throw new Error(
`e2e: backend library is empty (${tracks} tracks).\n${HELP}`,
);
}
console.log(
`e2e: backend up — ${tracks} tracks in ` +
`${health.libraries.map((l: any) => l.name).join(', ')}`,
);
}
+14
View File
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ES2022", "DOM"],
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"types": ["node"],
"allowImportingTsExtensions": true
},
"include": ["specs/**/*.ts", "support/**/*.ts", "playwright.config.ts"]
}