Peach: Local-first video metadata scraper and media manager.
fix(test): 隔离详情桩片源的媒体错误上报
longmeidao55794f2f3d13
diff --git a/frontend/e2e/item-detail.test.ts b/frontend/e2e/item-detail.test.tsindex 91c8c7a05..5106633d3 100644--- a/frontend/e2e/item-detail.test.ts+++ b/frontend/e2e/item-detail.test.ts@@ -841,6 +841,34 @@ describe('作品详情岛', () => {}});+ it('桩片源的连续解码错误不消耗真实诊断预算,其他错误继续下传', { timeout: 60_000 }, async () => {+ const opened = await openItemPage(browser, `/assets/${ITEM.plain}`, DESKTOP);+ try {+ const forwarded: unknown[] = [];+ await opened.page.context().route((url) => url.pathname === '/api/diagnostics/client-error', (route) => {+ forwarded.push(route.request().postDataJSON());+ return route.fulfill({ json: { recorded: false } });+ });+ const before = opened.stub.mediaErrors.length;+ const replies = await opened.page.evaluate(async () => {+ const send = async (kind: string, source_route: string) => (await fetch('/api/diagnostics/client-error', {+ method: 'POST', headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ kind, message: '夹具错误', playback: { source_route } }),+ })).json();+ const media = await Promise.all(Array.from({ length: 21 }, () => send('media', '/stream')));+ return { media, other: await send('error', '/stream'), external: await send('media', '/external') };+ });+ assert.deepEqual(replies.media, Array.from({ length: 21 }, () => ({ recorded: true })));+ assert.equal(opened.stub.mediaErrors.length - before, 21);+ assert.deepEqual(replies.other, { recorded: false });+ assert.deepEqual(replies.external, { recorded: false });+ assert.deepEqual(forwarded, [+ { kind: 'error', message: '夹具错误', playback: { source_route: '/stream' } },+ { kind: 'media', message: '夹具错误', playback: { source_route: '/external' } },+ ]);+ } finally { await opened.close() }+ });+it('手机 390:详情不横向溢出,侧栏排在播放区下面', { timeout: 60_000 }, async () => {const opened = await openItemPage(browser, `/assets/${ITEM.plain}`, MOBILE);try {diff --git a/frontend/e2e/item-fixture.ts b/frontend/e2e/item-fixture.tsindex 11c4e8960..76cebef77 100644--- a/frontend/e2e/item-fixture.ts+++ b/frontend/e2e/item-fixture.ts@@ -93,13 +93,15 @@ export interface ItemStub {writes: { url: string; body: Record<string, unknown> }[];/** 各读接口被请求了几次,按路径计。 */reads: Map<string, number>;+ /** 空片源的预期解码错误,独立于真实诊断服务的限流预算。 */+ mediaErrors: Record<string, unknown>[];}const body = (request: Request) => JSON.parse(request.postData() || '{}') as Record<string, unknown>;async function stub(page: Page, catalogIds: readonly number[] = CATALOG): Promise<ItemStub> {await mockSubtitleMemory(page);- const state: ItemStub = { writes: [], reads: new Map() };+ const state: ItemStub = { writes: [], reads: new Map(), mediaErrors: [] };const read = (path: string) => state.reads.set(path, (state.reads.get(path) || 0) + 1);const playlists = new Map<number, { id: number; name: string; ids: number[]; current: number | null }>([[PLAYLIST.id, { id: PLAYLIST.id, name: PLAYLIST.name, ids: [...PLAYLIST.items], current: 11 }],@@ -171,6 +173,13 @@ async function stub(page: Page, catalogIds: readonly number[] = CATALOG): Promis(route) => route.request().method() === 'GET' ? route.fallback() : route.fulfill({ json: { ok: true } }));await page.route((url) => url.pathname === '/api/stream-plan',(route) => route.fulfill({ json: { protocol: 'direct' } }));await page.route((url) => url.pathname === '/stream', (route) => route.fulfill({ status: 204, body: '' }));+ await page.route((url) => url.pathname === '/api/diagnostics/client-error', (route) => {+ const sent = body(route.request());+ const playback = sent.playback as { source_route?: string } | undefined;+ if (sent.kind !== 'media' || playback?.source_route !== '/stream') return route.fallback();+ state.mediaErrors.push(sent);+ return route.fulfill({ json: { recorded: true } });+ });await page.route((url) => ['/poster', '/cover', '/logo', '/entity-image', '/avatar'].includes(url.pathname), (route) => {const url = new URL(route.request().url());const cover = url.pathname === '/cover';