diff --git a/app/tool/changes_probe.mjs b/app/tool/changes_probe.mjs index 7c2f51c7..36a44d42 100644 --- a/app/tool/changes_probe.mjs +++ b/app/tool/changes_probe.mjs @@ -8,6 +8,10 @@ // headless Chrome through the Chrome DevTools Protocol, enables Flutter // semantics, clicks exact labels, verifies the body/labels change, copies the // raw patch and writes real PNG captures at phone and desktop widths. +// +// The Changes page shows one recorded visit at a time, so visit-only evidence +// (capture states, visit numbers) is collected by paging with Previous/Next +// rather than from a single body snapshot. import { createServer } from 'node:http'; import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'; import { spawn } from 'node:child_process'; @@ -181,6 +185,36 @@ try { if (!clicked) throw new Error(`No semantics label starting ${JSON.stringify(prefix)}: ${JSON.stringify(await labels())}`); await delay(450); }; + // The disabled Previous/Next is a semantics button with aria-disabled; the + // pager must stop at both ends instead of wrapping. + const buttonDisabled = (label) => evaluate(`(() => { + const wanted = ${JSON.stringify(label)}; + const node = [...document.querySelectorAll('flt-semantics[role="button"]')] + .find(x => (x.getAttribute('aria-label') || (x.innerText || '').trim()) === wanted); + return node ? node.getAttribute('aria-disabled') === 'true' : null; + })()`); + // Clipboard writes need a trusted user gesture, which a scripted semantics + // `.click()` is not; dispatch real mouse events at the control's centre. + const tapExact = async (label) => { + const point = await evaluate(`(() => { + const wanted = ${JSON.stringify(label)}; + const nodes = [...document.querySelectorAll('flt-semantics')]; + const node = nodes.find(x => x.getAttribute('aria-label') === wanted) + || nodes.find(x => (x.innerText || '').trim() === wanted); + if (!node) return null; + const rect = node.getBoundingClientRect(); + return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }; + })()`); + if (!point) throw new Error(`No semantics node for ${JSON.stringify(label)}: ${JSON.stringify(await labels())}`); + for (const type of ['mousePressed', 'mouseReleased']) { + await send('Input.dispatchMouseEvent', { type, x: point.x, y: point.y, button: 'left', clickCount: 1 }, session); + } + await delay(450); + }; + const visitPage = (text) => text.match(/\d+ of \d+ recorded visits/)?.[0] ?? null; + const visitStage = (text, stage) => text.includes(`\n${stage}\n`); + const headerLine = (text) => + text.split('\n').find((line) => line.startsWith('Changes · ')) ?? null; const activate = async () => { await delay(3500); await evaluate("document.querySelector('flt-semantics-placeholder')?.click()"); @@ -233,19 +267,127 @@ try { const firstBody = await bodyText(); const firstRow = 'Open diff for lib/features/changes/domain/unified_patch.dart'; const firstRowPresent = firstLabels.some((label) => label.startsWith(firstRow)); - const firstStates = ['Changes probe', 'Capture unavailable'].filter((label) => - firstBody.includes(label), - ); + // The run-wide aggregate header and the pager describe different scopes: the + // header covers every visit, the pager position scopes the shown visit. + const firstPage = { + header: headerLine(firstBody), + page: visitPage(firstBody), + stage: visitStage(firstBody, 'implementer'), + visit: firstBody.includes('Visit 1 · completed'), + previousDisabled: await buttonDisabled('Previous visit'), + nextDisabled: await buttonDisabled('Next visit'), + }; evidence.checks.push({ - check: 'run summary and capture states are present', - value: firstStates, + check: 'page 1 opens on the first recorded visit', + ...firstPage, fileRow: firstRowPresent, }); - if (firstStates.length !== 2 || !firstRowPresent) { - throw new Error(`Run summary or capture states missing: ${JSON.stringify(firstBody)}`); + if ( + firstPage.header !== 'Changes · capture unavailable' || + firstPage.page !== '1 of 5 recorded visits' || + !firstPage.stage || + !firstPage.visit + ) { + throw new Error(`Run summary or first visit missing: ${JSON.stringify(firstBody)}`); } + if (firstPage.previousDisabled !== true || firstPage.nextDisabled !== false) { + throw new Error(`Page 1 pager did not clamp at the start: ${JSON.stringify(firstPage)}`); + } + if (!firstRowPresent) throw new Error('Page 1 is missing the implementer file row'); await capture('d1-changes-phone-list', 390, 844); + // Page through every recorded visit. Each page keeps its own stage/visit + // heading and the run-wide header, and Next/Previous clamp at both ends. + await clickExact('Next visit'); + const secondBody = await bodyText(); + const secondPage = { + page: visitPage(secondBody), + stage: visitStage(secondBody, 'reviewer'), + visit: secondBody.includes('Visit 1 · completed'), + headerUnchanged: headerLine(secondBody) === firstPage.header, + previousDisabled: await buttonDisabled('Previous visit'), + rowPresent: (await labels()).some((label) => + label.startsWith('Open diff for lib/features/changes/widgets/file_diff_viewer.dart'), + ), + }; + evidence.checks.push({ check: 'Next opens the next recorded visit', ...secondPage }); + if ( + secondPage.page !== '2 of 5 recorded visits' || + !secondPage.stage || + !secondPage.visit || + !secondPage.headerUnchanged || + secondPage.previousDisabled !== false || + !secondPage.rowPresent + ) { + throw new Error(`Second visit page is wrong: ${JSON.stringify(secondBody)}`); + } + await capture('d1-changes-phone-page2', 390, 844); + + await clickExact('Next visit'); + const missingBody = await bodyText(); + evidence.checks.push({ + check: 'a later visit reports a missing capture', + page: visitPage(missingBody), + stage: visitStage(missingBody, 'ui_reviewer'), + captureUnavailable: missingBody.includes('Capture unavailable'), + }); + if ( + visitPage(missingBody) !== '3 of 5 recorded visits' || + !visitStage(missingBody, 'ui_reviewer') || + !missingBody.includes('Capture unavailable') + ) { + throw new Error(`Missing-capture visit page is wrong: ${JSON.stringify(missingBody)}`); + } + await capture('d1-changes-phone-page3-missing', 390, 844); + + await clickExact('Next visit'); + const unavailableBody = await bodyText(); + evidence.checks.push({ + check: 'a later visit reports an unavailable capture', + page: visitPage(unavailableBody), + stage: visitStage(unavailableBody, 'committer'), + diagnostic: unavailableBody.includes('Workspace snapshot unavailable'), + }); + if ( + visitPage(unavailableBody) !== '4 of 5 recorded visits' || + !visitStage(unavailableBody, 'committer') || + !unavailableBody.includes('Workspace snapshot unavailable') + ) { + throw new Error(`Unavailable-capture visit page is wrong: ${JSON.stringify(unavailableBody)}`); + } + await capture('d1-changes-phone-page4-unavailable', 390, 844); + + await clickExact('Next visit'); + const lastBody = await bodyText(); + evidence.checks.push({ + check: 'the last visit is a recorded no-change and Next is disabled', + page: visitPage(lastBody), + stage: visitStage(lastBody, 'verifier'), + empty: lastBody.includes('No changes observed'), + nextDisabled: await buttonDisabled('Next visit'), + }); + if ( + visitPage(lastBody) !== '5 of 5 recorded visits' || + !visitStage(lastBody, 'verifier') || + !lastBody.includes('No changes observed') || + (await buttonDisabled('Next visit')) !== true + ) { + throw new Error(`Last visit page is wrong: ${JSON.stringify(lastBody)}`); + } + await capture('d1-changes-phone-page5-last', 390, 844); + + await clickExact('Previous visit'); + const previousBody = await bodyText(); + evidence.checks.push({ + check: 'Previous returns to the prior visit', + page: visitPage(previousBody), + stage: visitStage(previousBody, 'committer'), + }); + if (visitPage(previousBody) !== '4 of 5 recorded visits') { + throw new Error(`Previous lost the visit: ${JSON.stringify(previousBody)}`); + } + + await navigate(`${origin}/`); const before = await bodyText(); await clickPrefix('Open diff for lib/features/changes/domain/unified_patch.dart'); const after = await bodyText(); @@ -284,7 +426,7 @@ try { origin, permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'], }); - await clickExact('Copy patch'); + await tapExact('Copy patch'); let clipboard = null; try { clipboard = await evaluate('navigator.clipboard.readText()'); @@ -344,34 +486,45 @@ try { evidence.checks.push({ check: 'filter field not exposed as a semantics input', value: false }); } - // Visit numbering: two stages appear twice in this compact fixture. The - // implementer's visits are position-derived (1, 2); the resumed reviewer - // visit records control.visit 6, which must win over its position. + // Visit numbering: two stages appear twice in this compact fixture. Each + // stage numbers its own visits, so paging must collect one number per page: + // the implementer's visits are position-derived (1, 2) and the resumed + // reviewer visit records control.visit 6, which must win over its position. await navigate(`${origin}/?visits=1`); - const visitText = await bodyText(); - const visitsFor = (stage) => [ - ...visitText.matchAll(new RegExp(`${stage}\\s+Visit (\\d+)`, 'g')), - ].map((match) => match[1]); - const implementerVisits = visitsFor('implementer'); - const reviewerVisits = visitsFor('reviewer'); - evidence.checks.push({ - check: 'repeated stages show their own visit numbers', - implementerVisits, - reviewerVisits, - }); - if (implementerVisits.join(',') !== '1,2') { - throw new Error(`implementer visits are not 1,2: ${JSON.stringify(visitText)}`); + const visitSequence = []; + for (let step = 0; step < 4; step++) { + const current = await bodyText(); + const stage = visitStage(current, 'implementer') + ? 'implementer' + : visitStage(current, 'reviewer') + ? 'reviewer' + : '?'; + visitSequence.push(`${stage}:${current.match(/Visit (\d+) ·/)?.[1] ?? '?'}`); + if (step < 3) await clickExact('Next visit'); } - if (reviewerVisits.join(',') !== '1,6') { - throw new Error(`reviewer visits are not 1,6 (control.visit): ${JSON.stringify(visitText)}`); + const lastVisitBody = await bodyText(); + evidence.checks.push({ + check: 'paged visit numbering keeps per-stage numbers and control.visit', + sequence: visitSequence, + page: visitPage(lastVisitBody), + nextDisabled: await buttonDisabled('Next visit'), + }); + if (visitSequence.join(',') !== 'implementer:1,reviewer:1,implementer:2,reviewer:6') { + throw new Error(`Visit numbers are not paged per stage: ${JSON.stringify(visitSequence)}`); + } + if (visitPage(lastVisitBody) !== '4 of 4 recorded visits') { + throw new Error(`Visit fixture did not reach its last page: ${JSON.stringify(lastVisitBody)}`); } const visitFile = await capture('d1-changes-phone-visits', 390, 844); await navigate(`${origin}/`); + await capture('d1-changes-desktop-list', 1280, 800); + // The reviewer's file row lives on the second visit page. + await clickExact('Next visit'); + await capture('d1-changes-desktop-page2', 1280, 800); await clickPrefix('Open diff for lib/features/changes/widgets/file_diff_viewer.dart'); await capture('d1-changes-desktop-diff', 1280, 800); await clickExact('Close diff'); - await capture('d1-changes-desktop-list', 1280, 800); // Presentation revision: the light theme and a narrow Cupertino surface, at // 2x so glyph advance, line tints and the popup inset are inspectable. @@ -389,12 +542,27 @@ try { await navigate(`${origin}/?theme=light`); await capture('d1-changes-desktop-light-list', 1280, 800); + // The reviewer's row is on the second visit page in the light theme too. + await clickExact('Next visit'); await clickPrefix('Open diff for lib/features/changes/widgets/file_diff_viewer.dart'); await capture('d1-changes-desktop-light-diff', 1280, 800); await clickExact('Close diff'); await navigate(`${origin}/?platform=cupertino&theme=light`); await capture('d1-changes-cupertino-light-list', 390, 844); + // The Cupertino pager uses native buttons; paging keeps the visit heading. + await clickExact('Next visit'); + const cupertinoSecond = await bodyText(); + evidence.checks.push({ + check: 'Cupertino pages to the second visit', + page: visitPage(cupertinoSecond), + stage: visitStage(cupertinoSecond, 'reviewer'), + }); + if (visitPage(cupertinoSecond) !== '2 of 5 recorded visits') { + throw new Error(`Cupertino pager did not advance: ${JSON.stringify(cupertinoSecond)}`); + } + await capture('d1-changes-cupertino-light-page2', 390, 844); + await clickExact('Previous visit'); await clickPrefix('Open diff for lib/features/changes/domain/unified_patch.dart'); await capture('d1-changes-cupertino-light-diff', 390, 844); await capture('d1-changes-cupertino-light-diff-2x', 390, 844, 2);