// A podcast feed channel's titles before any probe (plans/pacing-guard.md). // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test controller/feedTitlePrefilter.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { mkdtemp, mkdir } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import type { Paths } from "../lib/paths"; import { looksLikeFeedChannel, seedFeedTitles } from "./feedTitlePrefilter"; import { loadMetadataScan, settledByTitleFilterIds } from "./metadataScanStore"; import { extractVideoId } from "../lib/videoId"; const FEED = `Show Episode 1: the topicTue, 21 Oct 2026 10:00:00 GMT Episode 2: something elseWed, 22 Oct 2026 10:00:00 GMT `; const CONFIG = { url: "https://feeds.example.fm/show", downloadFilter: { include: "topic" }, } as const; const URLS = ["https://cdn.example.fm/ep1.mp3", "https://cdn.example.fm/ep2.mp3"]; test("which channels are read as a feed", () => { assert.equal(looksLikeFeedChannel(CONFIG as never, URLS), true); assert.equal(looksLikeFeedChannel({ url: CONFIG.url } as never, URLS), false, "no filter: nothing to settle"); assert.equal( looksLikeFeedChannel({ ...CONFIG, url: "https://www.youtube.com/@x" } as never, URLS), false, "a known platform is not a feed", ); assert.equal(looksLikeFeedChannel(CONFIG as never, ["https://example.fm/page/1", "https://example.fm/page/2"]), false); }); test("one feed read titles the unscanned episodes; the filter then settles the unwanted one with no probe", async () => { const root = await mkdtemp(path.join(os.tmpdir(), "feed-titles-")); const paths = { channelsDir: path.join(root, "channels") } as Paths; await mkdir(path.join(paths.channelsDir, "show"), { recursive: true }); let reads = 0; const lines: string[] = []; const n = await seedFeedTitles({ paths, slug: "show", config: CONFIG as never, playlistUrls: URLS, onLog: (l) => lines.push(l), fetchFeed: async () => { reads++; return FEED; }, }); assert.equal(reads, 1); assert.equal(n, 2); const scan = await loadMetadataScan(paths, "show"); const ep2 = extractVideoId(URLS[1])!; assert.equal(scan.entries[ep2]?.title, "Episode 2: something else"); const settled = await settledByTitleFilterIds(paths, "show", CONFIG as never); assert.deepEqual([...settled], [ep2]); // Everything known: no second read. await seedFeedTitles({ paths, slug: "show", config: CONFIG as never, playlistUrls: URLS, onLog: () => {}, fetchFeed: async () => { reads++; return FEED; } }); assert.equal(reads, 1); });