/** * Legend/filters predicate tests — the pure half of the graph-view filters * panel (isNodeVisible); the sigma reducers just consume its verdict. */ import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { displayCostTotals, isNodeVisible } from "../components/graph-view.tsx"; const node = { name: "Money multiplier", statement: "The maximum ratio of broad money a bank can create from each unit of base money.", }; describe("isNodeVisible (search predicate)", () => { it("is visible with an empty query", () => { assert.equal(isNodeVisible(node, ""), true); }); it("search matches the statement case-insensitively", () => { assert.equal(isNodeVisible(node, "MONEY multiplier"), true); }); it("search matches the statement when the name does not", () => { assert.equal(isNodeVisible(node, "MAXIMUM ratio"), true); assert.equal(isNodeVisible(node, " velocity"), false); }); it("search matches the name when the statement does not", () => { assert.equal(isNodeVisible(node, "money MULTIPLIER"), true); assert.equal(isNodeVisible(node, " banking"), false); }); it("whitespace-only query is no filter", () => { assert.equal(isNodeVisible(node, " "), true); }); }); describe("displayCostTotals (naming-free cost fold)", () => { const stage = (dollars: number, unpricedRuns = 0) => ({ runs: dollars > 0 ? 1 : 0, dollars, unpricedRuns, tokens: { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, reasoningTokens: 0, }, }); const costs = { stages: { extraction: stage(1.25, 1), audit: stage(0.75), naming: stage(9.99, 2), // dead channel — must never reach the display }, } as const; it("sums extraction + audit only — the dead namer's spend is invisible", () => { assert.equal(displayCostTotals(costs).totalDollars, 2); }); it("unpriced counts fold the same two stages", () => { assert.equal(displayCostTotals(costs).unpricedRuns, 1); }); });