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: bound owned Chrome teardown after process exit (#8678)

[._.]/ Adam Eivy2bc6e5a9aa70
diff --git a/server/services/htmlComposition/index.test.js b/server/services/htmlComposition/index.test.js
index f98838da4f..cf8dec9728 100644
--- a/server/services/htmlComposition/index.test.js
+++ b/server/services/htmlComposition/index.test.js
@@ -5,6 +5,7 @@ import { join } from 'node:path';
import { randomUUID } from 'node:crypto';
import { execFileSync, spawn } from 'node:child_process';
import { once } from 'node:events';
+import { killWithEscalation } from '../../lib/killWithEscalation.js';
import { chromium } from 'playwright-core';
import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../../lib/mockPathsDataRoot.js';
import { findFfmpeg } from '../../lib/ffmpeg.js';
@@ -62,9 +63,31 @@ describe.skipIf(!chrome || !ffmpeg)('HTML composition with real Chrome and ffmpe
}, 30000);
afterAll(async () => {
- await browser?.close();
- if (proc && proc.exitCode === null) { const exited = once(proc, 'close'); proc.kill(); await exited; }
- cleanupTempDataRoots();
+ let deadline;
+ let escalation;
+ try {
+ // Wait for process exit, not stdio close: Chrome descendants can retain
+ // stderr after the owned browser exits. Signal exits leave exitCode null.
+ // Subscribe before disconnect/termination so fast exits cannot be missed.
+ const running = proc && proc.exitCode === null && proc.signalCode === null;
+ let processSettled = !running;
+ let browserSettled = !browser;
+ const exited = running ? once(proc, 'exit').then(() => { processSettled = true; }) : Promise.resolve();
+ if (running) escalation = killWithEscalation(proc, {
+ label: 'HTML composition test Chrome', stillRunning: () => true, delayMs: 2000,
+ });
+ await Promise.race([
+ Promise.all([browser?.close().then(() => { browserSettled = true; }), exited]),
+ new Promise((_, reject) => {
+ deadline = setTimeout(() => reject(new Error(`HTML composition Chrome teardown stalled: browserSettled=${browserSettled}, processSettled=${processSettled}, exitCode=${proc?.exitCode}, signalCode=${proc?.signalCode}`)), 20000);
+ }),
+ ]);
+ } finally {
+ clearTimeout(deadline);
+ clearTimeout(escalation);
+ proc?.stderr?.destroy();
+ cleanupTempDataRoots();
+ }
});
it('awaits every seek, encodes exactly 12 frames, keeps the target hidden and registers a thumbnail', async () => {