import { test } from "node:test"; import assert from "node:assert/strict"; import { atTime, frameScanView } from "./frameScanView"; import type { FrameScanRecord } from "yt-dlp-transcript-common/lib/frameScan-server"; const record = (): FrameScanRecord => ({ format: "archilyzer-frame-scan", version: 1, profile: "poker", source: { savedVideo: "source-media.mp4", durationSeconds: 200 }, sampling: { everySeconds: 10, from: 0, to: 200, width: 1280, keyframesOnly: true, frames: 20, kept: 12, skippedDuplicates: 8 }, model: { route: "api", model: "claude-haiku-4-5", promptVersion: 1 }, costUsd: 0.0412, runs: [{ at: "2026-10-15T00:00:00Z", model: "claude-haiku-4-5", route: "api", frames: 20, read: 12, failed: 0, costUsd: 0.0412, stopped: "cap" }], readings: Array.from({ length: 12 }, (_, i) => ({ t: i * 10, phase: "table" })), duplicates: [], spoken: [], derived: { tournaments: [{ key: "synthetic cup", name: "Synthetic Cup", from: 30, to: 190, series: { stack: [[30, 20000], [90, 41000], [180, 0]], playersLeft: [[30, 85], [120, 9]] }, facts: { buyIn: 200, totalPlayers: 120 } }], events: [ { t: 60, kind: "pot", detail: "takes the pot 1,600 (8 BB)", source: "log", tournament: "synthetic cup" }, { t: 90, kind: "double-up", detail: "20,000 → 41,000 chips (2.1×)", source: "series", tournament: "synthetic cup" }, ], segments: [{ from: 0, to: 30, phase: "lobby" }, { from: 30, to: 200, phase: "table", tournament: "synthetic cup" }], flags: [{ t: 125, field: "playersLeft", spoken: 4, frame: 9, frameT: 120 }], misreads: [{ t: 40, field: "stack", value: 2000000 }], }, updatedAt: "2026-10-15T00:00:00Z", }); test("atTime: the platform's own time parameter", () => { assert.equal(atTime("https://www.youtube.com/watch?v=abc", 75.4), "https://www.youtube.com/watch?v=abc&t=75s"); assert.equal(atTime("https://rumble.com/v7abc-title.html", 3725), "https://rumble.com/v7abc-title.html?start=3725"); assert.equal(atTime("https://www.twitch.tv/videos/1", 3725), "https://www.twitch.tv/videos/1?t=1h2m5s"); assert.equal(atTime("https://example.com/v", 9), "https://example.com/v#t=9"); assert.equal(atTime(null, 9), null); assert.equal(atTime("not a url", 9), null); }); test("frameScanView: strip, charts, events with links, flags, summary", () => { const v = frameScanView(record(), "https://rumble.com/v7abc-title.html"); assert.deepEqual(v.strip.map((s) => [s.phase, s.leftPct, s.widthPct]), [["lobby", 0, 15], ["table", 15, 85]]); assert.equal(v.tournaments[0].name, "Synthetic Cup"); assert.deepEqual(v.tournaments[0].sparks.map((s) => [s.label, s.min, s.max, s.last]), [["Stack (chips)", 0, 41000, 0], ["Players left", 9, 85, 9]]); assert.match(v.tournaments[0].sparks[0].points, /^0\.0,/); assert.deepEqual(v.tournaments[0].facts, ["buy-in $200", "field 120"]); assert.deepEqual(v.events.map((e) => [e.at, e.kind, e.href]), [["1:30", "double-up", "https://rumble.com/v7abc-title.html?start=90"]]); assert.deepEqual(v.flags, ["2:05 Players left: said 4, the frame at 2:00 reads 9"]); assert.equal(v.summary, "20 frames every 10 s, 12 read (8 duplicates skipped) on claude-haiku-4-5 · $0.04 · 1 misread set aside · 1 smaller pot won"); assert.equal(v.stopped, "cap"); }); test("frameScanView: the hero, a person's corrections (release 32), and when it was re-derived", () => { const r = { ...record(), hints: { hero: "SynthHero" }, rederivedAt: "2026-10-16T09:30:00.000Z", corrections: [ { t: 40, at: "2026-10-16T09:29:00Z", by: "person" as const, misread: true as const, note: "the webcam" }, { t: 90, at: "2026-10-16T09:29:30Z", by: "person" as const, set: { "hero.stack": 41000, "tournament.name": null } }, ], }; const v = frameScanView(r, null); assert.equal(v.hero, "SynthHero"); assert.deepEqual(v.corrections, [ { t: 40, at: "0:40", what: "misread, set aside", note: "the webcam" }, { t: 90, at: "1:30", what: "hero.stack 41,000, tournament.name not shown", note: null }, ]); assert.match(v.summary, / · re-derived 2026-10-16 09:30$/); assert.equal(frameScanView(record(), null).hero, null); });