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(backup): isolate generated workflow admission fixtures

[._.]/ Adam Eivyb962d2946334
diff --git a/scripts/lib/vitestTempRootFixture.js b/scripts/lib/vitestTempRootFixture.js
index d97505f069..8a36014614 100644
--- a/scripts/lib/vitestTempRootFixture.js
+++ b/scripts/lib/vitestTempRootFixture.js
@@ -12,7 +12,11 @@ export function createVitestTempFixture(host, workspace, body) {
process.platform === 'win32' ? 'junction' : 'dir');
mkdirSync(join(root, 'src/test'), { recursive: true });
writeFileSync(join(root, 'src/test/setup.js'), '');
- writeFileSync(join(root, 'vitest.setup.js'), '');
+ // Generated workflow suites need the same private, real coordinators as the
+ // ordinary server runner, even though their setup omits unrelated mocks.
+ writeFileSync(join(root, 'vitest.setup.js'), workspace === 'server'
+ ? `import ${JSON.stringify(new URL('../../server/lib/admissionTestSetup.js', import.meta.url).href)};\n`
+ : '');
const testFile = workspace === 'client' ? 'src/lifecycle.test.js' : 'lifecycle.test.js';
writeFileSync(join(root, testFile), `
import { test, expect } from 'vitest';
diff --git a/scripts/writersRoomPromotionCleanup.test.js b/scripts/writersRoomPromotionCleanup.test.js
index e1f729ff17..78ef8fc54b 100644
--- a/scripts/writersRoomPromotionCleanup.test.js
+++ b/scripts/writersRoomPromotionCleanup.test.js
@@ -31,7 +31,7 @@ it('drains promotion fixture writes after another worker triggers fail-fast', ()
writeFileSync(join(fixture, 'lifecycle.test.js'), source + `
afterAll(async () => {
const { existsSync } = await import('node:fs');
- await expect.poll(() => existsSync(${JSON.stringify(finished)}), { timeout: 1000 }).toBe(true);
+ await vi.waitFor(() => expect(existsSync(${JSON.stringify(finished)})).toBe(true), { timeout: 1000 });
});
`);
writeFileSync(join(fixture, 'failure.test.js'), `
@@ -51,7 +51,7 @@ it('drains promotion fixture writes after another worker triggers fail-fast', ()
expect(result.status, output).toBe(1);
expect(output).toContain('controlled sibling failure');
expect(existsSync(finished), output).toBe(true);
- expect(output).not.toContain('test temp leak:');
+ expect(output).not.toMatch(/refused|unhandled|test temp leak:/i);
} finally {
rmSync(host, { recursive: true, force: true });
}
diff --git a/server/lib/admissionTestSetup.js b/server/lib/admissionTestSetup.js
new file mode 100644
index 0000000000..0de4cd0ab0
--- /dev/null
+++ b/server/lib/admissionTestSetup.js
@@ -0,0 +1,42 @@
+// Shared by the server setup and generated subprocess workflow fixtures.
+// Keep the real coordination protocol, while owning every journal and its cleanup.
+import { vi, afterAll } from 'vitest';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+
+// Exercise the real gate in workflow tests, with private test-owned journals.
+// Register teardown in setup (not inside a lazy mock factory); resetModules can
+// otherwise create a journal after the file's teardown hooks were collected.
+const coordinatorTestRoots = [];
+afterAll(() => {
+ for (const entry of coordinatorTestRoots.splice(0)) {
+ entry.closed = true;
+ entry.io.rmSync(entry.root, { recursive: true, force: true });
+ }
+});
+vi.mock('./maintenanceAdmission.js', async (importOriginal) => {
+ const actual = await importOriginal();
+ const io = await vi.importActual('node:fs');
+ const { randomUUID } = await vi.importActual('node:crypto');
+ const root = io.mkdtempSync(join(tmpdir(), 'maintenance-workflow-'));
+ const entry = { io, root, closed: false };
+ coordinatorTestRoots.push(entry);
+ return { ...actual, maintenance: actual.createMaintenanceAdmission(root, { io, makeId: randomUUID, assertWrite: path => {
+ // Domain suites mock fs/UUIDs wholesale. Keep the journal private and real.
+ if (entry.closed || path !== join(root, 'workflow-maintenance')) throw new Error('Unexpected maintenance test path');
+ } }) };
+});
+
+// Publication admission remains real, but never shares ownership with the install
+// or another test file. Use real fs/UUIDs even when domain suites mock them.
+vi.mock('./backupSharedAdmission.js', async (importOriginal) => {
+ const actual = await importOriginal();
+ const io = await vi.importActual('node:fs');
+ const { randomUUID } = await vi.importActual('node:crypto');
+ const root = io.mkdtempSync(join(tmpdir(), 'backup-admission-workflow-'));
+ const entry = { io, root, closed: false };
+ coordinatorTestRoots.push(entry);
+ return { ...actual, backupSharedAdmission: actual.createBackupSharedAdmission(root, { io, makeId: randomUUID, assertWrite: path => {
+ if (entry.closed || path !== root) throw new Error('Unexpected backup admission test path');
+ } }) };
+});
diff --git a/server/vitest.setup.js b/server/vitest.setup.js
index 905325be09..81affe0ae3 100644
--- a/server/vitest.setup.js
+++ b/server/vitest.setup.js
@@ -52,9 +52,8 @@
import { vi, afterAll } from 'vitest';
import { rmSync } from 'fs';
-import { tmpdir } from 'os';
-import { join } from 'path';
import { mockNoPeers } from './lib/mockPathsDataRoot.js';
+import './lib/admissionTestSetup.js';
// The server intentionally logs expected error paths, lifecycle transitions,
// and fallback decisions. With console interception disabled (see the config),
@@ -90,40 +89,3 @@ afterAll(() => {
try { rmSync(dir, { recursive: true, force: true }); } catch { /* already gone */ }
}
});
-
-// Exercise the real gate in workflow tests, with private test-owned journals.
-// Register teardown in setup (not inside a lazy mock factory); resetModules can
-// otherwise create a journal after the file's teardown hooks were collected.
-const maintenanceTestRoots = [];
-afterAll(() => {
- for (const entry of maintenanceTestRoots.splice(0)) {
- entry.closed = true;
- entry.io.rmSync(entry.root, { recursive: true, force: true });
- }
-});
-vi.mock('./lib/maintenanceAdmission.js', async (importOriginal) => {
- const actual = await importOriginal();
- const io = await vi.importActual('node:fs');
- const { randomUUID } = await vi.importActual('node:crypto');
- const root = io.mkdtempSync(join(tmpdir(), 'maintenance-workflow-'));
- const entry = { io, root, closed: false };
- maintenanceTestRoots.push(entry);
- return { ...actual, maintenance: actual.createMaintenanceAdmission(root, { io, makeId: randomUUID, assertWrite: path => {
- // Domain suites mock fs/UUIDs wholesale. Keep the journal private and real.
- if (entry.closed || path !== join(root, 'workflow-maintenance')) throw new Error('Unexpected maintenance test path');
- } }) };
-});
-
-// Publication admission remains real, but never shares ownership with the install
-// or another test file. Use real fs/UUIDs even when domain suites mock them.
-vi.mock('./lib/backupSharedAdmission.js', async (importOriginal) => {
- const actual = await importOriginal();
- const io = await vi.importActual('node:fs');
- const { randomUUID } = await vi.importActual('node:crypto');
- const root = io.mkdtempSync(join(tmpdir(), 'backup-admission-workflow-'));
- const entry = { io, root, closed: false };
- maintenanceTestRoots.push(entry);
- return { ...actual, backupSharedAdmission: actual.createBackupSharedAdmission(root, { io, makeId: randomUUID, assertWrite: path => {
- if (entry.closed || path !== root) throw new Error('Unexpected backup admission test path');
- } }) };
-});