import assert from "node:assert/strict"; import test from "node:test"; import { applyProposals, clipFromProposal, watchUrlAt } from "./assist.mjs"; test("watchUrlAt: the platform's page at a second, in its own form; an existing one replaced; not a URL, null", () => { assert.equal(watchUrlAt("https://www.youtube.com/watch?v=abc", 128.9), "https://www.youtube.com/watch?v=abc&t=128s"); assert.equal(watchUrlAt("https://www.youtube.com/watch?v=abc&t=5s", 3), "https://www.youtube.com/watch?v=abc&t=3s"); assert.equal(watchUrlAt("https://youtu.be/abc", 4), "https://youtu.be/abc?t=4s"); assert.equal(watchUrlAt("https://www.twitch.tv/videos/123", 3725), "https://www.twitch.tv/videos/123?t=1h2m5s"); assert.equal(watchUrlAt("https://rumble.com/v2abc-title.html", 61), "https://rumble.com/v2abc-title.html?start=61"); assert.equal(watchUrlAt("https://odysee.com/@a:1/b:2", 7), "https://odysee.com/@a:1/b:2?t=7"); assert.equal(watchUrlAt("https://example.com/x?t=1&y=2#h", 8), "https://example.com/x?y=2&t=8#h"); assert.equal(watchUrlAt("not a url", 3), null); assert.equal(watchUrlAt(null, 3), null); }); const P = (id: string, start: number, end: number, used = true) => ({ id, start, end, score: 0.5, why: "host laughs", used }); const linkAt = (s: number) => watchUrlAt("https://www.youtube.com/watch?v=vid", s); test("applyProposals with citeUrlAt: added clips link their second; a moved clip's derived link follows it; a link somebody wrote stays", () => { const clip = clipFromProposal(P("p001", 10.4, 20), { id: "r001", channel: "ch", video: "vid", citeUrlAt: linkAt }); assert.equal(clip.citeUrl, "https://www.youtube.com/watch?v=vid&t=10s"); assert.equal("citeUrl" in clipFromProposal(P("p001", 10.4, 20), { id: "r001", channel: "ch", video: "vid" }), false); const first = applyProposals([], { proposals: [P("p001", 10, 20), P("p002", 40, 50)], channel: "ch", video: "vid", citeUrlAt: linkAt }); assert.deepEqual(first.timeline.map((e) => e.citeUrl), ["https://www.youtube.com/watch?v=vid&t=10s", "https://www.youtube.com/watch?v=vid&t=40s"]); // A hand-written link (a mirror) on r002; r001 moves: its derived link follows, r002's stays. const tl = first.timeline.map((e) => ({ ...e })); tl[1].citeUrl = "https://mirror.example/x?t=40"; const second = applyProposals(tl, { proposals: [P("p001", 12, 20), P("p002", 42, 50)], channel: "ch", video: "vid", citeUrlAt: linkAt }); assert.deepEqual(second.timeline.map((e) => [e.id, e.cite, e.citeUrl]), [ ["r001", 12, "https://www.youtube.com/watch?v=vid&t=12s"], ["r002", 42, "https://mirror.example/x?t=40"], ]); // A clip from before the rule (no link) gains one even when nothing else moved; without the rule nothing changes. const bare = first.timeline.map(({ citeUrl: _c, ...e }) => e); const third = applyProposals(bare, { proposals: [P("p001", 10, 20), P("p002", 40, 50)], channel: "ch", video: "vid", citeUrlAt: linkAt }); assert.deepEqual(third.changes.updated, ["r001", "r002"]); assert.ok(third.timeline.every((e) => e.citeUrl)); const plain = applyProposals(bare, { proposals: [P("p001", 10, 20), P("p002", 40, 50)], channel: "ch", video: "vid" }); assert.equal(plain.changes.kept, 2); assert.ok(plain.timeline.every((e) => !("citeUrl" in e))); });