Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit f4486f4c8001ade8010460e2cf2529c02995fb98
parent a9fd81a09899fce946ddb07db50a6652f8c0e89e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  9 Nov 2026 23:23:07 -0500

umtool e2e: refuse an inherited REPORTS_DIR / CHANNELS_DIR / SONG_DIR that is not the fixture's

Playwright hands the app server and every CLI a spec spawns the shell's whole environment, and a variable the
config does not set wins by inheritance: REPORTS_DIR is read before the fixture's SONG_REPORTS_DIR, and a
spec's `{ ...process.env }` spawn carries CHANNELS_DIR and SONG_DIR along (2 Nov: a run wrote fixture state
into ~/reports). playwright.config.ts now throws first -- before the start-mode build, the fixture builder or
any spec -- naming each variable and its value, unless it points inside umtool/.e2e-song. The check is
lib/e2eEnvGuard.mjs, tested in test:scripts (unset, empty, inside, outside, a look-alike sibling, `..`).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Aumtool/lib/e2eEnvGuard.mjs | 47+++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/e2eEnvGuard.test.mjs | 29+++++++++++++++++++++++++++++
Mumtool/playwright.config.ts | 16+++++++++++++---
3 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/umtool/lib/e2eEnvGuard.mjs b/umtool/lib/e2eEnvGuard.mjs @@ -0,0 +1,47 @@ +// The umtool e2e suite's refusal of an inherited data root. +// +// Playwright hands the app server, the editor stub and every CLI a spec spawns +// this shell's whole environment. The config confines what it sets (the +// fixture's SONG_DIR, CHANNELS_DIR, ...), but a variable it does NOT set wins +// by inheritance: REPORTS_DIR is read before the fixture's SONG_REPORTS_DIR +// (lib/paths.mjs REPORTS_ROOT), and a spec's own spawn of a CLI with +// `{ ...process.env }` carries CHANNELS_DIR and SONG_DIR along. On 2 Nov a run +// that inherited them wrote fixture state into real projects under ~/reports. +// +// So a data root in the environment is refused, loudly and by name, unless it +// already points inside the suite's own fixture. Unset (or empty) is the +// normal case; the gate scripts `unset REPORTS_DIR CHANNELS_DIR SONG_DIR`. +import path from "node:path"; + +/** The variables that name a data root the suite must never inherit. */ +export const INHERITED_DATA_ROOTS = ["REPORTS_DIR", "CHANNELS_DIR", "SONG_DIR"]; + +const inside = (p, root) => { + const rel = path.relative(root, p); + return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel)); +}; + +/** + * Every inherited data root that is not the fixture's, as `{ name, value }`. + * @param {Record<string, string | undefined>} env + * @param {string} fixture the suite's fixture directory (e2e/.e2e-song) + */ +export function foreignDataRoots(env, fixture) { + const root = path.resolve(fixture); + return INHERITED_DATA_ROOTS.filter((name) => { + const v = env[name]; + return typeof v === "string" && v.trim() !== "" && !inside(path.resolve(v), root); + }).map((name) => ({ name, value: env[name] })); +} + +/** The refusal, naming each variable; null when there is nothing to refuse. */ +export function dataRootRefusal(env, fixture) { + const bad = foreignDataRoots(env, fixture); + if (!bad.length) return null; + return ( + `umtool e2e refuses to run: ${bad.map((b) => `${b.name}=${b.value}`).join(", ")} ` + + `${bad.length === 1 ? "is" : "are"} set in this shell and not the suite's fixture (${path.resolve(fixture)}). ` + + `The app server and the CLIs the specs spawn inherit it and would read and write real data there ` + + `(2 Nov: a run wrote fixture state into ~/reports). Unset it: \`unset ${bad.map((b) => b.name).join(" ")}\`.` + ); +} diff --git a/umtool/lib/e2eEnvGuard.test.mjs b/umtool/lib/e2eEnvGuard.test.mjs @@ -0,0 +1,29 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { dataRootRefusal, foreignDataRoots } from "./e2eEnvGuard.mjs"; + +const FIX = "/w/umtool/e2e/.e2e-song"; + +test("nothing set, or set empty, is the normal case", () => { + assert.equal(dataRootRefusal({}, FIX), null); + assert.equal(dataRootRefusal({ REPORTS_DIR: "", CHANNELS_DIR: " " }, FIX), null); +}); + +test("a root inside the fixture is the suite's own, and passes", () => { + assert.equal(dataRootRefusal({ CHANNELS_DIR: `${FIX}/channels`, SONG_DIR: `${FIX}/data`, REPORTS_DIR: FIX }, FIX), null); +}); + +test("an inherited root anywhere else is refused, naming each variable", () => { + const env = { REPORTS_DIR: "/home/u/reports", SONG_DIR: "/home/u/reports/quartering-uh-song/data", CHANNELS_DIR: `${FIX}/channels`, HOME: "/home/u" }; + assert.deepEqual(foreignDataRoots(env, FIX).map((b) => b.name), ["REPORTS_DIR", "SONG_DIR"]); + const msg = dataRootRefusal(env, FIX); + assert.match(msg, /REPORTS_DIR=\/home\/u\/reports/); + assert.match(msg, /SONG_DIR=\/home\/u\/reports\/quartering-uh-song\/data/); + assert.doesNotMatch(msg, /CHANNELS_DIR=/); + assert.match(msg, /unset REPORTS_DIR SONG_DIR/); +}); + +test("a sibling whose name merely starts with the fixture's is not inside it", () => { + assert.deepEqual(foreignDataRoots({ CHANNELS_DIR: `${FIX}-other/channels` }, FIX).map((b) => b.name), ["CHANNELS_DIR"]); + assert.deepEqual(foreignDataRoots({ REPORTS_DIR: `${FIX}/../reports` }, FIX).map((b) => b.name), ["REPORTS_DIR"]); +}); diff --git a/umtool/playwright.config.ts b/umtool/playwright.config.ts @@ -3,6 +3,7 @@ import { spawnSync } from "node:child_process"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; +import { dataRootRefusal } from "./lib/e2eEnvGuard.mjs"; // Test-only environment, declared here (one-core Phase 4 slice 3); every one // carries the E2E_ prefix: @@ -52,6 +53,18 @@ import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; // scripts/worktree.mjs), not test-only, and keep their names. const PORT = portFor("UMTOOL_E2E_PORT"); +// The package is "type": "module", so there is no __dirname here. +const FIXTURE = path.join(path.dirname(fileURLToPath(import.meta.url)), ".e2e-song"); + +// An inherited REPORTS_DIR / CHANNELS_DIR / SONG_DIR that is not the fixture's +// is refused before anything runs -- before the start-mode build, the fixture +// builder or a single spec (lib/e2eEnvGuard.mjs; 2 Nov a run wrote into +// ~/reports). +{ + const refusal = dataRootRefusal(process.env, FIXTURE); + if (refusal) throw new Error(refusal); +} + // The preflight's per-platform pacing, against the fixture's stub yt-dlp: 50 ms, // not the 30 s a real YouTube probe waits. On process.env, so the app server // and every worker (and the CLIs they spawn) inherit it. @@ -100,9 +113,6 @@ const APP_SERVER = // is in common/lib/ports.mjs (so scripts/worktree.mjs gives a worktree its own) // and in package.json's --ports spec (so the preflight sees it). const STUB_PORT = portFor("EDITOR_STUB_PORT"); -// The package is "type": "module", so there is no __dirname here. -const FIXTURE = path.join(path.dirname(fileURLToPath(import.meta.url)), ".e2e-song"); - // The suite NEVER runs against the real song dir. The tool writes to the same // files the CLI scripts do, and those hold thousands of real human verdicts -- // a spec that judged a clip would be indistinguishable from a person doing it.