// The archive link an entry's QR, deck QR, YouTube source line, lint check, // review cite link and moment lookup carry (site-links.mjs): a Twitch VOD's // directory id `` goes out as the record id `v` the archive serves — // decided by the channel's PLATFORM, never by the id being digits (an X status // id is digits too and goes out as it is). A temp CHANNELS_DIR with synthetic // channels; never the corpus. Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; const CHANNELS = mkdtempSync(path.join(tmpdir(), "site-links-")); for (const [slug, config] of [ ["twitchchan", { platform: "twitch" }], ["twitchbyurl", { url: "https://www.twitch.tv/somebody" }], ["xchan", { platform: "x" }], ["ytchan", { url: "https://www.youtube.com/@somebody" }], ]) { mkdirSync(path.join(CHANNELS, slug), { recursive: true }); writeFileSync(path.join(CHANNELS, slug, "config.json"), JSON.stringify(config)); } // CHANNELS_DIR is read when umtool/lib/paths.mjs loads: set it first. process.env.CHANNELS_DIR = CHANNELS; const { archiveMomentUrl, channelPlatform, siteRefOf } = await import("./site-links.mjs"); const { deckQrUrl } = await import("./deck.mjs"); const { momentLinkOf } = await import("./youtube.mjs"); const { qrUrlFor } = await import("./render-cards.mjs"); const { qrsOf } = await import("./lint.mjs"); const { derivedCiteUrl, citeUrlFor } = await import("../lib/projects/report.mjs"); const { resolveMoment } = await import("../lib/report/moments.mjs"); const { siteVideoId } = await import("yt-dlp-transcript-common/lib/videoDirId.mjs"); const ORIGIN = "https://example.pages.dev"; const N = "2468013579"; const XID = "1850000000000000000"; const twitchClip = { type: "clip", id: "t01", channel: "twitchchan", video: N, start: 125.4, end: 140, cite: 130 }; const xClip = { type: "clip", id: "x01", channel: "xchan", video: XID, start: 3.2, end: 9 }; const prov = { siteOrigin: ORIGIN, channelSlug: "ytchan" }; const twitchUrl = (t) => `${ORIGIN}/?v=twitchchan%2Fv${N}&t=${t}`; const xUrl = (t) => `${ORIGIN}/?v=xchan%2F${XID}&t=${t}`; test("siteVideoId: v only for Twitch; siteVideo wins; X digits and every other platform untouched", () => { assert.equal(siteVideoId({ video: N }, "twitch"), `v${N}`); assert.equal(siteVideoId(N, "twitch"), `v${N}`); assert.equal(siteVideoId({ video: `v${N}` }, "twitch"), `v${N}`, "already the record id"); assert.equal(siteVideoId({ video: XID }, "x"), XID); assert.equal(siteVideoId({ video: XID }, null), XID, "unknown platform: as written, never guessed from digits"); assert.equal(siteVideoId({ video: "a-url-slug", siteVideo: "v2embed" }, "rumble"), "v2embed"); assert.equal(siteVideoId({ video: "dQw4w9WgXcQ" }, "youtube"), "dQw4w9WgXcQ"); }); test("channelPlatform reads config.json (platform, else the url's host); none for an unknown channel", () => { assert.equal(channelPlatform("twitchchan"), "twitch"); assert.equal(channelPlatform("twitchbyurl"), "twitch"); assert.equal(channelPlatform("xchan"), "x"); assert.equal(channelPlatform("ytchan"), "youtube"); assert.equal(channelPlatform("nochan"), null); assert.deepEqual(siteRefOf({ video: N, platform: "twitch", channel: "nochan" }), { channel: "nochan", video: `v${N}` }, "an entry's own platform wins"); assert.deepEqual(siteRefOf({ video: N, channel: "nochan" }), { channel: "nochan", video: N }, "no config: as written"); assert.deepEqual(siteRefOf({ video: "slug", siteVideo: "v9", siteChannel: "site-chan", channel: "local" }), { channel: "site-chan", video: "v9" }); assert.equal(archiveMomentUrl({ video: N }, { siteOrigin: ORIGIN, channelSlug: "twitchbyurl" }, 7.9), `${ORIGIN}/?v=twitchbyurl%2Fv${N}&t=7`, "the provenance's channel decides"); }); test("a Twitch clip with no citeUrl: every builder links v; an X clip's digits get no v", () => { // the deck's QR (a clip's start) assert.equal(deckQrUrl(twitchClip, prov), twitchUrl(125)); assert.equal(deckQrUrl(xClip, prov), xUrl(3)); // the YouTube description's moment link (the cited second) assert.equal(momentLinkOf(twitchClip, prov), twitchUrl(130)); assert.equal(momentLinkOf(xClip, prov), xUrl(3)); // the rail / corner QR (render-cards) assert.equal(qrUrlFor(twitchClip, prov), twitchUrl(130)); assert.equal(qrUrlFor(xClip, prov), xUrl(3)); // the review page's cite link const m = { provenance: prov, timeline: [twitchClip, xClip] }; assert.equal(derivedCiteUrl(m, twitchClip), twitchUrl(125)); assert.equal(citeUrlFor(m, xClip), xUrl(3)); // a citeUrl still wins assert.equal(deckQrUrl({ ...twitchClip, citeUrl: "https://elsewhere/x" }, prov), "https://elsewhere/x"); }); test("lint measures the same link the corner QR draws", () => { const qrs = qrsOf({ provenance: prov, render: {}, timeline: [twitchClip, xClip] }); assert.deepEqual(qrs.map((q) => q.url), [twitchUrl(125), xUrl(3)]); }); test("a moment on the cut resolves to the archive's v page", () => { const schedule = { segments: [{ id: "t01", start: 0, duration: 14.6 }], total: 14.6, transition: 0 }; const got = resolveMoment({ schedule, manifest: { provenance: prov, timeline: [twitchClip] }, t: 2 }); assert.equal(got.video, N, "the local id stays the local id"); assert.equal(got.url, twitchUrl(127)); });