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: preserve process-exit cleanup from concurrent teardown fix

[._.]/ Adam Eivyc2d6526d3c22
diff --git a/server/services/htmlComposition/testBrowserCleanup.js b/server/services/htmlComposition/testBrowserCleanup.js
index a9da206b22..da55e4b05f 100644
--- a/server/services/htmlComposition/testBrowserCleanup.js
+++ b/server/services/htmlComposition/testBrowserCleanup.js
@@ -17,11 +17,12 @@ async function withinDeadline(action, timeoutMs, stage) {
async function terminateOwnedChrome(proc) {
if (!proc || proc.exitCode !== null || proc.signalCode !== null) return;
let escalation;
- let onClose;
- // Subscribe before kill: even an immediate close must settle this promise.
- const closed = new Promise(resolve => {
- onClose = resolve;
- proc.once('close', onClose);
+ let onExit;
+ // Subscribe before kill. Wait for exit, not stdio close: Chrome descendants
+ // can retain stderr after the owned process has terminated.
+ const exited = new Promise(resolve => {
+ onExit = resolve;
+ proc.once('exit', onExit);
});
try {
await withinDeadline(() => {
@@ -30,11 +31,11 @@ async function terminateOwnedChrome(proc) {
stillRunning: () => proc.exitCode === null && proc.signalCode === null,
delayMs: 3000,
});
- return closed;
+ return exited;
}, 10000, 'child termination');
} finally {
clearTimeout(escalation);
- proc.removeListener('close', onClose);
+ proc.removeListener('exit', onExit);
}
}
@@ -46,6 +47,7 @@ export async function _cleanupTestBrowser({ browser, proc, cleanup }) {
await withinDeadline(() => browser?.close(), 5000, 'browser disconnect').catch(error => errors.push(error));
await terminateOwnedChrome(proc).catch(error => errors.push(error));
} finally {
+ proc?.stderr?.destroy();
await cleanup();
}
if (errors.length) throw new AggregateError(errors, errors.map(error => error.message).join('; '));
diff --git a/server/services/htmlComposition/testBrowserCleanup.test.js b/server/services/htmlComposition/testBrowserCleanup.test.js
index 6f74d57617..e77421a53b 100644
--- a/server/services/htmlComposition/testBrowserCleanup.test.js
+++ b/server/services/htmlComposition/testBrowserCleanup.test.js
@@ -6,10 +6,11 @@ function child() {
const proc = new EventEmitter();
proc.exitCode = null;
proc.signalCode = null;
+ proc.stderr = { destroy: vi.fn() };
proc.kill = vi.fn(signal => {
if (signal === 'SIGKILL') {
proc.signalCode = signal;
- proc.emit('close', null, signal);
+ proc.emit('exit', null, signal);
}
return true;
});
@@ -26,15 +27,16 @@ describe('owned test Chrome cleanup', () => {
vi.restoreAllMocks();
});
- it('does not wait for a signal-exited child whose close event already fired', async () => {
+ it('does not wait for a signal-exited child whose exit event already fired', async () => {
const proc = child();
proc.signalCode = 'SIGTERM';
- proc.emit('close', null, 'SIGTERM');
+ proc.emit('exit', null, 'SIGTERM');
const cleanup = vi.fn();
await _cleanupTestBrowser({ proc, cleanup });
expect(proc.kill).not.toHaveBeenCalled();
expect(cleanup).toHaveBeenCalledOnce();
- expect(proc.listenerCount('close')).toBe(0);
+ expect(proc.stderr.destroy).toHaveBeenCalledOnce();
+ expect(proc.listenerCount('exit')).toBe(0);
expect(vi.getTimerCount()).toBe(0);
});
@@ -42,20 +44,20 @@ describe('owned test Chrome cleanup', () => {
const proc = child();
proc.kill.mockImplementation(signal => {
proc.signalCode = signal;
- proc.emit('close', null, signal);
+ proc.emit('exit', null, signal);
});
await _cleanupTestBrowser({ proc, cleanup: vi.fn() });
expect(proc.kill.mock.calls).toEqual([['SIGTERM']]);
- expect(proc.listenerCount('close')).toBe(0);
+ expect(proc.listenerCount('exit')).toBe(0);
expect(vi.getTimerCount()).toBe(0);
});
- it('escalates an ignored SIGTERM and waits for delayed close', async () => {
+ it('escalates an ignored SIGTERM and waits for delayed exit without waiting for inherited stderr', async () => {
const proc = child();
proc.kill.mockImplementation(signal => {
if (signal === 'SIGKILL') {
proc.signalCode = signal;
- setTimeout(() => proc.emit('close', null, signal), 100);
+ setTimeout(() => proc.emit('exit', null, signal), 100);
}
});
const cleanup = vi.fn();
@@ -66,7 +68,8 @@ describe('owned test Chrome cleanup', () => {
await vi.advanceTimersByTimeAsync(100);
await result;
expect(cleanup).toHaveBeenCalledOnce();
- expect(proc.listenerCount('close')).toBe(0);
+ expect(proc.stderr.destroy).toHaveBeenCalledOnce();
+ expect(proc.listenerCount('exit')).toBe(0);
expect(vi.getTimerCount()).toBe(0);
});
@@ -81,10 +84,11 @@ describe('owned test Chrome cleanup', () => {
await rejected;
expect(proc.kill).toHaveBeenLastCalledWith('SIGKILL');
expect(cleanup).toHaveBeenCalledOnce();
+ expect(proc.stderr.destroy).toHaveBeenCalledOnce();
expect(vi.getTimerCount()).toBe(0);
});
- it('reports both deadlines and cleans data even if disconnect and child close never settle', async () => {
+ it('reports both deadlines and cleans data even if disconnect and child exit never settle', async () => {
const proc = child();
proc.kill.mockImplementation(() => true);
const cleanup = vi.fn();
@@ -98,7 +102,8 @@ describe('owned test Chrome cleanup', () => {
await rejected;
expect(proc.kill.mock.calls).toEqual([['SIGTERM'], ['SIGKILL']]);
expect(cleanup).toHaveBeenCalledOnce();
- expect(proc.listenerCount('close')).toBe(0);
+ expect(proc.stderr.destroy).toHaveBeenCalledOnce();
+ expect(proc.listenerCount('exit')).toBe(0);
expect(vi.getTimerCount()).toBe(0);
});
});