Archilyzer · Source

archilyzer

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

commit 2975a8239fdfcd01496a03d5837c12205b1eef10
parent 5878590441d8294169e900a14891f47c1b41a83a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 10 Oct 2026 13:53:24 -0400

common, umtool: temp-dir tests no longer depend on the machine (release 24 H2)

attachMedia and preparePlayable take the store/root disk's free bytes as a
dep (`deps.freeBytes`, default getFreeBytes, as `probeDuration` and `probe`
are): their tests hand in plenty, and one test each judges the 2 GiB margin
with a fake. umtool's sources.test compares through the same tildify the code
applies, so a TMPDIR under $HOME passes. Product behaviour unchanged.

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

Diffstat:
Mcommon/controller/attachMedia.test.ts | 44++++++++++++++++++++++++++++++++++++++++++--
Mcommon/controller/attachMedia.ts | 5++++-
Mcommon/controller/preparePlayable.test.ts | 35++++++++++++++++++++++++++++++++++-
Mcommon/controller/preparePlayable.ts | 5++++-
Mumtool/lib/articles/sources.test.mjs | 20++++++++++++--------
5 files changed, 96 insertions(+), 13 deletions(-)

diff --git a/common/controller/attachMedia.test.ts b/common/controller/attachMedia.test.ts @@ -11,7 +11,12 @@ import { makeZip, type ZipFixtureEntry } from "../testing/makeZip"; import { loadSavedVideo } from "../lib/savedVideo-server"; import { savedVideoPath } from "../lib/savedVideo"; import { SAVED_VIDEOS_MARKER_FILENAME } from "../lib/savedVideoStore"; -import { attachMedia, parse7zListing, type AttachMediaOptions } from "./attachMedia"; +import { + ATTACH_MEDIA_DISK_MARGIN_BYTES, + attachMedia, + parse7zListing, + type AttachMediaOptions, +} from "./attachMedia"; // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test controller/attachMedia.test.ts // @@ -20,6 +25,7 @@ import { attachMedia, parse7zListing, type AttachMediaOptions } from "./attachMe // here; nothing reads a real archive or corpus. const SLUG = "demo"; +const PLENTY = 1024 ** 4; const sha = (b: Buffer) => createHash("sha256").update(b).digest("hex"); const bytes = (n: number, seed: number) => Buffer.from(Array.from({ length: n }, (_, i) => (i * seed + 3) & 0xff)); @@ -68,8 +74,16 @@ async function withFixture(fn: (ctx: Ctx) => Promise<void>, entries = ENTRIES): channelConfig: { name: "Demo", handling: "youtube", platform: "youtube" } as unknown as ChannelConfig, source: zip, onLog: (l) => lines.push(l), - deps: { probeDuration: async () => 61.5, now: () => new Date("2026-10-09T12:00:00Z") }, ...o, + // The store's free space is the fixture's, never the machine's (a /tmp + // tmpfs under 2 GiB free used to stop every attach): only the margin test + // below judges it. + deps: { + probeDuration: async () => 61.5, + now: () => new Date("2026-10-09T12:00:00Z"), + freeBytes: async () => PLENTY, + ...o.deps, + }, }); try { await fn({ dir, paths, zip, lines, opts }); @@ -249,6 +263,32 @@ test("guards: a store being moved stops the run; a store root that is not there }); }); +test("the disk margin: a store disk without the video plus 2 GiB free stops the run before any copy", async () => { + await withFixture(async ({ paths, opts, lines }) => { + const asked: string[] = []; + const r = await attachMedia( + opts({ + deps: { + freeBytes: async (dir) => { + asked.push(dir); + return ATTACH_MEDIA_DISK_MARGIN_BYTES + A.length - 1; + }, + }, + }), + ); + assert.deepEqual(r.attached, []); + assert.match(r.stopped ?? "", /^the store's disk has 2\.00 GB free; aaaaaaaaaaa needs 48\.8 KB plus 2\.00 GB$/); + assert.ok(lines.some((l) => /A re-run resumes/.test(l))); + assert.deepEqual(asked, [paths.savedVideosDir]); + assert.equal(await loadSavedVideo(videoDir(paths, "aaaaaaaaaaa")), null); + // One byte more and it attaches. + const ok = await attachMedia( + opts({ deps: { freeBytes: async () => ATTACH_MEDIA_DISK_MARGIN_BYTES + A.length } }), + ); + assert.deepEqual(ok.attached, ["aaaaaaaaaaa"]); + }); +}); + test("drain stops before the next video", async () => { await withFixture(async ({ opts }) => { const drain = new AbortController(); diff --git a/common/controller/attachMedia.ts b/common/controller/attachMedia.ts @@ -245,6 +245,9 @@ export type AttachMediaOptions = { now?: () => Date; probeDuration?: (file: string) => Promise<number | null>; openSource?: (source: string) => Promise<ArchiveSource>; + // The store disk's free bytes (default lib/diskSpace.ts getFreeBytes): + // a test names the disk it judges, never the machine's. + freeBytes?: (dir: string) => Promise<number>; }; }; @@ -418,7 +421,7 @@ export async function attachMedia(opts: AttachMediaOptions): Promise<AttachMedia onLog(`Stopped: ${result.stopped}`); break; } - const free = await getFreeBytes(storeRoot); + const free = await (opts.deps?.freeBytes ?? getFreeBytes)(storeRoot); if (free < media.size + ATTACH_MEDIA_DISK_MARGIN_BYTES) { result.stopped = `the store's disk has ${formatBytes(free)} free; ${id} needs ${formatBytes(media.size)} plus ${formatBytes(ATTACH_MEDIA_DISK_MARGIN_BYTES)}`; onLog(`Stopped: ${result.stopped}. A re-run resumes.`); diff --git a/common/controller/preparePlayable.test.ts b/common/controller/preparePlayable.test.ts @@ -10,6 +10,7 @@ import type { Paths } from "../lib/paths"; import type { ChannelConfig } from "../lib/channelConfig"; import { loadSavedVideo } from "../lib/savedVideo-server"; import { + PLAYABLE_DISK_MARGIN_BYTES, loadPlayableManifest, makePlayableTorrent, preparePlayable, @@ -76,8 +77,11 @@ async function withFixture(fn: (f: Fixture) => Promise<void>): Promise<void> { slug: SLUG, channelConfig: { name: "Demo", handling: "youtube", platform: "youtube" } as unknown as ChannelConfig, onLog: (l) => lines.push(l), - deps: { now: () => new Date("2026-10-09T12:00:00Z") }, ...o, + // The root's free space is the fixture's, never the machine's (a /tmp + // tmpfs under 2 GiB free used to stop every remux): only the margin test + // below judges it. + deps: { now: () => new Date("2026-10-09T12:00:00Z"), freeBytes: async () => 1024 ** 4, ...o.deps }, }); try { await fn({ dir, paths, root, opts, lines }); @@ -232,6 +236,35 @@ test("dryRun decides and writes nothing", { skip: !tools && "ffmpeg/ffprobe not }); }); +test("the disk margin: a root without the container plus 2 GiB free stops the run before any remux", async () => { + await withFixture(async ({ dir, paths, root, opts, lines }) => { + await writeFile(path.join(dir, "a.mp4"), Buffer.alloc(1000, 1)); + await saved(paths, "aaaaaaaaaaa", path.join(dir, "a.mp4"), "mp4"); + const asked: string[] = []; + let remuxes = 0; + const r = await preparePlayable( + opts({ + root, + deps: { + probe: async () => ({ formatName: "mov,mp4,m4a,3gp,3g2,mj2", ext: "mp4", vcodec: "h264", acodec: "aac" }), + remux: async () => { + remuxes += 1; + }, + freeBytes: async (d) => { + asked.push(d); + return PLAYABLE_DISK_MARGIN_BYTES + 999; + }, + }, + }), + ); + assert.deepEqual(r.prepared, []); + assert.equal(remuxes, 0); + assert.match(r.stopped ?? "", /^the playable root's disk has 2\.00 GB free; aaaaaaaaaaa needs about 1000 B plus 2\.00 GB$/); + assert.ok(lines.some((l) => /A re-run resumes/.test(l))); + assert.deepEqual(asked, [path.dirname(root)]); + }); +}); + test("the default root is playable/ beside the store's real directory; an absent drive refuses", async () => { await withFixture(async ({ dir, paths, opts }) => { await mkdir(paths.savedVideosDir, { recursive: true }); diff --git a/common/controller/preparePlayable.ts b/common/controller/preparePlayable.ts @@ -139,6 +139,9 @@ export type PreparePlayableOptions = { now?: () => Date; probe?: (file: string) => Promise<MediaProbe>; remux?: (src: string, dest: string, args: string[], signal?: AbortSignal) => Promise<void>; + // The playable root's free bytes (default lib/diskSpace.ts getFreeBytes): + // a test names the disk it judges, never the machine's. + freeBytes?: (dir: string) => Promise<number>; }; }; @@ -284,7 +287,7 @@ export async function preparePlayable(opts: PreparePlayableOptions): Promise<Pre result.prepared.push(id); continue; } - const free = await getFreeBytes(path.dirname(root)); + const free = await (opts.deps?.freeBytes ?? getFreeBytes)(path.dirname(root)); if (free < srcBytes + PLAYABLE_DISK_MARGIN_BYTES) { result.stopped = `the playable root's disk has ${formatBytes(free)} free; ${id} needs about ${formatBytes(srcBytes)} plus ${formatBytes(PLAYABLE_DISK_MARGIN_BYTES)}`; onLog(`Stopped: ${result.stopped}. A re-run resumes.`); diff --git a/umtool/lib/articles/sources.test.mjs b/umtool/lib/articles/sources.test.mjs @@ -7,7 +7,7 @@ import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; -import { clearSourcesCache, names, siteWorkspaces, sourceFor } from "./sources.mjs"; +import { clearSourcesCache, names, siteWorkspaces, sourceFor, tildify } from "./sources.mjs"; async function put(file, text) { await mkdir(path.dirname(file), { recursive: true }); @@ -38,23 +38,27 @@ async function fixture() { test("each layout finds its draft and generator", async () => { const root = await fixture(); const o = { reportsRoot: root }; + // sourceFor names a file the way a note shows it — `~/…` under the home + // directory — so the expectation goes through the same tildify, wherever + // TMPDIR puts the fixture. + const at = (rel) => tildify(path.join(root, rel)); const isr = await sourceFor("candalyzer", "polemic-israel", o); - assert.equal(isr.draft, path.join(root, "candace/polemics/drafts/israel.json")); - assert.equal(isr.generator, path.join(root, "candace/site/polemics.py")); + assert.equal(isr.draft, at("candace/polemics/drafts/israel.json")); + assert.equal(isr.generator, at("candace/site/polemics.py")); assert.match(isr.how, /draft matched by id polemic-israel/); const fc = await sourceFor("candalyzer", "deconstruction-fact-check", o); assert.equal(fc.draft, undefined); - assert.equal(fc.generator, path.join(root, "candace/site/make-report.py")); + assert.equal(fc.generator, at("candace/site/make-report.py")); const skg = await sourceFor("jasolyzer-private", "polemic-skg", o); - assert.equal(skg.draft, path.join(root, "pirate/polemics/drafts/skg.json")); - assert.equal(skg.generator, path.join(root, "pirate/polemics/make-site.py")); + assert.equal(skg.draft, at("pirate/polemics/drafts/skg.json")); + assert.equal(skg.generator, at("pirate/polemics/make-site.py")); // The decoy's draft id is exactly `blame`, but its workspace never names the site. const blame = await sourceFor("jeralyzer-private", "blame", o); - assert.equal(blame.draft, path.join(root, "quartering/polemics/drafts/blame.json")); - assert.equal(blame.generator, path.join(root, "quartering/polemics/make-site.py")); + assert.equal(blame.draft, at("quartering/polemics/drafts/blame.json")); + assert.equal(blame.generator, at("quartering/polemics/make-site.py")); assert.match(blame.how, /preferred over 1 other/); assert.equal(await sourceFor("candalyzer", "no-such-report", o), null);