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: isolate Vitest module caches in linked worktrees

[._.]/ Adam Eivy1d910b7c1fbd
diff --git a/client/vitest.config.js b/client/vitest.config.js
index 67eb880ff9..bf55f467fe 100644
--- a/client/vitest.config.js
+++ b/client/vitest.config.js
@@ -20,6 +20,8 @@ const config = defineConfig({
dedupe: ['three'],
},
test: {
+ // Vitest 5's module cache is separate from Vite cacheDir; dependencies may be shared by worktrees.
+ fsModuleCachePath: fileURLToPath(new URL('./.cache/vitest/modules', import.meta.url)),
globalSetup: [fileURLToPath(new URL('../scripts/vitestTempRootSetup.js', import.meta.url))],
env: {
TMPDIR: RUN_TEMP_ROOT,
diff --git a/scripts/lib/workspaceCacheFixture.js b/scripts/lib/workspaceCacheFixture.js
index d2e35ee7da..1d134133b1 100644
--- a/scripts/lib/workspaceCacheFixture.js
+++ b/scripts/lib/workspaceCacheFixture.js
@@ -38,6 +38,7 @@ function primaryDependencies(host, workspace) {
}
put(join(dependencies, '.vite/keep'), 'primary persistent cache');
put(join(dependencies, '.vite-temp/keep'), 'primary config scratch');
+ put(join(dependencies, '.vitest-cache/keep'), 'primary filesystem module cache');
return dependencies;
}
@@ -115,6 +116,7 @@ async function runTogether(fixtures, signal) {
}
const cachedResults = root => snapshot(root).filter(([name]) => name.endsWith('results.json'));
+const cachedModules = root => snapshot(join(root, 'modules')).filter(([name]) => /^[a-f0-9]{40}$/.test(name));
// Assertions are supplied by the owning Vitest workspace; this shared fixture
// imports only Node builtins and dependency-free fixture support.
@@ -125,16 +127,25 @@ export async function checkWorkspaceCacheIsolation(workspace, configName, cacheN
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);
+ const primaryModules = snapshot(join(dependencies, '.vitest-cache'));
await runTogether([a, b], signal);
+ expect(snapshot(join(dependencies, '.vitest-cache'))).toEqual(primaryModules);
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);
+ // Actual transformed module files, not just a resolved config or metadata.
+ for (const cache of [cacheA, cacheB]) {
+ expect(cachedModules(cache).length).toBeGreaterThan(0);
+ }
+ const modules = cachedModules(cacheA);
const sibling = snapshot(cacheB);
const names = snapshot(cacheA).map(([name]) => name);
await run(a, signal);
+ expect(cachedModules(cacheA)).toEqual(modules);
expect(snapshot(cacheA).map(([name]) => name)).toEqual(names);
expect(snapshot(cacheB)).toEqual(sibling);
+ expect(snapshot(join(dependencies, '.vitest-cache'))).toEqual(primaryModules);
expect([snapshot(join(dependencies, '.vite')), snapshot(join(dependencies, '.vite-temp'))]).toEqual(primary);
rmSync(a.root, { recursive: true });
expect(existsSync(cacheA)).toBe(false);
diff --git a/server/vitest.config.db.js b/server/vitest.config.db.js
index 9827292bef..76acf2dfe4 100644
--- a/server/vitest.config.db.js
+++ b/server/vitest.config.db.js
@@ -49,6 +49,8 @@ const config = defineConfig({
// Anchor to the config, even when --root or the caller cwd differs.
cacheDir: fileURLToPath(new URL('./.cache/vitest-db', import.meta.url)),
test: {
+ // Vitest 5's module cache is separate from Vite cacheDir; dependencies may be shared by worktrees.
+ fsModuleCachePath: fileURLToPath(new URL('./.cache/vitest-db/modules', import.meta.url)),
// Environment teardown also owns collection-only/skipped suite fixtures.
environment: fileURLToPath(new URL('./test/mediaRegistryEnvironment.js', import.meta.url)),
testTimeout: process.platform === 'win32' ? 30000 : 15000,
diff --git a/server/vitest.config.js b/server/vitest.config.js
index 16358a0e86..a511bc5983 100644
--- a/server/vitest.config.js
+++ b/server/vitest.config.js
@@ -49,6 +49,8 @@ const config = defineConfig({
// Anchor to the config, even when --root or the caller cwd differs.
cacheDir: fileURLToPath(new URL('./.cache/vitest', import.meta.url)),
test: {
+ // Vitest 5's module cache is separate from Vite cacheDir; dependencies may be shared by worktrees.
+ fsModuleCachePath: fileURLToPath(new URL('./.cache/vitest/modules', import.meta.url)),
// Environment teardown also owns collection-only/skipped suite fixtures.
environment: fileURLToPath(new URL('./test/mediaRegistryEnvironment.js', import.meta.url)),
...vitestCiPool(),