Archilyzer · Source

archilyzer

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

commit e28079bb6b32dd926c2de890e085774c52f2bad4
parent 5e10071f72436987ba11296acf3d4fa61ad6fbe1
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 27 Oct 2026 17:58:29 -0400

Take builds hold a lock and prune their project after; a render guards the disk

makeTake writes takes/<id>/.building.json (naming its --from take) for the
whole make, records `from` in take.json, and once the take is made prunes
the project's takes by its policy, the new take kept, with one line in the
take's log (UMTOOL_PRUNE_AFTER_BUILD=0 or "afterBuild": false turn it off;
it never fails the take). build-video writes <out>/.building.json while it
renders, and inside the heavy slot, before the render, runs the disk guard:
under UMTOOL_DISK_GUARD_GB (30) free it prunes every project's takes by
policy and says what that freed; under UMTOOL_DISK_FLOOR_GB (10) it refuses
the render with a sentence. The e2e suite turns both off.

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

Diffstat:
Mumtool/lib/report/takeMaker.mjs | 30++++++++++++++++++++++++++++++
Mumtool/lib/report/takePrune.test.mjs | 44++++++++++++++++++++++++++++++++++++++++++++
Mumtool/playwright.config.ts | 6++++++
Mumtool/report-to-video/build-video.mjs | 18+++++++++++++++++-
4 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/umtool/lib/report/takeMaker.mjs b/umtool/lib/report/takeMaker.mjs @@ -481,8 +481,35 @@ export async function linkSharedOut(projectDir, takeOut) { * batches are hard-linked in before the render (takeFrom.mjs), so the build * reuses whatever still matches. `keepFrames`: the build keeps its chrome * frames after the mux (build-video --keep-frames), for a later `from`. + * `pruneAfter: false`: no prune after the take is made (see below). + * + * While it builds, the take holds a build lock (`takes/<id>/.building.json`, + * naming `from`), so nothing prunes its work or its base's. Once it is made, + * the project's takes are pruned by its policy, this one kept, and what that + * freed is said in the log (takePrune.mjs; UMTOOL_PRUNE_AFTER_BUILD=0 or + * `"afterBuild": false` in takes/prune.json turns it off). */ export async function makeTake(projectDir, rawSpec, opts = {}) { + const prune = await import("./takePrune.mjs"); + let lockFile = null; + const onTakeDir = async (takeDir, id) => { + lockFile = await prune.writeBuildLock(takeDir, { take: id, from: opts.from ?? null }).catch(() => null); + }; + let r; + try { + r = await makeTakeLocked(projectDir, rawSpec, { ...opts, onTakeDir }); + } finally { + if (lockFile) await prune.removeBuildLock(lockFile); + } + if (!r.skipped && opts.pruneAfter !== false) { + const log = opts.log ?? (() => {}); + await prune.pruneAfterBuild(projectDir, { built: r.id, log: (line) => log(`${r.id}: ${line}`) }); + } + return r; +} + +/** makeTake's body; `onTakeDir` is called once the take's directory exists, before anything is linked or rendered. */ +async function makeTakeLocked(projectDir, rawSpec, opts) { const spec = checkSpec(rawSpec); const emit = opts.emit ?? (() => {}); const log = opts.log ?? (() => {}); @@ -543,6 +570,7 @@ export async function makeTake(projectDir, rawSpec, opts = {}) { if (spec.quick) renderDoc = /** @type {Record<string, any>} */ (mergePatch(renderDoc, QUICK_RENDER)); await mkdir(takeDir, { recursive: true }); + await opts.onTakeDir?.(takeDir, spec.id); const takeOut = path.join(takeDir, "out"); await (opts.ensureOut ?? ((d) => mkdir(d, { recursive: true })))(takeOut); const linked = await linkSharedOut(projectDir, takeOut); @@ -626,6 +654,8 @@ export async function makeTake(projectDir, rawSpec, opts = {}) { ...(spec.quick ? { quick: true } : {}), ...(covered ? { entries: { ids: covered.ids, basis: covered.basis } } : {}), baseHash: hashText(baseText), + // The take it was built from: the pruner keeps a kept take's base (takePrune.mjs). + ...(opts.from ? { from: opts.from } : {}), }; const tmp = `${takeFile}.tmp-${process.pid}`; await writeFile(tmp, JSON.stringify(doc, null, 2) + "\n", "utf8"); diff --git a/umtool/lib/report/takePrune.test.mjs b/umtool/lib/report/takePrune.test.mjs @@ -21,6 +21,7 @@ import { measurePaths, parseAge, planPrune, + pruneAfterBuild, pruneProject, readBuildLock, removeWorkPath, @@ -30,6 +31,7 @@ import { writeBuildLock, } from "./takePrune.mjs"; import { pruneCommand } from "./pruneCli.mjs"; +import { makeTake } from "./takeMaker.mjs"; import { framesOf, frameKeyOf } from "umtool-report-to-video/prune-frames"; const DAY = 24 * 3600 * 1000; @@ -384,6 +386,48 @@ test("the disk guard: above the threshold nothing happens; under it the policy r await assert.rejects(diskGuard({ dirs: ["/x"], env: { UMTOOL_DISK_GUARD_GB: "lots" }, free: async () => 1, pruneAll }), /not a number/); }); +test("after a take is made: its project pruned by the policy, the new take kept, said in its log; the lock held during the render", async () => { + const { dir, reports } = await root(); + await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: "fx", title: "Fx", render: { width: 64, height: 36, fps: 15 }, timeline: [{ type: "card", id: "k1", seconds: 2 }] }, null, 2) + "\n"); + const old = await mkTake(dir, "old", { builtAt: "2026-09-01T00:00:00Z" }); + const longAgo = new Date(Date.now() - 30 * DAY); + for (const f of ["take.json", "preview.mp4"]) await utimes(path.join(old, f), longAgo, longAgo); + await writeFile(path.join(dir, "takes", "prune.json"), JSON.stringify({ keep: 0 })); + const logs = []; + let lockDuring = null; + const render = async (job) => { + lockDuring = await readBuildLock(path.join(dir, "takes", "new", BUILD_LOCK)); + await mkdir(path.join(job.outDir, "sourced"), { recursive: true }); + const file = path.join(job.outDir, `${job.slug}.mp4`); + await writeFile(file, "render"); + return { file }; + }; + const r = await makeTake(dir, { id: "new", label: "New", window: "full" }, { render, probe: async () => 2, log: (l) => logs.push(l), from: null }); + assert.equal(r.skipped, false); + assert.equal(lockDuring?.pid, process.pid); + assert.equal(lockDuring?.take, "new"); + assert.equal(await readBuildLock(path.join(dir, "takes", "new", BUILD_LOCK)), null, "released after"); + assert.equal(await exists(path.join(old, "out", "sourced", "segments")), false, "the old take's work went"); + assert.ok(await exists(path.join(old, "preview.mp4"))); + assert.ok(logs.some((l) => /^new: prune: freed .* from 1 take\(s\): old/.test(l)), logs.join("\n")); + // Off in takes/prune.json: nothing pruned, nothing said. + const old2 = await mkTake(dir, "old2", { builtAt: "2026-09-01T00:00:00Z" }); + for (const f of ["take.json", "preview.mp4"]) await utimes(path.join(old2, f), longAgo, longAgo); + await writeFile(path.join(dir, "takes", "prune.json"), JSON.stringify({ keep: 0, afterBuild: false })); + logs.length = 0; + await makeTake(dir, { id: "new2", label: "New 2", window: "full" }, { render, probe: async () => 2, log: (l) => logs.push(l) }); + assert.ok(await exists(path.join(old2, "out", "sourced", "segments"))); + assert.equal(logs.some((l) => /prune:/.test(l)), false); + // pruneAfterBuild never throws: a bad policy file is said. + await writeFile(path.join(dir, "takes", "prune.json"), "{"); + const line = await pruneAfterBuild(dir, { built: "new", reportsRoot: reports }); + assert.match(line, /^prune: not run — .*does not parse/); + // A take made --from records it (what the pruner reads as its base). + await writeFile(path.join(dir, "takes", "prune.json"), JSON.stringify({ afterBuild: false })); + await makeTake(dir, { id: "twin", label: "Twin", window: "full" }, { render, probe: async () => 2, from: "new" }); + assert.equal(JSON.parse(await readFile(path.join(dir, "takes", "twin", "take.json"), "utf8")).from, "new"); +}); + test("the CLI: a dry run by default, --yes frees, --json, and its refusals", async () => { const { dir, reports } = await root(); await mkTake(dir, "a", { builtAt: "2026-09-01T00:00:00Z" }); diff --git a/umtool/playwright.config.ts b/umtool/playwright.config.ts @@ -49,6 +49,12 @@ process.env.E2E_AVAILABILITY_GAP_MS ??= "50"; // The same for a build's network clip fetches (report-to-video/build-video.mjs, // pacedClipFetch): 0 against the stub, not the real 30 s per clip. process.env.E2E_CLIP_FETCH_GAP_MS ??= "0"; +// No disk guard before a fixture's render (lib/report/takePrune.mjs): on a +// near-full disk it would prune the fixture's takes, or refuse the render, and +// a spec would fail for the machine, not the code. Nor the prune after a take +// is made: a spec that reads a take's out/ reads what its own steps left. +process.env.UMTOOL_DISK_GUARD ??= "0"; +process.env.UMTOOL_PRUNE_AFTER_BUILD ??= "0"; // START MODE BY DEFAULT, as the editor suite (plans/e2e-speed.md, S1): `next // dev` compiles each route on first use and again after a change, and the diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -6702,6 +6702,22 @@ async function renderSlot() { return withRenderSlot; } +// A render's two guards (umtool/lib/report/takePrune.mjs), loaded the same way +// as the gate: a build lock in its --out while it runs, so `umtool prune` (and +// a take build's own prune) leaves the work it is making alone; and, in the +// slot, right before the render starts, the disk guard -- under +// UMTOOL_DISK_GUARD_GB (30) free it prunes takes' work by each project's +// policy and says what that freed; still under UMTOOL_DISK_FLOOR_GB (10) the +// render is refused with a sentence. UMTOOL_DISK_GUARD=0 turns it off. +async function guardedRender(out, manifestPath, build) { + const href = new URL("../lib/report/takePrune.mjs", pathToFileURL(process.argv[1])).href; + const prune = await import(/* webpackIgnore: true */ href); + return prune.withBuildLock(out ? path.resolve(out) : null, { by: "build-video" }, async () => { + await prune.guardBeforeRender({ out, manifestPath, say: (message) => EMIT("note", { message }) }); + return build(); + }); +} + async function main() { const argv = process.argv.slice(2); const manifestPath = argv.find((a) => !a.startsWith("--")); @@ -6796,7 +6812,7 @@ async function main() { const fetchOnly = flag("--fetch-only"); const build = () => buildVideo({ manifestPath, opts, out: flag("--out"), only, fetchOnly }); const { failures } = takesHeavySlot({ opts, only, fetchOnly }) - ? await (await renderSlot())(["build-video", ...argv], build) + ? await (await renderSlot())(["build-video", ...argv], () => guardedRender(flag("--out"), manifestPath, build)) : await build(); // Non-zero on a partial run, so a caller that ignores the events still learns // the build did not produce what was asked for.