Archilyzer · Source

archilyzer

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

commit cd2898b5f9acba890459fead66412abe15c2f466
parent e81a64843ce898b203e5f912dac24b120278799e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 24 Nov 2026 18:58:56 -0500

space-suggestions REVIEW-1 B1, B4: the click re-checks the row; no former-original confirm

The button refuses a scan older than a day ("rescan first"), then asks the
held predicate again, then each target file's size, mtime and single link, and
a channel-wide eviction's whole set of old windows; a mismatch refuses the row
and says why. A body whose slug, id or file is not one path segment is
refused. The header comment no longer claims every writer guards. The
dispatcher never sends the former-original confirm, and the page has no tick.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Meditor/app/cleanup/space/actions.ts | 4++--
Meditor/app/cleanup/space/components/SpaceRow.tsx | 11++---------
Meditor/app/cleanup/space/lib/runSpaceAction.test.ts | 32+++++++++++++++++++++-----------
Meditor/app/cleanup/space/lib/runSpaceAction.ts | 59+++++++++++++++++++++++++++++++++++++++++++++++++----------
4 files changed, 74 insertions(+), 32 deletions(-)

diff --git a/editor/app/cleanup/space/actions.ts b/editor/app/cleanup/space/actions.ts @@ -17,10 +17,10 @@ export async function startSpaceScanAction(): Promise<StreamActionResult> { export async function runSpaceSuggestionAction( key: string, - opts: { dryRun?: boolean; ticked?: boolean } = {}, + opts: { dryRun?: boolean } = {}, ): Promise<SpaceRunOutcome> { const result = await readSpaceSuggestions(getPaths()); - const out = await runSpaceSuggestion({ result, key, dryRun: opts.dryRun === true, ticked: opts.ticked === true }); + const out = await runSpaceSuggestion({ result, key, dryRun: opts.dryRun === true }); if (!out.dryRun && out.ok) safeRevalidate(["/cleanup", "/cleanup/space"]); return out; } diff --git a/editor/app/cleanup/space/components/SpaceRow.tsx b/editor/app/cleanup/space/components/SpaceRow.tsx @@ -17,7 +17,6 @@ type Outcome = { ok: boolean; lines: string[]; jobIds: string[]; dryRun: boolean export function SpaceRow({ s, diskLabel }: { s: SpaceSuggestion; diskLabel: Record<string, string> }) { const router = useRouter(); const [open, setOpen] = useState(false); - const [ticked, setTicked] = useState(false); const [preview, setPreview] = useState<Outcome | null>(null); const [done, setDone] = useState<Outcome | null>(null); const [pending, start] = useTransition(); @@ -26,7 +25,7 @@ export function SpaceRow({ s, diskLabel }: { s: SpaceSuggestion; diskLabel: Reco const run = (dryRun: boolean) => start(async () => { - const out = await runSpaceSuggestionAction(s.key, { dryRun, ticked }); + const out = await runSpaceSuggestionAction(s.key, { dryRun }); if (dryRun) setPreview(out); else { setDone(out); @@ -105,14 +104,8 @@ export function SpaceRow({ s, diskLabel }: { s: SpaceSuggestion; diskLabel: Reco )} </div> )} - {s.tick && ( - <label className="flex items-center gap-1.5"> - <input type="checkbox" checked={ticked} onChange={(e) => setTicked(e.target.checked)} /> - {s.tick} - </label> - )} <div className="flex gap-2"> - <Button size="xs" disabled={pending || (!!s.tick && !ticked)} onClick={() => run(false)}> + <Button size="xs" disabled={pending} onClick={() => run(false)}> Confirm </Button> <Button size="xs" variant="ghost" disabled={pending} onClick={() => setOpen(false)}> diff --git a/editor/app/cleanup/space/lib/runSpaceAction.test.ts b/editor/app/cleanup/space/lib/runSpaceAction.test.ts @@ -36,43 +36,53 @@ test("the scan's own body runs, each action in turn; a dry run only where the wr row({ key: "a", actions: [{ op: "evict-clips", body: { slug: "s", id: "v1", olderThanDays: 30 } }, { op: "evict-clips", body: { slug: "s", id: "v2", olderThanDays: 30 } }] }), row({ key: "b", kind: "compress-captions", actions: [{ op: "compress-text", body: { slugs: ["s"], kinds: ["captions"] } }] }), ]); - const out = await runSpaceSuggestion({ result: r, key: "a", dryRun: false, runners }); + const out = await runSpaceSuggestion({ result: r, key: "a", dryRun: false, runners, recheck: async () => null }); assert.equal(out.ok, true); assert.deepEqual(out.jobIds, ["job-evict-clips", "job-evict-clips"]); assert.deepEqual(calls.map((c) => c.body.id), ["v1", "v2"]); // evict-clips' dry run is a job of its own: not offered as a preview. - const pre = await runSpaceSuggestion({ result: r, key: "a", dryRun: true, runners }); + const pre = await runSpaceSuggestion({ result: r, key: "a", dryRun: true, runners, recheck: async () => null }); assert.equal(pre.ok, false); assert.match(pre.lines[0], /no dry run/); - const dry = await runSpaceSuggestion({ result: r, key: "b", dryRun: true, runners }); + const dry = await runSpaceSuggestion({ result: r, key: "b", dryRun: true, runners, recheck: async () => null }); assert.equal(dry.ok, true); assert.equal(calls.at(-1)!.dryRun, true); assert.deepEqual(calls.at(-1)!.body, { slugs: ["s"], kinds: ["captions"] }); }); -test("refusals: an unknown key, a row with only a link, a disabled row, a missing tick, an op with no runner", async () => { +test("refusals: an unknown key, a row with only a link, a disabled row, an op with no runner, a body of the wrong shape", async () => { const { calls, runners } = recorder(); const r = result([ row({ key: "link", link: { href: "/x", label: "x" } }), row({ key: "off", actions: [{ op: "relocate", body: { slugs: ["s"], locationId: "p" } }], disabled: "does not fit" }), - row({ key: "tick", actions: [{ op: "drop-saved-alternate", body: { slug: "s", id: "v", file: "f", confirmFormerOriginal: true } }], tick: "I mean the former original" }), row({ key: "odd", actions: [{ op: "rm-rf", body: {} }] }), + row({ key: "bad", actions: [{ op: "delete-file", body: { slug: "../etc", id: "v", file: "a.part" } }] }), + row({ key: "badfile", actions: [{ op: "delete-file", body: { slug: "s", id: "v", file: "x/../../y" } }] }), ]); for (const [key, re] of [ ["nope", /no suggestion "nope"/], ["link", /nothing to run here/], ["off", /does not fit/], - ["tick", /I mean the former original/], ["odd", /not a writer this page runs: rm-rf/], + ["bad", /not a channel slug/], + ["badfile", /not a file name/], ] as const) { - const out = await runSpaceSuggestion({ result: r, key, dryRun: false, runners }); + const out = await runSpaceSuggestion({ result: r, key, dryRun: false, runners, recheck: async () => null }); assert.equal(out.ok, false, key); assert.match(out.lines.join(" "), re, key); } assert.equal(calls.length, 0); - const ticked = await runSpaceSuggestion({ result: r, key: "tick", dryRun: false, ticked: true, runners }); - assert.equal(ticked.ok, true); - assert.equal(calls.length, 1); +}); + +test("the click re-checks the row first: a refusal runs nothing and says why; the former-original flag is never sent", async () => { + const { calls, runners } = recorder(); + const r = result([row({ key: "p", actions: [{ op: "delete-file", body: { slug: "s", id: "v", file: "a.part" } }] })]); + const out = await runSpaceSuggestion({ result: r, key: "p", dryRun: false, runners, recheck: async () => "the last scan is 30 h old: rescan first" }); + assert.equal(out.ok, false); + assert.match(out.lines[0], /rescan first/); + assert.equal(calls.length, 0); + const src = await import("node:fs/promises").then((fs) => fs.readFile(new URL("./runSpaceAction.ts", import.meta.url), "utf8")); + assert.ok(!src.includes("confirm" + "FormerOriginal")); }); test("a failing action stops the rest and says so", async () => { @@ -81,7 +91,7 @@ test("a failing action stops the rest and says so", async () => { const r = result([ row({ key: "p", actions: [{ op: "delete-file", body: { slug: "s", id: "v", file: "a.part" } }, { op: "delete-file", body: { slug: "s", id: "v", file: "a.ytdl" } }] }), ]); - const out = await runSpaceSuggestion({ result: r, key: "p", dryRun: false, runners }); + const out = await runSpaceSuggestion({ result: r, key: "p", dryRun: false, runners, recheck: async () => null }); assert.equal(out.ok, false); assert.deepEqual(out.lines, ["refused: drive not answering", "1 more not run"]); }); diff --git a/editor/app/cleanup/space/lib/runSpaceAction.ts b/editor/app/cleanup/space/lib/runSpaceAction.ts @@ -1,16 +1,26 @@ -import type { SpaceScanResult } from "yt-dlp-transcript-common/lib/spaceSuggestions"; +import type { SpaceScanResult, SpaceSuggestion } from "yt-dlp-transcript-common/lib/spaceSuggestions"; import type { StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; import { formatBytes } from "yt-dlp-transcript-common/lib/format"; +import { isValidChannelSlug } from "yt-dlp-transcript-common/controller/channels"; // THE PAGE'S BUTTON, ON THE SERVER. It names a suggestion by its key; what runs // is the `actions` the SCAN wrote for it (`pnpm ops <op> --json <body>`), each // through the same action its ops route calls — compress-text, the cleanup // sweeps, relocate, evict-clips, delete-file, compact-saved-videos, // drop-saved-alternate, kept-failed-encodes, live-recording-verify. Nothing -// else: an op not in the table is refused, and no body comes from the browser. -// The writer refuses whatever it refuses when it runs (a busy video, a drive -// not answering, a channel mid-move), so a stale scan cannot make it act on -// what it would not. +// else: an op not in the table is refused, no body comes from the browser, +// and a body of the wrong shape (a slug, an id or a file name that is not one +// path segment) is refused. +// +// THE WRITERS DO NOT ALL GUARD WHAT THIS PAGE PROMISES (review 1, B4): the +// Files list's delete, for one, asks no do-not-clean, recording, job or +// marker. So before anything runs the row is RE-CHECKED against the disk as +// it is now (controller/spaceHold.ts recheckSpaceRow): a scan older than a day +// is refused, then the held predicate (do-not-clean, a must-keep or +// unfinished live recording, a job for the video, a relocation marker of the +// channel or of the store), then each target file's size, mtime and single +// link, and a channel-wide eviction's whole set of old windows. A mismatch +// refuses the row and says why. // // NOT "use server" (every export there is an endpoint): actions.ts wraps it. @@ -87,7 +97,6 @@ export const SPACE_RUNNERS: Record<string, SpaceRunner> = { const r = await dropSavedAlternateAction(str(body.slug), str(body.id), str(body.file), { dryRun: o.dryRun, confirmOriginal: body.confirmOriginal === true, - confirmFormerOriginal: body.confirmFormerOriginal === true, }); if (!r.ok) return fail(r.error); const verb = r.result.dryRun ? "would free" : "freed"; @@ -113,21 +122,51 @@ export const SPACE_RUNNERS: Record<string, SpaceRunner> = { }, }; +// THE BODY'S SHAPE: every slug a channel slug, every id and file one path +// segment. The scan writes these; a file edited by hand is refused here. +const SEGMENT = /^(?!\.\.?$)[\w.-]+$/; +export function bodyShapeProblem(body: Record<string, unknown>): string | null { + const slugs = [body.slug, ...(Array.isArray(body.slugs) ? body.slugs : [])]; + const items = Array.isArray(body.items) ? (body.items as Record<string, unknown>[]) : []; + const clear = body.clear && typeof body.clear === "object" ? (body.clear as Record<string, unknown>) : null; + for (const it of [...items, ...(clear ? [clear] : [])]) slugs.push(it.slug); + for (const v of slugs) if (v !== undefined && (typeof v !== "string" || !isValidChannelSlug(v))) return `"${String(v)}" is not a channel slug`; + const ids = [body.id, ...items.map((i) => i.id), ...(clear ? [clear.id] : [])]; + for (const v of ids) if (v !== undefined && (typeof v !== "string" || !SEGMENT.test(v))) return `"${String(v)}" is not a video id`; + if (body.file !== undefined && (typeof body.file !== "string" || !SEGMENT.test(body.file))) return `"${String(body.file)}" is not a file name in one path segment`; + return null; +} + +// The click-time re-check (controller/spaceHold.ts), loaded lazily so a test +// that names its own never reaches the registry or the disk. +async function defaultRecheck(result: Pick<SpaceScanResult, "computedAt">, row: SpaceSuggestion): Promise<string | null> { + const { recheckSpaceRow, SpaceHolds } = await import("yt-dlp-transcript-common/controller/spaceHold"); + const { getPaths } = await import("yt-dlp-transcript-common/lib/paths"); + const paths = getPaths(); + return recheckSpaceRow({ paths, result, row, holds: new SpaceHolds(paths) }); +} + export async function runSpaceSuggestion(opts: { - result: Pick<SpaceScanResult, "suggestions"> | null; + result: Pick<SpaceScanResult, "suggestions" | "computedAt"> | null; key: string; dryRun: boolean; - ticked?: boolean; runners?: Record<string, SpaceRunner>; + recheck?: (row: SpaceSuggestion) => Promise<string | null>; }): Promise<SpaceRunOutcome> { const runners = opts.runners ?? SPACE_RUNNERS; const s = opts.result?.suggestions.find((x) => x.key === opts.key); - if (!s) return fail(`no suggestion "${opts.key}" in the last scan: refresh the page`); + if (!s || !opts.result) return fail(`no suggestion "${opts.key}" in the last scan: refresh the page`); if (!s.actions?.length) return fail(`nothing to run here: ${s.link ? `see ${s.link.label}` : "this row is for information"}`); if (s.disabled) return fail(s.disabled); - if (s.tick && !opts.ticked) return fail(`tick "${s.tick}" first`); const unknown = s.actions.find((a) => !runners[a.op]); if (unknown) return fail(`not a writer this page runs: ${unknown.op}`); + for (const a of s.actions) { + const bad = bodyShapeProblem(a.body); + if (bad) return fail(`refused: ${bad}`); + } + const result = opts.result; + const problem = await (opts.recheck ?? ((row: SpaceSuggestion) => defaultRecheck(result, row)))(s); + if (problem) return fail(`refused: ${problem}`); if (opts.dryRun && s.actions.some((a) => !SPACE_DRY_RUNNABLE.has(a.op))) { return fail(`${s.actions[0].op} has no dry run that answers here: the numbers above are the scan's`); }