Files
learnharness/tests/render-graph-coverage.test.tsx
T
amosblomqvist 2678f04e7a feat: extraction coverage — message-granular ledger + token-batched runs (d132373 vision)
THE MESSAGE IS THE UNIT OF COVERAGE (vision-extraction-coverage.md): a
per-chat append-only ledger (coverage.jsonl) records which messages the
pipeline has extracted, by content fingerprint over exactly what the
extraction view sees (one shared line builder — core/coverage.ts); the
uncovered remainder is DERIVED at read time, never dual-tracked. A quiz
answer merging into the asking message re-opens only that message;
plan-block data-part attach never re-opens anything.

- The trigger (turn-service) replaces every-3-quiz-answers with
  uncovered-tokens >= EXTRACTION.chunkTokens (4096) — quiz-less sessions
  extract too, content size is the honest signal.
- runExtraction is now chunked: token-budgeted batches of the oldest
  uncovered consecutive messages (a tool call + result never split), each
  merged batch checkpointing its messages' coverage atomically — an abort
  or error loses at most the in-flight batch; merged batches stay covered.
- Observation refs are batch-tagged (obs:<batchTag>:<sourceId>): re-runs
  of the same batch dedupe; a re-opened message's fresh understanding
  lands as a new event. Fixes the old obs:p1 position-collision.
- New API: GET /api/graph/coverage (exact per-session derived coverage +
  running flags, most-uncovered first) and POST /api/graph/coverage/extract
  (manual run for one session, 409 while in flight).
- Graph view chrome: the coverage button opens a panel with every
  session's covered/uncovered tokens and a per-session Extract button —
  the manual answer to aborted runs, errors, and dormant tails. Renders
  even when the graph is empty: an empty graph with uncovered sessions is
  exactly when it matters. Polls only while open.
- Notes imports keep the whole-file checkpoint path (coverage undefined).
- Tests: pure-core coverage suite (11), chunked-pipeline suite (3:
  multi-batch + no-op, abort-keeps-earlier-batches + remainder re-run,
  re-open alone + data-part invisibility), panel render suite (5);
  pendingQuizAnswers and its tests deleted as dead code. 486/486.

Live-smoked on real GLM: manual extract of "teach me modal realism" ran
one batch, wrote 4 coverage entries, panel flipped to "1.3k covered ·
complete" with the button disabled, graph refetched (nodes 11), usage
persisted with real stats.
2026-09-15 17:41:56 +03:00

85 lines
3.1 KiB
TypeScript

import { renderToStaticMarkup } from "react-dom/server";
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { CoveragePanel, GraphCoverageControl } from "../components/graph-coverage.tsx";
// The extraction-coverage panel (vision-extraction-coverage.md, settled
// 2026-09-15): the graph view's window into WHAT the pipeline has covered,
// with a per-session "Extract" button for the uncovered remainder. Static
// markup can't click — the closed control and the panel body are pinned
// separately. (Interaction — the fetch + POST flow — is covered by the live
// smoke.)
describe("GraphCoverageControl", () => {
it("renders the coverage button in the chrome, closed by default", () => {
const html = renderToStaticMarkup(<GraphCoverageControl />);
assert.ok(html.includes("<button"));
assert.ok(html.includes("Extraction coverage"));
assert.ok(!html.includes('data-testid="coverage-panel"'), "the panel starts closed");
});
});
describe("CoveragePanel — exact per-session coverage data", () => {
const base = {
chatId: "chat_a",
title: "Modal logic",
updatedAt: "2026-09-15T00:00:00.000Z",
totalMessages: 12,
coveredMessages: 10,
uncoveredMessages: 2,
coveredTokens: 1536,
uncoveredTokens: 384,
running: false,
};
it("shows each session's covered/uncovered tokens and the Extract button", () => {
const html = renderToStaticMarkup(
<CoveragePanel chats={[base]} loaded isBusy={() => false} onExtract={() => {}} />,
);
assert.ok(html.includes("Modal logic"));
assert.ok(html.includes("1.5k covered"));
assert.ok(html.includes("384 uncovered"));
assert.ok(html.includes("(2 msgs)"));
assert.ok(html.includes(">Extract<"), "the uncovered session offers a manual extract");
});
it("a fully covered session shows · complete with a disabled Extract button", () => {
const html = renderToStaticMarkup(
<CoveragePanel
chats={[{ ...base, uncoveredMessages: 0, uncoveredTokens: 0, coveredMessages: 12, coveredTokens: 1920 }]}
loaded
isBusy={() => false}
onExtract={() => {}}
/>,
);
assert.ok(html.includes("· complete"));
assert.ok(html.includes("disabled"), "nothing to extract — the button is honest");
assert.ok(!html.includes(">Extract<") || html.includes("disabled"));
});
it("a running session shows extracting… and no clickable duplicate start", () => {
const html = renderToStaticMarkup(
<CoveragePanel
chats={[{ ...base, running: true }]}
loaded
isBusy={(c) => c.running}
onExtract={() => {}}
/>,
);
assert.ok(html.includes("extracting…"));
assert.ok(html.includes(">Running<"));
assert.ok(html.includes("disabled"), "single-flight: the in-flight run can't be double-started");
});
it("all-covered panel: the nothing-pending line, not a row list", () => {
const html = renderToStaticMarkup(
<CoveragePanel
chats={[{ ...base, uncoveredMessages: 0, uncoveredTokens: 0 }]}
loaded
isBusy={() => false}
onExtract={() => {}}
/>,
);
assert.ok(html.includes("Every session is fully extracted — nothing pending."));
});
});