diff --git a/tests/browser/workspace-activity.spec.mjs b/tests/browser/workspace-activity.spec.mjs index 8badc8c..af8ccd4 100644 --- a/tests/browser/workspace-activity.spec.mjs +++ b/tests/browser/workspace-activity.spec.mjs @@ -2,6 +2,13 @@ import { startCoverage, saveCoverage } from '../../tools/vendor/browser-coverage import { test, expect } from './fixtures.mjs'; import { seedConcept, openConcept, openProduction } from './concept-inventory.mjs'; +// The Activity store's periodic list read (activity-store.mjs POLL_MS) and the detail view's read throttle +// (activity-job-view.mjs DETAIL_INTERVAL_MS). +const POLL_MS = 15_000; +const DETAIL_INTERVAL_MS = 1_000; +// A request is reported to the test a little after the browser sends it; that delay is not a shorter wait. +const REPORT_SLACK_MS = 100; + // Activity (#249 Activity-1): the concept's Activity page (app.js renderActivity 732–738), its top-bar button // (index.html 51–52) and sidebar row (app.js ~341), with the recorded D52 (counts of running jobs), D53 (the progress // pill) and D54 (real job items). Fake jobs come from tests/browser/workspace_activity_fixture.py. @@ -278,8 +285,8 @@ test('reload during a scan reattaches to the running job', async ({ page, reques }); test('lost server clears the pill and marks jobs ended', async ({ page, request }) => { - // The failed re-reads back off for 1 + 2 + 4 s before the third is seen. - test.setTimeout(60_000); + // A poll interval after the restart, then failed re-reads backing off for 1 + 2 + 4 s. + test.setTimeout(90_000); await page.setViewportSize({ width: 1600, height: 1100 }); const job = await startJob(request); await step(request, job.id, { processed: 4000 }); @@ -296,9 +303,12 @@ test('lost server clears the pill and marks jobs ended', async ({ page, request await expect(items(page).first().locator('p')).toHaveText(LOST); await expect(items(page).first().locator('progress, .row-actions')).toHaveCount(0); await expect(navRow(page).locator('.nav-count')).toHaveCount(0); - // One re-read found the restart; there is no retry storm and no finish toast for a job that only vanished. - await page.waitForTimeout(2500); - expect(reads.length).toBeLessThanOrEqual(2); + // One re-read found the restart; there is no retry storm and no finish toast for a job that only vanished. The + // read after it is the periodic one, a whole poll interval later: any extra read lands in that gap and fails it. + const found = reads.length; + expect(found, 'reads that found the restart').toBeGreaterThanOrEqual(1); + await expect.poll(() => reads.length, { timeout: POLL_MS + 10_000 }).toBeGreaterThan(found); + expect(reads[found] - reads[found - 1], 'the next read waits for the poll').toBeGreaterThanOrEqual(POLL_MS - REPORT_SLACK_MS); await expect(toast(page)).toHaveText(''); // A server that cannot be read at all also ends the running job, then is read again with a growing backoff. @@ -314,8 +324,6 @@ test('lost server clears the pill and marks jobs ended', async ({ page, request // reads themselves are the evidence, so a slow runner noticing the ended job late cannot add a read to a window. await expect.poll(() => failed.length, { timeout: 20_000 }).toBeGreaterThanOrEqual(3); const gaps = failed.slice(1, 3).map((at, index) => at - failed[index]); - // A request is reported to the test a little after the browser sends it; that delay is not a shorter backoff. - const REPORT_SLACK_MS = 100; expect(gaps[0]).toBeGreaterThanOrEqual(2000 - REPORT_SLACK_MS); expect(gaps[1]).toBeGreaterThanOrEqual(4000 - REPORT_SLACK_MS); await page.unroute('**/prompt_manager/jobs**'); @@ -614,6 +622,8 @@ test('filter narrows the selected outcome', async ({ page, request }) => { test('job view renders 200-row cap note', async ({ page, request }) => { await page.setViewportSize({ width: 1600, height: 1100 }); + // The page's timers are Playwright's, running at real speed, so the M12 check below can run a read throttle out. + await page.clock.install(); const job = await startJob(request); await step(request, job.id, { processed: 260, bulk: { group: 'added', count: 250 }, records: [ ...Array.from({ length: 10 }, (_, index) => ({ group: 'no_metadata', path: `misc/plain_${index}.png`, detail: 'No prompt metadata in the file' })), @@ -653,11 +663,15 @@ test('job view renders 200-row cap note', async ({ page, request }) => { page.on('request', item => { if (new URL(item.url()).pathname === `/prompt_manager/jobs/${job.id}`) reads.push(Date.now()); }); await step(request, job.id, { processed: 300, bulk: { group: 'added', count: 40 } }); await expect(tiles(page).first().locator('dd')).toHaveText('290'); - await page.waitForTimeout(1500); + // Every read the counter update could have scheduled is due within one throttle interval: run it out, so any such + // read is sent before the log opens. Requests reach the test in the order they were sent, so once the log's read + // has answered, a read sent before it would already be listed. + await page.clock.runFor(DETAIL_INTERVAL_MS); expect(reads).toEqual([]); await scanLog(page).locator('summary').click(); await expect.poll(() => reads.length).toBe(1); await expect(scanLog(page).locator('pre')).toContainText('bulk/file_00039.png'); + expect(reads, 'only the log\'s own read').toHaveLength(1); }); test('cancel scan ends cancelled with partial counts', async ({ page, request }) => { @@ -687,14 +701,17 @@ test('cancel scan ends cancelled with partial counts', async ({ page, request }) test('busy start names the running job', async ({ page, request }) => { await page.setViewportSize({ width: 1600, height: 1100 }); + // The page's timers are Playwright's, so the toast's lifetime below is run out rather than waited for. + await page.clock.install(); const running = await startJob(request, { title: 'Database maintenance', kind: 'maintenance' }); await startFromImport(page); await expect(toast(page)).toHaveText('Another job is running: Database maintenance.'); await expect(toast(page).getByRole('link', { name: 'Database maintenance', exact: true })).toHaveAttribute('href', `#/activity/${running.id}`); await expect(page).toHaveURL(/#\/images$/); expect((await listed(request)).map(item => item.id)).toEqual([running.id]); - // Review M14: a toast with a link outlasts the plain 6.5 s, so the link stays reachable. - await page.waitForTimeout(7000); + // Review M14: a toast with a link outlasts the plain 6.5 s, so the link stays reachable. Running the page's timers + // 7 s on fires a 6.5 s clear for certain, however slowly this runner reached this line. + await page.clock.runFor(7000); await expect(toast(page).getByRole('link', { name: 'Database maintenance', exact: true })).toBeVisible(); await toast(page).getByRole('link', { name: 'Database maintenance', exact: true }).click(); await expect(heading(page).locator('h1')).toHaveText('Database maintenance');