Skip to content

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

test: report redacted Chrome startup facts on a silent startup hang (#9641)

Adam Eivy22282f3b55c4
diff --git a/server/services/codeAnimation/stages.realBrowser.db.test.js b/server/services/codeAnimation/stages.realBrowser.db.test.js
index 684f01781d..54e6df5ac9 100644
--- a/server/services/codeAnimation/stages.realBrowser.db.test.js
+++ b/server/services/codeAnimation/stages.realBrowser.db.test.js
@@ -4,14 +4,13 @@
// (portos_test) holds the project and run records; no provider is called.
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
import { createHash } from 'node:crypto';
-import { existsSync } from 'node:fs';
import { readFile, mkdir, writeFile } from 'node:fs/promises';
import { execFileSync, spawn } from 'node:child_process';
import { join } from 'node:path';
import { chromium } from 'playwright-core';
import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../../lib/mockPathsDataRoot.js';
import { findFfmpeg, findFfprobe } from '../../lib/ffmpeg.js';
-import { _cleanupTestBrowser, _waitForTestChrome, _testChromeCaptureArgs } from '../htmlComposition/testBrowserCleanup.js';
+import { _cleanupTestBrowser, _selectTestChrome, _waitForTestChrome, _testChromeCaptureArgs } from '../htmlComposition/testBrowserCleanup.js';
let endpoint;
vi.mock('../browserService.js', () => ({ cdpRequest: path => fetch(`${endpoint}${path}`) }));
@@ -35,10 +34,15 @@ const health = await checkHealth().catch(error => ({ connected: false, error: er
const dbReady = requireDbOrSkip('codeAnimation/stages.realBrowser.db.test', health.connected, health.error);
if (dbReady) await ensureSchema();
-const chrome = [process.env.CHROME_PATH, chromium.executablePath(),
- '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
- '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser',
-].find(path => path && existsSync(path));
+const selected = _selectTestChrome([
+ { source: 'env', path: process.env.CHROME_PATH },
+ { source: 'playwright', path: chromium.executablePath() },
+ { source: 'mac-app', path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' },
+ { source: 'system-google-chrome', path: '/usr/bin/google-chrome' },
+ { source: 'system-chromium', path: '/usr/bin/chromium' },
+ { source: 'system-chromium-browser', path: '/usr/bin/chromium-browser' },
+]);
+const chrome = selected?.path;
const ffmpeg = await findFfmpeg();
const ffprobe = await findFfprobe();
@@ -72,7 +76,7 @@ describe.skipIf(!dbReady || !chrome || !ffmpeg || !ffprobe)('Production stages w
const profile = join(lazyTempDataRoot('portos-code-animation-stages-'), 'chrome-test-profile');
proc = spawn(chrome, _testChromeCaptureArgs(profile), { stdio: ['ignore', 'ignore', 'pipe'] });
try {
- const ws = await _waitForTestChrome(proc);
+ const ws = await _waitForTestChrome(proc, 20000, { source: selected.source, executable: chrome, profile });
endpoint = new URL(ws).origin.replace('ws:', 'http:');
browser = await chromium.connectOverCDP(endpoint);
} catch (error) {
diff --git a/server/services/htmlComposition/testBrowserCleanup.js b/server/services/htmlComposition/testBrowserCleanup.js
index 696a6893b5..c9222fe0ba 100644
--- a/server/services/htmlComposition/testBrowserCleanup.js
+++ b/server/services/htmlComposition/testBrowserCleanup.js
@@ -1,3 +1,6 @@
+import { execFileSync } from 'node:child_process';
+import { existsSync } from 'node:fs';
+import { basename, join } from 'node:path';
import { killWithEscalation } from '../../lib/killWithEscalation.js';
// These owned browsers render on explicit seek(t), not wall/display time.
@@ -14,12 +17,47 @@ export function _testChromeCaptureArgs(profile) {
];
}
+// First existing candidate wins, as before, but the winner's source is an enum
+// that startup diagnostics can report without printing any path.
+export function _selectTestChrome(candidates) {
+ return candidates.find(({ path }) => path && existsSync(path));
+}
+
+function executableKind(executable) {
+ const name = basename(executable).toLowerCase();
+ if (name.includes('headless_shell') || name.includes('headless-shell')) return 'headless-shell';
+ if (name.includes('google chrome') || name.includes('google-chrome')) return 'google-chrome';
+ if (name.includes('chromium')) return 'chromium';
+ return name === 'chrome' ? 'chrome' : 'other';
+}
+
+// Redacted facts that separate "wrapper never reached Chrome" from "Chrome ran
+// but never published CDP": enums, booleans and a dotted version only, never
+// paths or process output. --version is bounded so a hung wrapper is itself
+// reported (version=unavailable) instead of stalling the diagnostic.
+export function _describeTestChromeStartup(proc, { source = 'unknown', executable, profile } = {}) {
+ let version = 'unavailable';
+ if (executable) {
+ try {
+ const out = execFileSync(executable, ['--version'], { timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
+ version = out.match(/\b\d+(?:\.\d+){1,3}\b/)?.[0] ?? 'unrecognized';
+ } catch { /* hung, crashed or missing: keep 'unavailable' */ }
+ }
+ const state = proc.exitCode !== null ? 'exited' : proc.signalCode !== null ? 'signaled' : 'running';
+ const port = profile ? existsSync(join(profile, 'DevToolsActivePort')) : 'unknown';
+ return `source=${source} kind=${executable ? executableKind(executable) : 'unknown'} version=${version}`
+ + ` spawned=${proc.spawnedSeen ? 'yes' : 'no'} pid=${proc.pid ? 'yes' : 'no'} state=${state}`
+ + ` profile=${profile ? (existsSync(profile) ? 'created' : 'missing') : 'unknown'} devToolsActivePort=${port}`;
+}
+
// Chrome writes its CDP address to stderr. Keep only a bounded tail and report
// known failure categories: raw stderr can contain the user's profile path.
-export function _waitForTestChrome(proc, timeoutMs = 20000) {
+export function _waitForTestChrome(proc, timeoutMs = 20000, startup) {
return new Promise((resolve, reject) => {
let stderr = '';
let timer;
+ let spawned = false;
+ const onSpawn = () => { spawned = true; };
const diagnostic = () => {
const categories = [
['sandbox', /sandbox/i],
@@ -29,10 +67,14 @@ export function _waitForTestChrome(proc, timeoutMs = 20000) {
['disk full', /no space left|ENOSPC/i],
['crashpad', /crashpad/i],
].filter(([, pattern]) => pattern.test(stderr)).map(([name]) => name);
- return categories.length ? `; stderr: ${categories.join(', ')}` : stderr ? '; Chrome emitted stderr' : '; no stderr';
+ const base = categories.length ? `; stderr: ${categories.join(', ')}` : stderr ? '; Chrome emitted stderr' : '; no stderr';
+ if (!startup) return base;
+ proc.spawnedSeen = spawned;
+ return `${base}; startup: ${_describeTestChromeStartup(proc, startup)}`;
};
const cleanup = () => {
clearTimeout(timer);
+ proc.removeListener('spawn', onSpawn);
proc.removeListener('error', onError);
proc.removeListener('exit', onExit);
proc.stderr.removeListener('data', onData);
@@ -55,6 +97,7 @@ export function _waitForTestChrome(proc, timeoutMs = 20000) {
const onExit = (code, signal) => finish(null, new Error(
`Test Chrome exited before startup (code ${Number.isInteger(code) ? code : 'none'}, signal ${/^[A-Z0-9]{1,32}$/.test(signal) ? signal : 'none'}${diagnostic()})`,
));
+ proc.once('spawn', onSpawn);
proc.once('error', onError);
proc.once('exit', onExit);
proc.stderr.on('data', onData);
diff --git a/server/services/htmlComposition/testBrowserCleanup.test.js b/server/services/htmlComposition/testBrowserCleanup.test.js
index 7deeb2faa5..5a583908f5 100644
--- a/server/services/htmlComposition/testBrowserCleanup.test.js
+++ b/server/services/htmlComposition/testBrowserCleanup.test.js
@@ -1,3 +1,6 @@
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
import { EventEmitter } from 'node:events';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { _cleanupTestBrowser, _waitForTestChrome, _withTestCaptureDiagnostics } from './testBrowserCleanup.js';
@@ -24,6 +27,7 @@ function startingChild() {
}
function expectStartupClean(proc) {
+ expect(proc.listenerCount('spawn')).toBe(0);
expect(proc.listenerCount('error')).toBe(0);
expect(proc.listenerCount('exit')).toBe(0);
expect(proc.stderr.listenerCount('data')).toBe(0);
@@ -65,6 +69,22 @@ describe('test Chrome startup', () => {
expectStartupClean(proc);
});
+ it('reports redacted startup facts on a silent timeout without paths or output', async () => {
+ const root = mkdtempSync(join(tmpdir(), 'example-secret-'));
+ const proc = startingChild();
+ proc.pid = 123;
+ const ready = _waitForTestChrome(proc, 20000, { source: 'playwright', executable: join(root, 'missing', 'chrome-headless-shell'), profile: join(root, 'profile') });
+ const rejected = expect(ready).rejects.toThrow(
+ 'no stderr; startup: source=playwright kind=headless-shell version=unavailable spawned=yes pid=yes state=running profile=missing devToolsActivePort=false',
+ );
+ proc.emit('spawn');
+ await vi.advanceTimersByTimeAsync(20000);
+ await rejected;
+ await expect(ready).rejects.not.toThrow('example-secret');
+ expectStartupClean(proc);
+ rmSync(root, { recursive: true });
+ });
+
it('keeps the startup deadline and clears listeners on timeout', async () => {
const proc = startingChild();
const ready = _waitForTestChrome(proc);