import { test } from "node:test"; import assert from "node:assert/strict"; import { parseSite } from "../lib/siteSchema"; import { channelSitesOf } from "./poolSummary"; // Run with: // pnpm --filter yt-dlp-transcript-common test // // channelSitesOf is the published `channel-sites.json` (compose-homepage) and // the map the summary attributes channels by. Release 14 slice HS: an unlisted // site (site.json `listed: false`) is in neither. test("channel-sites.json names listed sites only; a channel only an unlisted site exposes is absent", () => { const sites = [ parseSite("fixture-a", { channels: [{ slug: "a1" }, { slug: "shared" }] }), parseSite("fixture-b", { channels: [{ slug: "b1" }, { slug: "shared" }] }), parseSite("fixture-unlisted", { listed: false, channels: [{ slug: "shared" }, { slug: "own" }], }), ]; assert.deepEqual(channelSitesOf(sites), { a1: ["fixture-a"], shared: ["fixture-a", "fixture-b"], b1: ["fixture-b"], }); assert.ok(!JSON.stringify(channelSitesOf(sites)).includes("fixture-unlisted")); }); // Report sites: a CITED site is never listed either — its channels are its // citations' pool, not a published archive. test("channel-sites.json leaves out a cited site", () => { const sites = [ parseSite("fixture-a", { channels: [{ slug: "shared" }] }), parseSite("fixture-cited", { search: false, channels: [{ slug: "shared" }, { slug: "own" }] }), ]; assert.deepEqual(channelSitesOf(sites), { shared: ["fixture-a"] }); }); // Release 17 slice XP: a PRIVATE site is never listed, so it is in neither; and // with X posts private an X channel a public site leaves out of its build is // not mapped to that site (buildPoolSummary passes the narrowing). test("channel-sites.json leaves out a private site, and an X channel its public site withholds", async () => { const { publishedMemberSlugs } = await import("../lib/postsVisibility"); const sites = [ parseSite("fixture-a", { channels: [{ slug: "vids" }, { slug: "jer-x" }] }), parseSite("fixture-private", { audience: "private", channels: [{ slug: "vids" }, { slug: "jer-x" }, { slug: "own" }], }), ]; const configs: Record = { "jer-x": { sourceKind: "social", platform: "twitter" }, }; const privateX = { social: { x: { visibility: "private" } } }; assert.deepEqual( channelSitesOf(sites, (site) => publishedMemberSlugs(site, (slug) => configs[slug], privateX)), { vids: ["fixture-a"] }, ); assert.deepEqual(channelSitesOf(sites), { vids: ["fixture-a"], "jer-x": ["fixture-a"] }); });