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
fix(tests): kill a cancelled nested fixture run so its temp host is removed (#12924)
Adam Eivy04c37d33de86
diff --git a/scripts/imageCleanerCleanup.test.js b/scripts/imageCleanerCleanup.test.jsindex d74498f894..708726b807 100644--- a/scripts/imageCleanerCleanup.test.js+++ b/scripts/imageCleanerCleanup.test.js@@ -1,16 +1,23 @@-import { expect, it } from 'vitest';+import { afterAll, expect, it as vitestIt } from 'vitest';import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';+import { ownTestBodies } from '../server/lib/mockPathsDataRoot.js';import { createVitestTempFixture, fixtureReadyFailureSource, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';// The nested run's own ceiling; the outer budget adds headroom so it is never tighter.const RUN_CEILING_MS = 120000;+// A fail-fast failure in another file cancels this body while it awaits the nested+// run; own it so teardown waits for its `finally` to remove the host (#12924).+const owned = ownTestBodies(vitestIt);+const it = owned.it;+afterAll(() => owned.drain());+// Hold the real clean route at its first publication write, then let a different// worker cancel the test. Its body must finish before its gallery is removed.-it('drains the image cleaner request before removing its cancelled fixture', async () => {+it('drains the image cleaner request before removing its cancelled fixture', async ({ signal }) => {const host = mkdtempSync(join(tmpdir(), 'image-clean-cancel-'));try {const fixtureRun = createVitestTempFixture(host, 'server', '');@@ -69,7 +76,8 @@ it('drains the image cleaner request before removing its cancelled fixture', asyargs[args.indexOf('--maxWorkers') + 1] = '2';args.push('--bail=1', '--reporter=default', '--reporter=json', '--outputFile.json', resultsFile,'--reporter=junit', '--outputFile.junit', junitFile);- const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS);+ const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS, { signal });+ if (signal.aborted) return;const output = `${result.stdout}\n${result.stderr}`;expect(result.error, output).toBeUndefined();expect(result.status, output).toBe(1);diff --git a/scripts/lib/vitestTempRootFixture.js b/scripts/lib/vitestTempRootFixture.jsindex c49642ac70..fd0bc098c4 100644--- a/scripts/lib/vitestTempRootFixture.js+++ b/scripts/lib/vitestTempRootFixture.js@@ -51,8 +51,8 @@ export function createVitestTempFixture(host, workspace, body, config = 'vitest.const READY_POLL_MS = 15;-function readinessAborted(signal) {- const error = new Error('fixture readiness wait aborted');+function fixtureAborted(signal, message = 'fixture readiness wait aborted') {+ const error = new Error(message);error.name = 'AbortError';if (signal?.reason) error.cause = signal.reason;return error;@@ -66,7 +66,7 @@ function readinessAborted(signal) {*/export function waitForFixtureReady(file, { signal } = {}) {if (existsSync(file)) return Promise.resolve();- if (signal?.aborted) return Promise.reject(readinessAborted(signal));+ if (signal?.aborted) return Promise.reject(fixtureAborted(signal));return new Promise((resolve, reject) => {let settled = false;let watcher;@@ -80,7 +80,7 @@ export function waitForFixtureReady(file, { signal } = {}) {if (error) reject(error);else resolve();};- const onAbort = () => finish(readinessAborted(signal));+ const onAbort = () => finish(fixtureAborted(signal));const seen = () => { if (existsSync(file)) finish(); };signal?.addEventListener('abort', onAbort, { once: true });try {@@ -90,7 +90,7 @@ export function waitForFixtureReady(file, { signal } = {}) {return;}timer = setInterval(seen, READY_POLL_MS);- if (signal?.aborted) finish(readinessAborted(signal));+ if (signal?.aborted) finish(fixtureAborted(signal));else seen();});}@@ -132,10 +132,12 @@ function killProcessTree(child, { sweepGroup = false } = {}) {* Run a fixture to completion. The only clock is one generous ceiling — a cold* 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, after the whole detached- * process group is killed.+ * 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`:+ * 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).*/-export function runFixtureToCompletion({ args, options }, ceilingMs = FIXTURE_RUN_CEILING_MS) {+export function runFixtureToCompletion({ args, options }, ceilingMs = FIXTURE_RUN_CEILING_MS, { signal } = {}) {const { timeout: _bounded, ...spawnOptions } = options;return new Promise((resolve) => {const child = spawn(process.execPath, args, {@@ -153,6 +155,7 @@ export function runFixtureToCompletion({ args, options }, ceilingMs = FIXTURE_RUif (done) return;done = true;clearTimeout(timer);+ signal?.removeEventListener('abort', abort);killProcessTree(child, { sweepGroup: true }); // reap any worker the run left behindresolve({ status, stdout, stderr, error });};@@ -162,6 +165,13 @@ export function runFixtureToCompletion({ args, options }, ceilingMs = FIXTURE_RU// A survivor holding the pipes would defer 'close'; settle regardless.setTimeout(() => finish(null), 2000);}, ceilingMs);+ const abort = () => {+ error = fixtureAborted(signal, 'fixture run aborted');+ killProcessTree(child, { sweepGroup: true });+ setTimeout(() => finish(null), 2000);+ };+ if (signal?.aborted) abort();+ else signal?.addEventListener('abort', abort, { once: true });child.once('error', (spawnError) => { error = spawnError; finish(null); });child.once('close', finish);// Output ends at 'close', which a surviving worker holding the pipes defers:diff --git a/scripts/lib/vitestTempRootFixture.test.js b/scripts/lib/vitestTempRootFixture.test.jsindex d86c496562..2f61db94b9 100644--- a/scripts/lib/vitestTempRootFixture.test.js+++ b/scripts/lib/vitestTempRootFixture.test.js@@ -2,7 +2,7 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { describe, expect, it } from 'vitest';-import { waitForFixtureReady } from './vitestTempRootFixture.js';+import { runFixtureToCompletion, waitForFixtureReady } from './vitestTempRootFixture.js';describe('waitForFixtureReady', () => {it('resolves for a file that is already present and for one that appears later', async () => {@@ -40,3 +40,19 @@ describe('waitForFixtureReady', () => {}});});++describe('runFixtureToCompletion', () => {+ // A cancelled caller must not wait out the ceiling: its `finally` has to+ // remove the fixture host before the worker tears down (#12924).+ it('kills the nested run and settles promptly when the caller signal aborts', async () => {+ const controller = new AbortController();+ const started = Date.now();+ const pending = runFixtureToCompletion({+ args: ['-e', 'setInterval(() => {}, 1000)'], options: { env: process.env, timeout: 1 },+ }, 60000, { signal: controller.signal });+ setTimeout(() => controller.abort(), 100);+ const result = await pending;+ expect(result.error).toMatchObject({ name: 'AbortError', message: 'fixture run aborted' });+ expect(Date.now() - started).toBeLessThan(10000);+ });+});diff --git a/scripts/spriteWalkCleanup.test.js b/scripts/spriteWalkCleanup.test.jsindex f9a8888733..dc191869be 100644--- a/scripts/spriteWalkCleanup.test.js+++ b/scripts/spriteWalkCleanup.test.js@@ -1,19 +1,26 @@-import { expect, it } from 'vitest';+import { afterAll, expect, it as vitestIt } from 'vitest';import { mkdtempSync, rmSync, readFileSync, writeFileSync, existsSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';+import { ownTestBodies } from '../server/lib/mockPathsDataRoot.js';import { createVitestTempFixture, fixtureReadyFailureSource, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';// The nested run's own ceiling; the outer budget adds headroom so it is never tighter.const RUN_CEILING_MS = 120000;+// A fail-fast failure in another file cancels this body while it awaits the nested+// run; own it so teardown waits for its `finally` to remove the host (#12924).+const owned = ownTestBodies(vitestIt);+const it = owned.it;+afterAll(() => owned.drain());+// Pins the regression uniquely (#12660): a different worker's --bail=1 failure// settles a sprite-walk test's wrapper while its body is still writing into the// suite's tmpdir root. Teardown must wait for that body, or the body's next// store write recreates the root after `rmSync` and the run reports// `test temp leak: sprite-walk-test-`.-it('drains sprite-walk fixture writes after another worker triggers fail-fast', async () => {+it('drains sprite-walk fixture writes after another worker triggers fail-fast', async ({ signal }) => {const host = mkdtempSync(join(tmpdir(), 'sprite-walk-cancel-'));try {const fixtureRun = createVitestTempFixture(host, 'server', '');@@ -49,7 +56,8 @@ afterAll(async () => {writeFileSync(join(fixture, 'failure.test.js'), fixtureReadyFailureSource(ready));args[args.indexOf('--maxWorkers') + 1] = '2';args.push('--bail=1', '--testNamePattern', `${targetName}|controlled sibling failure`);- const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS);+ const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS, { signal });+ if (signal.aborted) return;const output = `${result.stdout}\n${result.stderr}`;expect(result.error, output).toBeUndefined();expect(result.status, output).toBe(1);