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): report Chrome startup state [C7]
Corey Olson493e368b0580
diff --git a/test/chrome-fixture.js b/test/chrome-fixture.jsindex 17297704..466f4cb7 100644--- a/test/chrome-fixture.js+++ b/test/chrome-fixture.js@@ -1,7 +1,7 @@/** Shared isolated Chrome launcher with bounded startup and complete process-group cleanup [C7]. */import { startFixtureChild as spawn } from './fixture-child.js';-import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';-import { tmpdir } from 'node:os';+import { chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { loadavg, tmpdir } from 'node:os';import { monitorEventLoopDelay } from 'node:perf_hooks';import { join, resolve } from 'node:path';@@ -29,6 +29,22 @@ function appendStderr(current, chunk) {return next.length <= STDERR_LIMIT ? next : next.slice(-STDERR_LIMIT);}+/** Describe launch state before cleanup changes whether the Chrome leader is still alive. */+function chromeStartupState(profile, launched) {+ const child = launched?.child;+ const leader = !child ? 'not started'+ : child.exitCode !== null ? `exited (code ${child.exitCode})`+ : child.signalCode !== null ? `exited (signal ${child.signalCode})` : 'still alive';+ const port = existsSync(join(profile, 'DevToolsActivePort')) ? 'present' : 'absent';+ const locks = ['SingletonLock', 'SingletonCookie', 'SingletonSocket']+ .filter((name) => {+ try { lstatSync(join(profile, name)); return true; }+ catch { return false; }+ });+ const profileLock = locks.length ? `present (${locks.join(', ')})` : 'absent';+ return `leader ${leader}; DevToolsActivePort ${port}; profile lock ${profileLock}; elapsed ${launched?.launchDurationMs ?? 0}ms; load average ${JSON.stringify(loadavg())}`;+}+/** Report whether the detached process group still has any members. */function processGroupExists(pid) {if (!pid) return false;@@ -230,13 +246,14 @@ export async function startChrome({rejectPending(pending, 'Isolated Chrome stopped before startup completed.');const launchDurationMs = launched?.launchDurationMs ?? 0;const stderr = launched?.stderr?.trimEnd();+ const startupState = chromeStartupState(profile, launched);let cleanupFailure = null;try { await launched?.close(); }catch (cleanupError) { cleanupFailure = cleanupError; }if (!cleanupFailure && ownedProfile) rmSync(profile, { recursive: true, force: true });const message = sanitizeStartupError(error);const cleanup = cleanupFailure ? `\n${cleanupFailure.message}; profile retained until the process group exits` : '';- throw new Error(`${message.message} (elapsed ${launchDurationMs}ms; ${startupTimeoutMs}ms DevTools budget)${stderr ? `\nChrome stderr:\n${stderr}` : ''}${cleanup}`);+ throw new Error(`${message.message} (elapsed ${launchDurationMs}ms; ${startupTimeoutMs}ms DevTools budget)\nChrome startup state: ${startupState}${stderr ? `\nChrome stderr:\n${stderr}` : ''}${cleanup}`);}}diff --git a/test/chrome-fixture.test.js b/test/chrome-fixture.test.jsindex 7aa583f9..15c24efb 100644--- a/test/chrome-fixture.test.js+++ b/test/chrome-fixture.test.js@@ -112,6 +112,66 @@ test('a missing DevTools port fails once with stderr and elapsed launch time [C7assert.equal(readFileSync(launches, 'utf8'), 'launch\n', 'the shared launcher never retries');});+/** Prove startup timeout diagnostics preserve process and profile state before cleanup [C7]. */+test("a DevTools port timeout names Chrome's state [C7]", async (t) => {+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-chrome-timeout-state-'));+ t.after(() => rmSync(directory, { recursive: true, force: true }));+ const startupTimeoutMs = 2_000;+ const liveProfile = join(directory, 'live-profile');+ const liveMarker = join(directory, 'live-starts');+ const liveExecutable = join(directory, 'chrome-live-no-port');+ writeFileSync(liveExecutable, [+ '#!/usr/bin/env node',+ "const fs = require('node:fs');",+ "fs.appendFileSync(process.env.CHROME_STARTS, 'start\\n');",+ "fs.writeFileSync(process.env.CHROME_PROFILE + '/SingletonLock', 'held');",+ "process.on('SIGTERM', () => process.exit(0));",+ 'setInterval(() => {}, 1000);',+ ].join('\n'));+ chmodSync(liveExecutable, 0o700);+ await assert.rejects(startChrome({+ executable: liveExecutable,+ profileDirectory: liveProfile,+ startupTimeoutMs,+ env: { ...process.env, CHROME_STARTS: liveMarker, CHROME_PROFILE: liveProfile },+ }), (error) => {+ assert.match(error.message, /leader still alive/u);+ assert.match(error.message, /DevToolsActivePort absent/u);+ assert.match(error.message, /profile lock present \(SingletonLock\)/u);+ assert.match(error.message, /elapsed \d+ms; 2000ms DevTools budget/u);+ assert.match(error.message, /load average \[/u);+ const elapsed = Number(/Chrome startup state:.*elapsed (\d+)ms/u.exec(error.message)?.[1]);+ assert.ok(elapsed >= startupTimeoutMs, `the live stand-in reached the startup budget: ${error.message}`);+ return true;+ });+ assert.equal(readFileSync(liveMarker, 'utf8'), 'start\n', 'the live stand-in launched only once');++ const exitedProfile = join(directory, 'exited-profile');+ const exitedMarker = join(directory, 'exited-starts');+ const exitedExecutable = join(directory, 'chrome-exits-no-port');+ writeFileSync(exitedExecutable, [+ '#!/usr/bin/env node',+ "const fs = require('node:fs');",+ "fs.appendFileSync(process.env.CHROME_STARTS, 'start\\n');",+ 'process.exit(7);',+ ].join('\n'));+ chmodSync(exitedExecutable, 0o700);+ await assert.rejects(startChrome({+ executable: exitedExecutable,+ profileDirectory: exitedProfile,+ startupTimeoutMs,+ env: { ...process.env, CHROME_STARTS: exitedMarker, CHROME_PROFILE: exitedProfile },+ }), (error) => {+ assert.match(error.message, /leader exited \(code 7\)/u);+ assert.match(error.message, /DevToolsActivePort absent/u);+ assert.match(error.message, /profile lock absent/u);+ assert.match(error.message, /elapsed \d+ms; 2000ms DevTools budget/u);+ assert.match(error.message, /load average \[/u);+ return true;+ });+ assert.equal(readFileSync(exitedMarker, 'utf8'), 'start\n', 'the exited stand-in launched only once');+});+/** Prove an unrelated process inheriting stderr cannot keep an exited owned Chrome open. */test('Chrome close releases inherited stderr after its owned process group exits [C7]', async t => {