// settings.privacy.hidePrivateSites and the research sources (review round 1, // M2): the flag filters what a PICKER draws (shownSources) and nothing else. // listSources() is also openSource's allow-list and every reader's default // (corpus, boards, case-verify, coverage, fetch, runs-board, triage), so with // the flag ON it must still name a private site's archive — a case on that // source keeps reading it. Temp dirs only; nothing is fetched. // // Run with: pnpm --filter umtool test import { test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; const D = mkdtempSync(path.join(tmpdir(), "umtool-privacy-sources-")); const SITES = path.join(D, "sites"); const SETTINGS = path.join(D, "settings.json"); for (const [id, extra] of [ ["priv", { audience: "private", siteUrl: "https://priv.invalid" }], ["pub", { siteUrl: "https://pub.invalid" }], ] as const) { mkdirSync(path.join(SITES, id), { recursive: true }); writeFileSync(path.join(SITES, id, "site.json"), JSON.stringify({ siteId: id, siteTitle: `T-${id}`, ...extra })); } mkdirSync(path.join(D, "export"), { recursive: true }); Object.assign(process.env, { SITES_DIR: SITES, SETTINGS_FILE: SETTINGS, TRANSCRIPT_LOCAL_DIR: path.join(D, "export"), TRANSCRIPT_HUB_URL: "" }); const srv = await import("yt-dlp-transcript-common/lib/privacy/privacy-server"); const { listSources, shownSources } = await import("./sources"); let t = 0; const set = (privacy: unknown) => { writeFileSync(SETTINGS, JSON.stringify({ privacy })); t += 10; const d = new Date(Date.UTC(2026, 0, 1) + t * 1000); utimesSync(SETTINGS, d, d); srv.resetPrivacyMemo(); }; const handles = (l: { handle: string }[]) => l.map((s) => s.handle).filter((h) => h.startsWith("remote:")).sort(); test("flag ON: listSources (the allow-list, the default) still has the private site; only the picker's list drops it", async () => { set({ hidePrivateSites: false }); const off = await listSources(); assert.deepEqual(handles(off), ["remote:https://priv.invalid", "remote:https://pub.invalid"]); assert.equal(await shownSources(off), off, "off: the very same list"); set({ hidePrivateSites: true }); const on = await listSources(); assert.deepEqual(handles(on), handles(off), "every non-UI caller sees the full list"); assert.deepEqual(handles(await shownSources(on)), ["remote:https://pub.invalid"]); // The chosen source stays drawn, without its name. const kept = (await shownSources(on, "remote:https://priv.invalid")).find((s) => s.handle === "remote:https://priv.invalid"); assert.equal(kept?.label, "A private site"); assert.equal(kept?.detail, ""); }); test.after(() => rmSync(D, { recursive: true, force: true }));