From 050d15eb77d567bd68138135253d734ffe5457e4 Mon Sep 17 00:00:00 2001 From: agorischek <6295280+agorischek@users.noreply.github.com> Date: Sat, 5 Dec 2026 02:22:41 +0000 Subject: [PATCH] Harness: one diff-mode test per scenario A test per renderer walked all 34 graph scenarios in both color modes and outgrew test.slow()'s 360 s on CI's Linux WebKit. One test per scenario gets a scenario's budget, and the shards split the walk. Refs #363 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .../renderers/harness/browser/diff.spec.ts | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/packages/renderers/harness/browser/diff.spec.ts b/packages/renderers/harness/browser/diff.spec.ts index f8e68e0c9..64d7f4e40 100644 --- a/packages/renderers/harness/browser/diff.spec.ts +++ b/packages/renderers/harness/browser/diff.spec.ts @@ -13,7 +13,7 @@ import {settled} from './settled.js' * sideways overflow. Set `PROJECTIONS_DIFF_SCREENSHOTS` to a directory to save * a screenshot of each at 1440 and 390 pixels. */ -const renderers = ['graph', 'database', 'dependency-injection', 'code-statistics', 'runtime-policy', 'api', 'agentic-workflows'] +const renderers = new Set(['graph', 'database', 'dependency-injection', 'code-statistics', 'runtime-policy', 'api', 'agentic-workflows']) const shots = process.env.PROJECTIONS_DIFF_SCREENSHOTS /** A comparison per renderer name whose diff is worth a picture; the first of each package otherwise. */ const pictured = new Set([ @@ -33,38 +33,36 @@ const pictured = new Set([ 'agentic-workflows/docs-bot', ]) -for (const directory of renderers) { - test(`${directory}: diff mode marks every change in its own form`, async ({page}, info) => { - test.slow() +// One test per scenario, so each has a scenario's budget and the shards share the renderers with the most scenarios: a +// test per renderer walked all 34 graph scenarios in both color modes and outgrew `test.slow()` on CI's Linux WebKit. +for (const {key} of scenarios.filter(item => renderers.has(item.directory))) { + test(`${key}: diff mode marks every change in its own form`, async ({page}, info) => { const inspector = harnessInspector() const mobile = info.project.name.endsWith('mobile') - const keys = scenarios.filter(item => item.directory === directory).map(item => item.key) - for (const key of keys) { - for (const colorMode of ['light', 'dark'] as const) { - const stage = await openStage(page, inspector, {scenario: key, comparisonMode: 'diff', colorMode}) - const state = await stage.state() - if (state.comparisonMode !== 'diff') continue - expect(state.capabilities?.comparisonModes, key).toContain('diff') - await stage.measure('settle') - const marks = await stage.frame.locator('[data-entity-id][data-change], [data-change] [data-entity-id]').count() - // Every renderer leaves its summary to the host's summary bar: kind counts with their changes, and its domain facts. - const summary = await stage.frame.locator('.pk-diff-summary, .graph-summary, .api-compatibility-counts').count() - expect(summary, `${key}: no summary row; the host's summary bar counts the changes`).toBe(0) - await expect.poll(async () => ((await stage.state()).summary ?? []).length, `${key}: a summary for the host`).toBeGreaterThan(0) - expect(marks, `${key}: changes are marked in place`).toBeGreaterThan(0) - const overflow = await stage.frame.locator('html').evaluate(root => root.scrollWidth - root.clientWidth) - expect(overflow, `${key} (${colorMode}): no sideways overflow`).toBeLessThanOrEqual(1) - if (shots && pictured.has(key) && info.project.name.startsWith('chromium')) { - mkdirSync(shots, {recursive: true}) - const width = mobile ? 390 : 1440 - await page.setViewportSize({width, height: mobile ? 844 : 900}) - // The frame takes the new width and the renderer refits before the picture. - await settled(async () => { - await stage.measure('settle') - return stage.frame.locator('body').evaluate(body => [innerWidth, body.scrollWidth, body.scrollHeight]) - }) - await stage.frame.locator('body').screenshot({path: `${shots}/${key.replace('/', '-')}-${colorMode}-${width}.png`}) - } + for (const colorMode of ['light', 'dark'] as const) { + const stage = await openStage(page, inspector, {scenario: key, comparisonMode: 'diff', colorMode}) + const state = await stage.state() + if (state.comparisonMode !== 'diff') continue + expect(state.capabilities?.comparisonModes, key).toContain('diff') + await stage.measure('settle') + const marks = await stage.frame.locator('[data-entity-id][data-change], [data-change] [data-entity-id]').count() + // Every renderer leaves its summary to the host's summary bar: kind counts with their changes, and its domain facts. + const summary = await stage.frame.locator('.pk-diff-summary, .graph-summary, .api-compatibility-counts').count() + expect(summary, `${key}: no summary row; the host's summary bar counts the changes`).toBe(0) + await expect.poll(async () => ((await stage.state()).summary ?? []).length, `${key}: a summary for the host`).toBeGreaterThan(0) + expect(marks, `${key}: changes are marked in place`).toBeGreaterThan(0) + const overflow = await stage.frame.locator('html').evaluate(root => root.scrollWidth - root.clientWidth) + expect(overflow, `${key} (${colorMode}): no sideways overflow`).toBeLessThanOrEqual(1) + if (shots && pictured.has(key) && info.project.name.startsWith('chromium')) { + mkdirSync(shots, {recursive: true}) + const width = mobile ? 390 : 1440 + await page.setViewportSize({width, height: mobile ? 844 : 900}) + // The frame takes the new width and the renderer refits before the picture. + await settled(async () => { + await stage.measure('settle') + return stage.frame.locator('body').evaluate(body => [innerWidth, body.scrollWidth, body.scrollHeight]) + }) + await stage.frame.locator('body').screenshot({path: `${shots}/${key.replace('/', '-')}-${colorMode}-${width}.png`}) } } })