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

test: use relative() for data/ containment and de-vacuous the real-PATHS guard

[._.]/ Adam Eivy072c27244ccd
diff --git a/server/lib/mockPathsDataRoot.js b/server/lib/mockPathsDataRoot.js
index 0c7f405980..ac33a4c217 100644
--- a/server/lib/mockPathsDataRoot.js
+++ b/server/lib/mockPathsDataRoot.js
@@ -42,7 +42,7 @@
import { mkdtempSync, rmSync } from 'fs';
import { tmpdir } from 'os';
-import { join, relative, sep } from 'path';
+import { isAbsolute, join, relative, sep } from 'path';
/**
* Allocate a unique temp dir suitable for use as `PATHS.data` in a test file.
@@ -89,10 +89,21 @@ export function makePathsProxy(actual, { dataRoot, extraOverrides = null, overri
? extraOverrides(root)
: (extraOverrides || {});
const realData = actual.PATHS.data;
+ // Containment via `relative()` rather than a `startsWith(realData + sep)`
+ // prefix test: it normalizes a trailing separator on `realData` and mixed
+ // separators, and it rejects a sibling that merely shares the prefix
+ // (`data-archive` → `../data-archive`) instead of matching it.
+ const relIfInside = (v) => {
+ if (typeof v !== 'string') return null;
+ const rel = relative(realData, v);
+ if (rel === '') return '.';
+ return !rel.startsWith(`..${sep}`) && rel !== '..' && !isAbsolute(rel) ? rel : null;
+ };
const rebased = Object.fromEntries(
Object.entries(actual.PATHS)
- .filter(([, v]) => typeof v === 'string' && (v === realData || v.startsWith(realData + sep)))
- .map(([k, v]) => [k, join(root, relative(realData, v))]),
+ .map(([k, v]) => [k, relIfInside(v)])
+ .filter(([, rel]) => rel !== null)
+ .map(([k, rel]) => [k, join(root, rel)]),
);
return { ...actual.PATHS, ...rebased, data: root, ...extras };
};
diff --git a/server/lib/mockPathsDataRoot.test.js b/server/lib/mockPathsDataRoot.test.js
index f83d816ef8..c80a56ecd5 100644
--- a/server/lib/mockPathsDataRoot.test.js
+++ b/server/lib/mockPathsDataRoot.test.js
@@ -1,7 +1,7 @@
import { describe, it, expect, afterAll } from 'vitest';
import { existsSync, rmSync } from 'fs';
import { tmpdir } from 'os';
-import { join, relative, sep } from 'path';
+import { join, sep } from 'path';
import { createTempDataRoot, makePathsProxy, mockNoPeers, mockNoPeerSync, mockPathsDataRoot } from './mockPathsDataRoot.js';
describe('mockPathsDataRoot', () => {
@@ -59,20 +59,40 @@ describe('mockPathsDataRoot', () => {
it('re-roots the real fileUtils PATHS so no member still points into the live install', async () => {
const { PATHS } = await import('./fileUtils.js');
const proxy = makePathsProxy({ PATHS }, { dataRoot: TMP });
- const dataRooted = Object.entries(PATHS)
- .filter(([, v]) => typeof v === 'string' && (v === PATHS.data || v.startsWith(PATHS.data + sep)));
- // Guard against a vacuous assertion if PATHS is ever restructured.
- expect(dataRooted.length).toBeGreaterThan(40);
- for (const [key] of dataRooted) {
- expect(`${key}=${proxy.PATHS[key]}`).toBe(`${key}=${join(TMP, relative(PATHS.data, PATHS[key]))}`);
- }
+ // Deliberately NOT the implementation's containment predicate — a plain
+ // prefix match over the PROXIED values. It is a superset of what the
+ // helper re-roots, so a member the helper failed to move is still caught
+ // here rather than being filtered out of the expectation alongside it.
+ const leaked = Object.entries(proxy.PATHS)
+ .filter(([, v]) => typeof v === 'string' && v.startsWith(PATHS.data))
+ .map(([k]) => k);
+ expect(leaked).toEqual([]);
+
+ // Hardcoded expectations — no shared derivation with the implementation.
+ expect(proxy.PATHS.data).toBe(TMP);
+ expect(proxy.PATHS.cos).toBe(join(TMP, 'cos'));
+ expect(proxy.PATHS.cosAgents).toBe(join(TMP, 'cos', 'agents'));
+ expect(proxy.PATHS.promptSkillsJobs).toBe(join(TMP, 'prompts', 'skills', 'jobs'));
+ expect(proxy.PATHS.brainSongbook).toBe(join(TMP, 'brain', 'songbook'));
+ expect(proxy.PATHS.digitalTwin).toBe(join(TMP, 'digital-twin'));
+
+ // Non-vacuity: most of PATHS must actually have moved.
+ const moved = Object.keys(PATHS).filter((k) => proxy.PATHS[k] !== PATHS[k]);
+ expect(moved.length).toBeGreaterThan(40);
+
// The four members that live outside data/ are untouched by construction.
for (const key of ['root', 'installRoot', 'slashdo', 'browserDownloads']) {
expect(proxy.PATHS[key]).toBe(PATHS[key]);
}
});
+ it('handles a trailing separator on the real PATHS.data', () => {
+ const trailing = { PATHS: { data: `/real/data${sep}`, images: '/real/data/images' } };
+ const proxy = makePathsProxy(trailing, { dataRoot: TMP });
+ expect(proxy.PATHS.images).toBe(join(TMP, 'images'));
+ });
+
it('passes non-PATHS exports through untouched', () => {
const proxy = makePathsProxy(fakeActual, { dataRoot: '/tmp/x' });
expect(proxy.ensureDir()).toBe('ensureDir-fn');