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: catch contiguous ../data climbs in the isolation guard, and de-vacuous the probe
[._.]/ Adam Eivy19a547e74959
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 687c63a6fd..63540c2e34 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -81,4 +81,4 @@- Internal: the series-autopilot unlock-pass test suite no longer reads the checkout's real `data/` directory. It partial-mocked `fileUtils.js` with an in-memory store but left `PATHS.data` pointing at the repo, and the series collection store enumerates that directory with a real `readdir` the mock never intercepts — so on any checkout with real series on disk, two sole-universe-ownership tests failed with what looked like a regression on whatever branch happened to be checked out. CI never saw it because a fresh checkout has no `data/`. `PATHS.data` now resolves to a per-run temp dir via the shared `makePathsProxy` helper, and three added assertions pin the isolation so it cannot quietly come back. The three sibling pipeline suites named as suspects were audited and are already isolated — they replace `series.js` outright and never reach the store. Test-only change; no production code touched.-- Internal: audited the whole server test suite for the "test reads the checkout's real `data/`" class that #3683 fixed one instance of, and closed the one other case it found. The audit was empirical rather than static — a full-suite baseline against an empty `data/`, then a second run with obviously-fake probe records planted in every `data/` subdirectory a service enumerates (prefix-aware, so the stores whose id allowlists require `iss-`/`ser-`/`stb-`/`game-` were actually reached) — and exactly one of 1301 test files failed only in the second run: the missions suite, which addressed `<repo>/data/cos/missions` directly with no mock at all, so it read the developer's live missions *and* wrote its own fixtures into them. It now runs against a per-run temp root, with two assertions pinning the isolation. The 67 suites that partial-mock `fileUtils.js` without redirecting `PATHS` were cleared by the same two-run diff — they replace the service graph wholesale and never reach a real `readdir`. A new repo-wide guard now fails the suite when a test names the checkout's own `data/` directory — either through an install-root anchor or a parent-directory climb — with the one deliberate exception documented in place (the creative-director prompt suite reads the installed prompt on purpose, to catch drift against a local edit). It deliberately does not police the third spelling, importing the real `PATHS` and reading a data-rooted member: 50 files do that, nearly all safely, so that one stays covered by the two-run probe, whose recipe is now written down beside the guard so it can be re-run. Test-only change; no production code touched.+- Internal: audited the whole server test suite for the "test reads the checkout's real `data/`" class that #3683 fixed one instance of, and closed the one case that was actually a bug. The audit was empirical rather than static — a full-suite baseline against an empty `data/`, then a second run with obviously-fake probe records planted in all 74 `data/` subdirectories a service enumerates (prefix-aware, so the stores whose id allowlists require `iss-`/`ser-`/`stb-`/`game-` were actually reached, and including the dirs `data.reference/` seeds rather than only the ones the `PATHS` table names) — and exactly one of 1301 test files failed only in the second run: the missions suite, which addressed `<repo>/data/cos/missions` directly with no mock at all, so it read the developer's live missions *and* wrote its own fixtures into them. It now runs against a per-run temp root, with assertions pinning both the path it writes to and the set it reads back. The 67 suites that partial-mock `fileUtils.js` without redirecting `PATHS` were cleared by the same two-run diff — they replace the service graph wholesale and never reach a real `readdir`. Two further suites do read the live install on purpose and are left alone: the creative-director prompt suite prefers the installed prompt so it catches drift against a local edit, and the opt-in vision integration test enumerates real screenshots to feed a real model. Neither writes anything back. A new repo-wide guard now fails the suite when any other test names the checkout's own `data/` directory, through an install-root anchor or a parent-directory climb, with those two exemptions documented in place. It deliberately does not police the third spelling, importing the real `PATHS` and reading a data-rooted member: 50 files do that, nearly all safely, so that one stays covered by the two-run probe, whose recipe is now recorded beside the guard so it can be re-run. Test-only change; no production code touched.diff --git a/server/lib/testDataIsolation.guards.test.js b/server/lib/testDataIsolation.guards.test.jsindex 4e773bab46..274176ed21 100644--- a/server/lib/testDataIsolation.guards.test.js+++ b/server/lib/testDataIsolation.guards.test.js@@ -58,18 +58,42 @@ const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');// sole offender after a rename.const SELF = relative(REPO_ROOT, fileURLToPath(import.meta.url));-// Deliberate exemption. `creativeDirectorPrompts.test.js` reads the INSTALLED-// stage prompt in preference to the committed `data.reference/` seed on purpose:-// the point is to catch drift between a locally-edited prompt and the code that-// renders it. It falls back to the seed when `data/` is absent, so CI is stable,-// and it only ever reads — it writes nothing into the user's data.-const ALLOWED = new Set(['server/lib/creativeDirectorPrompts.test.js']);+// Deliberate exemptions. Both READ the live install on purpose and write nothing+// into it, so neither can corrupt the user's data — the reason the rule exists.+// - creativeDirectorPrompts.test.js reads the INSTALLED stage prompt in+// preference to the committed `data.reference/` seed, to catch drift between+// a locally-edited prompt and the code that renders it. Falls back to the+// seed when `data/` is absent, so CI is stable.+// - visionTest.integration.test.js is an opt-in integration test whose stated+// premise is the live install: it enumerates the user's own screenshots to+// feed a real vision model, and skips itself when the directory is absent.+// A future false positive belongs here too — with a sentence saying why it's safe.+const ALLOWED = new Set([+ 'server/lib/creativeDirectorPrompts.test.js',+ 'server/services/visionTest.integration.test.js',+]);-// An install-root anchor or a parent climb, joined to a `data` path segment.+// Two shapes, because they need different bounds:+// 1. An install-root anchor (`process.cwd()`, `PATHS.root`/`installRoot`) or a+// standalone `'..'` join argument, followed on the SAME LINE by a `data`+// path segment. The line bound matters: allowing newlines here matches the+// 60 suites that mock `PATHS: { data: '/mock/data' }` across a few lines,+// where the `..` is only the module specifier of the `vi.mock` call. The+// cost is that a `join()` split across lines slips through — the empirical+// probe below is the backstop for that.+// 2. A CONTIGUOUS climb inside one string (`'../data'`, `'../../data/x'`).+// Contiguity is what makes this one safe to match without a window: it+// can't span two unrelated string literals the way shape 1 could.// The trailing lookahead spares `data.reference` / `data-foo` / `dataDir`, and-// the leading quote-or-slash class spares `'test-data'`.-const REAL_DATA_ROOT_RE =- /(?:process\.cwd\(\)|PATHS\.(?:root|installRoot)|['"]\.\.['"])[^\n;]*?['"`/]data(?![\w.-])/;+// the leading quote-or-separator class spares `'test-data'`.+const REAL_DATA_ROOT_RE = new RegExp([+ '(?:',+ '(?:process\\.cwd\\s*\\(\\)|PATHS\\.(?:root|installRoot)|[\'"`]\\.\\.[\'"`])',+ '[^\\n;]{0,160}?[\'"`/\\\\]data(?![\\w.-])',+ '|',+ '\\.\\.(?:[/\\\\]\\.\\.)*[/\\\\]data(?![\\w.-])',+ ')',+].join(''));// Scope to the test files the server runner globs (`server/vitest.config.js`).// Client tests run in jsdom and have no filesystem to leak into. Computed once —@@ -105,14 +129,18 @@ describe('test-data isolation guard', () => {].join('\n')).toEqual([]);});- it('would have caught both spellings that shipped', () => {- // A bypass probe, not a pattern unit test: these are the exact lines the two- // known instances carried, so a rule that stops matching them fails here- // instead of silently passing over a re-introduced leak.+ it('would have caught every spelling found in this repo', () => {+ // A bypass probe, not a pattern unit test: these are the exact lines the+ // three known instances carried, so a rule that stops matching them fails+ // here instead of silently passing over a re-introduced leak.expect(scan("const DATA_DIR = path.join(process.cwd(), 'data', 'cos', 'missions');")).toBe(true);expect(scan("const D = join(__HERE, '..', '..', 'data', 'prompts', 'stages');")).toBe(true);+ expect(scan("const S = resolve(__dirname, '../../data/screenshots');")).toBe(true);+ // Spellings not yet seen here, but a rename away from the ones above.expect(scan("join(PATHS.installRoot, 'data', 'runs')")).toBe(true);expect(scan('`${process.cwd()}/data/cos`')).toBe(true);+ expect(scan("join(__dirname, '../data/cos/missions')")).toBe(true);+ expect(scan("path.join(process.cwd(), '\\\\data\\\\cos')")).toBe(true);});it('spares the look-alikes that must stay legal', () => {@@ -121,5 +149,9 @@ describe('test-data isolation guard', () => {expect(scan("join(tempRoot, 'data', 'cos')")).toBe(false);expect(scan("join(__HERE, '..', '..', 'data.reference', 'prompts')")).toBe(false);expect(scan("import { PATHS } from '../lib/fileUtils.js'")).toBe(false);+ // A fake absolute path inside a mock factory. The `..` here belongs to the+ // module specifier, not to a climb — matching this flags 1 real suite+ // (creativeDirector/sceneEvaluator.test.js) for nothing.+ expect(scan("vi.mock('../../lib/fileUtils.js', () => ({ PATHS: { videoThumbnails: '/data/video-thumbnails' } }));")).toBe(false);});});diff --git a/server/services/missions.test.js b/server/services/missions.test.jsindex c93e07b95c..d77de32a89 100644--- a/server/services/missions.test.js+++ b/server/services/missions.test.js@@ -1,5 +1,5 @@import { describe, it, expect, beforeEach, afterEach, afterAll, vi } from 'vitest';-import { rmSync } from 'fs';+import { existsSync, rmSync } from 'fs';import path from 'path';import { mockPathsDataRoot } from '../lib/mockPathsDataRoot.js';@@ -27,9 +27,16 @@ afterAll(cleanup);// Dynamic import, not a static one: `missions.js` reads `PATHS.missions` into a// module-level const at load time, and a static import would run that load-// BEFORE the `const tempRoot` line above — the mock factory would then close-// over an uninitialized binding. Top-level await defers the load until after the-// temp root exists.+// BEFORE the `mockPathsDataRoot()` line above — the hoisted mock factory would+// then close over an uninitialized `makeProxy`. Top-level await defers the load+// until after it exists.+//+// So the static imports at the top of this file must never transitively reach+// `../lib/fileUtils.js`, or the factory runs during their evaluation and throws+// `Cannot access 'makeProxy' before initialization`. `vi.hoisted()` does NOT fix+// that — it hoists above the imports too, putting `mockPathsDataRoot` itself in+// TDZ (verified: `Cannot access '__vi_import_0__' before initialization`). Keep+// new static imports here dependency-free, or make them dynamic as well.const {createMission,getMission,@@ -399,8 +406,13 @@ describe('Missions Service — the suite is isolated from the checkout\'s real dexpect(PATHS.missions).toBe(DATA_DIR);});- it('counts only the missions this suite created', async () => {+ // Asserts WHERE the record landed, not just how many came back. A count alone+ // would pass on a fresh checkout with the redirect removed — real+ // `data/cos/missions` is empty there, so writing one and reading one back still+ // gives 1. Only the path assertion fails in that case.+ it('writes its missions under the temp root, and reads back only its own', async () => {await createMission({ id: 'test-isolation-probe', appId: 'test-app', name: 'Isolation Probe' });+ expect(existsSync(path.join(DATA_DIR, 'test-isolation-probe.json'))).toBe(true);const stats = await getStats();expect(stats.totalMissions).toBe(1);});