commit b6b4be3e00b4ff773a3f88c872c990e0c408ea0c
parent 6b49a2f625d1cd44b6a079f76ea3ffcbf5cdeca7
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 13 Nov 2026 17:25:26 -0500
clip cap: the raw height index through writeFileAtomic; the eviction test in controller/
The atomic-file sweep refuses a hand-made temp name, and the layer test a
lib/ test importing controller/.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/common/controller/fetchWindowsTier.test.ts b/common/controller/fetchWindowsTier.test.ts
@@ -8,10 +8,11 @@
import { test } from "node:test";
import assert from "node:assert/strict";
-import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
+import { mkdir, mkdtemp, readFile, readdir, rm, stat, utimes, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { fetchWindows, type FetchWindowsDeps, type FetchWindowsItem } from "./fetchWindows";
+import { evictClipWindows } from "./evictClipWindows";
import type { Paths } from "../lib/paths";
import type { ChannelConfig } from "../lib/channelConfig";
import type { SiteSettings } from "../lib/settings";
@@ -193,3 +194,26 @@ test("with no ask, a held 720 window answers as always, unprobed, whatever the s
assert.equal(r.lower, undefined);
});
});
+
+// EVICTION sees a tiered window as a window of its span: named, covered and by
+// age, each with its own `.h<tier>.json` (and a set-aside tiered one too).
+test("eviction sees a tiered window as a window of its span: named, covered and by age, with its sidecar", async () => {
+ await withCorpus(async ({ paths, clips }) => {
+ await writeFile(path.join(paths.channelsDir, "c", "config.json"), JSON.stringify({ handling: "transcribe", platform: "youtube" }));
+ for (const n of ["10.00-20.00.mp4", "10.00-20.00.json", "10.00-20.00.h1080.mp4", "10.00-20.00.h1080.json", "30.00-40.00.h1080.desynced.mp4", "30.00-40.00.h1080.desynced.json", "50.00-60.00.mp4"]) {
+ await writeFile(path.join(clips, n), "media");
+ }
+ const old = new Date(Date.now() - 400 * 86_400_000);
+ await utimes(path.join(clips, "30.00-40.00.h1080.desynced.mp4"), old, old);
+ const named = await evictClipWindows({ paths, slug: "c", id: "v1", windows: [{ from: 10, to: 20 }], olderThanDays: 0 });
+ assert.equal(named.windows, 2);
+ assert.deepEqual((await readdir(clips)).sort(), [
+ "30.00-40.00.h1080.desynced.json",
+ "30.00-40.00.h1080.desynced.mp4",
+ "50.00-60.00.mp4",
+ ]);
+ const aged = await evictClipWindows({ paths, slug: "c", id: "v1", olderThanDays: 30 });
+ assert.equal(aged.windows, 1);
+ assert.deepEqual(await readdir(clips), ["50.00-60.00.mp4"]);
+ });
+});
diff --git a/common/lib/clipWindowTier.test.ts b/common/lib/clipWindowTier.test.ts
@@ -1,13 +1,13 @@
// THE HEIGHT TIER (lib/clipWindow.ts): a window asked above 720 is its own
// cache entry beside the plain one. The names, the listing, the one-probe
-// height record, the tall lookup's order, the taller-from-saved decision and
-// the eviction — temp dirs, stubbed probes, no media.
+// height record, the tall lookup's order and the taller-from-saved decision —
+// temp dirs, stubbed probes, no media. (Eviction: controller/fetchWindowsTier.test.ts.)
//
// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/clipWindowTier.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
-import { mkdir, mkdtemp, readFile, readdir, rm, stat, utimes, writeFile } from "node:fs/promises";
+import { mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import {
@@ -31,7 +31,6 @@ import { tallerFromSaved, NO_SAVED_COPY_WHY } from "./clipWindowTier-server";
import { evidenceCutArgs, fittedHeight } from "./evidenceClip-server";
import { resolveCorpusSource, windowsFromBareNames } from "./evidenceClip.mjs";
import { DEFAULT_CLIPS_SETTINGS, sanitizeClips, windowMaxHeightOf } from "./clipSettings";
-import { evictClipWindows } from "../controller/evictClipWindows";
import type { Paths } from "./paths";
import type { SavedWindowSource } from "./savedVideoWindow-server";
@@ -240,26 +239,6 @@ test("taller from the saved copy: only when the copy is taller than the window;
});
});
-test("eviction sees a tiered window as a window of its span: named, covered and by age, with its sidecar", async () => {
- await withVideo(async ({ clips, paths }) => {
- for (const n of ["10.00-20.00.mp4", "10.00-20.00.json", "10.00-20.00.h1080.mp4", "10.00-20.00.h1080.json", "30.00-40.00.h1080.desynced.mp4", "30.00-40.00.h1080.desynced.json", "50.00-60.00.mp4"]) {
- await put(clips, n);
- }
- const old = new Date(Date.now() - 400 * 86_400_000);
- for (const n of ["30.00-40.00.h1080.desynced.mp4"]) await utimes(path.join(clips, n), old, old);
- const named = await evictClipWindows({ paths, slug: "demo", id: "v1", windows: [{ from: 10, to: 20 }], olderThanDays: 0 });
- assert.equal(named.windows, 2);
- assert.deepEqual((await readdir(clips)).sort(), [
- "30.00-40.00.h1080.desynced.json",
- "30.00-40.00.h1080.desynced.mp4",
- "50.00-60.00.mp4",
- ]);
- const aged = await evictClipWindows({ paths, slug: "demo", id: "v1", olderThanDays: 30 });
- assert.equal(aged.windows, 1);
- assert.deepEqual(await readdir(clips), ["50.00-60.00.mp4"]);
- });
-});
-
test("a site's evidence lookup reads the plain window even beside a taller one; a tall ask reads the taller", async () => {
await withVideo(async ({ clips, root }) => {
await put(clips, "10.00-20.00.mp4");
diff --git a/umtool/report-to-video/sources.mjs b/umtool/report-to-video/sources.mjs
@@ -60,7 +60,8 @@
// root arrives as an argument (see umtool/lib/paths.mjs on why that matters to
// the Next build).
import path from "node:path";
-import { readFile, rename, stat, writeFile } from "node:fs/promises";
+import { readFile, stat } from "node:fs/promises";
+import { writeFileAtomic } from "yt-dlp-transcript-common/lib/atomicFile.mjs";
import {
AUDIO_ONLY_PLATFORMS,
CORPUS_TIERS,
@@ -189,9 +190,7 @@ export async function rawHeightOf(rawDir, w, probe = ffprobeSource) {
// Re-read just before the write: another build may have recorded others.
const now = await readRawHeights(rawDir);
now[w.name] = { bytes: st.size, mtimeMs: st.mtimeMs, height: h };
- const file = rawHeightsPath(rawDir);
- const tmp = `${file}.${process.pid}.tmp`;
- await writeFile(tmp, JSON.stringify(now, null, 2) + "\n").then(() => rename(tmp, file)).catch(() => {});
+ await writeFileAtomic(rawHeightsPath(rawDir), JSON.stringify(now, null, 2) + "\n").catch(() => {});
return h;
}