// A STALLED DRIVE IS NOT ASKED: every page-and-poll path that would touch a // storage location's drive in-process asks the health state first // (lib/storageHealth.ts) and, on a stalled location, answers WITHOUT the call. // // RELEASE 17, THE MEDIA TIER: a relocated channel's TEXT is on the corpus disk // and only its media is on the drive (`channels//media` -> the drive, // one relative link per big file in `data//`). So a stalled drive holds // what opens a big file and nothing that reads text: the channel's counts, // its recency, its snapshot are read as usual, with no call on the drive. The // cases that need a channel whose TEXT is on the drive use the retired // whole-directory layout (`seedLegacy`), the one layout where it still is. // // No test stalls a real drive. The drive here is an ordinary temp directory // that answers every call at once; the health state is TOLD it is stalled. // Every node:fs and node:fs/promises call this file's code makes is recorded // (the buildIndex.test.ts spy, reads included), so a gate that let one call // through shows up as a recorded path under the drive — it cannot hide behind // a call that happened to answer quickly. // // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test controller/storageStall.test.ts import { after, beforeEach, test } from "node:test"; import assert from "node:assert/strict"; import { createRequire, syncBuiltinESMExports } from "node:module"; import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, symlinkSync, writeFileSync, } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import type { Paths } from "../lib/paths"; import type { StorageLocation } from "../lib/storageLocations"; import { assertChannelMediaReachable, ChannelMediaUnreachableError, ChannelTextUnreadableError, CHANNEL_MEDIA_MEMO_MS, clearRelocationMarker, forgetChannelMedia, inspectChannelMedia, } from "../lib/channelMedia"; import { HELD_REASON, isMediaHeld } from "../lib/channelMediaHold"; import { locationHealth, recordLocationHealth, registerLocationHealth, resetStorageHealth, setDriveCallBudget, } from "../lib/storageHealth"; import { probeLocation, probeLocationMemo, resetStorageProbeMemo, } from "../lib/storageVolumes"; import { volumeFreeBytes } from "./storageLocations"; import { readChannelStat } from "./channels"; import { buildRecencyKeys, clearRecencyCache } from "./recencyIndex"; import { relocationRootPresenceProblem } from "./relocateChannelMedia"; import { generateChannelSnapshot } from "./channelSnapshot"; import { inspectSavedVideosStore } from "./relocateSavedVideos"; import { listSavedVideos } from "./savedVideoInventory"; import type { SiteSettings } from "../lib/settings"; // ── the spy ──────────────────────────────────────────────────────────────── type Call = { fn: string; path: string }; let calls: Call[] = []; // THE HANG: a promise-API call whose (function, path) matches never settles — // what a read blocked on a stalled drive looks like from here. Recorded like // any other call. No drive is involved. let hang: ((c: Call) => boolean) | null = null; { const req = createRequire(import.meta.url); const fsCjs = req("node:fs") as Record; const fspCjs = req("node:fs/promises") as Record; const NAMES = [ "access", "appendFile", "chmod", "copyFile", "cp", "lstat", "mkdir", "open", "opendir", "readdir", "readFile", "readlink", "realpath", "rename", "rm", "rmdir", "stat", "statfs", "symlink", "unlink", "utimes", "writeFile", ]; const asPath = (v: unknown) => typeof v === "string" ? v : v instanceof URL ? fileURLToPath(v) : Buffer.isBuffer(v) ? v.toString() : null; const wrap = (mod: Record, name: string, promises = false) => { const fn = mod[name]; if (typeof fn !== "function") return; mod[name] = function (this: unknown, ...args: unknown[]) { const p = asPath(args[0]); if (p !== null) { const call = { fn: name, path: path.resolve(p) }; calls.push(call); if (promises && hang?.(call)) return new Promise(() => {}); } return (fn as (...a: unknown[]) => unknown).apply(this, args); }; }; for (const n of NAMES) { wrap(fspCjs, n, true); wrap(fsCjs, n); wrap(fsCjs, `${n}Sync`); } wrap(fsCjs, "existsSync"); wrap(fsCjs, "createReadStream"); syncBuiltinESMExports(); } // ── the corpus and the drive ─────────────────────────────────────────────── const ROOT = mkdtempSync(path.join(tmpdir(), "ttb-stall-")); after(() => rmSync(ROOT, { recursive: true, force: true })); const CORPUS = path.join(ROOT, "corpus"); const DRIVE = path.join(ROOT, "drive"); const SLUG = "on-drive"; const paths = { transcriptsDir: CORPUS, channelsDir: path.join(CORPUS, "channels"), lmdbPath: path.join(CORPUS, "index.mdb"), savedVideosDir: path.join(CORPUS, "saved-videos"), jobsDir: path.join(CORPUS, "jobs"), // A findmnt that leaves a mark if anything runs it. findmntBin: path.join(ROOT, "findmnt-ran.sh"), udisksctlBin: path.join(ROOT, "no-udisksctl"), } as unknown as Paths; const LOC: StorageLocation = { id: "usb", label: "USB drive", root: DRIVE, autoRepoint: false, }; // The media tier on the drive, and its one link: channels//media. const TARGET = path.join(DRIVE, SLUG, "media"); const LINK = path.join(paths.channelsDir, SLUG, "media"); // The text, on the corpus disk; vid1's audio is a tiered link into media/. const DATA = path.join(paths.channelsDir, SLUG, "data"); const TIERED = path.join(DATA, "vid1", "audio.mp3"); const CONFIG = { mediaDir: TARGET }; // The retired layout: data/ itself a link to the drive. const LEGACY_TARGET = path.join(DRIVE, SLUG, "data"); const LEGACY_CONFIG = { dataDir: LEGACY_TARGET }; let legacy = false; const FINDMNT_MARK = path.join(ROOT, "findmnt-ran"); function writeConfig(extra: Record): void { writeFileSync( path.join(paths.channelsDir, SLUG, "config.json"), JSON.stringify({ handling: "youtube", name: SLUG, url: `https://www.youtube.com/@${SLUG}/videos`, ...extra, }), ); } function seed(): void { legacy = false; rmSync(CORPUS, { recursive: true, force: true }); rmSync(DRIVE, { recursive: true, force: true }); mkdirSync(path.join(DATA, "vid1"), { recursive: true }); writeFileSync( path.join(DATA, "vid1", "metadata.info.json"), JSON.stringify({ id: "vid1", upload_date: "20260601" }), ); writeFileSync(path.join(DATA, "vid1", "transcript.en.vtt"), "WEBVTT\n"); mkdirSync(path.join(TARGET, "vid1"), { recursive: true }); writeFileSync(path.join(TARGET, "vid1", "audio.mp3"), "AUDIO"); symlinkSync(path.join("..", "..", "media", "vid1", "audio.mp3"), TIERED); writeConfig({ mediaDir: TARGET }); symlinkSync(TARGET, LINK); writeFileSync(paths.findmntBin, `#!/bin/sh\ntouch ${FINDMNT_MARK}\nexit 1\n`, { mode: 0o755, }); rmSync(FINDMNT_MARK, { force: true }); } // The channel on the retired layout: its whole data/ on the drive, `data` an // absolute link to it, `dataDir` recorded (and no media tier). function seedLegacy(): void { rmSync(LINK); rmSync(TIERED); writeFileSync(path.join(DATA, "vid1", "audio.mp3"), "AUDIO"); renameSync(DATA, LEGACY_TARGET); symlinkSync(LEGACY_TARGET, DATA); writeConfig({ dataDir: LEGACY_TARGET }); legacy = true; } // Anything that reaches the drive: a path under its root; through the media // link; a tiered file opened or statted through its link (an lstat or a // readlink of the link itself is on the corpus disk); and, on the legacy // layout, anything through `data/`. function onDrive(c: Call): boolean { const under = (p: string, base: string) => p === base || p.startsWith(base + path.sep); if (under(c.path, DRIVE) || under(c.path, LINK)) return true; const ofTheLink = ["lstat", "lstatSync", "readlink", "readlinkSync"].includes(c.fn); if (c.path === TIERED && !ofTheLink) return true; return legacy && under(c.path, DATA) && !(c.path === DATA && ofTheLink); } function stall(): void { recordLocationHealth(LOC, "stalled", { now: Date.now() }); } beforeEach(() => { hang = null; setDriveCallBudget(); resetStorageHealth(); forgetChannelMedia(); resetStorageProbeMemo(); clearRecencyCache(); seed(); calls = []; }); // ── inspectChannelMedia: the gate and the memo ───────────────────────────── const MARKER = path.join(paths.channelsDir, SLUG, ".relocating.json"); test("inspect with the config in hand: on a stalled drive only the marker is read, on the corpus disk", async () => { stall(); calls = []; const media = await inspectChannelMedia(paths, SLUG, CONFIG); assert.deepEqual(calls, [ { fn: "lstat", path: DATA }, { fn: "readFile", path: MARKER }, ]); assert.deepEqual(calls.filter(onDrive), []); assert.equal(media.status, "stalled"); assert.equal(media.target, TARGET); assert.match(String(media.detail), /^drive not answering \(location "USB drive", since /); // Held for the media, with a reason that names no path — and its text is // readable, so the builds do not hold it (release 17). assert.equal(isMediaHeld(media.status), true); assert.equal(media.text.readable, true); assert.doesNotMatch(HELD_REASON.stalled, /\//); }); test("inspect without the config reads config.json and nothing on the drive", async () => { stall(); calls = []; const media = await inspectChannelMedia(paths, SLUG); assert.equal(media.status, "stalled"); assert.deepEqual( calls.map((c) => [c.fn, path.relative(ROOT, c.path)]), [ ["readFile", path.join("corpus", "channels", SLUG, "config.json")], ["lstat", path.join("corpus", "channels", SLUG, "data")], ["readFile", path.join("corpus", "channels", SLUG, ".relocating.json")], ], ); }); test("the marker first: a channel mid-move on a stalled drive reads in-transition", async () => { writeFileSync( MARKER, JSON.stringify({ target: TARGET, direction: "back", startedAt: "", phase: "copy" }), ); stall(); calls = []; const media = await inspectChannelMedia(paths, SLUG, CONFIG); assert.equal(media.status, "in-transition"); assert.deepEqual(calls.filter(onDrive), []); // Remembered as a move: a second look within five seconds gives the move // back, not the stall. const again = await inspectChannelMedia(paths, SLUG, CONFIG); assert.equal(again.status, "in-transition"); }); test("the start-of-work guard refuses a stalled channel without a call", async () => { stall(); calls = []; await assert.rejects( () => assertChannelMediaReachable(paths, SLUG, CONFIG), (err: unknown) => err instanceof ChannelMediaUnreachableError && err.status === "stalled" && /drive not answering/.test(err.message), ); assert.deepEqual(calls.filter(onDrive), []); }); test("the memo: two inspects within 5 s stat the drive once; fresh and age each ask again", async () => { const t0 = 1_000_000; const targetStats = () => calls.filter((c) => c.fn === "stat" && c.path === TARGET).length; const a = await inspectChannelMedia(paths, SLUG, CONFIG, { now: t0 }); assert.equal(a.status, "ok"); assert.equal(targetStats(), 1); const b = await inspectChannelMedia(paths, SLUG, CONFIG, { now: t0 + 4_999 }); assert.equal(b.status, "ok"); assert.equal(targetStats(), 1, "a second inspect inside five seconds is remembered"); await inspectChannelMedia(paths, SLUG, CONFIG, { now: t0 + 4_999, fresh: true }); assert.equal(targetStats(), 2, "fresh bypasses the memo"); await inspectChannelMedia(paths, SLUG, CONFIG, { now: t0 + CHANNEL_MEDIA_MEMO_MS }); assert.equal(targetStats(), 3, "an answer five seconds old is asked again"); // A fresh answer is not remembered: the memo still holds the one from t0+5000. await inspectChannelMedia(paths, SLUG, CONFIG, { now: t0 + CHANNEL_MEDIA_MEMO_MS + 1 }); assert.equal(targetStats(), 3); }); test("the memo is keyed by the configured target, and a mover's forget clears it", async () => { const now = 2_000_000; const targetStats = () => calls.filter((c) => c.fn === "stat" && c.path === TARGET).length; await inspectChannelMedia(paths, SLUG, CONFIG, { now }); // Another configured target is another key. const other = await inspectChannelMedia(paths, SLUG, { mediaDir: path.join(DRIVE, "x", "media") }, { now }); assert.equal(other.status, "inconsistent"); forgetChannelMedia(SLUG); await inspectChannelMedia(paths, SLUG, CONFIG, { now }); assert.equal(targetStats(), 2); // clearRelocationMarker (the operator's last resort) forgets too. await clearRelocationMarker(paths, SLUG); await inspectChannelMedia(paths, SLUG, CONFIG, { now }); assert.equal(targetStats(), 3); }); test("the gate is asked before the memo: a stall is seen with an ok remembered", async () => { const now = 3_000_000; assert.equal((await inspectChannelMedia(paths, SLUG, CONFIG, { now })).status, "ok"); stall(); calls = []; const media = await inspectChannelMedia(paths, SLUG, CONFIG, { now: now + 1 }); assert.equal(media.status, "stalled"); assert.deepEqual(calls, []); }); // ── the other gated callers ──────────────────────────────────────────────── test("probeLocation and its memo: 'stalled', with no stat, no statfs and no findmnt", async () => { // A remembered "available" first, so the memo's gate is the thing tested. await probeLocationMemo(LOC, paths); rmSync(FINDMNT_MARK, { force: true }); stall(); calls = []; const direct = await probeLocation(LOC, paths); const memo = await probeLocationMemo(LOC, paths); assert.equal(direct.status, "stalled"); assert.equal(memo.status, "stalled"); assert.deepEqual(direct.identity, { known: false }); assert.equal(direct.freeBytes, undefined); assert.deepEqual(calls.filter(onDrive), []); assert.equal(existsSync(FINDMNT_MARK), false, "findmnt was not run"); }); test("volumeFreeBytes: a stalled location reads unknown, with no call on it", async () => { stall(); calls = []; const out = await volumeFreeBytes({ paths, locations: [LOC] }); assert.equal(out.usb, undefined); assert.equal(typeof out.internal, "number"); assert.deepEqual(calls.filter(onDrive), []); }); test("readChannelStat: a stalled MEDIA drive does not stop the count, and is not asked", async () => { const before = await readChannelStat(paths, SLUG); assert.equal(before?.videoCount, 1); assert.equal(before?.downloadCount, 1); stall(); calls = []; const during = await readChannelStat(paths, SLUG); assert.equal(during?.videoCount, 1); assert.equal(during?.downloadCount, 1, "the tiered audio is a name in the listing"); assert.deepEqual(calls.filter(onDrive), []); }); test("readChannelStat: no walk of a LEGACY channel's data/ on a stalled drive", async () => { seedLegacy(); const before = await readChannelStat(paths, SLUG); assert.equal(before?.videoCount, 1); stall(); calls = []; assert.equal(await readChannelStat(paths, SLUG), null); assert.deepEqual(calls.filter(onDrive), []); }); test("recency: a stalled MEDIA drive does not stop the tail read (metadata is text)", async () => { const args = { paths, meta: [{ slug: SLUG, config: CONFIG }], candidateIds: new Set(["vid1"]), owner: new Map([["vid1", SLUG]]), interpolate: false, fresh: true, }; stall(); calls = []; const keys = await buildRecencyKeys(args); assert.deepEqual(keys.get("vid1"), { key: "20260601", estimated: false }); assert.deepEqual(calls.filter(onDrive), []); }); test("recency: no tail read on a LEGACY channel's stalled drive, and no miss remembered for it", async () => { seedLegacy(); const owner = new Map([["vid1", SLUG]]); const meta = [{ slug: SLUG, config: LEGACY_CONFIG }]; const args = { paths, meta, candidateIds: new Set(["vid1"]), owner, interpolate: false, fresh: true, }; stall(); calls = []; const stalledKeys = await buildRecencyKeys(args); assert.deepEqual(calls.filter(onDrive), []); // Layer 4: an undatable id sorts oldest. assert.deepEqual(stalledKeys.get("vid1"), { key: "", estimated: false }); // The drive answers again: the same id is read now, because the stall was // not remembered as a miss. resetStorageHealth(); const keys = await buildRecencyKeys(args); assert.deepEqual(keys.get("vid1"), { key: "20260601", estimated: false }); assert.ok(calls.some((c) => c.fn === "open" && onDrive(c))); }); test("a move onto a stalled location is refused without a stat of its root", async () => { stall(); calls = []; const problem = await relocationRootPresenceProblem( DRIVE, { locations: [LOC], defaultLocationId: "" }, paths, ); assert.match(String(problem), /drive not answering/); assert.match(String(problem), /location "usb"/); assert.deepEqual(calls.filter(onDrive), []); }); test("a snapshot refresh of a stalled-MEDIA channel is written from its text; its media bytes are unknown", async () => { const ok = await generateChannelSnapshot(paths, SLUG); assert.equal(ok.totalMediaBytes, 5, "the tiered audio, statted through its link"); assert.equal(typeof ok.totalTextBytes, "number"); stall(); calls = []; const snap = await generateChannelSnapshot(paths, SLUG); assert.deepEqual(calls.filter(onDrive), []); assert.equal(snap.totals.downloaded, 1); assert.equal("totalMediaBytes" in snap, false, "unknown, never 0"); assert.equal("totalAudioBytes" in snap, false); assert.equal(typeof snap.totalTextBytes, "number"); const onDisk = JSON.parse( readFileSync(path.join(paths.channelsDir, SLUG, "snapshot.json"), "utf8"), ) as { totalMediaBytes?: number }; assert.equal(onDisk.totalMediaBytes, undefined); }); test("a snapshot refresh of a LEGACY channel throws before its walk", async () => { seedLegacy(); stall(); calls = []; await assert.rejects( () => generateChannelSnapshot(paths, SLUG), (err: unknown) => err instanceof ChannelTextUnreadableError && err.status === "legacy", ); assert.deepEqual(calls.filter(onDrive), []); }); test("the saved-video store on a stalled drive reads unreachable, without a stat through its link", async () => { const storeTarget = path.join(DRIVE, "saved-videos"); mkdirSync(storeTarget, { recursive: true }); symlinkSync(storeTarget, paths.savedVideosDir); const settings = { storage: { locations: [LOC], defaultLocationId: "", savedVideosLocationId: "usb" }, } as unknown as SiteSettings; assert.equal((await inspectSavedVideosStore(paths, settings)).status, "ok"); stall(); calls = []; const store = await inspectSavedVideosStore(paths, settings); assert.equal(store.status, "unreachable"); assert.match(String(store.detail), /^drive not answering \(location "USB drive"/); const followed = calls.filter( (c) => onDrive(c) || (c.path.startsWith(paths.savedVideosDir) && !["lstat", "readlink"].includes(c.fn)), ); assert.deepEqual(followed, []); }); test("the saved-video inventory, for a page: a stalled LEGACY channel is named, not read", async () => { // A saved video on the drive, so a channel that WAS read has an entry. // (savedVideoInventory reads through fs-extra, whose functions graceful-fs // captured before this file's spy was installed, so this case proves the skip // by what comes back, not by the spy.) The pointer is text: only on the // retired layout is it on the drive at all. seedLegacy(); writeFileSync( path.join(LEGACY_TARGET, "vid1", "saved-video.json"), JSON.stringify({ storedAt: "", dir: "/store", file: "v.mp4", bytes: 7 }), ); assert.equal((await listSavedVideos({ paths, notAnswering: [] })).length, 1); stall(); const notAnswering: string[] = []; assert.deepEqual(await listSavedVideos({ paths, notAnswering }), []); assert.deepEqual(notAnswering, [SLUG]); // Without the array (the backup job) nothing is skipped: it reads the drive. assert.equal((await listSavedVideos({ paths })).length, 1); }); // ── the watchdog: a call that does not answer in the budget ──────────────── // The location is registered (the health pass does that in the editor) but // answering; the hang makes one call on the drive never settle. The budget is // shortened to 100 ms; lib/storageHealth.test.ts holds the 3 s default. function hangOnDrive(fns: string[]): void { hang = (c) => fns.includes(c.fn) && onDrive(c); } async function watchdogCase( fns: string[], run: () => Promise, ): Promise { registerLocationHealth([LOC]); setDriveCallBudget(100); hangOnDrive(fns); calls = []; const started = Date.now(); const out = await run(); assert.ok(Date.now() - started < 2_000, "answered on the watchdog, not on the drive"); assert.equal(locationHealth("usb")?.state, "stalled", "the location is marked at once"); assert.match(String(locationHealth("usb")?.cause), /a read in the editor did not answer/); return out; } test("watchdog: inspect's target stat never answers → stalled, marked, and nothing more is asked of the drive", async () => { const media = (await watchdogCase(["stat"], () => inspectChannelMedia(paths, SLUG, CONFIG), )) as { status: string; detail?: string }; assert.equal(media.status, "stalled"); assert.match(String(media.detail), /^drive not answering \(location "USB drive"/); // The next inspect, the guard and the walk make no call on the drive — and // the walk, which reads text, still counts (release 17). calls = []; assert.equal((await inspectChannelMedia(paths, SLUG, CONFIG)).status, "stalled"); await assert.rejects(() => assertChannelMediaReachable(paths, SLUG, CONFIG)); assert.equal((await readChannelStat(paths, SLUG))?.videoCount, 1); assert.deepEqual(calls.filter(onDrive), []); // Cleared (two clean answers), the drive is asked again. recordLocationHealth(LOC, "ok"); recordLocationHealth(LOC, "ok"); hang = null; assert.equal( (await inspectChannelMedia(paths, SLUG, CONFIG, { fresh: true })).status, "ok", ); }); test("watchdog: a LEGACY video directory's read never answers mid-walk → readChannelStat answers null", async () => { seedLegacy(); for (const id of ["vid2", "vid3", "vid4", "vid5", "vid6"]) { mkdirSync(path.join(LEGACY_TARGET, id), { recursive: true }); } const out = await watchdogCase(["readdir"], async () => { // The walk's first readdir (of data/ itself, through the link) answers; // the video directories' do not. hang = (c) => c.fn === "readdir" && c.path.startsWith(path.join(DATA, "vid")); return readChannelStat(paths, SLUG); }); assert.equal(out, null); // At most four video directories were asked before the stall refused the rest. const asked = calls.filter((c) => c.fn === "readdir" && c.path.startsWith(path.join(DATA, "vid"))); assert.ok(asked.length <= 4, `${asked.length} video dirs asked`); }); test("watchdog: probeLocation's stat never answers → 'stalled'", async () => { const probe = (await watchdogCase(["stat"], () => probeLocation(LOC, paths))) as { status: string; }; assert.equal(probe.status, "stalled"); }); test("watchdog: volumeFreeBytes' stat never answers → unknown", async () => { const out = (await watchdogCase(["stat"], () => volumeFreeBytes({ paths, locations: [LOC] }), )) as Record; assert.equal(out.usb, undefined); }); test("watchdog: a LEGACY recency tail read never answers → not dated, not remembered as a miss", async () => { seedLegacy(); const args = { paths, meta: [{ slug: SLUG, config: LEGACY_CONFIG }], candidateIds: new Set(["vid1"]), owner: new Map([["vid1", SLUG]]), interpolate: false, fresh: true, }; const keys = (await watchdogCase(["open"], () => buildRecencyKeys(args))) as Map< string, { key: string } >; assert.equal(keys.get("vid1")?.key, ""); resetStorageHealth(); hang = null; assert.equal((await buildRecencyKeys(args)).get("vid1")?.key, "20260601"); }); test("watchdog: a move onto a root whose stat never answers is refused", async () => { const problem = await watchdogCase(["stat"], () => relocationRootPresenceProblem( DRIVE, { locations: [LOC], defaultLocationId: "" }, paths, ), ); assert.match(String(problem), /drive not answering/); }); test("watchdog (M3, release 17): a tiered file's stat never answers → the snapshot is written, its media bytes unknown", async () => { // Six more videos, each with a tiered audio link, so the walk has units // past the first to refuse. for (const id of ["vid2", "vid3", "vid4", "vid5", "vid6", "vid7"]) { mkdirSync(path.join(DATA, id), { recursive: true }); writeFileSync(path.join(DATA, id, "metadata.info.json"), JSON.stringify({ id })); mkdirSync(path.join(TARGET, id), { recursive: true }); writeFileSync(path.join(TARGET, id, "audio.mp3"), "AUDIO"); symlinkSync(path.join("..", "..", "media", id, "audio.mp3"), path.join(DATA, id, "audio.mp3")); } const tiered = (c: Call) => c.fn === "stat" && c.path.startsWith(DATA + path.sep) && c.path.endsWith(`${path.sep}audio.mp3`); const snap = (await watchdogCase(["stat"], async () => { // The text answers; a stat through a tiered link does not. hang = tiered; return generateChannelSnapshot(paths, SLUG); })) as Awaited>; assert.equal(snap.totals.downloaded, 7); assert.equal("totalMediaBytes" in snap, false, "unknown, never a partial sum"); // At most four video units reached the drive. const asked = new Set(calls.filter(tiered).map((c) => path.dirname(c.path))); assert.ok(asked.size <= 4, `${asked.size} video units asked`); });