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
fix: remove leaked mkdtemp fixture dirs across remaining test suites (#9000)
[._.]/ Adam Eivybc02de464c2f
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.jsindex 592044c690..b70dcff197 100644--- a/scripts/ci-test-plan.js+++ b/scripts/ci-test-plan.js@@ -245,6 +245,10 @@ export const ALWAYS_RUN_TESTS = ['server/lib/cliChildEnv.test.js','server/lib/editorial/proseTics.test.js','server/lib/generatedManifests.test.js',+ // Whole-tree scanner over git-tracked test files (#9000): a suite anywhere+ // in server/scripts/lib/autofixer can add a leaked mkdtemp call with no+ // import edge back to this guard.+ 'server/lib/mkdtempCleanup.guards.test.js',// Base-relative server import-growth guard (#7993). A new eager edge in a// widely reached module multiplies across suites this file does not import,// so impact selection would not reach it unless the diff touched this file.diff --git a/server/lib/mkdtempCleanup.guards.test.js b/server/lib/mkdtempCleanup.guards.test.jsindex 912f4974dd..13ee060528 100644--- a/server/lib/mkdtempCleanup.guards.test.js+++ b/server/lib/mkdtempCleanup.guards.test.js@@ -67,7 +67,7 @@ const TEST_HELPER_PATTERNS = [const MKDTEMP_PATTERN = /\b(?:mkdtemp|mkdtempSync)\s*\(\s*(?:join|path\.join)\s*\(\s*(?:tmpdir|process\.env\.\w+|os\.tmpdir)\s*\(\s*\)/g;const SKIP_MARKER = /SKIP\s*:\s*mkdtemp\s*cleanup/i;-const CLEANUP_PATTERN = /\b(?:rmSync|destroyGitSandbox|rm\()\s*\(/;+const CLEANUP_PATTERN = /\b(?:rmSync|rm|fs\.rm|destroyGitSandbox)\s*\(/;/*** Finds all git-tracked files in test-bearing trees that match test patterns or are test helpers.@@ -88,6 +88,38 @@ function findTestFiles() {return files;}+/**+ * Scans a single file's source for mkdtemp calls that lack a cleanup+ * mechanism. Returns an array of human-readable violation strings (empty+ * when the file is clean). Pulled out of the tree-wide test so a probe can+ * exercise the exact same code path against an inline fixture.+ */+function findViolationsInSource(file, src) {+ const violations = [];++ // Skip files with no mkdtemp calls+ if (!MKDTEMP_PATTERN.test(src)) return violations;++ // Check if there's any cleanup mechanism (rmSync, destroyGitSandbox, rm, etc.)+ const hasCleanup = CLEANUP_PATTERN.test(src);++ // Find each mkdtemp call and check for skip marker+ MKDTEMP_PATTERN.lastIndex = 0; // Reset regex+ for (const match of src.matchAll(MKDTEMP_PATTERN)) {+ // Check if this specific call has the skip marker nearby (within 2 lines before)+ const callIndex = match.index;+ const beforeCall = src.slice(Math.max(0, callIndex - 200), callIndex);+ const hasSkipMarker = SKIP_MARKER.test(beforeCall);++ if (!hasSkipMarker && !hasCleanup) {+ const lineNum = src.slice(0, callIndex).split('\n').length;+ violations.push(`${file} line ${lineNum}: mkdtemp without cleanup (add skip marker if justified)`);+ }+ }++ return violations;+}+describe('mkdtemp cleanup guard (#9000)', () => {it('finds test files to scan', () => {const files = findTestFiles();@@ -100,26 +132,7 @@ describe('mkdtemp cleanup guard (#9000)', () => {for (const file of findTestFiles()) {const src = readFileSync(join(REPO_ROOT, file), 'utf8');-- // Skip files with no mkdtemp calls- if (!MKDTEMP_PATTERN.test(src)) continue;-- // Check if there's any cleanup mechanism (rmSync, destroyGitSandbox, rm, etc.)- const hasCleanup = CLEANUP_PATTERN.test(src);-- // Find each mkdtemp call and check for skip marker- MKDTEMP_PATTERN.lastIndex = 0; // Reset regex- for (const match of src.matchAll(MKDTEMP_PATTERN)) {- // Check if this specific call has the skip marker nearby (within 2 lines before)- const callIndex = match.index;- const beforeCall = src.slice(Math.max(0, callIndex - 200), callIndex);- const hasSkipMarker = SKIP_MARKER.test(beforeCall);-- if (!hasSkipMarker && !hasCleanup) {- const lineNum = src.slice(0, callIndex).split('\n').length;- violations.push(`${file} line ${lineNum}: mkdtemp without cleanup (add skip marker if justified)`);- }- }+ violations.push(...findViolationsInSource(file, src));}if (violations.length > 0) {@@ -133,6 +146,24 @@ describe('mkdtemp cleanup guard (#9000)', () => {}});+ it('flags a probe fixture that mkdtemps with no cleanup (real code path)', () => {+ const probeSrc = `+ import { mkdtempSync } from 'fs';+ import { tmpdir } from 'os';+ import { join } from 'path';++ describe('probe', () => {+ it('leaks a temp dir', () => {+ const dir = mkdtempSync(join(tmpdir(), 'x-'));+ expect(dir).toBeTruthy();+ });+ });+ `;+ const violations = findViolationsInSource('probe/fixture.test.js', probeSrc);+ expect(violations).toHaveLength(1);+ expect(violations[0]).toMatch(/probe\/fixture\.test\.js line \d+: mkdtemp without cleanup/);+ });+describe('the guard recognizer', () => {it('detects mkdtemp calls', () => {const src = `@@ -153,7 +184,9 @@ describe('mkdtemp cleanup guard (#9000)', () => {it('detects skip markers', () => {const src = `// SKIP: mkdtemp cleanup — special case\nconst d = mkdtemp(join(tmpdir(), 'prefix-'));`;- const beforeCall = src.slice(0, src.indexOf('mkdtemp'));+ // The comment itself contains the word "mkdtemp", so find the actual+ // call site (the last occurrence) rather than the first.+ const beforeCall = src.slice(0, src.lastIndexOf('mkdtemp'));expect(SKIP_MARKER.test(beforeCall)).toBe(true);});diff --git a/server/lib/socketEventInventory.test.js b/server/lib/socketEventInventory.test.jsindex 061e6343a0..4c39a1d54e 100644--- a/server/lib/socketEventInventory.test.js+++ b/server/lib/socketEventInventory.test.js@@ -1,5 +1,5 @@-import { describe, expect, it } from 'vitest';-import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';+import { afterEach, describe, expect, it } from 'vitest';+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import {@@ -14,9 +14,22 @@ const write = (root, path, source) => {writeFileSync(target, source, 'utf8');};+const tempRoots = [];+const makeTempRoot = (prefix) => {+ const root = mkdtempSync(join(tmpdir(), prefix));+ tempRoots.push(root);+ return root;+};++afterEach(() => {+ for (const root of tempRoots.splice(0)) {+ rmSync(root, { recursive: true, force: true });+ }+});+describe('Socket.IO event inventory', () => {it('merges client/server declarations and normalizes bounded template events', async () => {- const root = mkdtempSync(join(tmpdir(), 'portos-socket-inventory-'));+ const root = makeTempRoot('portos-socket-inventory-');write(root, 'server/services/socket.js', `socket.on('demo:start', handler);io.emit('demo:done', data);@@ -37,7 +50,7 @@ describe('Socket.IO event inventory', () => {});it('classifies client lifecycle listeners and excludes the isolated runner tree', async () => {- const root = mkdtempSync(join(tmpdir(), 'portos-socket-file-'));+ const root = makeTempRoot('portos-socket-file-');write(root, 'server/sockets/empty.js', 'export default {};');write(root, 'server/cos-runner/isolated.js', `socket.emit('runner:internal');`);write(root, 'client/src/socket.js', `socket.on('connect', handler); socket.emit('shell:start', {});`);diff --git a/server/lib/testDataIsolation.guards.test.js b/server/lib/testDataIsolation.guards.test.jsindex 6061e4f326..287aecbc4b 100644--- a/server/lib/testDataIsolation.guards.test.js+++ b/server/lib/testDataIsolation.guards.test.js@@ -197,6 +197,7 @@ describe('test-data isolation guard', () => {'dies before afterEach leaves an untracked directory in the repo. Allocate a','temp directory instead:','',+ // SKIP: mkdtemp cleanup — error-message string literal, not a real call." const dir = await mkdtemp(join(tmpdir(), 'portos-<suite>-'));",'','Reading cwd as a value (workspacePath: process.cwd()) is fine — see #3823.',@@ -226,6 +227,8 @@ describe('test-data isolation guard', () => {expect(scanCwdFixture('workspacePath: process.cwd(),')).toBe(false);expect(scanCwdFixture('const TEST_WORKSPACE = process.cwd();')).toBe(false);expect(scanCwdFixture('getAppWorkspace.mockResolvedValue(process.cwd());')).toBe(false);+ // SKIP: mkdtemp cleanup — probe input for scanCwdFixture (a string literal+ // fed to the cwd-fixture scanner, not a real mkdtemp call the test creates).expect(scanCwdFixture("const dir = await mkdtemp(join(tmpdir(), 'portos-x-'));")).toBe(false);// An ordinary two-argument call that happens to take cwd first is not a// path build — requiring the join/resolve name is what keeps these out.