Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

chore(core): integrate accepted Chrome wait fix [H16,C7]

Corey Olsonf8d1702a7c52
diff --cc test/chrome-fixture.js
index c3e0cdc7,f8e7645e..16387f18
--- a/test/chrome-fixture.js
+++ b/test/chrome-fixture.js
@@@ -145,32 -140,22 +145,35 @@@ export async function startChrome(
async function navigate(nextUrl) {
await send('Page.navigate', { url: nextUrl }, 'navigate page');
}
- /** Wait until a page expression becomes truthy before its command deadline. */
+ /** Wait until a page expression becomes truthy, treating document-transition evaluation errors as pending. */
async function waitFor(expression, timeoutMs = commandTimeoutMs, label = 'wait for page condition') {
const waitDeadline = Date.now() + timeoutMs;
+ let lastEvaluationError = null;
while (Date.now() < waitDeadline) {
try {
- if (await evaluate(expression, label)) return;
+ if (await evaluate(expression, label, waitDeadline - Date.now())) return;
} catch (error) {
- if (error.code !== 'CDP_TIMEOUT' || Date.now() < waitDeadline) throw error;
- if (!(error instanceof Error) || !error.message.startsWith('Browser evaluation failed:')) throw error;
- lastEvaluationError = error;
++ if (error instanceof Error && error.message.startsWith('Browser evaluation failed:')) lastEvaluationError = error;
++ else if (error.code !== 'CDP_TIMEOUT' || Date.now() < waitDeadline) throw error;
}
- await pause(50);
+ await pause(Math.max(0, Math.min(50, waitDeadline - Date.now())));
}
- throw new Error(`Browser condition "${label}" did not arrive within ${timeoutMs}ms.`);
+ const exception = lastEvaluationError instanceof Error ? `; last evaluation failed: ${lastEvaluationError.message}` : '';
+ throw new Error(`Browser condition "${label}" did not arrive within ${timeoutMs}ms; expression: ${expression.slice(0, 200)}${exception}.`);
}
+ /** Wait for non-stream relay traffic to finish before an idle-network assertion. */
+ async function waitForRelayIdle(timeoutMs = commandTimeoutMs) {
+ const deadline = Date.now() + timeoutMs;
+ let quietSince = null;
+ while (Date.now() < deadline) {
+ if (relayRequests.size === 0) {
+ quietSince ??= Date.now();
+ if (Date.now() - quietSince >= 100) return;
+ } else quietSince = null;
+ await pause(20);
+ }
+ throw new Error(`Relay requests did not become idle within ${timeoutMs}ms.`);
+ }
/** Start asynchronous page work without holding a CDP Runtime.evaluate command open. */
async function startTask(expression, label) {
const taskId = '__pullboardFixtureTask' + ++taskSequence;
diff --cc test/chrome-fixture.test.js
index 69e09152,1f3dc136..9040d2d7
--- a/test/chrome-fixture.test.js
+++ b/test/chrome-fixture.test.js
@@@ -172,15 -149,65 +174,78 @@@ test('a failed browser evaluation name
}
});
+/** Prove a page condition cannot spend the much longer general command allowance. */
+test('a stalled condition uses its remaining operation budget [C7]', {
+ skip: !findChromeExecutable() && 'Chrome is not installed',
+}, async t => {
+ const chrome = await startChrome();
+ t.after(() => chrome.close());
+ const started = Date.now();
+ await assert.rejects(chrome.waitFor('new Promise(() => {})', 250, 'bounded condition'),
+ /Browser condition "bounded condition" did not arrive within 250ms/u);
+ assert.ok(Date.now() - started < 10_000, 'the 250ms operation never consumes the 15000ms command allowance');
+ assert.equal(await chrome.evaluate('1 + 1'), 2, 'timing out one command leaves the real DevTools connection usable');
+});
++
+ test('a wait that throws while the page changes keeps waiting [C7]', async (t) => {
+ let replacementResponse;
+ const server = createServer((request, response) => {
+ if (request.url === '/before') {
+ response.writeHead(200, { 'content-type': 'text/html' });
+ response.end('<!doctype html><body><script>window.goNext = () => location.replace("/next")</script>before</body>');
+ return;
+ }
+ if (request.url === '/next') {
+ response.writeHead(200, { 'content-type': 'text/html' });
+ response.write('<!doctype html><html><head><title>loading');
+ replacementResponse = response;
+ return;
+ }
+ if (request.url === '/observed-null') {
+ response.writeHead(204);
+ response.end();
+ server.emit('document-gap-observed');
+ replacementResponse?.end('</title></head><body>ready</body></html>');
+ return;
+ }
+ response.writeHead(404);
+ response.end();
+ });
+ server.listen(0, '127.0.0.1');
+ await once(server, 'listening');
+ const documentGapObserved = new Promise((resolveGap) => server.once('document-gap-observed', resolveGap));
+ t.after(() => {
+ server.closeAllConnections();
+ if (server.listening) server.close();
+ });
+
+ const chrome = await startChrome({ url: `http://127.0.0.1:${server.address().port}/before` });
+ try {
+ await chrome.waitFor("typeof window.goNext === 'function'", 5_000, 'initial document ready');
+ await chrome.evaluate('setTimeout(() => window.goNext(), 0); true');
+ const expression = "location.pathname === '/next' && document.body === null ? (() => { if (!window.__gapNotified) { window.__gapNotified = true; fetch('/observed-null'); } return document.body.textContent.includes('ready'); })() : document.body?.textContent.includes('ready') === true";
+ const waiting = chrome.waitFor(expression, 5_000, 'wait for the replacement document')
+ .then(() => ({ error: null }), (error) => ({ error }));
+ const first = await Promise.race([
+ documentGapObserved.then(() => ({ gapObserved: true })),
+ waiting.then((result) => ({ result })),
+ ]);
+ assert.equal(first.gapObserved, true, 'the real page expression observed its document without a body');
+ const waitResult = await waiting;
+ assert.equal(waitResult.error, null, 'the document-transition exception stays pending until the next page is ready');
+ assert.equal(await chrome.evaluate('document.body.textContent'), 'ready', 'the replacement document completed');
+
+ const alwaysThrows = '(() => { throw new Error("persistent evaluation failure"); })()';
+ const startedAt = Date.now();
+ await assert.rejects(chrome.waitFor(alwaysThrows, 350, 'always-throwing expression'), (error) => {
+ assert.match(error.message, /did not arrive within 350ms/u);
+ assert.match(error.message, /persistent evaluation failure/u);
+ assert.ok(error.message.includes(alwaysThrows), 'deadline diagnostic names the expression');
+ assert.ok(Date.now() - startedAt >= 350, 'the wait polls through its requested deadline');
+ return true;
+ });
+
+ } finally {
+ await chrome.close();
+ }
+ });