// "Cut from the stored media URL" (release 32 R6): umtool offers it only for a // record that stores a media file address the editor can cut from — an Odysee // record with its one CDN format — and finds a project clip's record the way // fetch-via-editor.mjs does. A synthetic corpus in a temp dir; no network. // // Run with: pnpm --filter umtool exec tsx --test lib/clips/stored.test.ts import { before, test } from "node:test"; import assert from "node:assert/strict"; import { mkdir, mkdtemp, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; let lib: typeof import("./stored"); let channels: string; async function record(slug: string, id: string, info: Record) { const dir = path.join(channels, slug, "data", id); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "metadata.info.json"), JSON.stringify(info)); } before(async () => { channels = path.join(await mkdtemp(path.join(os.tmpdir(), "umtool-stored-")), "channels"); process.env.CHANNELS_DIR = channels; lib = await import("./stored"); await record("od", "s1", { webpage_url: "https://odysee.com/@demo:1/s1:1", formats: [{ url: "https://player.odycdn.com/v6/streams/s1/f0.mp4", protocol: "https" }], }); await record("od", "n1", { webpage_url: "https://odysee.com/@demo:1/n1:1" }); await record("yt", "y1", { webpage_url: "https://www.youtube.com/watch?v=y1", formats: [{ url: "https://player.odycdn.com/v6/streams/y1/f0.mp4", protocol: "https" }], }); }); test("offered only for a record on an allowlisted platform that stores its CDN file", async () => { assert.deepEqual(await lib.storedUrlOf("od", "s1", channels), { stored: true, host: "player.odycdn.com", platform: "odysee" }); assert.deepEqual(await lib.storedUrlOf("od", "n1", channels), { stored: false }); assert.deepEqual(await lib.storedUrlOf("yt", "y1", channels), { stored: false }, "not an allowlisted platform"); assert.deepEqual(await lib.storedUrlOf("od", "missing", channels), { stored: false }); assert.deepEqual(await lib.storedUrlOf("..", "s1", channels), { stored: false }); }); test("a project clip's record: the clip's channel, else the manifest's; a ledger claim's too", () => { const m = { provenance: { channelSlug: "od" }, timeline: [{ id: "c1", video: "s1" }, { id: "c2", channel: "yt", video: "y1" }, { id: "t1", type: "card" }], ledger: [{ id: "l1", video: "n1" }], }; assert.deepEqual(lib.clipRecord(m, "c1"), { channel: "od", video: "s1" }); assert.deepEqual(lib.clipRecord(m, "c2"), { channel: "yt", video: "y1" }); assert.deepEqual(lib.clipRecord(m, "l1"), { channel: "od", video: "n1" }); assert.equal(lib.clipRecord(m, "t1"), null); assert.equal(lib.clipRecord(m, "nope"), null); });