import { test } from "node:test"; import assert from "node:assert/strict"; import { checkReading, quoteSpan } from "./lookoutRead"; import type { Cue } from "./vtt"; // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test lib/lookoutRead.test.ts // // A quote is evidence: what a reading keeps is the TRANSCRIPT's text for the // words the model pointed at, byte for byte as the cues say it, and its words // are counted after normalising — punctuation is no word (lane/lookout slice 2 // review, probe 2). const chunk: [number, string][] = [ [10, "I never said that he was lying about the money!"], [20, "And that is the truth, folks."], ]; const cues: Cue[] = [ { start: 10.4, end: 15.2, text: chunk[0]![1] }, { start: 20, end: 25.5, text: chunk[1]![1] }, ]; const read = (quote: string) => checkReading({ covers: "x", items: [{ kind: "claim", quote, why: "w", voice: "own", people: [] }] }, chunk, cues, 0); test("punctuation is no word: a quote of dashes and one word is too short", () => { const r = read("- - - - - - lying"); assert.deepEqual(r.chunk.items, []); assert.deepEqual(r.dropped.map((d) => d.reason), ["too-short"]); }); test("the stored quote is the transcript's text, never the model's case or punctuation", () => { const r = read("he was LYING about the money!!! And that"); assert.equal(r.chunk.items.length, 1); const [it] = r.chunk.items; assert.equal(it!.quote, "he was lying about the money! And that", "the cues' own words, across the cue break"); assert.equal(it!.start, 10); assert.equal(it!.end, 25.5, "the end of the cue it ends in"); }); test("a quote within one cue keeps that cue's words; a paraphrase or a skipped word is not found", () => { assert.equal(read("I never said that he was lying")!.chunk.items[0]!.quote, "I never said that he was lying"); assert.equal(read("I never said that he was lying")!.chunk.items[0]!.end, 15.2); assert.equal(read("said that he was lying about the money and that is the truth")!.chunk.items[0]!.quote, "said that he was lying about the money! And that is the truth,"); assert.deepEqual(read("never said that he was lying about money").dropped.map((d) => d.reason), ["not-in-transcript"]); assert.equal(quoteSpan("he was lying", [[0, "he was\tlying"]])?.text, "he was\tlying", "the cue's own spacing"); assert.equal(quoteSpan("", chunk), null); });