import { test } from "node:test"; import assert from "node:assert/strict"; import { toDisplaySummary } from "./transcripts-server"; import type { TranscriptSummary } from "./transcripts"; // Run with: node_modules/.bin/tsx --test common/lib/transcripts-server.test.ts function summary(over: Partial = {}): TranscriptSummary { return { slug: "test-channel/v1", id: "v1", channelSlug: "test-channel", title: "A stream", uploadDate: "20260101", duration: 3600, channel: "Test Channel", description: "", tags: ["keyword-one", "keyword-two"], isLivestream: false, ageRestricted: false, platform: "youtube", webpageUrl: "https://example.com/v1", ...over, }; } test("toDisplaySummary omits curatedTags entirely when there are none", () => { // The byte-identical-pages contract: an untagged corpus's summaries pages // must not gain a key, or every one of them is rewritten on upgrade. const display = toDisplaySummary(summary()); assert.equal("curatedTags" in display, false); assert.equal("curatedTags" in toDisplaySummary(summary({ curatedTags: [] })), false); // And the platform's keywords do NOT leak in under the new name. assert.equal(JSON.stringify(display).includes("keyword-one"), false); }); test("toDisplaySummary passes curatedTags through in order", () => { const display = toDisplaySummary( summary({ curatedTags: ["eva-collab", "eva-topic"] }), ); assert.deepEqual(display.curatedTags, ["eva-collab", "eva-topic"]); }); test("toDisplaySummary still derives the state fields it always did", () => { const available = toDisplaySummary(summary()); assert.equal(available.isDeleted, false); assert.equal(available.isUnlisted, false); assert.equal("state" in available, false); const deleted = toDisplaySummary(summary({ curatedTags: ["x"] }), { state: "deleted", }); assert.equal(deleted.state, "deleted"); assert.equal(deleted.isDeleted, true); assert.deepEqual(deleted.curatedTags, ["x"]); });