// Learned spellings, umtool's read (plans/umtool-redesign.md, R6.3): a watch's // learned.json as the series page lists it — each spelling with its cite, the // one whose candidates were dismissed run after run marked "suggest removing", // one whose name left the terms idle; the drops newest first. Temp stores only. import { after, before, 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 { Paths } from "yt-dlp-transcript-common/lib/paths"; import { createSchedule, parseCreate } from "yt-dlp-transcript-common/controller/reportSchedule"; import { recordLearnPass } from "yt-dlp-transcript-common/controller/learnedSpellings"; import { readSchedule } from "yt-dlp-transcript-common/lib/report/schedule/store"; import type { LearnedSpelling } from "yt-dlp-transcript-common/lib/report/draft/triage/learned"; let tmp: string; let paths: Paths; let lib: typeof import("./learned"); const at = "2026-10-14T10:00:00.000Z"; const spelling = (s: string, means: string, over: Partial = {}): LearnedSpelling => ({ spelling: s, means, quote: `then ${s} said so`, recording: "v1", channel: "chan-a", start: 65, hits: 2, source: "proposed", at, ...over }); before(async () => { tmp = await mkdtemp(path.join(os.tmpdir(), "umtool-learned-")); process.env.ARTICLES_DIR = path.join(tmp, "articles"); process.env.REPORTS_DIR = path.join(tmp, "reports"); process.env.SITES_DIR = path.join(tmp, "sites"); process.env.CHANNELS_DIR = path.join(tmp, "channels"); process.env.SETTINGS_FILE = path.join(tmp, "settings.json"); paths = { articlesDir: path.join(tmp, "articles"), exportIndexDir: path.join(tmp, "idx") } as unknown as Paths; await createSchedule(parseCreate({ shape: "watch", id: "guest-watch", topic: "Guest watch", channels: ["chan-a"], cadence: "weekly mon 06:00", tz: "UTC", terms: "Pia Tartlet|Ross Crumb", regex: true }), { paths }); const s = (await readSchedule("guest-watch", paths))!; await recordLearnPass( s, { pass: { at, trigger: "create", status: "done", model: "qwen3:8b", names: ["Pia Tartlet", "Ross Crumb"], notAsked: [], proposed: 4, kept: 0, dropped: 0, usd: 0 }, kept: [ spelling("pia tart lit", "Pia Tartlet", { url: "https://x.example/?v=chan-a%2Fv1&t=65" }), spelling("ross crum", "Ross Crumb", { source: "heard", k: 2, uses: [1, 2, 3, 4].map((k) => ({ k, at, candidates: 1, flagged: 0 })) }), spelling("old name", "Gone Person"), ], dropped: [ { spelling: "pea tartlet", means: "Pia Tartlet", source: "proposed", reason: "no-hits", why: "does not occur in scope", at }, { spelling: "ross", means: "Ross Crumb", source: "proposed", reason: "not-the-name", why: "another Ross", at }, ], termsKey: "re:Pia Tartlet|Ross Crumb", }, paths, new Date(at), ); lib = await import("./learned"); }); after(() => rm(tmp, { recursive: true, force: true })); test("readScheduleLearned: each spelling with its cite and state; drops newest first; the names a pass asks about", async () => { const s = (await readSchedule("guest-watch", paths))!; const v = await lib.readScheduleLearned(s); assert.deepEqual( v.rows.map((r) => [r.spelling, r.means, r.cite, r.suggestRemoving, r.idle]), [ ["pia tart lit", "Pia Tartlet", "chan-a/v1 at 1:05", false, false], ["ross crum", "Ross Crumb", "chan-a/v1 at 1:05", true, false], ["old name", "Gone Person", "chan-a/v1 at 1:05", false, true], ], ); assert.deepEqual(v.names, ["Pia Tartlet", "Ross Crumb"]); assert.deepEqual(v.dropped.map((d) => d.spelling), ["ross", "pea tartlet"]); assert.equal(v.lastPass?.trigger, "create"); assert.equal(v.lastPass?.kept, 3); assert.equal(v.cap, 20); // A schedule with nothing learned reads as an empty list. const none = await lib.readScheduleLearned({ ...s, id: "no-such" }); assert.deepEqual([none.rows.length, none.lastPass], [0, null]); });