// Learned spellings (umtool R6.3): the names a watch's terms watch; the // model's proposals checked; spellings escaped into the candidate query // (never a regex); tier 0's candidates a learned spelling brings, named; the // judge's heard spans checked verbatim; the confirmation dropping a spelling // with no hits, one the judge says is not the name, one whose line is not // verbatim — and keeping one with its proving line; the cap; suggest // removing; unlearn blocks a relearn; the alias a promotion would write; a // triage run end to end that hears, confirms and keeps a spelling. Stubs // only: no model, no corpus on disk. import { after, test } from "node:test"; import assert from "node:assert/strict"; import { mkdtemp, rm } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import type { EnumeratedAnswer, EnumerateFn, ListFn } from "../refresh/delta"; import type { CorpusToolsLike } from "../tasks/types"; import { EXTRACT_SYSTEM } from "../tasks/sweep-pipeline"; import { confirmSpellings, countViaEnumerate, keptByWindows, proveByHand, runLearnPass, type CountPhrasesFn } from "./confirm"; import { checkHeard, judgeCandidates } from "./judge"; import { CONFIRM_SYSTEM, LEARNED_CAP, coveredByTerms, PROPOSE_SYSTEM, SUGGEST_REMOVE_AFTER, activeLearned, emptyLearned, holdsSpelling, joinedQuery, learnDue, learnedAlternation, learnedWords, mergeLearned, namesOf, parseProposals, planAliasPromotion, recordUses, spellingPattern, suggestRemoving, termsKey, unlearnIn, type LearnedSpelling, } from "./learned"; import { createTriageRun, readTriageFile } from "./store"; import { runTriage } from "./task"; import { triageCandidates } from "./tier0"; import { TRIAGE_FORMAT, TRIAGE_VERSION, type TriageFile } from "./types"; const tmp = await mkdtemp(path.join(os.tmpdir(), "learned-")); after(() => rm(tmp, { recursive: true, force: true })); // ─── a corpus, stubbed (synthetic names: nothing here is a real person) ─── type Rec = { id: string; date: string; title: string; lines: string[] }; const CHAN = "synth-kitchen"; const NAME = "Synth Kitchen"; const RECS: Rec[] = [ { id: "a-01", date: "20261001", title: "Guest night", lines: ["tonight Pia Tartlet is on the show", "she brought the pies", "thanks Pia"] }, // The mis-hearing: "pia tart lit" for Pia Tartlet. { id: "b-02", date: "20261008", title: "Pie talk", lines: ["welcome back everyone", "my friend pia tart lit is joining us later", "she runs the bakery downtown"] }, { id: "c-03", date: "20261010", title: "Market day", lines: ["the tart lit up the whole room", "we sold out by noon", "see you next week"] }, { id: "d-04", date: "20261012", title: "Late stream", lines: ["pia tart lit could not make it tonight", "so it is just me", "we will bake bread"] }, ]; const ymd = (d: string) => `${d.slice(0, 4)}-${d.slice(4, 6)}-${d.slice(6, 8)}`; const matcher = (args: Record) => { const q = String(args.query); if (args.regex === true) { const re = new RegExp(q, "i"); return (l: string) => re.test(l); } return (l: string) => l.toLowerCase().includes(q.toLowerCase()); }; function enumerateOver(recs: Rec[]): EnumerateFn & { calls: Record[] } { const calls: Record[] = []; const fn = (async (args: Record): Promise => { calls.push(args); const any = args.query === "." && args.regex === true; const m = matcher(args); const ids = Array.isArray(args.ids) ? new Set(args.ids as string[]) : null; const rows = recs .filter((r) => !ids || ids.has(r.id)) .map((r) => ({ r, n: any ? 1 : r.lines.filter(m).length })) .filter((x) => x.n > 0) .map(({ r, n }) => ({ id: r.id, kind: "video" as const, channel: NAME, date: ymd(r.date), matches: n, title: r.title })); return { rows, partial: false, unreached: [] }; }) as EnumerateFn & { calls: Record[] }; fn.calls = calls; return fn; } const listOver = (recs: Rec[]): ListFn => async () => ({ rows: recs.map((r) => ({ id: r.id, channel: NAME, channelSlug: CHAN, date: ymd(r.date), title: r.title, hasTranscript: true })), complete: true, unreached: [], problems: [] }); const stamp = (s: number) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}|${s}`; function corpusOver(recs: Rec[]): CorpusToolsLike { return { source: "local:/fake/out", tools: [], async call(name, args = {}) { if (name === "get_transcripts") { const ids = (args.video_ids as string[]) ?? []; const re = typeof args.query === "string" && args.regex === true ? new RegExp(args.query, "i") : null; const qs = [...(Array.isArray(args.queries) ? (args.queries as string[]) : []), ...(typeof args.query === "string" && !re ? [args.query] : [])].map((q) => q.toLowerCase()); return ids .map((id) => { const r = recs.find((x) => x.id === id); if (!r) return `## ${id}\n- video_id: ${id}\n(not found)`; const any = !re && !qs.length; const lines = r.lines.map((t, i) => ({ s: i * 5, t })).filter((l) => any || re?.test(l.t) || qs.some((q) => l.t.toLowerCase().includes(q))); return [`## ${r.title}`, `- video_id: ${id}`, `- moment_base: https://synth.example/?v=${CHAN}%2F${id}&t=`, ...lines.map((l) => `[${stamp(l.s)}] ${l.t}`)].join("\n"); }) .join("\n---\n"); } throw new Error(`the stub has no ${name}`); }, }; } const cuesOver = (recs: Rec[]) => async (_c: string, id: string) => { const r = recs.find((x) => x.id === id); return r ? r.lines.map((text, i) => ({ start: i * 5, end: i * 5 + 4.8, text })) : null; }; type Asked = { system: string; user: string }; // The excerpt line holding a spelling (what an honest judge quotes). const lineHolding = (user: string, spelling: string) => user .split("\n") .map((l) => l.replace(/^\[[\d:]+\]\s*/, "")) .find((l) => !l.includes(":") && l.toLowerCase().includes(spelling.toLowerCase())) ?? ""; function askScript(answer: (a: Asked) => unknown) { const asked: Asked[] = []; const ask = async (system: string, user: string): Promise => { asked.push({ system, user }); return answer({ system, user }) as T; }; return { ask, asked }; } const learnedOf = (spelling: string, over: Partial = {}): LearnedSpelling => ({ spelling, means: "Pia Tartlet", quote: "my friend pia tart lit is joining us later", recording: "b-02", channel: CHAN, start: 5, hits: 2, source: "proposed", at: "2026-10-14T00:00:00.000Z", ...over, }); // ─── names, proposals, the query ─── test("namesOf: a watch's proper names — capitalised alternatives only; lowercase phrases and regex classes skipped; \\b anchors stripped", () => { const terms = "co-?host|co host|guest host|\\bguests?\\b|Melonie|\\bMelanie\\b|Melanie Mac|Hannah Claire|[Gg]othix|Styx|joining the show"; assert.deepEqual(namesOf(terms, true), ["Melonie", "Melanie", "Melanie Mac", "Hannah Claire", "Styx"]); assert.deepEqual(namesOf("Pia Tartlet", false), ["Pia Tartlet"]); assert.deepEqual(namesOf("contest", false), []); assert.deepEqual(namesOf("co-host|guest-host|pia tartlet", true), []); assert.deepEqual(namesOf("(Pia|Pea) Tartlet|Pia Tartlet", true), ["Pia Tartlet"]); assert.equal(termsKey("Pia Tartlet", false), "lit:Pia Tartlet"); assert.equal(termsKey("", true), null); }); test("parseProposals: the name itself, a repeat, a known spelling, junk and long phrases are put aside; at most k", () => { const known = new Set(["pia tart"]); const r = parseProposals("Pia Tartlet", { spellings: ["Pia Tartlet", "pia tart lit", "\"Pea Tartlet\"", "pia tart lit", "Pia Tart", "x", "one two three four five", "Pia Tartlett", "Peter Tart", "P Tartlet"] }, { k: 3, known }); assert.deepEqual(r.spellings, ["pia tart lit", "Pea Tartlet", "Pia Tartlett"]); assert.deepEqual(r.dropped.map((d) => d.reason).sort(), ["invalid", "invalid", "known"]); assert.deepEqual(parseProposals("X", null).spellings, []); }); test("a spelling is an ESCAPED literal in the query, never a regex — joined to regex terms or escaped literal terms", () => { assert.equal(spellingPattern("pia tart lit"), "\\bpia tart lit\\b"); assert.equal(spellingPattern("Mr. T (live)"), "\\bMr\\. T \\(live\\)"); assert.equal(spellingPattern("a+b.*"), "\\ba\\+b\\.\\*"); assert.equal(learnedAlternation(["pia tart lit", "Pea Tartlet", "pia tart lit"]), "\\bpia tart lit\\b|\\bPea Tartlet\\b"); assert.equal(learnedAlternation([]), null); assert.deepEqual(joinedQuery("Pia|Tartlet", true, []), { query: "Pia|Tartlet", regex: true }); assert.deepEqual(joinedQuery("Pia|Tartlet", true, ["pia tart lit"]), { query: "(?:Pia|Tartlet)|\\bpia tart lit\\b", regex: true }); assert.deepEqual(joinedQuery("Pia (Tartlet)", false, ["x.y"]), { query: "(?:Pia \\(Tartlet\\))|\\bx\\.y\\b", regex: true }); // A regex-looking spelling matches only itself. assert.equal(holdsSpelling("we said a+b today", "a+b"), true); assert.equal(holdsSpelling("we said aab today", "a+b"), false); assert.equal(holdsSpelling("the tart lit up", "pia tart lit"), false); assert.equal(learnedWords(2), "terms + 2 learned"); }); // ─── tier 0 ─── test("tier 0: the learned spellings join the candidate query (escaped, bounded by the new ids); a candidate they alone bring names them", async () => { const enumerate = enumerateOver(RECS); const r = await triageCandidates( { scope: { channels: [CHAN] }, terms: "Pia Tartlet", topics: [], known: new Set(["a-01"]), since: null, max: 40, learned: ["pia tart lit", "Pea Tartlet"] }, { enumerate, list: listOver(RECS) }, ); const byId = Object.fromEntries(r.tier0.candidates.map((c) => [c.id, c])); assert.deepEqual(Object.keys(byId).sort(), ["b-02", "d-04"]); assert.deepEqual(byId["b-02"]!.by, ["learned"]); assert.deepEqual(byId["b-02"]!.learned, ["pia tart lit"]); assert.deepEqual(r.tier0.learned, { spellings: ["pia tart lit", "Pea Tartlet"], matched: 2 }); const learnedQ = enumerate.calls.find((c) => String(c.query).includes("pia tart lit") && String(c.query).includes("|")); assert.equal(learnedQ?.query, "\\bpia tart lit\\b|\\bPea Tartlet\\b"); assert.equal(learnedQ?.regex, true); assert.deepEqual((learnedQ?.ids as string[]).sort(), ["b-02", "c-03", "d-04"]); // "the tart lit up" (c-03) is not the spelling: whole words. assert.equal(byId["c-03"], undefined); }); // ─── tier 1: heard spans ─── test("the judge's heard spans: verbatim in the window and the cues, a watched name — else put aside with why", async () => { const chunk: [number, string][] = RECS[1]!.lines.map((t, i) => [i * 5, t]); const out = await checkHeard( [ { span: "pia tart lit", means: "Pia Tartlet" }, { span: "pia tartlit", means: "Pia Tartlet" }, { span: "the bakery", means: "Someone Else" }, { span: "Pia Tartlet", means: "Pia Tartlet" }, ], { id: "b-02", title: "Pie talk", slug: CHAN, chunk, names: ["Pia Tartlet"], cues: cuesOver(RECS) }, ); assert.deepEqual(out[0], { span: "pia tart lit", means: "Pia Tartlet", id: "b-02", channel: CHAN, title: "Pie talk", at: 5, line: "my friend pia tart lit is joining us later", checked: "cues" }); assert.deepEqual(out.slice(1).map((x) => ("reason" in x ? x.reason : "kept")), ["not verbatim in its window", "not a watched name"]); // A span the cues do not hold near that second is put aside too. const drift = await checkHeard([{ span: "pia tart lit", means: "Pia Tartlet" }], { id: "b-02", title: "Pie talk", slug: CHAN, chunk, names: ["Pia Tartlet"], cues: async () => [{ start: 0, text: "something else entirely" }] }); assert.match((drift[0] as { reason: string }).reason, /not in the transcript's cues/); }); test("judgeCandidates with names: the prompt asks for heard spans; a verbatim one is kept beside the flags", async () => { const { ask, asked } = askScript(() => ({ relevant: false, items: [], heard: [{ span: "pia tart lit", means: "Pia Tartlet" }, { span: "pia tartlit", means: "Pia Tartlet" }] })); const j = await judgeCandidates( { question: "Who joined the show?", candidates: [{ id: "b-02", channel: NAME, title: "Pie talk", date: "2026-10-08", matches: 1, by: ["learned"] }], terms: "Pia Tartlet|\\bpia tart lit\\b", regex: true, topics: [], channels: [CHAN], names: ["Pia Tartlet"] }, { corpus: corpusOver(RECS), ask, model: "qwen3:8b", cuesOf: cuesOver(RECS) }, ); assert.match(asked[0]!.system, /mishear these watched names: "Pia Tartlet"/); assert.equal(j.heard.length, 1); assert.equal(j.heard[0]!.span, "pia tart lit"); assert.deepEqual(j.heardDropped.map((h) => h.reason), ["not verbatim in its window"]); // Without names, the judge's prompt is the sweep pipeline's own. const plain = askScript(() => ({ relevant: false, items: [] })); await judgeCandidates({ question: "Q?", candidates: [{ id: "b-02", channel: NAME, title: "Pie talk", date: null, matches: 1, by: ["terms"] }], terms: "pia", topics: [], channels: [CHAN] }, { corpus: corpusOver(RECS), ask: plain.ask, model: "m" }); assert.equal(plain.asked[0]!.system, EXTRACT_SYSTEM); }); // ─── the confirmation ─── // A second corpus for the confirmation's rule: three windows of one spelling. const RECS2: Rec[] = [ { id: "w-01", date: "20260901", title: "Night one", lines: ["tonight pia tart lit is judging", "the pies were great", "we could not find the oven"] }, { id: "w-02", date: "20260910", title: "Night two", lines: ["pia tart lit joined us again", "she brought cherries", "we could not stop eating"] }, { id: "w-03", date: "20260920", title: "Night three", lines: ["thanks pia tart lit for coming", "see you soon", "goodbye"] }, { id: "w-04", date: "20260925", title: "Bakery day", lines: ["the downtown bakery opened", "lines around the block", "great day"] }, ]; const spellingOf = (user: string) => /Spelling in the transcript: (.*)/.exec(user)?.[1] ?? ""; const titleOf = (user: string) => /Video: (.*)/.exec(user)?.[1] ?? ""; test("confirmSpellings: kept by a majority of the windows read (2 of up to 3), each verdict kept; one window needs 3 recordings; no hits, not the name, not verbatim, too few — dropped with why", async () => { const base = countViaEnumerate(listOver(RECS2), enumerateOver(RECS2)); // "downtown bakery" is in one recording; this count says three (its other two unreadable), so one window decides. const count: CountPhrasesFn = async (a) => { const c = await base(a); if (c.counts["downtown bakery"]) c.counts["downtown bakery"] = { ...c.counts["downtown bakery"], recordings: 3 }; return c; }; const { ask } = askScript(({ system, user }) => { assert.equal(system, CONFIRM_SYSTEM); const sp = spellingOf(user); const t = titleOf(user); const line = lineHolding(user, sp); if (sp === "pia tart lit") return t === "Night two" ? { means: false, quote: line, reason: "another Pia" } : { means: true, quote: line, reason: "the guest" }; if (sp === "tart lit") return t === "Night three" ? { means: true, quote: line, reason: "maybe" } : { means: false, quote: line, reason: "not her" }; if (sp === "could not") return { means: true, quote: "she could not ever make it", reason: "invented" }; return { means: true, quote: line, reason: "her bakery" }; }); const r = await confirmSpellings( { pending: ["Pea Tartlet", "pia tart lit", "tart lit", "could not", "downtown", "downtown bakery"].map((spelling) => ({ spelling, means: "Pia Tartlet", source: "proposed" as const })), question: "Who joined the show?", scope: { channels: [CHAN] }, at: "2026-10-14T00:00:00.000Z", }, { corpus: corpusOver(RECS2), ask, count, cuesOf: cuesOver(RECS2) }, ); assert.deepEqual( r.dropped.map((d) => [d.spelling, d.reason]), [ ["Pea Tartlet", "no-hits"], ["tart lit", "not-the-name"], ["could not", "not-verbatim"], ["downtown", "too-few"], ], ); assert.equal(r.dropped[1]!.why, "1 of 3 windows read said it means the name, quoting a verbatim line (needs 2): not her"); assert.deepEqual(r.dropped[1]!.windows?.map((w) => [w.recording, w.means]), [["w-03", true], ["w-02", false], ["w-01", false]]); assert.match(r.dropped[3]!.why, /occurs in only 1 recording: one window needs 3/); assert.deepEqual(r.kept.map((k) => [k.spelling, k.recording, k.quote, k.hits]), [ // 2 of 3: the newest yes is its proving line. ["pia tart lit", "w-03", "thanks pia tart lit for coming", 3], // 1 window, 3 recordings. ["downtown bakery", "w-04", "the downtown bakery opened", 3], ]); assert.deepEqual(r.kept[0]!.windows?.map((w) => [w.recording, w.means, w.verbatim]), [["w-03", true, true], ["w-02", false, true], ["w-01", true, true]]); assert.equal(r.kept[0]!.url, "https://synth.example/?v=synth-kitchen%2Fw-03&t=0"); }); test("keptByWindows: the rule on its own", () => { const w = (means: boolean, verbatim = true) => ({ recording: "r", start: 0, means, verbatim, reason: means ? "yes" : "no" }); assert.equal(keptByWindows([w(true), w(true)], 2).keep, true); assert.equal(keptByWindows([w(true), w(false), w(true)], 3).keep, true); assert.equal(keptByWindows([w(true), w(false)], 2).reason, "not-the-name"); assert.equal(keptByWindows([w(true), w(true, false)], 2).reason, "not-verbatim"); assert.equal(keptByWindows([w(true)], 3).keep, true); assert.equal(keptByWindows([w(true)], 2).reason, "too-few"); assert.equal(keptByWindows([w(false)], 9).reason, "not-the-name"); assert.equal(keptByWindows([], 9).reason, "unread"); }); test("confirmSpellings: a count that read part of the scope and found nothing is unread, never no-hits", async () => { const count: CountPhrasesFn = async (a) => ({ counts: Object.fromEntries(a.phrases.map((p) => [p, { recordings: 0, lines: 0, examples: [] }])), complete: false, problems: ["Other (stopped at page 2 of 5)"], listed: 10 }); const r = await confirmSpellings({ pending: [{ spelling: "x y", means: "X Y", source: "proposed" }], question: "Q?", scope: { channels: [CHAN] }, at: "t" }, { corpus: corpusOver(RECS), ask: askScript(() => ({})).ask, count }); assert.equal(r.dropped[0]!.reason, "unread"); }); test("runLearnPass: proposals asked per name, checked, then confirmed", async () => { const count = countViaEnumerate(listOver(RECS), enumerateOver(RECS)); const { ask, asked } = askScript(({ system }) => system === PROPOSE_SYSTEM ? { spellings: ["pia tart lit", "Pia Tartlet", "Pea Tartlet", "Pia Tartlet tonight"] } : { means: true, quote: lineHolding(asked.at(-1)!.user, "pia tart lit"), reason: "her" }, ); // A spelling the terms' own query already finds adds nothing ("Pia Tartlet tonight" under "Pia Tartlet"). const r = await runLearnPass( { names: ["Pia Tartlet"], question: "Who joined?", scope: { channels: [CHAN] }, known: new Set(), at: "t", covered: coveredByTerms("Pia Tartlet|guest", true) }, { corpus: corpusOver(RECS), ask, count, cuesOf: cuesOver(RECS) }, ); assert.deepEqual(r.proposed.map((p) => p.spelling), ["pia tart lit", "Pea Tartlet"]); assert.deepEqual(r.kept.map((k) => k.spelling), ["pia tart lit"]); assert.deepEqual(r.dropped.map((d) => [d.spelling, d.reason, d.why]), [ ["Pia Tartlet tonight", "known", "the terms already match it"], ["Pea Tartlet", "no-hits", "does not occur in scope (4 recordings counted)"], ]); assert.equal(coveredByTerms("Melanie Mac", false)("Melanie Mack"), true); assert.equal(coveredByTerms("Gothix", false)("Gothics"), false); assert.match(asked[0]!.user, /Name: Pia Tartlet/); }); // ─── the file's rules ─── test("mergeLearned: the cap, a blocked spelling never relearned; unlearn blocks; recordUses and suggest removing", () => { let f = emptyLearned("w", "t0"); const many = Array.from({ length: LEARNED_CAP + 2 }, (_, i) => learnedOf(`spelling ${i}`)); const m = mergeLearned(f, { kept: many, dropped: [], at: "t1" }); assert.equal(m.file.learned.length, LEARNED_CAP); assert.deepEqual(m.dropped.map((d) => d.reason), ["cap", "cap"]); f = mergeLearned(emptyLearned("w", "t0"), { kept: [learnedOf("pia tart lit")], dropped: [], at: "t1" }).file; const u = unlearnIn(f, "Pia Tart Lit", "t2"); assert.equal(u.removed?.spelling, "pia tart lit"); assert.equal(u.file.learned.length, 0); const again = mergeLearned(u.file, { kept: [learnedOf("pia tart lit", { source: "heard" })], dropped: [], at: "t3" }); assert.equal(again.added.length, 0); assert.equal(again.dropped[0]!.reason, "blocked"); // Uses: four runs with candidates, none flagged → suggest removing. let g = mergeLearned(emptyLearned("w", "t0"), { kept: [learnedOf("pia tart lit")], dropped: [], at: "t1" }).file; for (let k = 1; k < SUGGEST_REMOVE_AFTER; k++) g = recordUses(g, k, `t${k}`, new Map([["pia tart lit", { candidates: 1, flagged: 0 }]])); assert.equal(suggestRemoving(g.learned[0]!), false); g = recordUses(g, 9, "t9", new Map([["pia tart lit", { candidates: 0, flagged: 0 }]])); assert.equal(suggestRemoving(g.learned[0]!), false); g = recordUses(g, SUGGEST_REMOVE_AFTER, "t", new Map([["PIA tart lit", { candidates: 2, flagged: 0 }]])); assert.equal(suggestRemoving(g.learned[0]!), true); g = recordUses(g, 10, "t", new Map([["pia tart lit", { candidates: 1, flagged: 1 }]])); assert.equal(suggestRemoving(g.learned[0]!), false); // Active: a spelling whose name left the terms is idle. assert.deepEqual(activeLearned(g, ["Pia Tartlet"]).length, 1); assert.deepEqual(activeLearned(g, ["Someone Else"]).length, 0); }); test("learnDue: never proposed, the terms changed, a week since the last pass", () => { const now = new Date("2026-10-14T00:00:00.000Z"); assert.equal(learnDue(null, "lit:X", now), "create"); const f = { ...emptyLearned("w", "t"), proposedAt: "2026-10-10T00:00:00.000Z", termsKey: "lit:X" }; assert.equal(learnDue(f, "lit:X", now), null); assert.equal(learnDue(f, "lit:Y", now), "terms"); assert.equal(learnDue({ ...f, proposedAt: "2026-10-07T00:00:00.000Z" }, "lit:X", now), "weekly"); assert.equal(learnDue(f, null, now), null); }); test("planAliasPromotion: a new alias for the name, or the spelling added to the alias that names it", () => { const l = learnedOf("pia tart lit"); const fresh = planAliasPromotion([], l, "w"); assert.equal(fresh.action, "new"); assert.deepEqual(fresh.alias, { id: "pia-tartlet", label: "Pia Tartlet", triggers: ["pia tartlet", "pia tart lit"], suggestion: "\\bPia Tartlet\\b|\\bpia tart lit\\b", useRegex: true, enabled: true, note: "learned by watch w from synth-kitchen/b-02 at 0:05", }); const existing = { id: "pia", label: "Pia Tartlet", triggers: ["pia tartlet"], suggestion: "\\bpia tartlet\\b", useRegex: true, enabled: true, note: "her name" }; const add = planAliasPromotion([existing], l, "w"); assert.equal(add.action, "trigger"); assert.deepEqual(add.alias.triggers, ["pia tartlet", "pia tart lit"]); assert.equal(add.alias.suggestion, "\\bpia tartlet\\b|\\bpia tart lit\\b"); assert.equal(add.alias.note, 'her name; "pia tart lit" learned by watch w from synth-kitchen/b-02 at 0:05'); const none = planAliasPromotion([add.alias], l, "w"); assert.equal(none.action, "none"); // A taken id gets a suffix. assert.equal(planAliasPromotion([{ ...existing, id: "pia-tartlet", label: "Other", triggers: ["other"] }], l, "w").alias.id, "pia-tartlet-2"); }); // ─── a triage run end to end ─── test("runTriage with learned spellings and names: terms + N learned, the heard span confirmed and kept for the job to write", async () => { const paths = { articlesDir: path.join(tmp, "reports-run") }; const at = "2026-10-14T00:00:00.000Z"; const f0 = await createTriageRun( (k): TriageFile => ({ format: TRIAGE_FORMAT, version: TRIAGE_VERSION, owner: "pia-watch", k, status: "queued", model: "qwen3:8b", provider: "local", question: "Who joined the show?", scope: { channels: [CHAN] }, terms: "Pia Tartlet|tonight", regex: true, topics: [], threshold: { strong: 1, weak: 3 }, since: "2026-10-01", knownCount: null, createdAt: at, cost: { tier0: 0, tier1: 0 }, summary: "queued", warnings: [], }), paths, "pia-watch", ); const { ask } = askScript(({ system, user }) => { if (system === CONFIRM_SYSTEM) return { means: true, quote: /d-04|Late stream/.test(user) ? "pia tart lit could not make it tonight" : "my friend pia tart lit is joining us later", reason: "the guest" }; if (/Late stream/.test(user)) return { relevant: true, items: [{ quote: "pia tart lit could not make it tonight", claim: "The guest could not come.", on_topic: true, strength: 3 }], heard: [{ span: "pia tart lit", means: "Pia Tartlet" }] }; return { relevant: false, items: [] }; }); const enumerate = enumerateOver(RECS); const { file } = await runTriage( { owner: "pia-watch", k: f0.k, learned: [learnedOf("Pea Tartlet")], names: ["Pia Tartlet"], known: new Set(["pia tartlet", "pea tartlet"]) }, { llm: {} as never, corpus: corpusOver(RECS), paths, ask, enumerate, list: listOver(RECS), cuesOf: cuesOver(RECS), now: () => new Date(at) }, ); assert.equal(file.status, "done"); assert.deepEqual(file.learned, { n: 1, spellings: ["Pea Tartlet"] }); assert.match(file.summary, /· terms \+ 1 learned —/); assert.equal(file.heard?.[0]?.span, "pia tart lit"); assert.deepEqual(file.learning?.kept.map((l) => [l.spelling, l.source, l.k, l.recording]), [["pia tart lit", "heard", f0.k, "d-04"]]); const back = await readTriageFile("pia-watch", f0.k, paths); assert.equal(back?.learning?.kept.length, 1); }); test("proveByHand (release 32): counted in scope, the proving line found by code, no model; no hits is refused", async () => { const count = countViaEnumerate(listOver(RECS), enumerateOver(RECS)); const corpus = corpusOver(RECS); const at = "2026-10-16T12:00:00.000Z"; const got = await proveByHand({ spelling: "Pia Tart Lit", means: "Pia Tartlet", scope: { channels: [CHAN] }, at }, { corpus, count }); assert.equal(got.ok, true); const l = (got as { spelling: LearnedSpelling }).spelling; // The newest recording holding it first: d-04, its first line. assert.deepEqual([l.spelling, l.means, l.recording, l.channel, l.start, l.quote, l.hits, l.source], ["Pia Tart Lit", "Pia Tartlet", "d-04", CHAN, 0, "pia tart lit could not make it tonight", 2, "hand"]); assert.equal(l.url, `https://synth.example/?v=${CHAN}%2Fd-04&t=0`); const none = await proveByHand({ spelling: "Pya Tortlet", means: "Pia Tartlet", scope: { channels: [CHAN] }, at }, { corpus, count }); assert.deepEqual(none.ok ? null : none.reason, "no-hits"); });