console: kept browser test waits for commits before polling
TestDemoClaimKeptHeadless failed once on main CI (0acb2767) with CDP -32000 "Inspected target navigated or closed". The kept shell replaces itself with /demo/claim once its exchange lands, and the script polled Runtime.evaluate straight through that navigation, so a command could reach the outgoing document as the new one committed. The failure came 3.61 s into the Go test, before scene 1 ever reaches its reload (about 4.7 s into the script locally), so the shell's replace is the race hit. Page.reload had the same shape: it answers before its navigation commits, and the settled check's condition is already true on the outgoing page. Track main-frame Page.frameNavigated commits and, after each step that navigates, wait without sending commands until exactly the expected documents have committed (kept shell then /demo/claim; one /demo/claim for the reload), bounded at 15 s like until(). Every assertion stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+19
−0
internal/console/testdata/demo_claim_kept_browser.mjs+19 −0
diff --git a/internal/console/testdata/demo_claim_kept_browser.mjs b/internal/console/testdata/demo_claim_kept_browser.mjs| index e270fbe9c..ed6176671 100644 |
| --- a/internal/console/testdata/demo_claim_kept_browser.mjs |
| +++ b/internal/console/testdata/demo_claim_kept_browser.mjs |
| @@ -12,6 +12,8 @@ const chrome = spawn(binary, ['--headless', '--no-sandbox', '--disable-gpu', |
| let sequence = 0, buffered = '', session; |
| const pending = new Map(); |
| const violations = []; |
| +// Every document the tab's main frame commits, in order (fragment excluded). |
| +const commits = []; |
| chrome.stdio[4].on('data', bytes => { |
| buffered += bytes.toString(); |
| let end; |
| @@ -19,6 +21,7 @@ chrome.stdio[4].on('data', bytes => { |
| const message = JSON.parse(buffered.slice(0, end)); |
| buffered = buffered.slice(end + 1); |
| if (message.method === 'Runtime.bindingCalled' && message.params.name === 'keptCSP') violations.push(message.params.payload); |
| + if (message.method === 'Page.frameNavigated' && message.sessionId === session && !message.params.frame.parentId) commits.push(message.params.frame.url); |
| const resolve = pending.get(message.id); |
| if (resolve) { pending.delete(message.id); resolve(message); } |
| } |
| @@ -43,6 +46,17 @@ async function until(expression) { |
| } |
| throw Error('browser_condition_timeout: ' + await evaluate('JSON.stringify({text:document.body.innerText,email:document.getElementById("email")?.value,focus:document.activeElement.tagName,valid:document.querySelector("form")?.checkValidity()})')); |
| } |
| +// The kept shell replaces itself with /demo/claim once its exchange lands, |
| +// and Page.reload answers before its navigation commits. A command that |
| +// reaches the outgoing document as the next one commits fails with -32000 |
| +// "Inspected target navigated or closed" (main CI, 2026-11-19), and a |
| +// condition polled too soon can pass on the outgoing page. So a step that |
| +// navigates waits, sending nothing, until the main frame has committed |
| +// exactly the documents it expects, and only then polls the page. |
| +async function committed(since, urls) { |
| + for (let i = 0; i < 150 && commits.length - since < urls.length; i++) await new Promise(resolve => setTimeout(resolve, 100)); |
| + assert.deepEqual(commits.slice(since), urls); |
| +} |
| const timer = setTimeout(() => { chrome.kill('SIGKILL'); process.exitCode = 1; }, 170000); |
| try { |
| @@ -70,7 +84,10 @@ try { |
| await call('Network.clearBrowserCookies'); |
| await call('Emulation.setDeviceMetricsOverride', {width:scene.Width,height:900,deviceScaleFactor:1,mobile:false}); |
| await call('Emulation.setEmulatedMedia',{features:[{name:'prefers-color-scheme',value:scene.Theme},{name:'prefers-reduced-motion',value:'no-preference'}]}); |
| + const origin = new URL(scene.URL).origin; |
| + let since = commits.length; |
| await call('Page.navigate',{url:scene.URL}); |
| + await committed(since,[origin+'/demo/claim/kept',origin+'/demo/claim']); |
| if (scene.Mode === 'live') { |
| await until('location.hash === "" && document.getElementById("claim")?.dataset.state === "claiming"'); |
| await shot(scene,'progress'); |
| @@ -90,7 +107,9 @@ try { |
| assert(cookies.every(cookie => cookie.name !== 'carlos_console_session')); |
| const statusCookie = cookies.find(cookie => cookie.name === 'carlos_demo_claim_flow'); |
| assert(statusCookie?.httpOnly && statusCookie.secure && statusCookie.path === '/demo/claim'); |
| + since = commits.length; |
| await call('Page.reload',{ignoreCache:true}); |
| + await committed(since,[origin+'/demo/claim']); |
| await until('document.readyState === "complete" && document.getElementById("claim")?.dataset.state === "claimed"'); |
| await new Promise(resolve => setTimeout(resolve,1800)); |
| assert.equal(await evaluate('window.keptReveals'),0); |