A full parallel run intermittently failed the first few tests: unmocked /api/v1 calls fell through to the dev proxy, whose backend isn't running under E2E, so each incurred a slow ECONNREFUSED round-trip + Vite error logging that piled up across 8 workers at cold start. - Add e2e/fixtures.ts: a shared `test` whose auto-use fixture installs an `**/api/v1/**` fallback (fast 503, logged) for any endpoint a spec didn't mock. Registered before the test body, so per-test routes still win; only genuine gaps land here. Turns silent mock-gap hangs into instant, attributable failures — and cuts the full run ~96s → ~25s. - Point all 22 specs at ./fixtures instead of @playwright/test. - retries: 1 in the config as a safety net for the residual Vite cold-compile timing (re-runs on the now-warm server). Two consecutive full runs: 110 passed, 0 flaky, no retries consumed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
221 lines
8.2 KiB
TypeScript
221 lines
8.2 KiB
TypeScript
import { test, expect, type Page } from './fixtures';
|
|
|
|
// E2E for the admin Crawler "History" tab: the Live/History toggle, the
|
|
// searchable/filterable job log, and inline requeue of a dead job. The
|
|
// live status + SSE stream are left pending so the test focuses on history
|
|
// (the live dashboard is exercised by its own status mocks elsewhere).
|
|
|
|
const DESKTOP = { width: 1280, height: 720 } as const;
|
|
|
|
const deadJobId = 'd1111111-1111-1111-1111-111111111111';
|
|
const doneJobId = 'd2222222-2222-2222-2222-222222222222';
|
|
|
|
const adminUser = {
|
|
id: 'u11111111-1111-1111-1111-111111111111',
|
|
username: 'admin',
|
|
created_at: '2026-01-01T00:00:00Z',
|
|
is_admin: true
|
|
};
|
|
|
|
type Captured = { requeue: Record<string, unknown> | null };
|
|
|
|
async function mockAdmin(page: Page, cap: Captured) {
|
|
await page.route('**/api/v1/auth/config', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ self_register_enabled: true, private_mode: false })
|
|
})
|
|
);
|
|
await page.route('**/api/v1/auth/me', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ user: adminUser })
|
|
})
|
|
);
|
|
await page.route('**/api/v1/auth/me/preferences', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ reader_mode: 'single', reader_page_gap: 'small' })
|
|
})
|
|
);
|
|
await page.route('**/api/v1/me/bookmarks*', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ items: [], page: { limit: 50, offset: 0, total: 0 } })
|
|
})
|
|
);
|
|
await page.route('**/api/v1/admin/system', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
disk: null,
|
|
memory: { total_bytes: 1, used_bytes: 0, percent_used: 0 },
|
|
cpu: { percent_used: 0 },
|
|
alerts: []
|
|
})
|
|
})
|
|
);
|
|
|
|
// Leave the live status fetch + SSE stream pending so the Live view
|
|
// stays in its "Loading…" state and doesn't churn; History is what we test.
|
|
await page.route('**/api/v1/admin/crawler', () => new Promise(() => {}));
|
|
await page.route('**/api/v1/admin/crawler/stream', () => new Promise(() => {}));
|
|
await page.route('**/api/v1/admin/crawler/dead-jobs**', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ items: [], page: { limit: 20, offset: 0, total: 0 } })
|
|
})
|
|
);
|
|
|
|
await page.route('**/api/v1/admin/crawler/history**', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
items: [
|
|
{
|
|
id: deadJobId,
|
|
state: 'dead',
|
|
kind: 'sync_chapter_content',
|
|
manga_id: 'm-1',
|
|
manga_title: 'Naruto',
|
|
chapter_id: 'c-1',
|
|
chapter_number: 700,
|
|
page_number: null,
|
|
source_key: null,
|
|
attempts: 5,
|
|
max_attempts: 5,
|
|
last_error: 'boom: upstream 500',
|
|
updated_at: '2026-06-15T00:00:00Z'
|
|
},
|
|
{
|
|
id: doneJobId,
|
|
state: 'done',
|
|
kind: 'analyze_page',
|
|
manga_id: 'm-2',
|
|
manga_title: 'Bleach',
|
|
chapter_id: 'c-2',
|
|
chapter_number: 3,
|
|
page_number: 7,
|
|
source_key: null,
|
|
attempts: 1,
|
|
max_attempts: 5,
|
|
last_error: null,
|
|
updated_at: '2026-06-15T00:00:00Z'
|
|
}
|
|
],
|
|
page: { limit: 25, offset: 0, total: 2 }
|
|
})
|
|
})
|
|
);
|
|
|
|
// Summary registered first (broad glob); the more-specific /ops route is
|
|
// registered after so it wins for the ops URL (Playwright: last match wins).
|
|
await page.route('**/api/v1/admin/crawler/metrics**', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
summary: [
|
|
{ op: 'manga_list', avg_ms: 42000, n: 8, ok: 8, failed: 0, avg_items: 50 },
|
|
{ op: 'manga_detail', avg_ms: 1300, n: 210, ok: 205, failed: 5, avg_items: null },
|
|
{ op: 'manga_cover', avg_ms: 480, n: 180, ok: 176, failed: 4, avg_items: null },
|
|
{ op: 'chapter', avg_ms: 6800, n: 430, ok: 421, failed: 9, avg_items: 32 }
|
|
]
|
|
})
|
|
})
|
|
);
|
|
await page.route('**/api/v1/admin/crawler/metrics/ops**', (r) =>
|
|
r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
items: [
|
|
{
|
|
id: 'op-1',
|
|
op: 'chapter',
|
|
manga_id: 'm-1',
|
|
manga_title: 'Berserk',
|
|
chapter_id: 'c-1',
|
|
chapter_number: 12,
|
|
outcome: 'ok',
|
|
duration_ms: 6100,
|
|
items: 20,
|
|
error: null,
|
|
finished_at: '2026-06-15T00:00:00Z'
|
|
}
|
|
],
|
|
page: { limit: 25, offset: 0, total: 1 }
|
|
})
|
|
})
|
|
);
|
|
|
|
await page.route('**/api/v1/admin/crawler/dead-jobs/requeue', (r) => {
|
|
cap.requeue = JSON.parse(r.request().postData() ?? '{}');
|
|
return r.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ requeued: 1 })
|
|
});
|
|
});
|
|
}
|
|
|
|
test.describe('/admin/crawler history', () => {
|
|
test('toggle to History lists jobs and requeues a dead job inline', async ({
|
|
page
|
|
}) => {
|
|
const cap: Captured = { requeue: null };
|
|
await mockAdmin(page, cap);
|
|
await page.setViewportSize(DESKTOP);
|
|
await page.goto('/admin/crawler');
|
|
|
|
await page.getByTestId('crawler-tab-history').click();
|
|
|
|
const deadRow = page.getByTestId(`crawler-history-row-${deadJobId}`);
|
|
await expect(deadRow).toContainText('Naruto · Ch 700');
|
|
await expect(deadRow).toContainText('dead');
|
|
|
|
const doneRow = page.getByTestId(`crawler-history-row-${doneJobId}`);
|
|
await expect(doneRow).toContainText('Bleach · Ch 3 · p7');
|
|
|
|
// Click the dead row to expand its error detail.
|
|
await deadRow.click();
|
|
await expect(
|
|
page.getByTestId('crawler-history').locator('.errrow')
|
|
).toContainText('boom: upstream 500');
|
|
|
|
// Inline requeue posts scope=job.
|
|
await page.getByTestId(`crawler-history-requeue-${deadJobId}`).click();
|
|
await expect.poll(() => cap.requeue).toEqual({ scope: 'job', job_id: deadJobId });
|
|
});
|
|
|
|
test('Metrics tab shows averages by type, derived per-page, and the ops log', async ({
|
|
page
|
|
}) => {
|
|
const cap: Captured = { requeue: null };
|
|
await mockAdmin(page, cap);
|
|
await page.setViewportSize(DESKTOP);
|
|
await page.goto('/admin/crawler');
|
|
|
|
await page.getByTestId('crawler-tab-metrics').click();
|
|
|
|
// Per-type averages.
|
|
await expect(page.getByTestId('crawler-metrics-row-chapter')).toContainText('6.8s');
|
|
await expect(page.getByTestId('crawler-metrics-row-manga_cover')).toContainText(
|
|
'480ms'
|
|
);
|
|
// Derived per-page row: 6800ms ÷ 32 ≈ 213ms.
|
|
await expect(page.getByTestId('crawler-metrics-perpage')).toContainText('213ms');
|
|
|
|
// Recent-ops log shows individual durations.
|
|
await expect(page.getByTestId('crawler-op-op-1')).toContainText('6.1s');
|
|
await expect(page.getByTestId('crawler-op-op-1')).toContainText('Berserk · Ch 12');
|
|
});
|
|
});
|