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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
test(core): accept rounded Chrome budget boundary [C7]
Corey Olson5cb76016ef22
diff --git a/test/chrome-fixture.js b/test/chrome-fixture.jsindex e7aed797..82fd2379 100644--- a/test/chrome-fixture.js+++ b/test/chrome-fixture.js@@ -11,6 +11,11 @@ const CLEANUP_TIMEOUT_MS = 5_000;const GROUP_POLL_MS = 20;const STDERR_LIMIT = 128 * 1024;+/** Treat only a one-millisecond CDP timer rounding difference as the exact operation-budget boundary. */+export function isRoundedBudgetBoundary(reportedMs, elapsedMs, budgetMs) {+ return reportedMs === budgetMs - 1 && elapsedMs === budgetMs;+}+/** Find an installed Chrome without making browser availability a product-test failure. */export function findChromeExecutable() {return [process.env.PULLBOARD_CHROME, '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',@@ -147,14 +152,21 @@ export async function startChrome({}/** 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;+ const waitStartedAt = Date.now();+ const waitDeadline = waitStartedAt + timeoutMs;let lastEvaluationError = null;while (Date.now() < waitDeadline) {try {if (await evaluate(expression, label, waitDeadline - Date.now())) return;} catch (error) {if (error instanceof Error && error.message.startsWith('Browser evaluation failed:')) lastEvaluationError = error;- else if (error.code !== 'CDP_TIMEOUT' || Date.now() < waitDeadline) throw error;+ else {+ const cdpTimeout = error.code === 'CDP_TIMEOUT'+ && /timed out after (\d+)ms/u.exec(error.message);+ const roundedBoundary = cdpTimeout+ && isRoundedBudgetBoundary(Number(cdpTimeout[1]), Date.now() - waitStartedAt, timeoutMs);+ if (error.code !== 'CDP_TIMEOUT' || (Date.now() < waitDeadline && !roundedBoundary)) throw error;+ }}await pause(Math.max(0, Math.min(50, waitDeadline - Date.now())));}diff --git a/test/chrome-fixture.test.js b/test/chrome-fixture.test.jsindex 60f60bf9..fc983ccd 100644--- a/test/chrome-fixture.test.js+++ b/test/chrome-fixture.test.js@@ -5,9 +5,9 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, wrimport { createServer } from 'node:http';import { loadavg, tmpdir } from 'node:os';import { join } from 'node:path';-import { monitorEventLoopDelay, performance } from 'node:perf_hooks';+import { monitorEventLoopDelay } from 'node:perf_hooks';import { test } from 'node:test';-import { findChromeExecutable, launchChromeProcess, startChrome } from './chrome-fixture.js';+import { findChromeExecutable, isRoundedBudgetBoundary, launchChromeProcess, startChrome } from './chrome-fixture.js';/** Pause between checks while waiting for a fixture helper's readiness marker. */function pause(ms) {@@ -184,21 +184,34 @@ test('a stalled condition uses its remaining operation budget [C7]', {const budgetMs = 250;const scheduler = monitorEventLoopDelay({ resolution: 10 });scheduler.enable();- const startedAt = performance.now();+ const startedAt = Date.now();let failure;try { await chrome.waitFor('new Promise(() => {})', budgetMs, 'bounded condition'); }catch (error) { failure = error; }- const elapsedMs = performance.now() - startedAt;+ const elapsedMs = Date.now() - startedAt;scheduler.disable();const schedulerSlackMs = Math.ceil(scheduler.max / 1e6);const details = `budget=${budgetMs}ms elapsed=${Math.round(elapsedMs)}ms schedulerSlack=${schedulerSlackMs}ms loadavg=${JSON.stringify(loadavg())}`;- assert.ok(failure instanceof Error && /Browser condition "bounded condition" did not arrive within 250ms/u.test(failure.message),+ const cdpTimeout = failure instanceof Error+ && /DevTools Runtime\.evaluate "bounded condition" timed out after (\d+)ms/u.exec(failure.message);+ const conditionTimeout = failure instanceof Error+ && /Browser condition "bounded condition" did not arrive within 250ms/u.test(failure.message);+ assert.ok(conditionTimeout || (cdpTimeout && isRoundedBudgetBoundary(Number(cdpTimeout[1]), elapsedMs, budgetMs)),`the stalled page condition should time out at its operation budget; ${details}; failure=${failure?.message ?? 'none'}`);assert.ok(elapsedMs <= budgetMs + schedulerSlackMs,`the 250ms condition stayed within its measured budget plus scheduler delay; ${details}`);assert.equal(await chrome.evaluate('1 + 1'), 2, 'timing out one command leaves the real DevTools connection usable');});+test('a timeout at the budget boundary passes [C7]', () => {+ assert.equal(isRoundedBudgetBoundary(249, 250, 250), true,+ 'a 249ms CDP report rounded to 250ms by the shared wall clock is at the budget boundary');+ assert.equal(isRoundedBudgetBoundary(248, 250, 250), false,+ 'a two-millisecond early CDP timeout is outside the rounding boundary');+ assert.equal(isRoundedBudgetBoundary(249, 251, 250), false,+ 'elapsed time beyond the budget is not accepted as a rounding boundary');+});+test('a wait that throws while the page changes keeps waiting [C7]', async (t) => {let replacementResponse;const server = createServer((request, response) => {