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: retain Chrome startup evidence when owned cleanup fails (#9641)
[._.]/ Adam Eivy16eecde880a0
diff --git a/server/services/codeAnimation/export.realBrowser.test.js b/server/services/codeAnimation/export.realBrowser.test.jsindex 941e2770ff..833a1389b4 100644--- a/server/services/codeAnimation/export.realBrowser.test.js+++ b/server/services/codeAnimation/export.realBrowser.test.js@@ -120,17 +120,14 @@ describe.skipIf(!chrome || !ffmpeg || !ffprobe)('Code Animation frame-exact expoendpoint = 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;+ // Retain the owned handle for afterAll if termination itself fails.+ await _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots, startupError: error });}- }, 30000);+ // Enclose the existing startup (20s), disconnect (5s) and owned-child+ // termination (10s) budgets without cutting off evidence.+ }, 40000);- afterAll(() => _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots }));+ afterAll(() => _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots }), 20000);it('exports duration × fps unique frames from a slow renderFrame, matching direct screenshots, as BT.709 H.264 with the controls hidden', async () => {state.html = FIXTURE;diff --git a/server/services/codeAnimation/stages.realBrowser.db.test.js b/server/services/codeAnimation/stages.realBrowser.db.test.jsindex 54e6df5ac9..f63fec8108 100644--- a/server/services/codeAnimation/stages.realBrowser.db.test.js+++ b/server/services/codeAnimation/stages.realBrowser.db.test.js@@ -80,17 +80,18 @@ describe.skipIf(!dbReady || !chrome || !ffmpeg || !ffprobe)('Production stages wendpoint = new URL(ws).origin.replace('ws:', 'http:');browser = await chromium.connectOverCDP(endpoint);} catch (error) {- await _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots });- proc = undefined;- throw error;+ // Retain the owned handle for afterAll if termination itself fails.+ await _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots, startupError: error });}- }, 30000);+ // Enclose the existing startup (20s), version probe (up to 3s), disconnect+ // (5s) and owned-child termination (10s) budgets without cutting off evidence.+ }, 40000);afterAll(async () => {if (projectId) await query('DELETE FROM code_animation_projects WHERE id = $1', [projectId]);await _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots });await close();- });+ }, 20000);it('turns a frozen original into measured findings, a repaired revision and a real MP4, with a real style frame and pilot', async () => {projectId = (await createProductionProject({ manifest })).id;diff --git a/server/services/htmlComposition/testBrowserCleanup.js b/server/services/htmlComposition/testBrowserCleanup.jsindex 89d33d91c1..52173e43ac 100644--- a/server/services/htmlComposition/testBrowserCleanup.js+++ b/server/services/htmlComposition/testBrowserCleanup.js@@ -319,17 +319,24 @@ async function terminateOwnedChrome(proc, observeProcess) {// Test-only lifecycle boundary. Disconnect failure must not strand the owned// child, and neither failure may prevent removal of temporary test data.-export async function _cleanupTestBrowser({ browser, proc, cleanup, observeProcess = _testChromeProcessFacts }) {- const errors = [];+// A startup failure remains primary even if teardown also fails.+export async function _cleanupTestBrowser({ browser, proc, cleanup, startupError, observeProcess = _testChromeProcessFacts }) {+ const errors = startupError ? [startupError] : [];+ const cleanupFailure = (stage, error) => {+ const code = /^[A-Z0-9_]{1,32}$/.test(error?.code) ? error.code : 'unknown';+ errors.push(new Error(`Test Chrome ${stage} cleanup failed (${code})`));+ };try {await withinDeadline(() => browser?.close(), 5000, 'browser disconnect',() => `; process: ${describeProcess(proc, observeProcess)}`).catch(error => errors.push(error));await terminateOwnedChrome(proc, observeProcess).catch(error => errors.push(error));} finally {- proc?.stderr?.destroy();- await cleanup();+ try { proc?.stderr?.destroy(); } catch (error) { cleanupFailure('stderr', error); }+ try { await cleanup(); } catch (error) { cleanupFailure('temporary data', error); }}- if (errors.length) throw new AggregateError(errors, errors.map(error => error.message).join('; '));+ if (startupError && errors.length === 1) throw startupError;+ if (errors.length) throw new AggregateError(errors, errors.map(error => error.message).join('; '),+ startupError ? { cause: startupError } : undefined);}// Wrap the REAL encoder only in browser tests. Never print paths, page source,diff --git a/server/services/htmlComposition/testBrowserCleanup.test.js b/server/services/htmlComposition/testBrowserCleanup.test.jsindex de2dfa82d4..132f7ffd2b 100644--- a/server/services/htmlComposition/testBrowserCleanup.test.js+++ b/server/services/htmlComposition/testBrowserCleanup.test.js@@ -383,6 +383,44 @@ describe('owned test Chrome cleanup', () => {vi.restoreAllMocks();});+ it('retains no-stderr startup evidence when both owned termination and data cleanup fail', async () => {+ const proc = startingChild();+ proc.stderr.destroy = vi.fn(() => { throw new Error('/private/example-secret'); });+ proc.kill.mockImplementation(() => true); // Neither signal produces an exit.+ const observeProcess = () => 'os=linux child=uninterruptible worker=runnable';+ const startup = _waitForTestChrome(proc, 20000, undefined, { observeProcess }).catch(error => error);+ await vi.advanceTimersByTimeAsync(20000);+ const startupError = await startup;+ expect(startupError.message).toContain('did not start within 20000ms; no stderr');+ const cleanup = vi.fn(() => { throw Object.assign(new Error('/private/example-secret'), { code: 'EACCES' }); });+ const result = _cleanupTestBrowser({ proc, cleanup, startupError, observeProcess }).catch(error => error);+ await vi.advanceTimersByTimeAsync(10000);+ const error = await result;+ expect(error).toBeInstanceOf(AggregateError);+ expect(error.cause).toBe(startupError);+ expect(error.errors[0]).toBe(startupError);+ expect(error.message).toContain('did not start within 20000ms; no stderr; process: os=linux child=uninterruptible');+ expect(error.message).toContain('child termination exceeded 10000ms deadline');+ expect(error.message).toContain('stderr cleanup failed (unknown); Test Chrome temporary data cleanup failed (EACCES)');+ expect(error.message).not.toContain('example-secret');+ expect(proc.kill.mock.calls).toEqual([['SIGTERM'], ['SIGKILL']]);+ expect(cleanup).toHaveBeenCalledOnce();+ expectStartupClean(proc);+ });++ it('rethrows the original startup failure after successful owned cleanup', async () => {+ const proc = child();+ const startupError = new Error('Test Chrome did not start within 20000ms; no stderr');+ const cleanup = vi.fn();+ const result = _cleanupTestBrowser({ proc, cleanup, startupError });+ const rejected = expect(result).rejects.toBe(startupError);+ await vi.advanceTimersByTimeAsync(3000);+ await rejected;+ expect(cleanup).toHaveBeenCalledOnce();+ expect(proc.stderr.destroy).toHaveBeenCalledOnce();+ expect(vi.getTimerCount()).toBe(0);+ });+it('does not wait for a signal-exited child whose exit event already fired', async () => {const proc = child();proc.signalCode = 'SIGTERM';