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: own and serialize workspace cache fixtures (#13226)
Adam Eivy81824e5f1d21
diff --git a/client/src/test/workspaceCaches.test.js b/client/src/test/workspaceCaches.test.jsindex 125e043709..b31b1eabc9 100644--- a/client/src/test/workspaceCaches.test.js+++ b/client/src/test/workspaceCaches.test.js@@ -3,11 +3,12 @@ import { describe, expect, it } from 'vitest';import { checkDevCacheIsolation, checkWorkspaceCacheIsolation } from '../../../scripts/lib/workspaceCacheFixture.js';describe('checkout-owned client Vite caches with shared dependencies', () => {- it('client vitest.config.js keeps concurrent publications separate and reuses its owned cache', async () => {- await checkWorkspaceCacheIsolation('client', 'vitest.config.js', 'vitest', expect);+ it('client vitest.config.js keeps concurrent publications separate and reuses its owned cache', async ({ signal, task }) => {+ expect(task.file.projectName).toBe('capture');+ await checkWorkspaceCacheIsolation('client', 'vitest.config.js', 'vitest', expect, signal);});- it.each(['npm', 'PM2'])('%s resolves real dev configs relative to each checkout without config-bundle scratch', async source => {- await checkDevCacheIsolation(source, expect);+ it('npm and PM2 resolve real dev configs relative to each checkout without config-bundle scratch', async ({ signal }) => {+ await checkDevCacheIsolation(expect, signal);});});diff --git a/client/vitest.config.js b/client/vitest.config.jsindex 78d2d1082e..67eb880ff9 100644--- a/client/vitest.config.js+++ b/client/vitest.config.js@@ -5,7 +5,7 @@ import { bootstrapVitestTempRoot } from '../scripts/lib/vitestTempRoot.js';import { VITEST_WATCH_OPTIONS } from '../scripts/lib/vitestWatch.js';import { CLIENT_TEST_EXCLUDE, CLIENT_TEST_INCLUDE } from '../scripts/lib/workspaceTests.js';-import { applyRunnerSelection, vitestCiPool, vitestRunnerSelection } from '../scripts/vitestCiPool.js';+import { applyRunnerSelection, vitestCaptureProjects, vitestCiPool, vitestRunnerSelection } from '../scripts/vitestCiPool.js';import { TEST_TIMEOUT_MS } from './src/test/timeouts.js';const RUN_TEMP_ROOT = bootstrapVitestTempRoot();@@ -70,5 +70,13 @@ const config = defineConfig({// The CI runner's explicit selection (closure-related files, minus the ones// the test memo already verified) arrives as a file, not as CLI selectors.-config.test = applyRunnerSelection(config.test, vitestRunnerSelection());+const runnerSelection = vitestRunnerSelection();+config.test = applyRunnerSelection(config.test, runnerSelection);+// Real nested runners retain the client budget, but get quiet startup after+// parallel DOM/scanner work. The root still owns one shared run temp root.+config.test.projects = vitestCaptureProjects(config.test, {+ cacheDir: config.cacheDir,+ selection: runnerSelection,+ exclusiveTests: ['src/test/workspaceCaches.test.js'],+}).map(project => ({ ...project, plugins: config.plugins, resolve: config.resolve, server: config.server }));export default config;diff --git a/scripts/lib/workspaceCacheFixture.js b/scripts/lib/workspaceCacheFixture.jsindex 5d72b29116..d2e35ee7da 100644--- a/scripts/lib/workspaceCacheFixture.js+++ b/scripts/lib/workspaceCacheFixture.js@@ -1,10 +1,9 @@-import { spawn } from 'node:child_process';import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { createRequire } from 'node:module';import { dirname, join, relative } from 'node:path';import { fileURLToPath, pathToFileURL } from 'node:url';-import { createVitestTempFixture } from './vitestTempRootFixture.js';+import { createVitestTempFixture, runFixtureToCompletion } from './vitestTempRootFixture.js';const REPO = fileURLToPath(new URL('../../', import.meta.url));const link = (target, path) => {@@ -83,29 +82,34 @@ function checkout(host, name, workspace, configName, dependencies) {args.push('--root', root, '--maxWorkers', '1');// This proof exercises cache publication, not DOM behavior. Three client// launches otherwise pay for happy-dom against one 15s enclosing budget.- if (workspace === 'client') args.push('--environment', 'node');+ if (workspace === 'client') {+ args.push('--environment', 'node', '--project', 'parallel');+ // The synthetic test is Node-only even when project settings override CLI+ // environment defaults. Do not initialize DOM or an empty capture project.+ const test = join(root, 'src/lifecycle.test.js');+ put(test, `// @vitest-environment node\n${readFileSync(test, 'utf8')}`);+ }// Test roots and the caller's cwd differ from the config's parent directory.const cwd = join(parent, 'caller');mkdirSync(cwd);return { ...fixture, args: [fixture.args[0], ...args], options: { ...fixture.options, cwd }, root };}-function run({ args, options }) {- return new Promise((resolve, reject) => {- const child = spawn(process.execPath, args, { ...options, stdio: ['ignore', 'pipe', 'pipe'] });- let output = '';- child.stdout.on('data', chunk => { output += chunk; });- child.stderr.on('data', chunk => { output += chunk; });- child.once('error', reject);- child.once('close', (code, signal) => {- if (code === 0) resolve(output);- else reject(new Error(`fixture failed (${code ?? signal}): ${output}`));- });- });+async function run(fixture, signal) {+ const result = await runFixtureToCompletion(fixture, undefined, { signal });+ if (result.error) {+ result.error.stdout = result.stdout;+ result.error.stderr = result.stderr;+ throw result.error;+ }+ const output = `${result.stdout}${result.stderr}`;+ if (result.status !== 0) throw new Error(`fixture failed (${result.status}): ${output}`);+ return output;}-async function runTogether(fixtures) {- const results = await Promise.allSettled(fixtures.map(run));+async function runTogether(fixtures, signal) {+ // Settle every owned child before the caller removes their shared host.+ const results = await Promise.allSettled(fixtures.map(fixture => run(fixture, signal)));for (const result of results) if (result.status === 'rejected') throw result.reason;return results.map(result => result.value);}@@ -114,21 +118,21 @@ const cachedResults = root => snapshot(root).filter(([name]) => name.endsWith('r// Assertions are supplied by the owning Vitest workspace; this shared fixture// imports only Node builtins and dependency-free fixture support.-export async function checkWorkspaceCacheIsolation(workspace, configName, cacheName, expect) {+export async function checkWorkspaceCacheIsolation(workspace, configName, cacheName, expect, signal) {const host = mkdtempSync(join(tmpdir(), 'workspace-cache-'));try {const dependencies = primaryDependencies(host, workspace);const primary = [snapshot(join(dependencies, '.vite')), snapshot(join(dependencies, '.vite-temp'))];const a = checkout(host, 'a', workspace, configName, dependencies);const b = checkout(host, 'b', workspace, configName, dependencies);- await runTogether([a, b]);+ await runTogether([a, b], signal);const cacheA = join(a.root, '.cache', cacheName);const cacheB = join(b.root, '.cache', cacheName);expect(cachedResults(cacheA).length).toBeGreaterThan(0);expect(cachedResults(cacheB).length).toBeGreaterThan(0);const sibling = snapshot(cacheB);const names = snapshot(cacheA).map(([name]) => name);- await run(a);+ await run(a, signal);expect(snapshot(cacheA).map(([name]) => name)).toEqual(names);expect(snapshot(cacheB)).toEqual(sibling);expect([snapshot(join(dependencies, '.vite')), snapshot(join(dependencies, '.vite-temp'))]).toEqual(primary);@@ -140,7 +144,7 @@ export async function checkWorkspaceCacheIsolation(workspace, configName, cacheN}}-export async function checkDevCacheIsolation(source, expect) {+export async function checkDevCacheIsolation(expect, signal) {const host = mkdtempSync(join(tmpdir(), 'workspace-dev-cache-'));try {const dependencies = primaryDependencies(host, 'client');@@ -149,10 +153,14 @@ export async function checkDevCacheIsolation(source, expect) {npm: JSON.parse(readFileSync(join(REPO, 'client/package.json'), 'utf8')).scripts.dev.split(' '),PM2: createRequire(import.meta.url)(join(REPO, 'ecosystem.config.cjs')).apps.find(app => app.name === 'portos-ui').args.split(' '),};- const devArgs = commands[source];- const loaderAt = devArgs.indexOf('--configLoader');- const loader = loaderAt === -1 ? undefined : devArgs[loaderAt + 1];- expect(loader).toBe('runner');+ // Both launchers load the same real config with the same loader. Inspect+ // each launch command, then resolve each checkout once rather than+ // repeating identical Vite startup for npm and PM2.+ for (const devArgs of Object.values(commands)) {+ const loaderAt = devArgs.indexOf('--configLoader');+ expect(loaderAt === -1 ? undefined : devArgs[loaderAt + 1]).toBe('runner');+ }+ const loader = 'runner';const fixtures = ['a', 'b'].map(name => checkout(host, name, 'client', 'vitest.config.js', dependencies));for (const fixture of fixtures) {const parent = dirname(fixture.root);@@ -169,7 +177,7 @@ export async function checkDevCacheIsolation(source, expect) {process.stdout.write(config.cacheDir);`);fixture.args = [script];}- const outputs = await runTogether(fixtures);+ const outputs = await runTogether(fixtures, signal);expect(outputs[0]).not.toBe(outputs[1]);expect([snapshot(join(dependencies, '.vite')), snapshot(join(dependencies, '.vite-temp'))]).toEqual(primary);expect(fixtures.map(fixture => relative(host, fixture.options.cwd).replaceAll('\\', '/'))).toEqual(['a/caller', 'b/caller']);diff --git a/scripts/vitestCiPool.js b/scripts/vitestCiPool.jsindex 214147eb0b..87ad65191a 100644--- a/scripts/vitestCiPool.js+++ b/scripts/vitestCiPool.js@@ -72,6 +72,8 @@ const EXCLUSIVE_TESTS = ['scripts/run-local-code-review.test.js','lib/workTracker.trackerInstructions.test.js','../scripts/ci-test-plan.test.js',+ // Three real nested runners need quiet startup, with owned cancellation.+ '../scripts/workspaceCaches.test.js','../scripts/persistentMindProcessAuditCleanup.test.js','../scripts/writersRoomPromotionCleanup.test.js',];@@ -110,12 +112,12 @@ export function applyRunnerSelection(test, selection) {return applied;}-export function vitestCaptureProjects(test, { cacheDir, selection = { include: null, exclude: [] } } = {}) {+export function vitestCaptureProjects(test, { cacheDir, selection = { include: null, exclude: [] }, exclusiveTests = EXCLUSIVE_TESTS } = {}) {const { include, exclude, ...shared } = test;// An explicit selection narrows the capture group too; its fixed include// would otherwise run every exclusive suite on every scoped plan.const captureInclude = selection.include === null- ? EXCLUSIVE_TESTS : EXCLUSIVE_TESTS.filter(file => selection.include.includes(file));+ ? exclusiveTests : exclusiveTests.filter(file => selection.include.includes(file));// Vite concatenates inherited include arrays: extending the broad root// glob would also run EVERY unit file in the capture project. Copy shared// worker settings explicitly and leave run-wide ownership at the root.@@ -130,7 +132,7 @@ export function vitestCaptureProjects(test, { cacheDir, selection = { include: n...shared,name: 'parallel',include,- exclude: [...exclude, ...EXCLUSIVE_TESTS],+ exclude: [...exclude, ...exclusiveTests],sequence: { groupOrder: 0 },},},diff --git a/scripts/vitestCiPool.test.js b/scripts/vitestCiPool.test.jsindex 9221e6fe14..e1c7f62966 100644--- a/scripts/vitestCiPool.test.js+++ b/scripts/vitestCiPool.test.js@@ -130,6 +130,7 @@ it('runs parallel units before exclusive, nonduplicated captures and cutover pro['cutover', 'services/databaseMaintenanceCutover.test.js'],['assembly', 'services/creativeDirector/videoAssembly.test.js'],['process-audit-cleanup', '../scripts/persistentMindProcessAuditCleanup.test.js'],+ ['workspace-caches', '../scripts/workspaceCaches.test.js'],]) {put(path, `${common}test('${name}', async ({ task }) => {expect(task.file.projectName).toBe('capture');@@ -153,7 +154,7 @@ it('runs parallel units before exclusive, nonduplicated captures and cutover proexpect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);const events = readFileSync(join(fixture, 'events'), 'utf8').trim().split('\n');expect(events.slice(0, 2).sort()).toEqual(['unit-a', 'unit-b']);- expect(events.slice(2).sort()).toEqual(['assembly', 'cutover', 'film-look', 'html', 'music', 'process-audit-cleanup', 'suno']);+ expect(events.slice(2).sort()).toEqual(['assembly', 'cutover', 'film-look', 'html', 'music', 'process-audit-cleanup', 'suno', 'workspace-caches']);} finally {rmSync(scratch, { recursive: true, force: true });}@@ -182,6 +183,16 @@ describe('vitestRunnerSelection', () => {expect(capture.test.include).toEqual([EXCLUSIVE_CAPTURE_TESTS[0]]);expect(parallel.test.exclude).toContain(EXCLUSIVE_CAPTURE_TESTS[0]);expect(vitestCaptureProjects({ include: ['**/*.test.js'], exclude: [] })[1].test.include.length).toBeGreaterThan(1);+ // Client-owned process fixtures use the same ordering without importing+ // the server's exclusive file list or widening a scoped/memo selection.+ for (const selection of [{ include: null, exclude: [] }, { include: ['src/unit.test.js'], exclude: [] }]) {+ const projects = vitestCaptureProjects({ include: ['src/**/*.test.js'], exclude: selection.exclude }, {+ selection, exclusiveTests: ['src/test/workspaceCaches.test.js'],+ });+ expect(projects[0].test.exclude).toEqual(['src/test/workspaceCaches.test.js']);+ expect(projects[1].test.include).toEqual(selection.include === null ? ['src/test/workspaceCaches.test.js'] : []);+ expect(projects[1].test.fileParallelism).toBe(false);+ }});it('refuses a selection it cannot read rather than widening to the whole suite', () => {diff --git a/scripts/workspaceCaches.test.js b/scripts/workspaceCaches.test.jsindex 4ff421fa3b..eb90bec2a1 100644--- a/scripts/workspaceCaches.test.js+++ b/scripts/workspaceCaches.test.js@@ -1,4 +1,5 @@-import { readFileSync } from 'node:fs';+import { readFileSync, readdirSync } from 'node:fs';+import { tmpdir } from 'node:os';import { join } from 'node:path';import { fileURLToPath } from 'node:url';import { describe, expect, it } from 'vitest';@@ -21,10 +22,19 @@ describe('checkout-owned server Vite caches with shared dependencies', () => {}});- it.each([- ['vitest.config.js', 'vitest'],- ['vitest.config.db.js', 'vitest-db'],- ])('server %s keeps concurrent publications separate and reuses its owned cache', async (configName, cacheName) => {- await checkWorkspaceCacheIsolation('server', configName, cacheName, expect);- });+ for (const [configName, cacheName] of [['vitest.config.js', 'vitest'], ['vitest.config.db.js', 'vitest-db']]) {+ it(`server ${configName} keeps concurrent publications separate and reuses its owned cache`, async ({ signal }) => {+ await checkWorkspaceCacheIsolation('server', configName, cacheName, expect, signal);+ });+ }++ it('settles cancelled concurrent cache publishers before removing their shared host', async () => {+ const before = readdirSync(tmpdir()).filter(name => name.startsWith('workspace-cache-'));+ const controller = new AbortController();+ const pending = checkWorkspaceCacheIsolation('server', 'vitest.config.js', 'vitest', expect, controller.signal);+ // Both launches have started synchronously, before the first await.+ controller.abort();+ await expect(pending).rejects.toMatchObject({ name: 'AbortError' });+ expect(readdirSync(tmpdir()).filter(name => name.startsWith('workspace-cache-'))).toEqual(before);+ }, 15000);});