Archilyzer · Source

archilyzer

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

commit 89deae0e5fa49160dcf6f100f1cbd2cd7e02807c
parent 23beef0ef827fb1cf4d9c2b22ef2c42d3126776a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  9 Nov 2026 20:46:45 -0500

umtool: the rail's nits -- params decoded once, the usage index compared cheaply, the spec's CSRF and evict-by-file checks (L5 review 3)

The page uses Next's params as they come (already decoded). loadUsageIndex decides whether to write from what was parsed or dropped and an entry-by-entry dirIds compare, never a JSON.stringify of the whole index. ingredient-rail.spec: a foreign Origin is a 403, a text/plain body a 415, a keyless start a 400 the editor never hears; the evict asks by the window's file.

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

Diffstat:
Mumtool/app/ingredients/[channel]/[id]/page.tsx | 7++++---
Mumtool/e2e/ingredient-rail.spec.ts | 15++++++++++++++-
Mumtool/lib/ingredients/usedIn.mjs | 16++++++++++------
3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/umtool/app/ingredients/[channel]/[id]/page.tsx b/umtool/app/ingredients/[channel]/[id]/page.tsx @@ -20,13 +20,14 @@ type Search = { window?: string; stage?: string }; export async function generateMetadata({ params }: { params: Promise<Params> }): Promise<Metadata> { const { channel, id } = await params; - return { title: `${decodeURIComponent(channel)}/${decodeURIComponent(id)} · life cycle · umtool` }; + return { title: `${channel}/${id} · life cycle · umtool` }; } export default async function IngredientPage({ params, searchParams }: { params: Promise<Params>; searchParams: Promise<Search> }) { const { channel, id } = await params; - const ch = decodeURIComponent(channel); - const vid = decodeURIComponent(id); + // Next hands the segments over decoded already: decoding again would turn a literal % into something else. + const ch = channel; + const vid = id; if (!isChannelSlug(ch) || !isVideoId(vid)) notFound(); const search = await searchParams; const data = await readIngredient(ch, vid, typeof search.window === "string" ? search.window : null); diff --git a/umtool/e2e/ingredient-rail.spec.ts b/umtool/e2e/ingredient-rail.spec.ts @@ -191,7 +191,7 @@ test("each action asks first -- what it costs, the queue it lands on -- then pos expect(fetch.map((r) => !!r.dryRun)).toEqual([true, false]); expect(fetch[1].items?.map((i) => `${i.slug}/${i.id}#${i.clipId}`)).toEqual(["railchan/railvid#ra2"]); const evicts = railAsks("evict-clips").length; - await runAction(page, "evict-200.00-230.00", { cost: "disk" }); + await runAction(page, "evict-200.00-230.00.mp4", { cost: "disk" }); expect(railAsks("evict-clips").slice(evicts)).toMatchObject([{ slug: "railchan", id: "railvid", windows: ["200.00-230.00"] }]); // Published: umtool's own link check (/api/report/links) -- the site refuses at once, so the link is unverified. @@ -209,3 +209,16 @@ test("each action asks first -- what it costs, the queue it lands on -- then pos .poll(async () => ((await (await request.get("/api/jobs")).json()) as { running: unknown }).running, { timeout: 90_000 }) .toBeNull(); }); + +test("another site's page may not start an action: a foreign Origin is refused, and so is a body that is not JSON", async ({ request }) => { + const body = { action: "transcribe", ch: "railchan", id: "railvid", step: "plan" }; + const foreign = await request.post("/api/ingredients/action", { data: body, headers: { origin: "http://evil.example", "sec-fetch-site": "cross-site" } }); + expect(foreign.status()).toBe(403); + const form = await request.post("/api/ingredients/action", { data: JSON.stringify(body), headers: { "content-type": "text/plain" } }); + expect(form.status()).toBe(415); + // A start without the plan's key is refused before the editor is asked. + const asked = railAsks("transcribe-one").length; + const keyless = await request.post("/api/ingredients/action", { data: { ...body, step: "start" } }); + expect(keyless.status()).toBe(400); + expect(railAsks("transcribe-one").length).toBe(asked); +}); diff --git a/umtool/lib/ingredients/usedIn.mjs b/umtool/lib/ingredients/usedIn.mjs @@ -235,16 +235,20 @@ async function writeUsageIndex(file, index) { export async function loadUsageIndex({ reportsRoot, channelsDir, file = usageIndexPath(reportsRoot), write = true, walk, resolveDir }) { const previous = await readUsageIndex(file); const built = await buildUsageIndex({ reportsRoot, channelsDir, previous, ...(walk ? { walk } : {}), ...(resolveDir ? { resolveDir } : {}) }); - const changed = - !previous || - built.stats.parsed > 0 || - built.stats.dropped > 0 || - JSON.stringify(previous.byIngredient) !== JSON.stringify(built.index.byIngredient) || - JSON.stringify(previous.dirIds ?? {}) !== JSON.stringify(built.index.dirIds); + // byIngredient is a function of the files' clips and the directory ids alone: with no manifest parsed or + // dropped and the same directory answers, it is what was written -- no need to compare the whole index. + const changed = !previous || built.stats.parsed > 0 || built.stats.dropped > 0 || !sameDirIds(previous.dirIds, built.index.dirIds); if (write && changed) await writeUsageIndex(file, built.index).catch(() => {}); return { ...built, file, written: write && changed }; } +/** Do two dirIds maps agree, entry by entry? */ +function sameDirIds(a, b) { + const ka = Object.keys(a ?? {}); + if (ka.length !== Object.keys(b ?? {}).length) return false; + return ka.every((k) => b[k] && b[k].dir === a[k]?.dir && (b[k].dataMtimeMs ?? null) === (a[k]?.dataMtimeMs ?? null)); +} + /** * The rows for one ingredient. `id` may be either Rumble id: it is resolved to * its directory first (`dirId`, when the caller has it already).