2026-09-05 21:35:07 +03:00
|
|
|
/**
|
|
|
|
|
* 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";
|
2026-09-24 19:25:37 +03:00
|
|
|
import { displayCostTotals, isNodeVisible } from "../components/graph-view.tsx";
|
2026-09-05 21:35:07 +03:00
|
|
|
|
2026-09-08 22:23:07 +03:00
|
|
|
const node = {
|
2026-09-09 00:40:02 +03:00
|
|
|
name: "Money multiplier",
|
|
|
|
|
statement: "The maximum ratio of broad money a bank can create from each unit of base money.",
|
2026-09-08 22:23:07 +03:00
|
|
|
};
|
2026-09-05 21:35:07 +03:00
|
|
|
|
2026-09-09 01:24:08 +03:00
|
|
|
describe("isNodeVisible (search predicate)", () => {
|
|
|
|
|
it("is visible with an empty query", () => {
|
|
|
|
|
assert.equal(isNodeVisible(node, ""), true);
|
2026-09-05 21:35:07 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-08 22:23:07 +03:00
|
|
|
it("search matches the statement case-insensitively", () => {
|
2026-09-09 01:24:08 +03:00
|
|
|
assert.equal(isNodeVisible(node, "MONEY multiplier"), true);
|
2026-09-05 21:35:07 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-09 00:40:02 +03:00
|
|
|
it("search matches the statement when the name does not", () => {
|
2026-09-09 01:24:08 +03:00
|
|
|
assert.equal(isNodeVisible(node, "MAXIMUM ratio"), true);
|
|
|
|
|
assert.equal(isNodeVisible(node, " velocity"), false);
|
2026-09-05 21:35:07 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-09 00:40:02 +03:00
|
|
|
it("search matches the name when the statement does not", () => {
|
2026-09-09 01:24:08 +03:00
|
|
|
assert.equal(isNodeVisible(node, "money MULTIPLIER"), true);
|
|
|
|
|
assert.equal(isNodeVisible(node, " banking"), false);
|
2026-09-09 00:40:02 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-05 21:35:07 +03:00
|
|
|
it("whitespace-only query is no filter", () => {
|
2026-09-09 01:24:08 +03:00
|
|
|
assert.equal(isNodeVisible(node, " "), true);
|
2026-09-05 21:35:07 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-09 01:24:08 +03:00
|
|
|
|
2026-09-24 19:25:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2026-09-30 16:38:45 +03:00
|
|
|
it("sums the live stages only — the dead namer's spend is invisible", () => {
|
2026-09-24 19:25:37 +03:00
|
|
|
assert.equal(displayCostTotals(costs).totalDollars, 2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("unpriced counts fold the same two stages", () => {
|
|
|
|
|
assert.equal(displayCostTotals(costs).unpricedRuns, 1);
|
|
|
|
|
});
|
|
|
|
|
});
|