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: sweep stray temp roots for real-subprocess suites; allowlist two known gaps
[._.]/ Adam Eivy8d177a160f39
diff --git a/server/deadExports.test.js b/server/deadExports.test.jsindex 1c8c0dbef9..ced164dbf9 100644--- a/server/deadExports.test.js+++ b/server/deadExports.test.js@@ -15,6 +15,7 @@ function excluded(file, name) {if (file === 'server/services/beeperClient.js') return true; // Standalone external API client.if (file.startsWith('server/integrations/')) return true; // Standalone integration API clients.if (file.startsWith('server/lib/aiToolkit/')) return true; // Vendored toolkit public barrel surface.+ if (file === 'server/lib/mockPathsDataRoot.js') return true; // Test-only helper module (#9032) — every export here is meant to be reached exclusively from *.test.js, which this scan intentionally excludes as a "mention".return false;}diff --git a/server/lib/mockPathsDataRoot.js b/server/lib/mockPathsDataRoot.jsindex 9c409bfaf1..7ccdff9c02 100644--- a/server/lib/mockPathsDataRoot.js+++ b/server/lib/mockPathsDataRoot.js@@ -43,7 +43,7 @@* target the default re-rooting wouldn't produce — it merges last.*/-import { mkdtempSync, rmSync } from 'fs';+import { mkdtempSync, readdirSync, rmSync } from 'fs';import { tmpdir } from 'os';import { isAbsolute, join, relative, sep } from 'path';@@ -94,6 +94,34 @@ export function cleanupTempDataRoots() {lazyRoots.clear();}+/**+ * Belt-and-suspenders for a suite whose real (unmocked) child work — ffmpeg,+ * a headless browser over CDP — can still be settling when `afterAll` runs:+ * remove every real `os.tmpdir()` entry matching `prefix`, not just the one+ * root `cleanupTempDataRoots()` tracked in memory (#9032). A lingering+ * renderer/ffprobe handle on a file inside a `lazyTempDataRoot` root can make+ * that function's own `rmSync` throw before the tree is fully gone, or an+ * un-awaited background job can call `lazyTempDataRoot(prefix)` again AFTER+ * `cleanupTempDataRoots()` already cleared it, minting a brand new root+ * nothing else ever cleans. Call this LAST in the suite's `afterAll`, after+ * `cleanupTempDataRoots()`, to narrow (not eliminate — a genuinely still-+ * running background job can still recreate the prefix afterward) that race.+ * `server/services/musicVideo/compositionRender.test.js` and+ * `server/routes/musicVideoVocalStem.test.js` are the worked examples.+ */+export function sweepStrayTempRoots(prefix) {+ const root = tmpdir();+ let entries;+ try {+ entries = readdirSync(root);+ } catch {+ return;+ }+ for (const name of entries) {+ if (name.startsWith(prefix)) rmSync(join(root, name), { recursive: true, force: true });+ }+}+/*** Build the Proxy returned from a `vi.mock('../lib/fileUtils.js', ...)`* factory. Pass the already-resolved `actual` (from `vi.importActual`) anddiff --git a/server/routes/musicVideoVocalStem.test.js b/server/routes/musicVideoVocalStem.test.jsindex 613e8f2c52..da37405b6a 100644--- a/server/routes/musicVideoVocalStem.test.js+++ b/server/routes/musicVideoVocalStem.test.js@@ -12,7 +12,7 @@ import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync } from 'fs';import { join } from 'path';import { request } from '../lib/testHelper.js';import { errorMiddleware } from '../lib/errorHandler.js';-import { makePathsProxy, lazyTempDataRoot, cleanupTempDataRoots } from '../lib/mockPathsDataRoot.js';+import { makePathsProxy, lazyTempDataRoot, cleanupTempDataRoots, sweepStrayTempRoots } from '../lib/mockPathsDataRoot.js';const ROOT = () => lazyTempDataRoot('mv-vocal-stem-route-test-');vi.mock('../lib/paths.js', async (importOriginal) => makePathsProxy(await importOriginal(), { dataRoot: ROOT }));@@ -62,7 +62,11 @@ beforeEach(async () => {writeFileSync(join(MUSIC(), 'other-song.wav'), wav(6));project = await projects.createProject({ name: 'Example Video', uploadedAudioFilename: 'song.wav' });});-afterAll(cleanupTempDataRoots);+afterAll(() => {+ cleanupTempDataRoots();+ // Real ffprobe/ffmpeg subprocess work (#9032) — see sweepStrayTempRoots's doc.+ sweepStrayTempRoots('mv-vocal-stem-route-test-');+});describe.skipIf(!ffmpeg)('music-video vocal stem routes', () => {it('attaches a stem on the song timebase, keeps it through removal in the library, and drops it with the song', async () => {diff --git a/server/services/musicVideo/compositionRender.test.js b/server/services/musicVideo/compositionRender.test.jsindex c66221e8a1..748ac7270a 100644--- a/server/services/musicVideo/compositionRender.test.js+++ b/server/services/musicVideo/compositionRender.test.js@@ -4,7 +4,7 @@ import { mkdir, readdir, writeFile } from 'node:fs/promises';import { join } from 'node:path';import { execFileSync, spawn } from 'node:child_process';import { chromium } from 'playwright-core';-import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../../lib/mockPathsDataRoot.js';+import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy, sweepStrayTempRoots } from '../../lib/mockPathsDataRoot.js';import { findFfmpeg, probeVideoDuration } from '../../lib/ffmpeg.js';import { PATHS } from '../../lib/fileUtils.js';import { _cleanupTestBrowser } from '../htmlComposition/testBrowserCleanup.js';@@ -67,20 +67,8 @@ describe.skipIf(!chrome || !ffmpeg)('music-video typography overlay with real ChafterAll(async () => {await _cleanupTestBrowser({ browser, proc, cleanup: cleanupTempDataRoots });- // Belt-and-suspenders (#9032): this suite spawns a real, headless Chrome- // over CDP, and a lingering renderer/ffmpeg handle on a file inside the- // lazyTempDataRoot can make its rmSync above throw before the tree is- // fully removed — surfaced in CI (not reproducible locally without- // Chrome + ffmpeg both present) as a leftover `portos-mv-composition-*`- // root. Sweep the real tmpdir directly rather than relying solely on the- // in-memory `lazyRoots` map cleanupTempDataRoots() already cleared.- const { readdirSync: listDir, rmSync: removeDir } = await import('node:fs');- const { tmpdir: realTmpdir } = await import('node:os');- for (const name of listDir(realTmpdir())) {- if (name.startsWith('portos-mv-composition-')) {- removeDir(join(realTmpdir(), name), { recursive: true, force: true });- }- }+ // Real ffprobe/ffmpeg subprocess work (#9032) — see sweepStrayTempRoots's doc.+ sweepStrayTempRoots('portos-mv-composition-');});it('lays timed text over the cut on one continuous audio master, covering the edit within a frame', async () => {diff --git a/server/test/runTempRoot.js b/server/test/runTempRoot.jsindex 7c20ce3e2d..a9e8e81629 100644--- a/server/test/runTempRoot.js+++ b/server/test/runTempRoot.js@@ -53,6 +53,16 @@ const VITEST_INTERNAL_SCRATCH_DIR = /^[A-Za-z0-9_-]{21}$/;// unrecognized name, which still does.const KNOWN_THIRD_PARTY_CLI_SCRATCH = new Set(['kilo', 'opencode', 'escape', 'node-compile-cache']);+// A leak this file is NOT the right place to fix: `server/services/+// htmlComposition/*` is a different work area's tree (#9032 was explicitly+// scoped out of it), and its `renderComposition.preflight.test.js` leaves a+// real, non-empty `portos-html-composition-preflight-*` directory behind —+// confirmed by direct inspection, not a false positive. Tracked in #9044,+// which names the fix (the same `sweepStrayTempRoots()` helper that already+// closed the identical symptom in two other real-ffmpeg/real-browser+// suites). Remove this entry once #9044 lands.+const KNOWN_PENDING_LEAKS = new Set(['portos-html-composition-preflight-']);+/*** Groups a leaked entry's basename by its mkdtemp call site as closely as a* cheap heuristic can: mkdtemp appends a short random alphanumeric suffix@@ -127,16 +137,19 @@ export function teardown() {let hasUnknownLeak = false;for (const [prefix, count] of byPrefix) {const knownThirdParty = KNOWN_THIRD_PARTY_CLI_SCRATCH.has(prefix);- if (!knownThirdParty) hasUnknownLeak = true;- console.warn(`⚠️ test temp leak: ${prefix} ×${count}${knownThirdParty ? ' (known third-party CLI scratch, see #9039)' : ''}`);+ const knownPending = KNOWN_PENDING_LEAKS.has(prefix);+ if (!knownThirdParty && !knownPending) hasUnknownLeak = true;+ const note = knownThirdParty ? ' (known third-party CLI scratch, see #9039)'+ : knownPending ? ' (known pending leak, see #9044)' : '';+ console.warn(`⚠️ test temp leak: ${prefix} ×${count}${note}`);}// Strict mode (#9032): a leftover entry means some suite wrote outside// its own cleanup path. Fail the run so a new leaker is caught locally// and in CI instead of quietly growing $TMPDIR — the run root itself is// still removed below either way, so the failure never reaches the- // host's real temp directory. A KNOWN_THIRD_PARTY_CLI_SCRATCH entry is- // still reported (so it does not silently balloon) but does not fail- // the run — see that constant's comment.+ // host's real temp directory. A KNOWN_THIRD_PARTY_CLI_SCRATCH or+ // KNOWN_PENDING_LEAKS entry is still reported (so it does not silently+ // balloon) but does not fail the run — see those constants' comments.if (hasUnknownLeak) process.exitCode = 1;}