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: diagnose Chrome startup failures in export acceptance (#9296)
[._.]/ Adam Eivya59576e60f05
diff --git a/server/services/codeAnimation/export.realBrowser.test.js b/server/services/codeAnimation/export.realBrowser.test.jsindex f75537fcff..6c430eff97 100644--- a/server/services/codeAnimation/export.realBrowser.test.js+++ b/server/services/codeAnimation/export.realBrowser.test.js@@ -9,7 +9,7 @@ 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 } from '../htmlComposition/testBrowserCleanup.js';+import { _cleanupTestBrowser, _waitForTestChrome } from '../htmlComposition/testBrowserCleanup.js';const state = vi.hoisted(() => ({ html: '' }));let endpoint;@@ -79,16 +79,19 @@ describe.skipIf(!chrome || !ffmpeg || !ffprobe)('Code Animation frame-exact expobeforeAll(async () => {const profile = join(lazyTempDataRoot('portos-code-animation-export-'), 'chrome-test-profile');proc = spawn(chrome, ['--headless=new', '--no-sandbox', '--no-first-run', '--disable-background-networking', '--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank'], { stdio: ['ignore', 'ignore', 'pipe'] });- const ws = await new Promise((resolve, reject) => {- const timer = setTimeout(() => reject(new Error('Test Chrome did not start')), 20000);- proc.once('error', reject);- proc.stderr.on('data', bytes => {- const match = bytes.toString().match(/DevTools listening on (ws:\/\/\S+)/);- if (match) { clearTimeout(timer); resolve(match[1]); }- });- });- endpoint = new URL(ws).origin.replace('ws:', 'http:');- browser = await chromium.connectOverCDP(endpoint);+ try {+ const ws = await _waitForTestChrome(proc);+ endpoint = new URL(ws).origin.replace('ws:', 'http:');+ browser = await chromium.connectOverCDP(endpoint);+ } catch (error) {+ try {+ await _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots });+ proc = undefined;+ } catch (cleanupError) {+ throw new AggregateError([error, cleanupError], `${error.message}; cleanup: ${cleanupError.message}`);+ }+ throw error;+ }}, 30000);afterAll(() => _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots }));diff --git a/server/services/htmlComposition/testBrowserCleanup.js b/server/services/htmlComposition/testBrowserCleanup.jsindex da55e4b05f..63ae610c5e 100644--- a/server/services/htmlComposition/testBrowserCleanup.js+++ b/server/services/htmlComposition/testBrowserCleanup.js@@ -1,5 +1,54 @@import { killWithEscalation } from '../../lib/killWithEscalation.js';+// 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) {+ return new Promise((resolve, reject) => {+ let stderr = '';+ let timer;+ const diagnostic = () => {+ const categories = [+ ['sandbox', /sandbox/i],+ ['profile in use', /profile.*(?:in use|lock)|ProcessSingleton/i],+ ['permission denied', /permission denied|EACCES/i],+ ['missing file or library', /not found|ENOENT|shared librar/i],+ ['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 cleanup = () => {+ clearTimeout(timer);+ proc.removeListener('error', onError);+ proc.removeListener('exit', onExit);+ proc.stderr.removeListener('data', onData);+ };+ const finish = (value, error) => {+ cleanup();+ if (error) reject(error);+ else resolve(value);+ };+ const onData = bytes => {+ stderr = (stderr + bytes.toString()).slice(-8192);+ // Wait for the terminating newline: a stream chunk can end mid-URL.+ const match = stderr.match(/(?:^|\n)DevTools listening on (ws:\/\/[^\r\n]+)\r?\n/);+ if (match) finish(match[1]);+ };+ const onError = error => {+ const code = /^[A-Z0-9_]{1,32}$/.test(error.code) ? error.code : 'spawn error';+ finish(null, new Error(`Test Chrome failed to spawn (${code}${diagnostic()})`));+ };+ 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('error', onError);+ proc.once('exit', onExit);+ proc.stderr.on('data', onData);+ timer = setTimeout(() => finish(null, new Error(`Test Chrome did not start within ${timeoutMs}ms${diagnostic()}`)), timeoutMs);+ if (proc.exitCode !== null || proc.signalCode !== null) onExit(proc.exitCode, proc.signalCode);+ });+}+async function withinDeadline(action, timeoutMs, stage) {let timer;try {diff --git a/server/services/htmlComposition/testBrowserCleanup.test.js b/server/services/htmlComposition/testBrowserCleanup.test.jsindex e77421a53b..686619ebec 100644--- a/server/services/htmlComposition/testBrowserCleanup.test.js+++ b/server/services/htmlComposition/testBrowserCleanup.test.js@@ -1,6 +1,6 @@import { EventEmitter } from 'node:events';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { _cleanupTestBrowser } from './testBrowserCleanup.js';+import { _cleanupTestBrowser, _waitForTestChrome } from './testBrowserCleanup.js';function child() {const proc = new EventEmitter();@@ -17,6 +17,64 @@ function child() {return proc;}+function startingChild() {+ const proc = child();+ proc.stderr = new EventEmitter();+ return proc;+}++function expectStartupClean(proc) {+ expect(proc.listenerCount('error')).toBe(0);+ expect(proc.listenerCount('exit')).toBe(0);+ expect(proc.stderr.listenerCount('data')).toBe(0);+ expect(vi.getTimerCount()).toBe(0);+}++describe('test Chrome startup', () => {+ beforeEach(() => vi.useFakeTimers());+ afterEach(() => vi.useRealTimers());++ it('waits for a complete DevTools address across stderr chunks', async () => {+ const proc = startingChild();+ const ready = _waitForTestChrome(proc);+ proc.stderr.emit('data', Buffer.from('noise\nDevTools listening on ws://127.0.0.1:4'));+ proc.stderr.emit('data', Buffer.from('321/devtools/browser/example'));+ expect(proc.listenerCount('exit')).toBe(1);+ proc.stderr.emit('data', Buffer.from('\n'));+ await expect(ready).resolves.toBe('ws://127.0.0.1:4321/devtools/browser/example');+ expectStartupClean(proc);+ });++ it('reports an early exit promptly without exposing stderr paths', async () => {+ const proc = startingChild();+ const ready = _waitForTestChrome(proc);+ proc.stderr.emit('data', Buffer.from('profile at /private/example-secret is locked; ProcessSingleton failed\n'));+ proc.exitCode = 1;+ proc.emit('exit', 1, null);+ await expect(ready).rejects.toThrow('code 1, signal none; stderr: profile in use');+ await expect(ready).rejects.not.toThrow('example-secret');+ expectStartupClean(proc);+ });++ it('reports a spawn error without exposing its raw message', async () => {+ const proc = startingChild();+ const ready = _waitForTestChrome(proc);+ proc.emit('error', Object.assign(new Error('/private/example-secret/chrome'), { code: 'ENOENT' }));+ await expect(ready).rejects.toThrow('failed to spawn (ENOENT; no stderr)');+ await expect(ready).rejects.not.toThrow('example-secret');+ expectStartupClean(proc);+ });++ it('keeps the startup deadline and clears listeners on timeout', async () => {+ const proc = startingChild();+ const ready = _waitForTestChrome(proc);+ const rejected = expect(ready).rejects.toThrow('did not start within 20000ms; no stderr');+ await vi.advanceTimersByTimeAsync(20000);+ await rejected;+ expectStartupClean(proc);+ });+});+describe('owned test Chrome cleanup', () => {beforeEach(() => {vi.useFakeTimers();