// Tests for measure-slice.mjs: the odometer rule, a row's landing second, the // state after each event, the totals, the settings, and the deck schedule's // `measure`. Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { isRealtimeLoss, isUsable, kindOf, lossRuns, measureOn, measureSettingsProblems, measureSlice, pinnedRows, spokenAt, spokenNumbers, validateMeasureSettings, } from "./measure-slice.mjs"; import { estimateSchedule, validateChrome } from "./deck.mjs"; import { scheduleSlices } from "./modules/index.mjs"; import { validateClaims } from "./factcheck.mjs"; import { goalBoard } from "./measure-goals.mjs"; import { boundAgrees, measureScoreboard, measureTotals } from "./measure-totals.mjs"; import { nextReading } from "./panel-model.mjs"; const SCHEMA = { kind: "measure", unit: "lb", yMin: 210, yMax: 400, bandGapDays: 60, tracks: [ { key: "weight", role: "value", label: "Weight" }, { key: "regime", role: "regime", label: "Diet", regimes: ["keto", "carnivore", "glp1", "off"] }, { key: "drinking", role: "regime", label: "Drinking", regimes: ["dry", "drinking"] }, ], forms: ["current", "past", "delta", "goal", "goal_loss", "overweight_by", "status"], regimes: [ { key: "keto", label: "Keto" }, { key: "carnivore", label: "Carnivore" }, { key: "glp1", label: "GLP-1" }, { key: "off", label: "No diet" }, { key: "dry", label: "Dry" }, { key: "drinking", label: "Drinking" }, ], fields: [{ key: "qualifier", label: "Bound", kind: "enum", options: [">", "<", "≈"], appliesTo: { scope: "weight" }, render: "cell" }], }; /** An adjudicated row, the six fields filled with the boring answer. */ const row = (o) => ({ scope: "weight", scopeBasis: "his words", scopeConfidence: "read", valueKind: "uttered", flags: [], asOf: null, ...o, }); const LEDGER = [ row({ id: "w01", date: "2024-01-01", population: "past", asOf: "2008-06-30", value: 368, display: "368 lb", entryId: "c1" }), row({ id: "w02", date: "2024-01-05", population: "delta", value: -9, display: "-9", entryId: "c1" }), row({ id: "w03", date: "2024-02-01", population: "delta", value: -19.4, display: "-19.4" }), // A loss in the past with no date to put in asOf: marked retro, not counted. row({ id: "w04", date: "2024-02-02", population: "delta", value: -64, display: "-64", retro: true, entryId: "c2" }), // A retrospective (asOf): not counted either. row({ id: "w05", date: "2024-02-03", population: "delta", value: -45, asOf: "2020-01-01", display: "-45" }), // > 60 days on: a new run… row({ id: "w06", date: "2025-04-01", population: "delta", value: -7.5, display: "-7.5", entryId: "c3" }), row({ id: "w07", date: "2025-05-01", population: "past", asOf: "2025-03-20", value: 349, display: "349 lb", entryId: "c3" }), row({ id: "w08", date: "2025-05-10", population: "current", value: 335, display: "335 lb", entryId: "c4" }), row({ id: "w09", date: "2025-05-20", population: "delta", value: -40, qualifier: "≈", display: "-40", entryId: "c4" }), // …a lower figure later in the same run does not lower its peak. row({ id: "w10", date: "2025-06-05", population: "delta", value: -29.2, display: "-29.2", entryId: "c5" }), row({ id: "w11", date: "2025-06-06", population: "goal_loss", value: -65, display: "lose 65", deadline: "by Christmas", due: "2025-12-25", entryId: "c5" }), // An explicit run: a claim his words put in the 2024 run (it does not open run 2). row({ id: "w12", date: "2025-09-01", population: "delta", value: -30, run: 0, display: "-30" }), row({ id: "r01", date: "2025-04-01", scope: "regime", population: "status", value: "keto", event: "start", display: "keto", entryId: "c3" }), // "Off GLP-1" while on keto: keto stands (the off-scope fix). row({ id: "r02", date: "2025-05-10", scope: "regime", population: "status", value: "glp1", event: "off", display: "off GLP-1", entryId: "c4" }), row({ id: "r03", date: "2025-06-05", scope: "regime", population: "status", value: "carnivore", event: "start", display: "carnivore", entryId: "c5" }), row({ id: "d01", date: "2025-05-10", scope: "drinking", population: "status", value: "dry", event: "start", display: "dry", entryId: "c4" }), row({ id: "p01", date: "2025-06-05", population: "promise", value: null, display: "post a video of the scale", entryId: "c5" }), row({ id: "p02", date: "2025-07-01", population: "promise_check", value: null, display: "pull up a video", promise: "p01" }), ]; const TIMELINE = [ { type: "title", id: "z0", seconds: 4 }, { type: "clip", id: "c1", video: "v1", start: 100, end: 120, quoteStart: 104 }, { type: "clip", id: "c2", video: "v2", start: 10, end: 20, quoteStart: 12 }, { type: "clip", id: "c3", video: "v3", start: 50, end: 70, quoteStart: 51 }, { type: "clip", id: "c4", video: "v4", start: 0, end: 30, quoteStart: 2, claim: "w08" }, { type: "clip", id: "c5", video: "v5", start: 200, end: 230, quoteStart: 205 }, ]; const SEGMENTS = [ { id: "z0", start: 0, duration: 4 }, { id: "c1", start: 4, duration: 20 }, { id: "c2", start: 24, duration: 10 }, { id: "c3", start: 34, duration: 20 }, { id: "c4", start: 54, duration: 30 }, { id: "c5", start: 84, duration: 30 }, ]; const manifest = (measure = { scopes: ["weight", "regime"], scale: { min: 220, max: 400 } }) => ({ ledgerSchema: SCHEMA, ledger: LEDGER, timeline: TIMELINE, render: { fps: 30, transition: 0, chrome: { engine: "hyperframes", layout: "deck", deck: { measure } } }, }); // c4's words: "I weighed three hundred thirty five … I'm down about forty pounds". const words = (list) => list.map(([text, start]) => ({ text, start, end: start + 0.2 })); const WORDS = new Map([ ["c4", { from: "words", words: words([["I", 3], ["weighed", 3.3], ["three", 4], ["hundred", 4.3], ["thirty", 4.6], ["five", 4.9], ["and", 10], ["I'm", 11], ["down", 11.3], ["about", 11.6], ["forty", 12], ["pounds", 12.4]]) }], ]); const CLOCK = new Map([["c1", 100], ["c2", 10], ["c3", 50], ["c4", 0], ["c5", 200]]); test("the odometer: the highest real-time claim per run, summed; a gap past bandGapDays starts a run; a row's run wins", () => { const { runs, runOf, total } = lossRuns(LEDGER, SCHEMA); assert.deepEqual(runs.map((r) => [r.run, r.start, r.peak, r.row]), [[0, "2024-01-05", 30, "w12"], [1, "2025-04-01", 40, "w09"]]); assert.equal(total, 70); assert.equal(runOf.has("w04"), false, "a retro loss is not on the odometer"); assert.equal(runOf.has("w05"), false, "a retrospective (asOf) is not either"); assert.equal(runOf.get("w12"), 0, "his words put w12 in the first run"); assert.equal(isRealtimeLoss(row({ population: "delta", value: 5 }), SCHEMA), false, "a gain is no loss"); // Without the explicit run, w12 is three months after w10: a run of its own. const plain = lossRuns(LEDGER.map((r) => (r.id === "w12" ? { ...r, run: undefined } : r)), SCHEMA); assert.deepEqual(plain.runs.map((r) => r.peak), [19.4, 40, 30]); assert.equal(plain.total, 89.4); }); test("the numbers he says: digits and words, a point, a hundred", () => { const ns = (s) => spokenNumbers(s.split(" ").map((text) => ({ text }))).map((n) => n.value); assert.deepEqual(ns("at two hundred ninety one point five for a total"), [291.5]); assert.deepEqual(ns("I'm down fifty eight point two"), [58.2]); assert.deepEqual(ns("about a hundred and ten to go, 60 lbs and 291.5"), [110, 60, 291.5]); assert.equal(spokenAt({ value: -40 }, "lost", WORDS.get("c4").words), 12); assert.equal(spokenAt({ value: 335 }, "stated", WORDS.get("c4").words), 4); assert.equal(spokenAt({ value: 999 }, "stated", WORDS.get("c4").words), null); assert.equal(spokenAt({ value: "keto" }, "diet", words([["on", 1], ["keto", 2]]), -Infinity, SCHEMA), 2); assert.equal(kindOf({ scope: "regime", population: "status" }, SCHEMA), "diet"); assert.equal(kindOf({ population: "promise_check" }, SCHEMA), "promiseCheck"); }); test("events: the rows the cut shows, in cut order, at the second the figure is said", () => { const sl = measureSlice(manifest(), { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); assert.equal(sl.version, 1); assert.deepEqual(sl.scopes, ["weight", "regime"]); assert.deepEqual(sl.scale, { min: 220, max: 400 }); assert.equal(sl.asOfRender, "2025-07-10"); const at = Object.fromEntries(sl.events.map((e) => [e.row, [e.t, e.tFrom, e.segment]])); // c4's two rows at their words: 54 + 4 and 54 + 12; its "off GLP-1" at the quote. assert.deepEqual(at.w08, [58, "words", "c4"]); assert.deepEqual(at.w09, [66, "words", "c4"]); assert.deepEqual(at.r02, [56, "quote", "c4"]); // No words: the quote's start, mapped through the clip's clock. assert.deepEqual(at.w02, [8, "quote", "c1"]); assert.deepEqual(at.w04, [26, "quote", "c2"]); for (let i = 1; i < sl.events.length; i += 1) assert.ok(sl.events[i].t >= sl.events[i - 1].t, "in cut order"); // Scopes: no drinking row, shown or hidden. assert.ok(![...sl.events, ...sl.hidden].some((e) => e.row === "d01")); // Hidden: in scope, on no entry of the cut. assert.deepEqual(sl.hidden.map((e) => e.row), ["w03", "w05", "p02", "w12"]); assert.ok(sl.hidden.every((e) => e.t === null)); const w09 = sl.events.find((e) => e.row === "w09"); assert.equal(w09.kind, "lost"); assert.equal(w09.run, 1); assert.equal(w09.qualifier, "≈"); assert.equal(sl.events.find((e) => e.row === "w04").run, null, "retro: on screen, not on the odometer"); }); test("state: after each event, from the shown rows only", () => { const sl = measureSlice(manifest(), { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); assert.equal(sl.state.length, sl.events.length + 1); assert.equal(sl.state[0].t, 0); assert.equal(sl.state[0].current, null); assert.deepEqual(sl.state[0].lost, { total: 0, runs: [] }); const after = (id) => sl.state[sl.events.findIndex((e) => e.row === id) + 1]; assert.deepEqual(after("w08").current, { value: 335, qualifier: null, row: "w08", date: "2025-05-10" }); assert.deepEqual(after("w08").net, { from: { value: 368, date: "2008-06-30", row: "w01" }, to: { value: 335, date: "2025-05-10", row: "w08" }, value: -33 }); // Keto stands through "off GLP-1". assert.equal(after("r02").diet.regime, "keto"); assert.equal(after("r02").diet.n, 1); const last = sl.state[sl.state.length - 1]; assert.equal(last.diet.regime, "carnivore"); assert.equal(last.diet.n, 2); // The odometer as the cut has shown it: w12 is hidden, so run 0's peak is the 9 shown. assert.deepEqual(last.lost, { total: 49, runs: [{ run: 0, start: "2024-01-05", peak: 9, row: "w02" }, { run: 1, start: "2025-04-01", peak: 40, row: "w09" }] }); for (let i = 1; i < sl.state.length; i += 1) assert.ok(sl.state[i].lost.total >= sl.state[i - 1].lost.total, "the odometer only goes up"); // "Lose 65" against the start of its run: the 349 he remembers (asOf 20 March, 12 days before). assert.deepEqual(last.goal, { value: 284, loss: 65, deadline: "by Christmas", due: "2025-12-25", row: "w11", display: "284 lb", base: { value: 349, row: "w07", from: "runStart", date: "2025-05-01" } }); assert.deepEqual(last.goals, ["w11"]); assert.deepEqual(last.remembered.map((r) => r.row), ["w01", "w07"]); assert.deepEqual(last.promises, [{ row: "p01", said: "2025-06-05", what: "post a video of the scale", due: null, kept: false, checks: [], claims: [], outcome: null }]); }); test("totals: the whole record in scope", () => { const sl = measureSlice(manifest(), { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); const t = sl.totals; assert.equal(t.lost, 70); assert.equal(t.runs, 2); assert.deepEqual(t.net, { from: 368, to: 335, value: -33, fromRow: "w01", toRow: "w08" }); assert.equal(t.goals, 1); assert.deepEqual(t.promises, [{ row: "p01", said: "2025-06-05", what: "post a video of the scale", due: null, kept: false, checks: ["p02"], claims: [], outcome: null }]); assert.deepEqual(t.span, { from: "2008-06-30", to: "2025-09-01" }); assert.deepEqual(t.under300, { said: 0, rows: [] }); assert.equal(t.diets, 1, "keto -> carnivore is one change; off GLP-1 none"); }); test("the settings: their shape, their scopes against the ledger, and when a cut writes a slice", () => { assert.deepEqual(validateMeasureSettings(undefined), []); assert.deepEqual(validateMeasureSettings({ scopes: ["weight"], scale: { min: 220, max: 400 }, asOf: "2026-11-05" }), []); assert.deepEqual(validateMeasureSettings({ scopes: [], scale: { min: 4, max: 2 }, asOf: "Nov 5", x: 1 }), [ "render.chrome.deck.measure.x is not a measure setting (scopes, scale, asOf, ghosts, flash)", "render.chrome.deck.measure.scopes must be a list of the ledger's track keys (at least one)", "render.chrome.deck.measure.scale.min must be below scale.max", "render.chrome.deck.measure.asOf must be a date (YYYY-MM-DD)", ]); assert.deepEqual(measureSettingsProblems(manifest({ scopes: ["weight", "gym"] })), [ 'render.chrome.deck.measure.scopes: "gym" is not a track of the ledger (weight, regime, drinking)', ]); assert.deepEqual(measureSettingsProblems({ ...manifest(), ledgerSchema: undefined }), ['render.chrome.deck.measure needs a measure ledger (ledgerSchema.kind "measure")']); assert.equal(measureOn(manifest()), true); assert.equal(measureOn({ ...manifest(), render: { chrome: { layout: "deck", deck: {} } } }), false); assert.throws(() => measureSlice(manifest({ scopes: ["gym"] }), { segments: SEGMENTS }), /not a track/); // The deck refuses a bad one where it refuses everything else. const m = manifest({ scale: { min: 1 } }); assert.match(validateChrome(m.render.chrome, m.render).join("\n"), /deck\.measure\.scale must be \{ min, max \}/); // No scopes: every track. assert.deepEqual(measureSlice(manifest({}), { segments: SEGMENTS }, { asOf: "2025-07-10" }).scopes, ["weight", "regime", "drinking"]); }); test("the deck schedule carries `measure` only for a measure cut, and the slices hand it on", () => { const m = manifest(); const doc = estimateSchedule(m); assert.ok(doc.measure, "a measure cut's schedule carries the slice"); assert.equal(doc.measure.events.length, LEDGER.filter((r) => r.entryId && r.scope !== "drinking").length); assert.equal(scheduleSlices(doc).measure, doc.measure); const plain = estimateSchedule({ ...m, render: { ...m.render, chrome: { engine: "hyperframes", layout: "deck", deck: {} } } }); assert.equal("measure" in plain, false, "no setting: the schedule it always was"); assert.equal("measure" in scheduleSlices(plain), false); // The ledger pin and the entryId name the same rows. assert.deepEqual(pinnedRows(TIMELINE, LEDGER).get("c4"), ["w08", "w09", "r02", "d01"]); assert.deepEqual(validateClaims(m), []); }); test("another speaker's rows feed the promises and move none of his numbers", () => { const plain = measureSlice(manifest(), { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); const savvy = [ row({ id: "s01", date: "2025-06-06", population: "promise_claim", value: null, speaker: "madamsavvy", promise: "p01", paidOn: "2025-06-06", display: "bought the 5 bags", label: "\"I bought the 5 bags\"", citeUrl: "https://x.com/MadamSavvy/status/1", entryId: "c5" }), // Her figures are hers: no reading, loss or goal of his. row({ id: "s02", date: "2025-06-07", population: "current", value: 250, speaker: "madamsavvy", display: "250 lb", entryId: "c5" }), row({ id: "s03", date: "2025-06-07", population: "delta", value: -99, speaker: "madamsavvy", display: "-99", entryId: "c5" }), row({ id: "s04", date: "2025-06-08", population: "goal_loss", value: -10, speaker: "madamsavvy", display: "lose 10" }), ]; const m = { ...manifest(), ledger: [...LEDGER, ...savvy] }; const sl = measureSlice(m, { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); const strip = (t) => JSON.stringify({ ...t, promises: t.promises.map(({ claims: _c, ...p }) => p) }); assert.equal(strip(sl.totals), strip(plain.totals), "the totals are his alone"); const claim = sl.events.find((e) => e.row === "s01"); assert.equal(claim.kind, "promiseClaim"); assert.equal(claim.speaker, "madamsavvy"); assert.equal(sl.events.find((e) => e.row === "s03").run, null, "her loss is no run of his"); const last = sl.state[sl.state.length - 1]; const was = plain.state[plain.state.length - 1]; for (const k of ["current", "lost", "net", "goal", "goals", "diet", "remembered"]) assert.deepEqual(last[k], was[k], k); assert.deepEqual(last.promises[0].claims, [{ row: "s01", speaker: "madamsavvy", date: "2025-06-06", paidOn: "2025-06-06", label: "\"I bought the 5 bags\"" }]); assert.deepEqual(sl.totals.promises[0].claims.map((c) => c.row), ["s01"]); assert.deepEqual(plain.state.at(-1).promises[0].claims, [], "a promise with no claim has an empty list"); }); test("a promise's outcome: how it ended, and \"kept\" keeps it -- the totals untouched", () => { const plain = measureSlice(manifest(), { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); const strip = (t) => JSON.stringify({ ...t, promises: t.promises.map(({ outcome: _o, kept: _k, ...p }) => p) }); const withOutcome = (outcome, speaker) => measureSlice({ ...manifest(), ledger: [...LEDGER, row({ id: "o01", date: "2025-06-20", population: "promise_outcome", value: null, promise: "p01", outcome, ...(speaker ? { speaker } : {}), display: outcome, label: `${outcome} by 20 June`, entryId: "c5" })], }, { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); const refunded = withOutcome("refunded", "madamsavvy"); assert.equal(strip(refunded.totals), strip(plain.totals), "an outcome moves no total"); const ev = refunded.events.find((e) => e.row === "o01"); assert.deepEqual([ev.kind, ev.outcome, ev.speaker], ["promiseOutcome", "refunded", "madamsavvy"]); const p = refunded.state.at(-1).promises[0]; assert.deepEqual(p.outcome, { kind: "refunded", date: "2025-06-20", row: "o01" }); assert.equal(p.kept, false, "refunded is not kept"); assert.deepEqual(refunded.totals.promises[0].outcome, { kind: "refunded", date: "2025-06-20", row: "o01" }); for (const k of ["current", "lost", "net", "goal", "diet"]) assert.deepEqual(refunded.state.at(-1)[k], plain.state.at(-1)[k], k); const kept = withOutcome("kept"); assert.equal(kept.state.at(-1).promises[0].kept, true); assert.equal(kept.totals.promises[0].kept, true); assert.equal(plain.state.at(-1).promises[0].outcome, null); }); // --------------------------------------------------------------------------- // The operator's rulings of 6 Nov: a bound that agrees with the weight in force does not move it; an unresolved // row and another speaker's count in no tally. // --------------------------------------------------------------------------- test("boundAgrees: a bound the specific weight satisfies agrees; one it contradicts, or a bound in force, does not", () => { const at = (value, extra = {}) => ({ value, qualifier: null, ...extra }); assert.equal(boundAgrees({ value: 300, qualifier: ">" }, at(342)), true); assert.equal(boundAgrees({ value: 300, qualifier: ">" }, at(291)), false, "contradicts: new information"); assert.equal(boundAgrees({ value: 300, qualifier: ">" }, at(300)), false, "300 is not over 300"); assert.equal(boundAgrees({ value: 300, qualifier: "<" }, at(291)), true); assert.equal(boundAgrees({ value: 300, qualifier: "<" }, at(305)), false); assert.equal(boundAgrees({ value: 390, qualifier: "≈" }, at(388)), true); assert.equal(boundAgrees({ value: 390, qualifier: "≈" }, at(380)), false); assert.equal(boundAgrees({ value: 335, range: [330, 340] }, at(337)), true); assert.equal(boundAgrees({ value: 335, range: [330, 340] }, at(342)), false); assert.equal(boundAgrees({ value: 342 }, at(300)), false, "a specific reading always moves it"); assert.equal(boundAgrees({ value: 300, qualifier: ">" }, null), false, "nothing in force: as today"); assert.equal(boundAgrees({ value: 300, qualifier: ">" }, at(320, { qualifier: ">" })), false, "a bound in force is replaced as today"); }); test("a bound that agrees with the weight in force leaves the needle and the number; one that contradicts moves them", () => { const rows = (...extra) => [ row({ id: "a1", date: "2025-05-01", population: "current", value: 342, display: "342 lb", entryId: "c3" }), ...extra, ]; const sliceOf = (ledger) => measureSlice({ ...manifest(), ledger }, { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); const currentAfter = (sl, id) => sl.state[sl.events.findIndex((e) => e.row === id) + 1].current; // ">300" at 342: the 342 stands -- its event is still there (its ghost tick, the trail's point). const agree = sliceOf(rows(row({ id: "a2", date: "2025-05-10", population: "current", value: 300, qualifier: ">", display: ">300 lb", entryId: "c4" }))); assert.equal(currentAfter(agree, "a2").row, "a1"); assert.equal(currentAfter(agree, "a2").value, 342); assert.ok(agree.events.some((e) => e.row === "a2" && e.kind === "stated")); // "<300" at 342 contradicts it: new information, the needle moves. const contra = sliceOf(rows(row({ id: "a2", date: "2025-05-10", population: "current", value: 300, qualifier: "<", display: "<300 lb", entryId: "c4" }))); assert.deepEqual([currentAfter(contra, "a2").row, currentAfter(contra, "a2").qualifier], ["a2", "<"]); // A bound with nothing specific in force behaves as it did: it is the reading. const first = sliceOf([row({ id: "a2", date: "2025-05-10", population: "current", value: 300, qualifier: ">", display: ">300 lb", entryId: "c4" })]); assert.equal(currentAfter(first, "a2").row, "a2"); // The panel's reading cell keeps the same rule. const prev = nextReading(null, row({ id: "a1", date: "2025-05-01", population: "current", value: 342, display: "342 lb" }), SCHEMA); assert.equal(nextReading(prev, row({ id: "a2", date: "2025-05-10", population: "current", value: 300, qualifier: ">", display: ">300 lb" }), SCHEMA).row, "a1"); assert.equal(nextReading(prev, row({ id: "a3", date: "2025-05-10", population: "current", value: 300, qualifier: "<", display: "<300 lb" }), SCHEMA).row, "a3"); }); test("an unresolved row (a joke) counts in no tally -- goals set, the goal, diets, promises, the odometer, under 300 -- pinned or not", () => { const sliceOf = (ledger) => measureSlice({ ...manifest(), ledger }, { segments: SEGMENTS }, { words: WORDS, clock: CLOCK, asOf: "2025-07-10" }); const plain = sliceOf(LEDGER); const joke = { scopeConfidence: "unresolved" }; const extra = [ // w44's shape: "only way I'm losing 100 lbs is by amputation" -- unpinned, and a pinned one besides. row({ id: "j1", date: "2025-06-07", population: "goal_loss", value: -100, display: "lose 100", ...joke }), row({ id: "j2", date: "2025-06-07", population: "goal", value: 200, display: "200", entryId: "c5", ...joke }), row({ id: "j3", date: "2025-06-07", scope: "regime", population: "status", value: "glp1", event: "start", display: "glp1", entryId: "c5", ...joke }), row({ id: "j4", date: "2025-06-07", population: "delta", value: -150, display: "-150", entryId: "c5", ...joke }), row({ id: "j5", date: "2025-06-07", population: "promise", value: null, display: "a joke promise", entryId: "c5", ...joke }), ]; const sl = sliceOf([...LEDGER, ...extra]); for (const k of ["goals", "goalRepeats", "diets", "lost", "runs", "under300"]) assert.deepEqual(sl.totals[k], plain.totals[k], k); assert.deepEqual(sl.totals.promises.map((p) => p.row), plain.totals.promises.map((p) => p.row)); const last = sl.state.at(-1), was = plain.state.at(-1); for (const k of ["goal", "goals", "diet", "lost", "current"]) assert.deepEqual(last[k], was[k], k); // Pinned, it is still an event (on screen), marked; the goal board passes over it. assert.equal(sl.events.find((e) => e.row === "j2").unresolved, true); assert.equal(plain.events.find((e) => e.row === "w11").unresolved, undefined, "a usable row's event is as it was"); assert.ok(!goalBoard(sl).some((b) => b.active.some((g) => g.row === "j2"))); assert.equal(isUsable({ scopeConfidence: "unresolved" }), false); assert.equal(isUsable({ scopeConfidence: "read" }), true); }); test("the scoreboard's tallies (goals set, diets, pledges) count neither an unresolved row nor another speaker's", () => { const base = [ row({ id: "g1", date: "2025-01-01", population: "goal", value: 250, display: "250" }), row({ id: "r1", date: "2025-01-02", scope: "regime", population: "status", value: "keto", event: "start", display: "keto" }), ]; const noise = [ row({ id: "g2", date: "2025-02-01", population: "goal_loss", value: -100, display: "lose 100", scopeConfidence: "unresolved" }), row({ id: "g3", date: "2025-02-02", population: "goal", value: 200, display: "200", speaker: "madamsavvy" }), row({ id: "r2", date: "2025-02-03", scope: "regime", population: "status", value: "carnivore", event: "start", display: "carnivore", speaker: "madamsavvy" }), row({ id: "r3", date: "2025-02-04", scope: "regime", population: "status", value: "glp1", event: "start", display: "glp1", scopeConfidence: "unresolved" }), ]; const board = (ledger) => measureScoreboard(measureTotals(ledger, SCHEMA, { strict: false })).final; const a = board(base), b = board([...base, ...noise]); assert.deepEqual([b.goals.count, b.diets.count, b.pledges.count], [a.goals.count, a.diets.count, a.pledges.count]); assert.equal(b.goals.last.id, "g1"); });