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: contain Chrome scratch across test runners

Adam Eivy9ad2d5143d9d
diff --git a/client/vitest.config.js b/client/vitest.config.js
index 2330c73e28..52c0570558 100644
--- a/client/vitest.config.js
+++ b/client/vitest.config.js
@@ -20,6 +20,7 @@ export default defineConfig({
TMPDIR: RUN_TEMP_ROOT,
TMP: RUN_TEMP_ROOT,
TEMP: RUN_TEMP_ROOT,
+ MAC_CHROMIUM_TMPDIR: RUN_TEMP_ROOT,
NODE_DISABLE_COMPILE_CACHE: '1',
},
// Four DOM workers exhausted Testing Library's async budget on the public
diff --git a/scripts/lib/vitestTempRoot.js b/scripts/lib/vitestTempRoot.js
index 6fc016452a..e288be64da 100644
--- a/scripts/lib/vitestTempRoot.js
+++ b/scripts/lib/vitestTempRoot.js
@@ -59,6 +59,9 @@ export function bootstrapVitestTempRoot() {
process.env.TMPDIR = root;
process.env.TMP = root;
process.env.TEMP = root;
+ // Chromium on macOS ignores TMPDIR in favor of this override. Without it,
+ // test-owned socket/download scratch escapes the root and its teardown.
+ process.env.MAC_CHROMIUM_TMPDIR = root;
process.env.NODE_DISABLE_COMPILE_CACHE = '1';
return root;
}
diff --git a/scripts/lib/vitestTempRootFixture.js b/scripts/lib/vitestTempRootFixture.js
index 9424ddeeb1..43e83484ce 100644
--- a/scripts/lib/vitestTempRootFixture.js
+++ b/scripts/lib/vitestTempRootFixture.js
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
const repo = fileURLToPath(new URL('../../', import.meta.url));
-export function createVitestTempFixture(host, workspace, body) {
+export function createVitestTempFixture(host, workspace, body, config = 'vitest.config.js') {
const root = join(host, 'fixture');
mkdirSync(root);
symlinkSync(join(repo, workspace, 'node_modules'), join(root, 'node_modules'),
@@ -18,7 +18,8 @@ export function createVitestTempFixture(host, workspace, body) {
writeFileSync(join(root, 'vitest.setup.js'), workspace === 'server'
? `import ${JSON.stringify(new URL('../../server/test/admissionSetup.js', import.meta.url).href)};\n`
: '');
- const testFile = workspace === 'client' ? 'src/lifecycle.test.js' : 'lifecycle.test.js';
+ const testFile = config === 'vitest.config.db.js' ? 'db.test.js'
+ : workspace === 'client' ? 'src/lifecycle.test.js' : 'lifecycle.test.js';
writeFileSync(join(root, testFile), `
import { test, expect } from 'vitest';
import { tmpdir } from 'node:os';
@@ -27,6 +28,9 @@ export function createVitestTempFixture(host, workspace, body) {
import { bootstrapVitestTempRoot } from ${JSON.stringify(new URL('./vitestTempRoot.js', import.meta.url).href)};
test('lifecycle', async () => {
const first = tmpdir();
+ // Check before re-bootstrap: the real config must already have forwarded
+ // Chromium's macOS temp override into every workspace worker.
+ expect(process.env.MAC_CHROMIUM_TMPDIR).toBe(first);
expect(bootstrapVitestTempRoot()).toBe(first);
expect(process.env.PORTOS_TEST_TEMP_ROOT).toBe(first);
${body}
@@ -40,7 +44,7 @@ export function createVitestTempFixture(host, workspace, body) {
delete env.VITEST_WORKER_ID;
return {
args: [join(repo, workspace, 'node_modules/vitest/vitest.mjs'), 'run',
- '--config', join(repo, workspace, 'vitest.config.js'), '--root', root, '--maxWorkers', '1'],
+ '--config', join(repo, workspace, config), '--root', root, '--maxWorkers', '1'],
options: { cwd: join(repo, workspace), env, encoding: 'utf8', timeout: 20000 },
};
}
diff --git a/scripts/vitestTempRoot.test.js b/scripts/vitestTempRoot.test.js
index 768f2c0e77..d18ac3925f 100644
--- a/scripts/vitestTempRoot.test.js
+++ b/scripts/vitestTempRoot.test.js
@@ -9,28 +9,30 @@ import { isProcessAlive } from '../server/test/processAlive.js';
describe('real workspace runner temp lifecycle', () => {
const workspace = 'server';
- for (const outcome of ['success', 'failure', 'leak']) {
- it(`${workspace} removes framework scratch on ${outcome}, preserving host artifacts`, () => {
- const host = mkdtempSync(join(tmpdir(), 'vrt-'));
- try {
- // Even nanoid-looking pre-existing directories belong to the host.
- const untouched = 'A'.repeat(21);
- mkdirSync(join(host, untouched));
- writeFileSync(join(host, untouched, 'keep'), 'host data');
- const body = outcome === 'failure' ? "expect(true).toBe(false);"
- : outcome === 'leak' ? "writeFileSync(join(tmpdir(), 'fixture-leak'), 'unexpected');"
- : 'expect(true).toBe(true);';
- const { args, options } = createVitestTempFixture(host, workspace, body);
- const result = spawnSync(process.execPath, args, options);
- expect(result.error).toBeUndefined();
- expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(outcome === 'success' ? 0 : 1);
- if (outcome === 'leak') expect(result.stderr).toContain('test temp leak: fixture-leak');
- expect(readdirSync(host).sort()).toEqual([untouched, 'fixture'].sort());
- } finally {
- rmSync(host, { recursive: true, force: true });
- }
- }, 25000);
- }
+ describe.each(['vitest.config.js', 'vitest.config.db.js'])('%s', (config) => {
+ for (const outcome of ['success', 'failure', 'leak']) {
+ it(`${workspace} removes framework scratch on ${outcome}, preserving host artifacts`, () => {
+ const host = mkdtempSync(join(tmpdir(), 'vrt-'));
+ try {
+ // Even nanoid-looking pre-existing directories belong to the host.
+ const untouched = 'A'.repeat(21);
+ mkdirSync(join(host, untouched));
+ writeFileSync(join(host, untouched, 'keep'), 'host data');
+ const body = outcome === 'failure' ? "expect(true).toBe(false);"
+ : outcome === 'leak' ? "writeFileSync(join(tmpdir(), 'fixture-leak'), 'unexpected');"
+ : 'expect(true).toBe(true);';
+ const { args, options } = createVitestTempFixture(host, workspace, body, config);
+ const result = spawnSync(process.execPath, args, options);
+ expect(result.error).toBeUndefined();
+ expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(outcome === 'success' ? 0 : 1);
+ if (outcome === 'leak') expect(result.stderr).toContain('test temp leak: fixture-leak');
+ expect(readdirSync(host).sort()).toEqual([untouched, 'fixture'].sort());
+ } finally {
+ rmSync(host, { recursive: true, force: true });
+ }
+ }, 25000);
+ }
+ });
it('reuses config ownership on reimport and reclaims it after interruption, preserving a live owner', async () => {
const host = mkdtempSync(join(tmpdir(), 'vrt-'));
diff --git a/server/services/htmlComposition/ownedBrowser.js b/server/services/htmlComposition/ownedBrowser.js
index 0409f7cb13..d912cabe91 100644
--- a/server/services/htmlComposition/ownedBrowser.js
+++ b/server/services/htmlComposition/ownedBrowser.js
@@ -39,7 +39,7 @@ async function removeProfile(profile, attempts = 20, delayMs = 50) {
// still denies IP egress.
function previewBrowserEnv() {
const env = { USER: 'portos-preview' };
- for (const key of ['PATH', 'HOME', 'TMPDIR', 'TEMP', 'TMP', 'LANG', 'LC_ALL', 'SYSTEMROOT', 'WINDIR', 'COMSPEC', 'PATHEXT']) {
+ for (const key of ['PATH', 'HOME', 'TMPDIR', 'TEMP', 'TMP', 'MAC_CHROMIUM_TMPDIR', 'LANG', 'LC_ALL', 'SYSTEMROOT', 'WINDIR', 'COMSPEC', 'PATHEXT']) {
if (process.env[key]) env[key] = process.env[key];
}
return env;
diff --git a/server/services/htmlComposition/ownedBrowser.test.js b/server/services/htmlComposition/ownedBrowser.test.js
index cc816ce043..21d00bcf7b 100644
--- a/server/services/htmlComposition/ownedBrowser.test.js
+++ b/server/services/htmlComposition/ownedBrowser.test.js
@@ -181,6 +181,7 @@ describe('owned composition capture browser lifecycle', () => {
});
it('launches the jailed pipe browser without a DevTools port or inherited tokens', async () => {
+ vi.stubEnv('MAC_CHROMIUM_TMPDIR', '/synthetic/test-temp');
answerHandshake();
const owner = await launchCompositionBrowser({
isolation: 'required',
@@ -196,6 +197,7 @@ describe('owned composition capture browser lifecycle', () => {
expect(args.join('\n')).not.toContain('proxy-bypass');
expect(args).not.toContain('--remote-debugging-port=0');
expect(options.env.USER).toBe('portos-preview');
+ expect(options.env.MAC_CHROMIUM_TMPDIR).toBe('/synthetic/test-temp');
expect(options.env.PORTOS_API_TOKEN).toBeUndefined();
expect(options.detached).toBe(true);
await owner.close();
diff --git a/server/vitest.config.db.js b/server/vitest.config.db.js
index 7c1f90b5ea..464174f43a 100644
--- a/server/vitest.config.db.js
+++ b/server/vitest.config.db.js
@@ -1,5 +1,10 @@
import { defineConfig } from 'vitest/config';
+import { fileURLToPath } from 'node:url';
import { DB_TEST_INCLUDE } from '../scripts/lib/dbTestFiles.js';
+import { bootstrapVitestTempRoot } from '../scripts/lib/vitestTempRoot.js';
+
+// This independent runner owns the same fixture/browser scratch as npm test.
+const RUN_TEMP_ROOT = bootstrapVitestTempRoot();
// Same reason as vitest.config.js: an inherited NODE_ENV (PM2 exports
// 'development') is NOT overridden by vitest's own default, and the DB guards
@@ -37,12 +42,18 @@ export default defineConfig({
testTimeout: process.platform === 'win32' ? 30000 : 15000,
// Explicit 'vitest' imports only, matching vitest.config.js (#9049).
globals: false,
+ globalSetup: [fileURLToPath(new URL('../scripts/vitestTempRootSetup.js', import.meta.url))],
setupFiles: ['./vitest.setup.js'],
// One file at a time — these suites assume exclusive access to their tables.
fileParallelism: false,
env: {
NODE_ENV: 'test',
PGDATABASE: process.env.PGTESTDATABASE || 'portos_test',
+ NODE_DISABLE_COMPILE_CACHE: '1',
+ TMPDIR: RUN_TEMP_ROOT,
+ TMP: RUN_TEMP_ROOT,
+ TEMP: RUN_TEMP_ROOT,
+ MAC_CHROMIUM_TMPDIR: RUN_TEMP_ROOT,
},
include: DB_TEST_INCLUDE,
exclude: [
diff --git a/server/vitest.config.js b/server/vitest.config.js
index ce5b243908..4fac5c47c9 100644
--- a/server/vitest.config.js
+++ b/server/vitest.config.js
@@ -49,6 +49,7 @@ const config = defineConfig({
TMPDIR: RUN_TEMP_ROOT,
TMP: RUN_TEMP_ROOT,
TEMP: RUN_TEMP_ROOT,
+ MAC_CHROMIUM_TMPDIR: RUN_TEMP_ROOT,
},
// 30s on every platform (#7951). This WAS 10s off Windows, and the split
// has always been a fiction: the cost it budgets for is vitest's transform