// The recurring reports' Inbox decisions (R5): a failed or held tick is Your // call, a finished edition is Review -- and each lands in its group. import assert from "node:assert/strict"; import test from "node:test"; import { scheduleDecisions } from "./schedules.mjs"; import { annotate, summarizeGroups } from "./groups.mjs"; import { whatOf } from "./what.mjs"; const how = { current: (a) => (a === "cohost-2026-10-07" ? 1 : null), articleHref: (a) => `/articles/${a}?tab=iterations`, settingsHref: "/settings/generation" }; const series = (over = {}) => ({ id: "cohost", shape: "series", topic: "Co-host updates", href: "/series/cohost", piece: "s:cohost", call: null, editions: [ { n: 1, title: "Co-host updates · week of 2026-09-30", status: "done", article: "cohost-2026-10-07", usd: 1.2, at: "2026-10-07T10:00:00.000Z", window: { from: "2026-09-30", to: "2026-10-07" } }, { n: 2, title: "Co-host updates · week of 2026-10-07", status: "quiet", usd: 0, at: "2026-10-14T10:00:00.000Z", window: { from: "2026-10-07", to: "2026-10-14" } }, { n: 3, title: "Co-host updates · week of 2026-10-14", status: "done", article: "cohost-2026-10-21", usd: 2.5, at: "2026-10-21T10:00:00.000Z", window: { from: "2026-10-14", to: "2026-10-21" } }, ], ...over, }); test("a finished edition nothing has made current is a Review card on the series; a quiet one and a current one are not", () => { const d = scheduleDecisions([series()], how); assert.equal(d.length, 1); assert.deepEqual( { kind: d[0].kind, piece: d[0].piece, target: d[0].target, href: d[0].href, project: d[0].project }, { kind: "edition-ready", piece: "s:cohost", target: "Co-host updates · week of 2026-10-14", href: "/articles/cohost-2026-10-21?tab=iterations", project: "series/cohost" }, ); assert.match(d[0].why, /2026-10-14 … 2026-10-21\) is done · \$2\.50/); const [row] = annotate(d, { pieceOf: () => null, lifecycleOf: () => "active" }); assert.equal(row.group, "review"); assert.equal(row.action.label, "Review edition"); assert.equal(whatOf("edition-ready"), "edition ready"); }); test("a failed tick is Your call (Tick now, on the schedule's page); a held one too (Raise cap, on the policy)", () => { const failed = scheduleDecisions([series({ editions: [], call: { at: "2026-10-21T10:00:00.000Z", status: "failed", reason: "not wired: R4's stage 1", usd: 0 } })], how); const held = scheduleDecisions( [{ id: "shop", shape: "living", topic: "The shop", article: "shop", href: "/articles/shop", piece: "a:articles/shop", call: { at: "2026-10-21T10:00:00.000Z", status: "held-by-cap", reason: "the day's Claude API spend is $20.00", estimateUsd: 5, usd: 0 } }], how, ); const rows = annotate([...failed, ...held], { pieceOf: () => null, lifecycleOf: () => "active" }); assert.deepEqual( rows.map((r) => [r.kind, r.group, r.action.label, r.action.href, r.project]), [ ["tick-failed", "your-call", "Tick now", "/series/cohost", "series/cohost"], ["tick-held", "your-call", "Raise cap", "/settings/generation", "sites/articles/shop"], ], ); assert.match(rows[1].why, /held by a cap: the day's Claude API spend is \$20\.00 · up to \$5\.00 a tick/); const groups = summarizeGroups(rows); assert.equal(groups.find((g) => g.id === "your-call").cards.length, 2); assert.equal(whatOf("tick-failed"), "tick failed"); assert.equal(whatOf("tick-held"), "tick held by a cap"); }); test("a watch's escalated tick is Worth researching (Your call): the flags and what the sweep kept; its action the board; settled or below the threshold, none", () => { const tick = (k, o = {}) => ({ at: `2026-10-2${k}T10:00:00.000Z`, status: "done", article: `cowatch-2026-10-2${k}`, iteration: 1, usd: 0.42, triage: { k, escalated: true, candidates: 6, flagged: 2, dismissed: 4, top: [{ f: "f1", id: "v1", line: "I was on the show last week", score: 3, reason: "She says she was a guest." }], usd: { tier1: 0, tier2: 0.42 } }, ...o, }); const watch = { id: "cowatch", shape: "watch", topic: "Co-host watch", href: "/series/cowatch", piece: "s:cowatch", call: null, ticks: [tick(1), tick(2), tick(3, { status: "no-change", article: undefined, triage: { k: 3, escalated: false, candidates: 2, flagged: 0, dismissed: 2, top: [], usd: { tier1: 0, tier2: 0 } } })], }; const worth = (s, k) => (k === 2 ? { href: "/research/cowatch-2026-10-22", settled: true, findings: 1 } : { href: `/research/cowatch-2026-10-2${k}`, settled: false, findings: 3 }); const d = scheduleDecisions([watch], { ...how, worth }); assert.deepEqual( d.map((x) => [x.kind, x.target, x.href, x.piece, x.project]), [["worth-researching", "cowatch-2026-10-21", "/research/cowatch-2026-10-21", "s:cowatch", "series/cowatch"]], ); assert.equal(d[0].why, "2 flagged of 6 new · “I was on the show last week” — She says she was a guest. · the sweep kept 3 findings · $0.42"); const [row] = annotate(d, { pieceOf: () => null, lifecycleOf: () => "active" }); assert.deepEqual([row.group, row.category, row.action.label], ["your-call", "spend", "Open the board"]); assert.equal(whatOf("worth-researching"), "worth researching"); // Without the board's word (it could not be made): the triage page. const bare = scheduleDecisions([{ ...watch, ticks: [tick(1)] }], how); assert.equal(bare[0].href, "/series/cowatch/triage/1"); }); test("R6.1: a partial tick is Your call (tick partial), its reason naming what the scan did not reach — never quiet", () => { const d = scheduleDecisions( [series({ editions: [], call: { at: "2026-10-21T10:00:00.000Z", status: "partial", reason: "partial — not reached: Jeremy Hambly, TheQuartering (Rumble); nothing flagged in what was read", usd: 0 } })], how, ); const [row] = annotate(d, { pieceOf: () => null, lifecycleOf: () => "active" }); assert.deepEqual([row.kind, row.group, row.action.label, row.action.href], ["tick-partial", "your-call", "See what was missed", "/series/cohost"]); assert.equal(row.why, "partial — not reached: Jeremy Hambly, TheQuartering (Rumble); nothing flagged in what was read"); assert.equal(whatOf("tick-partial"), "tick partial"); });