Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: report owned Chromium launch facts and keep fixture timings in CI (#9641)
Adam Eivy0b0ab77e102d
diff --git a/client/src/test/README.md b/client/src/test/README.mdindex 89bea1442f..1f642f2896 100644--- a/client/src/test/README.md+++ b/client/src/test/README.md@@ -10,7 +10,7 @@ a new one.| --- | --- || `actWarnings.js` | React act(...) warning diagnostics — records the test active when a warning was observed, without claiming to identify where asynchronous work began. || `ariaRefAssertions.js` | Asserts a rendered tree's `aria-controls`/`aria-labelledby` IDREFs all resolve to a real element. |-| `browserFixture.js` | `startBrowserFixture` — phase-bounded Vite + Chromium + warmup startup for `*.browser.test.js` (a stalled Chromium launch is retried once with a fresh process), naming the stalled phase and closing everything it started. |+| `browserFixture.js` | `startBrowserFixture` — phase-bounded Vite + Chromium + warmup startup for `*.browser.test.js` (a stalled Chromium launch is retried once with a fresh process), naming the stalled phase and closing everything it started; a timed-out launch attempt reports redacted Linux facts about its own browser child, and on GitHub Actions the ready/failure lines are kept in the step summary. || `classNameScan.js` | Shared string-literal scanner (comment-stripping + literal walk) for the class-string convention guards. || `dndKeyboardDrag.js` | Drives a real `@dnd-kit` keyboard drag under happy-dom, stubbing the layout happy-dom can't provide. || `downloadPreflightConfirm.js` | `clickStartDownload` — waits for the confirm button to be enabled (built on `enabledBarrier.js`) before clicking, then settles. |diff --git a/client/src/test/browserFixture.js b/client/src/test/browserFixture.jsindex c1f3bb74b2..178ee47381 100644--- a/client/src/test/browserFixture.js+++ b/client/src/test/browserFixture.js@@ -36,10 +36,22 @@* pages the first attempt did read stay in the kernel's cache, so a slow disk* loses no progress, and a child that wedged is replaced rather than waited* on. Vite's budget pays for it: it starts in well under 2s even under load.+ *+ * The retry hides the stall it recovers from, and the launch error names no+ * state, so each attempt also observes its own browser child shortly before+ * its deadline, with the DB launcher's redacted Linux process facts (#9641).+ * Those facts are reported only for an attempt that then timed out: in the+ * startup error, or on the ready line when the retry recovered. A launch that+ * settles first discards them. Vitest's CI `--silent=passed-only` drops a+ * passing fixture's console output, so on GitHub Actions the ready and failure+ * lines are also appended to the job's step summary, which keeps the passing+ * timings for comparison with the runner's Chrome warm-up.*/+import { appendFileSync, closeSync, openSync, opendirSync, readSync } from 'node:fs';import { mkdtemp, rm } from 'node:fs/promises';import { tmpdir } from 'node:os';import { join } from 'node:path';+import { _testChromeProcessFacts } from '../../../server/services/htmlComposition/testBrowserCleanup.js';export const BROWSER_FIXTURE_STARTUP_MS = 60000;@@ -54,6 +66,80 @@ const PHASE_NAMES = { vite: 'Vite server start', chromium: 'Chromium launch', waconst timeoutError = ms => Object.assign(new Error(`timed out after ${ms}ms`), { name: 'TimeoutError' });+// Linux-only, bounded reads: up to 64 worker threads' `children` lists and one+// 4096-byte stat prefix per child. Never read cmdline, environ or links, and+// never print a PID or process name — only counts and the shared process facts.+const readPrefix = (path) => {+ const fd = openSync(path, 'r');+ try {+ const bytes = Buffer.alloc(4096);+ return bytes.subarray(0, readSync(fd, bytes, 0, bytes.length, 0)).toString();+ } finally { closeSync(fd); }+};+const listDir = (path) => {+ const dir = opendirSync(path);+ const names = [];+ try {+ let entry;+ for (let count = 0; count < 64 && (entry = dir.readSync()); count++) names.push(entry.name);+ } finally { dir.closeSync(); }+ return names;+};+const BROWSER_PROCESS_NAME = /^(chrome|chromium|google-chrome|headless_shell|chrome-headless)/;++/**+ * Starts observing one launch attempt: the worker's browser children that+ * already exist (an earlier attempt still exiting) are excluded, and the+ * returned function describes the one browser child that appeared since. Only+ * a direct child of this worker is ever inspected, so the PID is owned; the+ * shared facts re-check that its parent is this worker.+ */+export function _observeOwnedBrowserLaunch({+ platform = process.platform, workerPid = process.pid, read = readPrefix, list = listDir,+ processFacts = _testChromeProcessFacts,+} = {}) {+ if (platform !== 'linux') return () => 'os=unsupported';+ // A thread or child that exits between the listing and its read is skipped,+ // but no readable `children` list at all (a kernel without them) means the+ // observation is unavailable — never an empty one.+ const readOrNull = (path) => { try { return read(path); } catch { return null; } };+ const browserChildren = () => {+ const pids = new Set();+ let readable = false;+ for (const tid of list(`/proc/${workerPid}/task`).filter(name => /^[1-9]\d*$/.test(name))) {+ const children = readOrNull(`/proc/${workerPid}/task/${tid}/children`);+ if (children === null) continue;+ readable = true;+ for (const pid of children.trim().split(/\s+/)) {+ if (!/^[1-9]\d*$/.test(pid)) continue;+ const stat = readOrNull(`/proc/${pid}/stat`) ?? '';+ const name = stat.slice(stat.indexOf('(') + 1, stat.lastIndexOf(')'));+ if (BROWSER_PROCESS_NAME.test(name)) pids.add(pid);+ }+ }+ if (!readable) throw new Error('no readable children list');+ return pids;+ };+ let earlier;+ try { earlier = browserChildren(); } catch { earlier = null; }+ return () => {+ if (!earlier) return 'browserChildren=unavailable';+ let fresh;+ try { fresh = [...browserChildren()].filter(pid => !earlier.has(pid)); }+ catch { return 'browserChildren=unavailable'; }+ if (fresh.length !== 1) return `browserChildren=${fresh.length}`;+ return `browserChildren=1 ${processFacts({ pid: Number(fresh[0]), exitCode: null, signalCode: null }, { workerPid })}`;+ };+}++// Appends one line to the GitHub Actions step summary, when there is one. The+// summary only retains evidence: a write failure never changes the fixture.+const retainLine = (line) => {+ const summary = process.env.GITHUB_STEP_SUMMARY;+ if (!summary) return;+ try { appendFileSync(summary, `- ${line}\n`); } catch { /* evidence only */ }+};+const withDeadline = (promise, ms, onTimeout) => {let timer;const deadline = new Promise((_, reject) => {@@ -71,10 +157,12 @@ const withDeadline = (promise, ms, onTimeout) => {* @param {object} [options.launchOptions] - extra `chromium.launch` options (executablePath, args, …)* @param {(page: object, origin: string) => Promise<void>} [options.warmup] - first navigation; the page is closed afterward* @param {object} [options.phaseMs] - per-phase budgets; defaults to BROWSER_FIXTURE_PHASE_MS+ * @param {() => () => string} [options.observeLaunch] - starts observing a launch attempt; defaults to _observeOwnedBrowserLaunch* @returns {Promise<{ origin: string, browser: object, server: object, temp: string, close: () => Promise<void> }>}*/export async function startBrowserFixture({name, createServer, viteConfig, chromium, launchOptions = {}, warmup, phaseMs = BROWSER_FIXTURE_PHASE_MS,+ observeLaunch = _observeOwnedBrowserLaunch,}) {const budget = phaseMs.vite + phaseMs.chromium + phaseMs.warmup + phaseMs.cleanup;if (budget >= BROWSER_FIXTURE_STARTUP_MS) {@@ -113,23 +201,51 @@ export async function startBrowserFixture({retried = '';return value;};+ // Facts of every launch attempt that timed out, in attempt order, and the+ // recorder of the attempt in flight.+ const launchFacts = [];+ let recordTimedOutAttempt;// One Chromium process. A browser that arrives after its attempt was// abandoned is closed at once; one that arrives in time joins `own`, which- // closes it at once if the fixture has failed meanwhile.+ // closes it at once if the fixture has failed meanwhile. Shortly before its+ // deadline, an attempt still pending samples its child: Playwright's own+ // launch timeout kills that child at the deadline, so a later look would+ // describe the kill rather than the stall.const launchOnce = (timeout) => {+ const number = launchFacts.length + 1;let abandoned = false;+ let settled = false;+ let recorded = false;+ let facts;+ let sample;+ try { sample = observeLaunch(); } catch { sample = () => 'unavailable'; }+ const sampleAt = timeout - Math.min(1000, Math.floor(timeout / 10));+ const timer = setTimeout(() => {+ if (settled) return;+ try { facts = sample(); } catch { facts = 'unavailable'; }+ }, sampleAt);+ const settle = () => { settled = true; clearTimeout(timer); };const launching = chromium.launch({headless: true,timeout,...launchOptions,env: { ...process.env, ...launchOptions.env, TMPDIR: temp, TMP: temp, TEMP: temp },}).then((launched) => {+ settle();if (abandoned) launched.close().catch(() => {});else own(() => launched.close());return launched;- });- return { launching, abandon: () => { abandoned = true; } };+ }, (error) => { settle(); throw error; });+ const record = () => {+ if (recorded) return;+ recorded = true;+ settle();+ launchFacts.push(facts === undefined ? `attempt ${number}: not sampled` : `attempt ${number} at ${sampleAt}ms: ${facts}`);+ };+ recordTimedOutAttempt = record;+ return { launching, abandon: () => { abandoned = true; record(); } };};+ const describeLaunchFacts = () => (launchFacts.length ? `; launch facts: ${launchFacts.join('; ')}` : '');try {const server = await runPhase('vite', async () => {@@ -176,15 +292,22 @@ export async function startBrowserFixture({}// Passing runs record their phase timings too, so CI logs show how close// each budget runs before one of them fails.- console.log(`🧪 ${name} browser fixture ready (${completed.join(', ')})`);+ const ready = `🧪 ${name} browser fixture ready (${completed.join(', ')}${describeLaunchFacts()})`;+ console.log(ready);+ retainLine(ready);return { origin, browser, server, temp, close: closeOwned };} catch (error) {failed = true;+ // The phase deadline abandons the attempt in flight; Playwright's own+ // launch timeout carries the same error name. A crash records nothing.+ if (phase === 'chromium' && error.name === 'TimeoutError') recordTimedOutAttempt?.();const cleanup = await withDeadline(closeOwned().then(() => 'cleaned up'), phaseMs.cleanup,() => new Error(`timed out after ${phaseMs.cleanup}ms`)).catch(cleanupError => `cleanup failed: ${cleanupError.message}`);const done = completed.length ? completed.join(', ') : 'none';- throw new Error(`${name} startup failed during ${PHASE_NAMES[phase]}: ${error.message} `- + `(completed: ${done}; ${cleanup})`, { cause: error });+ const failure = `${name} startup failed during ${PHASE_NAMES[phase]}: ${error.message} `+ + `(completed: ${done}; ${cleanup}${describeLaunchFacts()})`;+ retainLine(`❌ ${failure}`);+ throw new Error(failure, { cause: error });}}diff --git a/client/src/test/browserFixture.test.js b/client/src/test/browserFixture.test.jsindex bbe0490e7b..d6a05a4528 100644--- a/client/src/test/browserFixture.test.js+++ b/client/src/test/browserFixture.test.js@@ -1,7 +1,9 @@// @vitest-environment node-import { describe, expect, it, vi } from 'vitest';-import { existsSync } from 'node:fs';-import { startBrowserFixture } from './browserFixture.js';+import { afterEach, describe, expect, it, vi } from 'vitest';+import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { _observeOwnedBrowserLaunch, startBrowserFixture } from './browserFixture.js';const PHASE_MS = { vite: 50, chromium: 50, warmup: 50, cleanup: 50 };const SCOPED = { optimizeDeps: { entries: ['src/Example.jsx'] } };@@ -12,9 +14,36 @@ const fakeVite = () => {return { server, createServer: vi.fn(async () => server) };};const fakeBrowser = (page) => ({ close: vi.fn(async () => {}), newPage: vi.fn(async () => page) });+// Each launch attempt's observation reports which attempt it described and+// when it was taken, so a test can prove the facts came from before the kill.+const fakeObserver = () => {+ const samples = [];+ const observeLaunch = vi.fn(() => {+ const attempt = observeLaunch.mock.calls.length;+ return () => { samples.push(attempt); return `state-${attempt}`; };+ });+ return { observeLaunch, samples };+};+const summaryDirs = [];+const stubStepSummary = () => {+ const dir = mkdtempSync(join(tmpdir(), 'fixture-summary-'));+ summaryDirs.push(dir);+ const file = join(dir, 'summary.md');+ vi.stubEnv('GITHUB_STEP_SUMMARY', file);+ return { read: () => (existsSync(file) ? readFileSync(file, 'utf8') : '') };+};++afterEach(() => {+ vi.useRealTimers();+ vi.unstubAllEnvs();+ for (const dir of summaryDirs.splice(0)) rmSync(dir, { recursive: true, force: true });+});describe('startBrowserFixture', () => {- it('retries a stalled Chromium launch once, then names the phase and closes every browser that arrives late', async () => {+ it('retries a stalled Chromium launch once, then names the phase, reports both attempts\' facts and closes every browser that arrives late', async () => {+ // Real deadlines, sampled 2ms before each one, would race a loaded runner.+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });+ const summary = stubStepSummary();const { server, createServer } = fakeVite();const late = [fakeBrowser(), fakeBrowser()];const arrive = [];@@ -22,13 +51,27 @@ describe('startBrowserFixture', () => {const browser = late[arrive.length];arrive.push(() => resolve(browser));})) };+ const { observeLaunch, samples } = fakeObserver();let temp;const viteConfig = vi.fn(dir => { temp = dir; return SCOPED; });- const error = await startBrowserFixture({ name: 'example', createServer, viteConfig, chromium, phaseMs: PHASE_MS })+ const failing = startBrowserFixture({ name: 'example', createServer, viteConfig, chromium, phaseMs: PHASE_MS, observeLaunch }).catch(caught => caught);-- expect(error.message).toMatch(/^example startup failed during Chromium launch: timed out after 50ms \(retried after a first attempt timed out after 25ms\) \(completed: Vite server start \d+ms; cleaned up\)$/);+ // Not vi.waitFor: under fake timers it advances them on every check.+ while (!chromium.launch.mock.calls.length) await new Promise(resolve => setImmediate(resolve));+ await vi.advanceTimersByTimeAsync(22);+ expect(samples).toEqual([]);+ await vi.advanceTimersByTimeAsync(1);+ // Sampled while the first launch was still pending, before its deadline.+ expect(samples).toEqual([1]);+ await vi.advanceTimersByTimeAsync(2);+ expect(chromium.launch).toHaveBeenCalledTimes(2);+ await vi.advanceTimersByTimeAsync(25);+ vi.useRealTimers();+ const error = await failing;++ expect(error.message).toMatch(/^example startup failed during Chromium launch: timed out after 50ms \(retried after a first attempt timed out after 25ms\) \(completed: Vite server start \d+ms; cleaned up; launch facts: attempt 1 at 23ms: state-1; attempt 2 at 23ms: state-2\)$/);+ expect(summary.read()).toBe(`- ❌ ${error.message}\n`);expect(server.close).toHaveBeenCalledTimes(1);expect(existsSync(temp)).toBe(false);// Each attempt is a fresh process whose own launch timeout kills it.@@ -51,13 +94,20 @@ describe('startBrowserFixture', () => {const chromium = { launch: vi.fn().mockReturnValueOnce(new Promise(resolve => { arrive = () => resolve(stalled); })).mockResolvedValueOnce(retried) };+ const { observeLaunch, samples } = fakeObserver();+ const summary = stubStepSummary();const log = vi.spyOn(console, 'log').mockImplementation(() => {});const fixture = await startBrowserFixture({ name: 'example', createServer, viteConfig: () => SCOPED, chromium,- phaseMs: PHASE_MS });+ phaseMs: { ...PHASE_MS, chromium: 2000 }, observeLaunch });expect(fixture.browser).toBe(retried);- expect(log).toHaveBeenCalledWith(expect.stringMatching(/Chromium launch \d+ms \(retried after a first attempt timed out after 25ms\)/));+ // The recovered stall keeps its facts; the retry settled before sampling.+ const ready = /^🧪 example browser fixture ready \(Vite server start \d+ms, Chromium launch \d+ms \(retried after a first attempt timed out after 1000ms\); launch facts: attempt 1 at 900ms: state-1\)$/;+ expect(log).toHaveBeenCalledWith(expect.stringMatching(ready));+ expect(samples).toEqual([1]);+ // Vitest's CI silent mode drops that console line; the step summary keeps it.+ expect(summary.read()).toMatch(new RegExp(`^- ${ready.source.slice(1, -1)}\\n$`));log.mockRestore();arrive();await vi.waitFor(() => expect(stalled.close).toHaveBeenCalledTimes(1));@@ -92,13 +142,62 @@ describe('startBrowserFixture', () => {const chromium = { launch: vi.fn(async () => browser) };const cause = new Error('net::ERR_CONNECTION_REFUSED');+ const { observeLaunch, samples } = fakeObserver();+const error = await startBrowserFixture({ name: 'example', createServer, viteConfig: () => SCOPED, chromium,- phaseMs: PHASE_MS, warmup: async () => { throw cause; } }).catch(caught => caught);+ phaseMs: PHASE_MS, observeLaunch, warmup: async () => { throw cause; } }).catch(caught => caught);- expect(error.message).toMatch(/during first page warmup: net::ERR_CONNECTION_REFUSED \(completed: Vite server start \d+ms, Chromium launch \d+ms; cleaned up\)/);+ // A launch that settled in time carries no launch facts.+ expect(error.message).toMatch(/during first page warmup: net::ERR_CONNECTION_REFUSED \(completed: Vite server start \d+ms, Chromium launch \d+ms; cleaned up\)$/);+ expect(samples).toEqual([]);expect(error.cause).toBe(cause);expect(page.close).toHaveBeenCalledTimes(1);expect(browser.close).toHaveBeenCalledTimes(1);expect(server.close).toHaveBeenCalledTimes(1);});});++describe('_observeOwnedBrowserLaunch', () => {+ // A fake /proc: `children` lists per worker thread, and each child's stat.+ const fakeProc = (state) => ({+ list: (path) => {+ if (path !== '/proc/42/task') throw new Error(`unexpected ${path}`);+ return ['42', '43', 'not-a-thread'];+ },+ read: (path) => {+ if (state.unreadable) throw new Error('ENOENT');+ const thread = path.match(/^\/proc\/42\/task\/(\d+)\/children$/);+ if (thread) return `${state.children[thread[1]] ?? ''} `;+ const pid = path.match(/^\/proc\/(\d+)\/stat$/)?.[1];+ if (state.names[pid]) return `${pid} (${state.names[pid]}) S 42 42 42 0 -1`;+ throw new Error('ENOENT');+ },+ });++ it('describes only the browser child this worker spawned for the attempt, without its PID or name', () => {+ const state = { children: { 42: '1100 1200' }, names: { 1100: 'chrome', 1200: 'esbuild', 1300: 'chrome', 1400: 'node' } };+ const processFacts = vi.fn(() => 'os=linux child=uninterruptible');+ const sample = _observeOwnedBrowserLaunch({ platform: 'linux', workerPid: 42, processFacts, ...fakeProc(state) });+ // The earlier attempt's browser (1100) is still exiting; the new one is on another thread.+ state.children = { 42: '1100 1200', 43: '1300 1400' };++ expect(sample()).toBe('browserChildren=1 os=linux child=uninterruptible');+ expect(processFacts).toHaveBeenCalledWith({ pid: 1300, exitCode: null, signalCode: null }, { workerPid: 42 });++ // Two candidates cannot be told apart, and none means nothing was spawned+ // or it already exited: neither is inspected.+ processFacts.mockClear();+ state.children = { 42: '1100', 43: '1300 1500' };+ state.names[1500] = 'headless_shell';+ expect(sample()).toBe('browserChildren=2');+ state.children = { 42: '1100' };+ expect(sample()).toBe('browserChildren=0');+ expect(processFacts).not.toHaveBeenCalled();+ });++ it('reports an unreadable process table as unavailable, never as an empty one', () => {+ const state = { children: {}, names: {}, unreadable: true };+ expect(_observeOwnedBrowserLaunch({ platform: 'linux', workerPid: 42, ...fakeProc(state) })()).toBe('browserChildren=unavailable');+ expect(_observeOwnedBrowserLaunch({ platform: 'darwin' })()).toBe('os=unsupported');+ });+});