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: run remaining nested-Vitest cleanup fixtures asynchronously (#13149)
Adam Eivy8415bd71593f
diff --git a/scripts/backupDbCaseBoundary.test.js b/scripts/backupDbCaseBoundary.test.jsindex f90db5269e..7de6682e32 100644--- a/scripts/backupDbCaseBoundary.test.js+++ b/scripts/backupDbCaseBoundary.test.js@@ -1,9 +1,19 @@-import { expect, it } from 'vitest';-import { spawnSync } from 'node:child_process';-import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { afterAll, expect, it as vitestIt } from 'vitest';+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';-import { createVitestTempFixture } from './lib/vitestTempRootFixture.js';+import { ownTestBodies } from '../server/lib/mockPathsDataRoot.js';+import { createVitestTempFixture, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';++// Async nested run: a synchronous spawn clock fails with ETIMEDOUT under+// full-suite load (#13149). 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());const ownTestBodiesUrl = new URL('../server/lib/mockPathsDataRoot.js', import.meta.url).href;@@ -15,12 +25,13 @@ const ownTestBodiesUrl = new URL('../server/lib/mockPathsDataRoot.js', import.me// timed-out body is held at that gap deterministically: it resumes only when// the next case's body releases it, or on a fallback timer when that body is// (correctly) still gated.-it('keeps a timed-out case between restores from overlapping the next case', () => {+it('keeps a timed-out case between restores from overlapping the next case', async ({ signal }) => {const host = mkdtempSync(join(tmpdir(), 'restore-boundary-'));try {const fixture = join(host, 'fixture');const resultsPath = join(fixture, 'results.json');- const { args, options } = createVitestTempFixture(host, 'server', '');+ const fixtureRun = createVitestTempFixture(host, 'server', '');+ const { args, options } = fixtureRun;writeFileSync(join(fixture, 'boundary.test.js'), `import { afterAll, beforeEach, describe, it as vitestIt } from 'vitest';import { writeFileSync } from 'node:fs';@@ -76,9 +87,10 @@ it('keeps a timed-out case between restores from overlapping the next case', ()// CI's github-actions reporter repeats each failure as an annotation; the// fixture's own default-reporter output is what the assertions count.delete options.env.GITHUB_ACTIONS;- const result = spawnSync(process.execPath, args, options);- const output = `${result.stdout}\n${result.stderr}`;- expect(result.error).toBeUndefined();+ const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS, { signal });+ if (signal.aborted) return;+ const output = `${result.stdout}\n${result.stderr}\nlifecycle phases: results=${existsSync(resultsPath)}`;+ expect(result.error, output).toBeUndefined();expect(result.status, output).toBe(1);expect(output.match(/Test timed out in 50ms/g), output).toHaveLength(2);const results = JSON.parse(readFileSync(resultsPath, 'utf8'));@@ -89,4 +101,4 @@ it('keeps a timed-out case between restores from overlapping the next case', ()} finally {rmSync(host, { recursive: true, force: true });}-}, 25000);+}, RUN_CEILING_MS + 15000);diff --git a/scripts/documentGenerationCleanup.test.js b/scripts/documentGenerationCleanup.test.jsindex 14192c8133..775579f5c8 100644--- a/scripts/documentGenerationCleanup.test.js+++ b/scripts/documentGenerationCleanup.test.js@@ -1,22 +1,33 @@-import { expect, it } from 'vitest';-import { spawnSync } from 'node:child_process';-import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { afterAll, expect, it as vitestIt } from 'vitest';+import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';-import { createVitestTempFixture, fixtureReadyFailureSource } from './lib/vitestTempRootFixture.js';+import { ownTestBodies } from '../server/lib/mockPathsDataRoot.js';+import { createVitestTempFixture, fixtureReadyFailureSource, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';++// Async nested run: a synchronous spawn clock fails with ETIMEDOUT under+// full-suite load (#13149). 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());// A sibling fails only once document authoring is inside its provider call.// The cancelled body must finish staging its candidate before teardown removes// the lazy data root; otherwise that staging write recreates the root (#12254).-it('settles document authoring before fail-fast data-root cleanup', () => {+it('settles document authoring before fail-fast data-root cleanup', async ({ signal }) => {const host = mkdtempSync(join(tmpdir(), 'mv-document-cancel-'));try {const fixture = join(host, 'fixture');const ready = join(fixture, 'ready');const events = join(fixture, 'events');const finished = join(fixture, 'finished');- const { args, options } = createVitestTempFixture(host, 'server', '');+ const fixtureRun = createVitestTempFixture(host, 'server', '');+ const { args, options } = fixtureRun;const sourcePath = fileURLToPath(new URL('../server/services/musicVideo/documentGeneration.test.js', import.meta.url));const header = "it('preflights selected media before a provider call and stages a reviewable 30-second document', async () => {";const generate = "const { document: candidate } = await generateMixedMediaDocument(id, { providerId: 'stub-provider', model: 'fixture-model' });";@@ -58,9 +69,11 @@ it('settles document authoring before fail-fast data-root cleanup', () => {writeFileSync(join(fixture, 'failure.test.js'), fixtureReadyFailureSource(ready));args[args.indexOf('--maxWorkers') + 1] = '2';args.push('--bail=1', '--testNamePattern', 'preflights selected media before a provider call|controlled sibling failure');- const result = spawnSync(process.execPath, args, options);- const output = `${result.stdout}\n${result.stderr}`;- expect(result.error).toBeUndefined();+ const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS, { signal });+ if (signal.aborted) return;+ const phases = [`events=${existsSync(events) ? JSON.stringify(readFileSync(events, 'utf8')) : 'absent'}`, ...['ready', 'finished'].map(name => `${name}=${existsSync(join(fixture, name))}`)].join(' ');+ const output = `${result.stdout}\n${result.stderr}\nlifecycle phases: ${phases}`;+ expect(result.error, output).toBeUndefined();expect(result.status, output).toBe(1);expect(output).toContain('controlled sibling failure');expect(readFileSync(events, 'utf8'), output).toBe('provider-ready\nroot-at-resume:true\nauthoring-assertions-complete\nbody-settled\n');@@ -68,4 +81,4 @@ it('settles document authoring before fail-fast data-root cleanup', () => {} finally {rmSync(host, { recursive: true, force: true });}-}, 25000);+}, RUN_CEILING_MS + 15000);diff --git a/scripts/duplicateDetectionCleanup.test.js b/scripts/duplicateDetectionCleanup.test.jsindex 5689631c48..df7b9c78f8 100644--- a/scripts/duplicateDetectionCleanup.test.js+++ b/scripts/duplicateDetectionCleanup.test.js@@ -1,21 +1,32 @@-import { expect, it } from 'vitest';-import { spawnSync } from 'node:child_process';+import { afterAll, expect, it as vitestIt } from 'vitest';import { mkdtempSync, readFileSync, rmSync, writeFileSync, existsSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';-import { createVitestTempFixture, fixtureReadyFailureSource } from './lib/vitestTempRootFixture.js';+import { ownTestBodies } from '../server/lib/mockPathsDataRoot.js';+import { createVitestTempFixture, fixtureReadyFailureSource, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';++// Async nested run: a synchronous spawn clock fails with ETIMEDOUT under+// full-suite load (#13149). 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: a different worker's --bail=1 failure cancels a// duplicate-detection test while its body still owns store writes into the// fixture root, which the suite's teardown must not remove underneath it.-it('drains duplicate-detection fixture writes after another worker triggers fail-fast', () => {+it('drains duplicate-detection fixture writes after another worker triggers fail-fast', async ({ signal }) => {const host = mkdtempSync(join(tmpdir(), 'dd-cancel-'));try {const fixture = join(host, 'fixture');const ready = join(fixture, 'ready');const finished = join(fixture, 'finished');- const { args, options } = createVitestTempFixture(host, 'server', '');+ const fixtureRun = createVitestTempFixture(host, 'server', '');+ const { args, options } = fixtureRun;const sourcePath = fileURLToPath(new URL('../server/services/duplicateDetection.test.js', import.meta.url));const header = "it('reports linkedSeriesCount per universe', async () => {";const source = readFileSync(sourcePath, 'utf8')@@ -35,9 +46,11 @@ it('drains duplicate-detection fixture writes after another worker triggers failconst workerIndex = args.indexOf('--maxWorkers');args[workerIndex + 1] = '2';args.push('--bail=1');- const result = spawnSync(process.execPath, args, options);- const output = `${result.stdout}\n${result.stderr}`;- expect(result.error).toBeUndefined();+ const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS, { signal });+ if (signal.aborted) return;+ const phases = ['ready', 'finished'].map(name => `${name}=${existsSync(join(fixture, name))}`).join(' ');+ const output = `${result.stdout}\n${result.stderr}\nlifecycle phases: ${phases}`;+ expect(result.error, output).toBeUndefined();expect(result.status, output).toBe(1);expect(output).toContain('controlled sibling failure');expect(existsSync(finished), output).toBe(true);@@ -45,4 +58,4 @@ it('drains duplicate-detection fixture writes after another worker triggers fail} finally {rmSync(host, { recursive: true, force: true });}-}, 25000);+}, RUN_CEILING_MS + 15000);diff --git a/scripts/persistentMindProcessAuditCleanup.test.js b/scripts/persistentMindProcessAuditCleanup.test.jsindex 459cd17e23..5d98ca7dff 100644--- a/scripts/persistentMindProcessAuditCleanup.test.js+++ b/scripts/persistentMindProcessAuditCleanup.test.js@@ -1,21 +1,32 @@-import { expect, it } from 'vitest';-import { spawnSync } from 'node:child_process';+import { afterAll, expect, it as vitestIt } from 'vitest';import { mkdtempSync, readFileSync, rmSync, writeFileSync, existsSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';-import { createVitestTempFixture, fixtureReadyFailureSource } from './lib/vitestTempRootFixture.js';+import { ownTestBodies } from '../server/lib/mockPathsDataRoot.js';+import { createVitestTempFixture, fixtureReadyFailureSource, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';++// Async nested run: a synchronous spawn clock fails with ETIMEDOUT under+// full-suite load (#13149). 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: a different worker's --bail=1 failure cancels a// process-audit test while its body still owns fixture writes (an archived job// and a ledger write) into the shared root that the suite's afterAll removes.-it('drains process-audit fixture writes after another worker triggers fail-fast', () => {+it('drains process-audit fixture writes after another worker triggers fail-fast', async ({ signal }) => {const host = mkdtempSync(join(tmpdir(), 'pa-cancel-'));try {const fixture = join(host, 'fixture');const ready = join(fixture, 'ready');const finished = join(fixture, 'finished');- const { args, options } = createVitestTempFixture(host, 'server', '');+ const fixtureRun = createVitestTempFixture(host, 'server', '');+ const { args, options } = fixtureRun;const sourcePath = fileURLToPath(new URL('../server/services/persistentMindProcessAudit.test.js', import.meta.url));const header = "it('holds an ambiguous create durably instead of publishing twice', async () => {";const source = readFileSync(sourcePath, 'utf8')@@ -35,7 +46,8 @@ it('drains process-audit fixture writes after another worker triggers fail-fast'const workerIndex = args.indexOf('--maxWorkers');args[workerIndex + 1] = '2';args.push('--bail=1');- const result = spawnSync(process.execPath, args, options);+ const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS, { signal });+ if (signal.aborted) return;const output = `${result.stdout}\n${result.stderr}`;const diagnostics = [`Child error: ${result.error?.stack ?? 'none'}; code: ${result.error?.code ?? 'none'}`,@@ -52,4 +64,4 @@ it('drains process-audit fixture writes after another worker triggers fail-fast'} finally {rmSync(host, { recursive: true, force: true });}-}, 25000);+}, RUN_CEILING_MS + 15000);diff --git a/scripts/writersRoomLiveDirectorCleanup.test.js b/scripts/writersRoomLiveDirectorCleanup.test.jsindex 05b755078f..7ea62fda36 100644--- a/scripts/writersRoomLiveDirectorCleanup.test.js+++ b/scripts/writersRoomLiveDirectorCleanup.test.js@@ -1,12 +1,22 @@-import { expect, it } from 'vitest';-import { spawnSync } from 'node:child_process';+import { afterAll, expect, it as vitestIt } from 'vitest';import { existsSync, 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 { createVitestTempFixture, fixtureReadyFailureSource } from './lib/vitestTempRootFixture.js';+import { ownTestBodies } from '../server/lib/mockPathsDataRoot.js';+import { createVitestTempFixture, fixtureReadyFailureSource, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';-it('drains Live Director writes before cleaning a cancelled test fixture', () => {+// Async nested run: a synchronous spawn clock fails with ETIMEDOUT under+// full-suite load (#13149). 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());++it('drains Live Director writes before cleaning a cancelled test fixture', async ({ signal }) => {const host = mkdtempSync(join(tmpdir(), 'wr-live-cancel-'));try {const fixture = join(host, 'fixture');@@ -14,7 +24,8 @@ it('drains Live Director writes before cleaning a cancelled test fixture', () =>const finished = join(fixture, 'finished');const resultsPath = join(host, 'results.json');const runDiagnosticsPath = join(host, 'run.json');- const { args, options } = createVitestTempFixture(host, 'server', '');+ const fixtureRun = createVitestTempFixture(host, 'server', '');+ const { args, options } = fixtureRun;const sourcePath = fileURLToPath(new URL('../server/services/writersRoom/liveDirector.test.js', import.meta.url));const source = readFileSync(sourcePath, 'utf8').replace(/(['"])(\.\.?\/[^'"]+)\1/g, (_, quote, specifier) => JSON.stringify(resolve(dirname(sourcePath), specifier)))@@ -39,12 +50,11 @@ it('drains Live Director writes before cleaning a cancelled test fixture', () =>args[workerIndex + 1] = '2';args.push('--bail=1', '--reporter=json', `--outputFile.json=${resultsPath}`,`--reporter=${fileURLToPath(new URL('./vitestRunDiagnostics.js', import.meta.url))}`);- const result = spawnSync(process.execPath, args, {- ...options,- env: { ...options.env, PORTOS_CI_DIAGNOSTICS_PATH: runDiagnosticsPath },- });- const output = `${result.stdout}\n${result.stderr}`;- expect(result.error).toBeUndefined();+ const result = await runFixtureToCompletion({ args, options: { ...options, env: { ...options.env, PORTOS_CI_DIAGNOSTICS_PATH: runDiagnosticsPath } } }, RUN_CEILING_MS, { signal });+ if (signal.aborted) return;+ const phases = ['ready', 'finished'].map(name => `${name}=${existsSync(join(fixture, name))}`).join(' ');+ const output = `${result.stdout}\n${result.stderr}\nlifecycle phases: ${phases}`;+ expect(result.error, output).toBeUndefined();expect(result.status, output).toBe(1);expect(existsSync(finished), output).toBe(true);expect(output).not.toMatch(/refused|unhandled|test temp leak: wr-live-test-/i);@@ -58,4 +68,4 @@ it('drains Live Director writes before cleaning a cancelled test fixture', () =>} finally {rmSync(host, { recursive: true, force: true });}-}, 25000);+}, RUN_CEILING_MS + 15000);diff --git a/scripts/writersRoomPromotionCleanup.test.js b/scripts/writersRoomPromotionCleanup.test.jsindex 3bff594f59..464d4f0d0c 100644--- a/scripts/writersRoomPromotionCleanup.test.js+++ b/scripts/writersRoomPromotionCleanup.test.js@@ -1,20 +1,31 @@-import { expect, it } from 'vitest';-import { spawnSync } from 'node:child_process';+import { afterAll, expect, it as vitestIt } from 'vitest';import { mkdtempSync, readFileSync, rmSync, writeFileSync, existsSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';-import { createVitestTempFixture, fixtureReadyFailureSource } from './lib/vitestTempRootFixture.js';+import { ownTestBodies } from '../server/lib/mockPathsDataRoot.js';+import { createVitestTempFixture, fixtureReadyFailureSource, runFixtureToCompletion } from './lib/vitestTempRootFixture.js';++// Async nested run: a synchronous spawn clock fails with ETIMEDOUT under+// full-suite load (#13149). 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: a different worker's --bail=1 failure cancels// the promotion test while its body still owns an asynchronous persistence call.-it('drains promotion fixture writes after another worker triggers fail-fast', () => {+it('drains promotion fixture writes after another worker triggers fail-fast', async ({ signal }) => {const host = mkdtempSync(join(tmpdir(), 'wr-cancel-'));try {const fixture = join(host, 'fixture');const ready = join(fixture, 'ready');const finished = join(fixture, 'finished');- const { args, options } = createVitestTempFixture(host, 'server', '');+ const fixtureRun = createVitestTempFixture(host, 'server', '');+ const { args, options } = fixtureRun;const sourcePath = fileURLToPath(new URL('../server/services/writersRoom/promoteToPipeline.test.js', import.meta.url));const source = readFileSync(sourcePath, 'utf8').replace(/(['"])(\.\.?\/[^'"]+)\1/g, (_, quote, specifier) => JSON.stringify(resolve(dirname(sourcePath), specifier)))@@ -38,9 +49,11 @@ it('drains promotion fixture writes after another worker triggers fail-fast', ()const workerIndex = args.indexOf('--maxWorkers');args[workerIndex + 1] = '2';args.push('--bail=1');- const result = spawnSync(process.execPath, args, options);- const output = `${result.stdout}\n${result.stderr}`;- expect(result.error).toBeUndefined();+ const result = await runFixtureToCompletion(fixtureRun, RUN_CEILING_MS, { signal });+ if (signal.aborted) return;+ const phases = ['ready', 'finished'].map(name => `${name}=${existsSync(join(fixture, name))}`).join(' ');+ const output = `${result.stdout}\n${result.stderr}\nlifecycle phases: ${phases}`;+ expect(result.error, output).toBeUndefined();expect(result.status, output).toBe(1);expect(output).toContain('controlled sibling failure');expect(existsSync(finished), output).toBe(true);@@ -48,4 +61,4 @@ it('drains promotion fixture writes after another worker triggers fail-fast', ()} finally {rmSync(host, { recursive: true, force: true });}-}, 25000);+}, RUN_CEILING_MS + 15000);