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

fix(tests): retain fixture evidence when nested runs cannot confirm closure (#13314)

[._.]/ Adam Eivy367d41f4727f
diff --git a/scripts/lib/vitestTempRootFixture.js b/scripts/lib/vitestTempRootFixture.js
index 8fa6d2a2cb..0442a02ea0 100644
--- a/scripts/lib/vitestTempRootFixture.js
+++ b/scripts/lib/vitestTempRootFixture.js
@@ -152,7 +152,8 @@ function killProcessTree(child, { sweepGroup = false } = {}) {
* import graph on a loaded host can take over a minute, so `createVitestTempFixture`'s
* fixed `timeout` (kept for spawnSync callers) is dropped. Resolves like spawnSync's
* result; `error` is set only when the ceiling is reached or `signal` aborts, after
- * the whole detached process group is killed. Pass the calling test's `signal`:
+ * the detached process group is signalled. `closeConfirmed` is false when the
+ * close watchdog settles first; retain the host and report the error then. Pass the calling test's `signal`:
* a fail-fast cancellation otherwise leaves the body awaiting the nested run while
* the worker tears down, so its `finally` never removes the host (#12924).
*/
@@ -170,13 +171,19 @@ export function runFixtureToCompletion({ args, options }, ceilingMs = FIXTURE_RU
child.stdout.setEncoding('utf8').on('data', (chunk) => { stdout += chunk; });
child.stderr.setEncoding('utf8').on('data', (chunk) => { stderr += chunk; });
let done = false;
+ let closeConfirmed = false;
const finish = (status) => {
if (done) return;
done = true;
clearTimeout(timer);
signal?.removeEventListener('abort', abort);
killProcessTree(child, { sweepGroup: true }); // reap any worker the run left behind
- resolve({ status, stdout, stderr, error });
+ if (!closeConfirmed) {
+ const unconfirmed = new Error('fixture run process close unconfirmed');
+ error = error ? new AggregateError([error, unconfirmed], 'fixture run failed and process close is unconfirmed', { cause: error }) : unconfirmed;
+ error.code = 'FIXTURE_CLOSE_UNCONFIRMED';
+ }
+ resolve({ status, stdout, stderr, error, closeConfirmed });
};
const timer = setTimeout(() => {
error = new Error(`fixture run exceeded ${ceilingMs}ms`);
@@ -191,8 +198,12 @@ export function runFixtureToCompletion({ args, options }, ceilingMs = FIXTURE_RU
};
if (signal?.aborted) abort();
else signal?.addEventListener('abort', abort, { once: true });
- child.once('error', (spawnError) => { error = spawnError; finish(null); });
- child.once('close', finish);
+ child.once('error', (spawnError) => {
+ error = spawnError;
+ // Failed spawns also emit close. Do not release the host on error alone.
+ setTimeout(() => finish(null), 2000);
+ });
+ child.once('close', status => { closeConfirmed = true; finish(status); });
// Output ends at 'close', which a surviving worker holding the pipes defers:
// sweep the group as soon as the leader exits, with a bounded wait for the pipes.
child.once('exit', () => {
diff --git a/scripts/lib/vitestWatchFixtureSettlement.test.js b/scripts/lib/vitestWatchFixtureSettlement.test.js
index 833d4f34b2..cd2e45dddf 100644
--- a/scripts/lib/vitestWatchFixtureSettlement.test.js
+++ b/scripts/lib/vitestWatchFixtureSettlement.test.js
@@ -7,7 +7,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
vi.mock('node:child_process', () => ({ spawn: vi.fn(), spawnSync: vi.fn() }));
import { spawn } from 'node:child_process';
-import { runWatchConfigRestart } from './vitestTempRootFixture.js';
+import { runFixtureToCompletion, runWatchConfigRestart } from './vitestTempRootFixture.js';
const tick = () => new Promise(resolve => setImmediate(resolve));
@@ -65,6 +65,18 @@ describe('watch fixture process settlement', () => {
await expect(result).resolves.toMatchObject({ name: 'AbortError' });
});
+ it('keeps a nested run close watchdog failure distinct from confirmed cancellation', async () => {
+ fixture({ ready: false });
+ vi.useFakeTimers();
+ const controller = new AbortController();
+ const pending = runFixtureToCompletion({ args: [], options: {} }, 60000, { signal: controller.signal });
+ controller.abort();
+ await vi.advanceTimersByTimeAsync(2000);
+ const result = await pending;
+ expect(result.closeConfirmed).toBe(false);
+ expect(result.error).toMatchObject({ code: 'FIXTURE_CLOSE_UNCONFIRMED', cause: { name: 'AbortError' } });
+ });
+
it('reports unconfirmed close as cleanup failure even after cancellation', async () => {
const child = fixture({ ready: false });
vi.useFakeTimers();
diff --git a/scripts/vitestTempRootCancellation.test.js b/scripts/vitestTempRootCancellation.test.js
index 3dd2e19fd4..81699c0428 100644
--- a/scripts/vitestTempRootCancellation.test.js
+++ b/scripts/vitestTempRootCancellation.test.js
@@ -19,6 +19,7 @@ afterAll(() => owned.drain());
// gate waits for cancellation, so a fast restart cannot finish the scenario early.
owned.it('drains the active lifecycle watcher after a sibling fails, preserving an external owner', async ({ signal }) => {
const host = mkdtempSync(join(tmpdir(), 'watch-cancel-'));
+ let cleanupConfirmed = true;
try {
const run = createVitestTempFixture(host, 'server', '');
const fixture = join(host, 'fixture');
@@ -42,22 +43,25 @@ owned.it('drains the active lifecycle watcher after a sibling fails, preserving
run.args[run.args.indexOf('--maxWorkers') + 1] = '2';
run.args.push('--bail=1', '--testNamePattern', 'server watch-config restart|controlled sibling failure');
const result = await runFixtureToCompletion(run, 120000, { signal });
+ cleanupConfirmed = result.closeConfirmed;
+ if (!cleanupConfirmed) throw result.error;
if (signal.aborted) return;
// Deliberately bounded diagnostics: no nested output, paths, PIDs or env.
const state = JSON.stringify({ ready: existsSync(ready), finished: existsSync(finished), status: result.status, error: result.error?.name ?? null });
- expect(result.error, state).toBeUndefined();
+ expect(Boolean(result.error), state).toBe(false);
expect(result.status, state).toBe(1);
- expect(result.stderr, state).toContain('controlled sibling failure');
+ expect(result.stderr.includes('controlled sibling failure'), state).toBe(true);
expect(existsSync(finished), state).toBe(true);
- expect(result.stderr, state).not.toMatch(/test temp leak:|test process leak:|Unhandled|ENOTEMPTY|ENOENT/);
+ expect(/test temp leak:|test process leak:|Unhandled|ENOTEMPTY|ENOENT/.test(result.stderr), state).toBe(false);
expect(readFileSync(join(live, 'keep'), 'utf8')).toBe('synthetic external owner');
} finally {
- rmSync(host, { recursive: true, force: true });
+ if (cleanupConfirmed) rmSync(host, { recursive: true, force: true });
}
}, 135000);
owned.it('retains the lifecycle host and fails when watcher settlement is unconfirmed', async ({ signal }) => {
const host = mkdtempSync(join(tmpdir(), 'watch-unconfirmed-'));
+ let cleanupConfirmed = true;
try {
const run = createVitestTempFixture(host, 'server', '');
const fixture = join(host, 'fixture');
@@ -84,14 +88,17 @@ afterAll(() => {
`);
run.args.push('--testNamePattern', 'server watch-config restart');
const result = await runFixtureToCompletion(run, 120000, { signal });
+ cleanupConfirmed = result.closeConfirmed;
+ if (!cleanupConfirmed) throw result.error;
if (signal.aborted) return;
const state = JSON.stringify({ status: result.status, retained: existsSync(retained), error: result.error?.name ?? null });
- expect(result.error, state).toBeUndefined();
+ expect(Boolean(result.error), state).toBe(false);
expect(result.status, state).toBe(1);
- expect(result.stderr, state).toContain('synthetic close unconfirmed');
+ expect(result.stderr.includes('synthetic close unconfirmed'), state).toBe(true);
+ expect(existsSync(retained), state).toBe(true);
expect(JSON.parse(readFileSync(retained, 'utf8'))).toEqual({ present: true, original: true });
- expect(result.stderr, state).toContain('test temp leak: vrt-');
+ expect(result.stderr.includes('test temp leak: vrt-'), state).toBe(true);
} finally {
- rmSync(host, { recursive: true, force: true });
+ if (cleanupConfirmed) rmSync(host, { recursive: true, force: true });
}
}, 135000);