import test from "node:test"; import assert from "node:assert/strict"; import { mkdir, mkdtemp, readdir, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; // Run with: // pnpm -C editor exec tsx --test "app/channels/*/lib/fixIncompleteTranscript.test.ts" // // CLEARING A TRUNCATED TRANSCRIPT CLEARS ITS CAPTIONS IN BOTH FORMS (lane // text-compress-captions). A track stored as `transcript..vtt.zst` // (lib/storedText.ts) missed by the clear would bring the cleared transcript // back. Temp corpus, synthetic names. const ROOT = await mkdtemp(path.join(os.tmpdir(), "clear-incomplete-")); process.env.TRANSCRIPTS_DIR = ROOT; process.env.SETTINGS_FILE = path.join(ROOT, "settings.json"); const { clearIncompleteTranscriptOne } = await import("./fixIncompleteTranscript"); const { getPaths } = await import("yt-dlp-transcript-common/lib/paths"); const { encodeStoredBytes } = await import("yt-dlp-transcript-common/lib/storedText-server"); test.after(() => rm(ROOT, { recursive: true, force: true })); test("every caption track goes, stored or plain, and the metadata stays", async () => { const dir = path.join(ROOT, "channels", "synth", "data", "vid00000001"); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "metadata.info.json"), "{}"); await writeFile(path.join(dir, "audio.mp3"), "A"); await writeFile(path.join(dir, "transcript.json"), "{}"); await writeFile(path.join(dir, "transcript.en.vtt.zst"), await encodeStoredBytes(Buffer.from("WEBVTT\n\nstored\n"))); await writeFile(path.join(dir, "transcript.en-orig.vtt"), "WEBVTT\n\nplain\n"); await writeFile(path.join(dir, "transcript.en-orig.vtt.zst"), await encodeStoredBytes(Buffer.from("WEBVTT\n\nolder\n"))); const out = await clearIncompleteTranscriptOne({ slug: "synth", videoId: "vid00000001", paths: getPaths() }); assert.equal(out.removed, 4, "audio, transcript.json and the two caption tracks (each in every form)"); assert.deepEqual(await readdir(dir), ["metadata.info.json"]); });