commit a75c84c30db354f2fa821b23bc70ea47915bf98f
parent ea9c23650198f1798e4d94c5a7889a308a1ba0c2
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 10 Nov 2026 10:32:24 -0500
umtool: review fixes -- SONG_DIR allowed by the e2e guard, the draft import's refs checked, realpath, the --in-take hint's project
- lib/e2eEnvGuard.mjs: SONG_DIR is no longer refused -- it is the documented way to run the song-data specs
against a copy, and only the fixture builder reads it (to copy from). REPORTS_DIR and CHANNELS_DIR still are.
Paths are compared through realpath on both sides (a missing tail kept as written), so a worktree reached
through a symlinked parent is its own fixture.
- POST /api/report/takes/tools {op: "import"} with no take: draftImportArgv (takeImport.mjs) builds the argv
with every word checked -- a word starting with "-" is a 400 ("p:1 --take t1" would have taken the take-patch
path, "--as x" renamed the item), every word must parse as <project>:<item>[,…], the anchor is an entry id.
- posts --in-take: the deprecation line names the project inTakeCommand parsed, not a guess.
Tests: e2eEnvGuard.test.mjs (SONG_DIR=/elsewhere accepted, a symlinked parent either way round);
takeScope.test.mjs (draftImportArgv: argv as built, flags and malformed words refused).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
7 files changed, 112 insertions(+), 23 deletions(-)
diff --git a/umtool/app/api/report/takes/tools/route.ts b/umtool/app/api/report/takes/tools/route.ts
@@ -3,6 +3,7 @@ import { refuseCaller } from "@/lib/report/caller";
import { lintCommand } from "@/lib/report/lintCli.mjs";
import { takeCommand } from "@/lib/report/takeCli.mjs";
import { timelineCommand } from "@/lib/report/timelineCli.mjs";
+import { ImportRefused, draftImportArgv } from "@/lib/report/takeImport.mjs";
import { isTakeId, listTakes } from "@/lib/report/takes.mjs";
import { REPORTS_ROOT } from "@/lib/paths";
import { addStep } from "@/lib/queue/store.mjs";
@@ -91,10 +92,15 @@ export async function POST(request: Request) {
return Response.json({ exit: 0, queued: step.qid }, { headers: { "cache-control": "no-store" } });
}
if (body.op === "import" && !take) {
- const refs = typeof body.refs === "string" ? body.refs.trim() : "";
- if (!refs) return Response.json({ error: "import needs <project>:<item>[,<item>…]" }, { status: 400 });
- const place = typeof body.after === "string" && body.after ? ["--after", body.after] : typeof body.before === "string" && body.before ? ["--before", body.before] : [];
- const exit = await timelineCommand([project.id, "import-item", ...refs.split(/\s+/), ...place, ...(body.dryRun ? ["--dry-run"] : []), "--json"], { root: REPORTS_ROOT, out: io.log, err: io.err });
+ // Every word checked before it becomes argv (draftImportArgv): no flag rides in on the refs.
+ let argv: string[];
+ try {
+ argv = draftImportArgv(project.id, { refs: body.refs, after: body.after, before: body.before, dryRun: !!body.dryRun });
+ } catch (e) {
+ if (e instanceof ImportRefused) return Response.json({ error: e.message }, { status: 400 });
+ throw e;
+ }
+ const exit = await timelineCommand(argv, { root: REPORTS_ROOT, out: io.log, err: io.err });
return answer(exit);
}
if (!take) return Response.json({ error: `${String(body.op)} needs a take` }, { status: 400 });
diff --git a/umtool/lib/e2eEnvGuard.mjs b/umtool/lib/e2eEnvGuard.mjs
@@ -11,13 +11,31 @@
// 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`.
+//
+// SONG_DIR IS NOT ONE OF THEM. It is the documented way to run the song-data
+// specs against a copy (AGENTS.md; e2e/fixtures/make-fixture.mjs), and only the
+// fixture builder reads it -- READ-ONLY, to derive the empty-state copy and link
+// the heavy audio; the app server is given the fixture's own SONG_DIR after it.
+import { realpathSync } from "node:fs";
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"];
+export const INHERITED_DATA_ROOTS = ["REPORTS_DIR", "CHANNELS_DIR"];
+
+/** A path with its links resolved (a worktree reached through a symlinked parent), else as given. */
+const real = (p) => {
+ const abs = path.resolve(p);
+ try {
+ return realpathSync(abs);
+ } catch {
+ // Missing: resolve the nearest parent that exists, and keep the rest as written.
+ const parent = path.dirname(abs);
+ return parent === abs ? abs : path.join(real(parent), path.basename(abs));
+ }
+};
const inside = (p, root) => {
- const rel = path.relative(root, p);
+ const rel = path.relative(real(root), real(p));
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
};
@@ -27,10 +45,10 @@ const inside = (p, root) => {
* @param {string} fixture the suite's fixture directory (e2e/.e2e-song)
*/
export function foreignDataRoots(env, fixture) {
- const root = path.resolve(fixture);
+ const root = fixture;
return INHERITED_DATA_ROOTS.filter((name) => {
const v = env[name];
- return typeof v === "string" && v.trim() !== "" && !inside(path.resolve(v), root);
+ return typeof v === "string" && v.trim() !== "" && !inside(v, root);
}).map((name) => ({ name, value: env[name] }));
}
diff --git a/umtool/lib/e2eEnvGuard.test.mjs b/umtool/lib/e2eEnvGuard.test.mjs
@@ -1,4 +1,7 @@
import assert from "node:assert/strict";
+import { mkdir, mkdtemp, rm, symlink } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import path from "node:path";
import test from "node:test";
import { dataRootRefusal, foreignDataRoots } from "./e2eEnvGuard.mjs";
@@ -10,20 +13,39 @@ test("nothing set, or set empty, is the normal case", () => {
});
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);
+ assert.equal(dataRootRefusal({ CHANNELS_DIR: `${FIX}/channels`, 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"]);
+test("an inherited REPORTS_DIR or CHANNELS_DIR anywhere else is refused, naming each variable", () => {
+ const env = { REPORTS_DIR: "/home/u/reports", CHANNELS_DIR: "/home/u/transcripts/channels", HOME: "/home/u" };
+ assert.deepEqual(foreignDataRoots(env, FIX).map((b) => b.name), ["REPORTS_DIR", "CHANNELS_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/);
+ assert.match(msg, /CHANNELS_DIR=\/home\/u\/transcripts\/channels/);
+ assert.match(msg, /unset REPORTS_DIR CHANNELS_DIR/);
+});
+
+test("SONG_DIR elsewhere is accepted: the documented copy the fixture builder reads from, and nothing else sees", () => {
+ assert.equal(dataRootRefusal({ SONG_DIR: "/elsewhere/song-copy/data" }, FIX), null);
+ assert.deepEqual(foreignDataRoots({ SONG_DIR: "/elsewhere", REPORTS_DIR: "/home/u/reports" }, FIX).map((b) => b.name), ["REPORTS_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"]);
});
+
+test("a worktree reached through a symlinked parent is its own fixture, either way round", async () => {
+ const root = await mkdtemp(path.join(tmpdir(), "e2e-guard-"));
+ try {
+ const realFix = path.join(root, "real", "umtool", ".e2e-song");
+ await mkdir(path.join(realFix, "channels"), { recursive: true });
+ await symlink(path.join(root, "real"), path.join(root, "link"));
+ const viaLink = path.join(root, "link", "umtool", ".e2e-song");
+ assert.equal(dataRootRefusal({ CHANNELS_DIR: path.join(viaLink, "channels") }, realFix), null);
+ assert.equal(dataRootRefusal({ CHANNELS_DIR: path.join(realFix, "channels"), REPORTS_DIR: path.join(viaLink, "reports-not-yet") }, viaLink), null);
+ assert.deepEqual(foreignDataRoots({ REPORTS_DIR: path.join(root, "real", "elsewhere") }, viaLink).map((b) => b.name), ["REPORTS_DIR"]);
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs
@@ -456,12 +456,7 @@ export async function postsCommand(args, { root = REPORTS_ROOT, out = (s) => con
err(e instanceof Error ? e.message : String(e));
return 2;
}
- if (scoped) {
- const { takeEditDeprecation } = await import("./takeDeprecation.mjs");
- const proj = scoped.rest.filter((w) => !w.startsWith("--"))[1] ?? null;
- err(takeEditDeprecation(`posts ${scoped.verb ?? ""} --in-take`.replace(/\s+/g, " "), { project: proj, take: scoped.take }));
- return inTakeCommand(scoped, { root, out, err });
- }
+ if (scoped) return inTakeCommand(scoped, { root, out, err });
const words = [];
const flags = new Map();
const multis = new Map();
@@ -776,6 +771,8 @@ async function inTakeCommand({ verb, take, rest }, { root, out, err }) {
}
if (!words[1]) throw new CliError(`which project? umtool posts ${verb} <project> … --in-take ${take}`);
const project = await projectOf(words[1], root);
+ // Deprecated (L3 S6): it still lands, and says so in one line naming the project as parsed.
+ err((await import("./takeDeprecation.mjs")).takeEditDeprecation(`posts ${verb} --in-take`, { project: project.id, take }));
const { isTakeId, takesDirOf, TAKE_FILE } = await import("./takes.mjs");
if (!isTakeId(take)) throw new CliError(`"${take}" is not a take id (lower-case letters, digits, dashes)`);
if (!(await stat(path.join(takesDirOf(project.dir), take, TAKE_FILE)).catch(() => null))) {
diff --git a/umtool/lib/report/takeImport.mjs b/umtool/lib/report/takeImport.mjs
@@ -69,6 +69,36 @@ export function parseImportRef(ref) {
return items.length ? { project: s.slice(0, i), items } : null;
}
+/**
+ * The argv of `umtool timeline <project> import-item …` for a page's ask (POST /api/report/takes/tools, op
+ * "import" with no take), every word CHECKED: the refs are split on whitespace, and a word that starts with "-" is
+ * refused -- a flag smuggled in the refs ("p:1 --take t1" would take the take-patch path, "--as x" rename the
+ * item) -- as is any word that is not `<project>:<item>[,<item>…]`. The anchor is an entry id. Throws
+ * ImportRefused (the route's 400) saying which word and why.
+ *
+ * @param {string} projectId
+ * @param {{ refs?: unknown, after?: unknown, before?: unknown, dryRun?: unknown }} ask
+ * @returns {string[]}
+ */
+export function draftImportArgv(projectId, { refs, after = null, before = null, dryRun = false }) {
+ const words = typeof refs === "string" ? refs.trim().split(/\s+/).filter(Boolean) : [];
+ if (!words.length) throw new ImportRefused("import needs <project>:<item>[,<item>…]");
+ for (const w of words) {
+ if (w.startsWith("-")) throw new ImportRefused(`"${w}" is a flag, not an item: the refs are <project>:<item>[,<item>…] only`);
+ if (!parseImportRef(w)) throw new ImportRefused(`"${w}" is not <project>:<item>[,<item>…]`);
+ }
+ const anchor = (v, name) => {
+ if (v === null || v === undefined || v === "") return null;
+ const a = String(v);
+ if (!/^[A-Za-z0-9._:-]{1,120}$/.test(a) || a.startsWith("-")) throw new ImportRefused(`${name} "${a}" is not an entry id`);
+ return a;
+ };
+ const a = anchor(after, "after");
+ const b = anchor(before, "before");
+ if (a && b) throw new ImportRefused("after or before, not both");
+ return [projectId, "import-item", ...words, ...(a ? ["--after", a] : b ? ["--before", b] : []), ...(dryRun ? ["--dry-run"] : []), "--json"];
+}
+
/** The entry `ref` names in a timeline: its id, its post's id, or `p-<postId>`. */
export function findEntry(timeline, ref) {
const r = String(ref ?? "");
diff --git a/umtool/lib/report/takeScope.test.mjs b/umtool/lib/report/takeScope.test.mjs
@@ -16,7 +16,7 @@ import { TakeScopeRefused, withTakeScope } from "./takeScope.mjs";
import { updateRender } from "./manifest.mjs";
import { readManifest } from "../projects/report.mjs";
import { resolveTakeManifest } from "./takeManifest.mjs";
-import { postsInDateOrder, parseImportRef } from "./takeImport.mjs";
+import { ImportRefused, draftImportArgv, postsInDateOrder, parseImportRef } from "./takeImport.mjs";
import { lintCommand, namedFileProblems } from "./lintCli.mjs";
import { postsCommand } from "./postsCli.mjs";
import { takeCommand } from "./takeCli.mjs";
@@ -328,6 +328,21 @@ test("timeline import-item: items of another project INTO THE DRAFT -- cloned, f
assert.equal((await timeline("dimp-dst", "import-item", "dimp-src:p-99")).code, 1);
});
+test("draftImportArgv: a page's import ask becomes checked argv -- no flag rides in on the refs, every word a ref, the anchor an entry id", () => {
+ assert.deepEqual(draftImportArgv("p", { refs: " src:p-1,p-2 other/x:7 ", after: "p-1", dryRun: true }), ["p", "import-item", "src:p-1,p-2", "other/x:7", "--after", "p-1", "--dry-run", "--json"]);
+ assert.deepEqual(draftImportArgv("p", { refs: "src:p-1", before: "c02" }), ["p", "import-item", "src:p-1", "--before", "c02", "--json"]);
+ const refused = (ask, re) => assert.throws(() => draftImportArgv("p", ask), (e) => e instanceof ImportRefused && re.test(e.message));
+ refused({ refs: "src:p-1 --take t1" }, /"--take" is a flag, not an item/);
+ refused({ refs: "src:p-1 --as x" }, /"--as" is a flag/);
+ refused({ refs: "-x" }, /is a flag/);
+ refused({ refs: "src:p-1 t1" }, /"t1" is not <project>:<item>/);
+ refused({ refs: " " }, /import needs/);
+ refused({ refs: 7 }, /import needs/);
+ refused({ refs: "src:p-1", after: "--take" }, /after "--take" is not an entry id/);
+ refused({ refs: "src:p-1", before: "a b" }, /before "a b" is not an entry id/);
+ refused({ refs: "src:p-1", after: "a", before: "b" }, /not both/);
+});
+
test("--draft --from <take>: a draft that starts from another take's patch (a --patch over it), its timeline its own", async () => {
const a = await project("draft-from", [post("1", "2026-10-30T10:00:00.000Z"), post("2", "2026-10-30T11:00:00.000Z")]);
assert.equal((await take("draft-from", "--id", "base", "--label", "Base", "--draft", "--patch-json", JSON.stringify({ timeline: [post("2", "2026-10-30T11:00:00.000Z")], render: { posts: { slurs: { on: false } } } }))).code, 0);
diff --git a/umtool/playwright.config.ts b/umtool/playwright.config.ts
@@ -56,7 +56,8 @@ 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
+// An inherited REPORTS_DIR / CHANNELS_DIR that is not the fixture's (SONG_DIR is read only by
+// the fixture builder, and only to copy from: the documented way to run against a copy)
// 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).