coverage meter one-truth fix + chunk-budget setting UI: fetchGraphRead resolves through the shared core resolver (the stale 4096 fallback filled the ring at half the 8192 truth); Graph section gains the extraction chunk budget row (floor 500, empty = factory) and the master switch composes instead of replacing the section

This commit is contained in:
amosblomqvist
2026-10-02 21:18:51 +03:00
parent 2ef09b0282
commit 76387b043b
4 changed files with 152 additions and 30 deletions
+53
View File
@@ -8,6 +8,7 @@ import {
CoverageMenuBody,
CoverageRingDetail,
CoverageRingGlyph,
fetchGraphRead,
ringFill,
type SessionCoverage,
} from "../components/extraction-coverage.tsx";
@@ -34,6 +35,58 @@ function coverage(over: Partial<SessionCoverage> = {}): SessionCoverage {
};
}
describe("fetchGraphRead — one truth with the extraction trigger (2026-10-02)", () => {
// The meter's denominator MUST be the number the server's
// effectiveSettings gate waits for. The old hand-rolled fallback
// read the raw delta and guessed `?? 4096` — a stale pre-setting-era
// constant — so an unset budget filled the ring at half the truth
// (owner repro: 6k shown full, extraction correctly silent at 8192).
// Now the raw delta resolves through the SAME core resolver.
const stub = (payload: unknown, ok = true) => {
const real = globalThis.fetch;
globalThis.fetch = (async () =>
new Response(JSON.stringify(payload), { status: ok ? 200 : 500 })) as typeof fetch;
return () => {
globalThis.fetch = real;
};
};
it("an absent graph section denominates at the factory 8192 — never 4096, never a missing ring", async () => {
const restore = stub({ settings: { version: 1 } });
const read = await fetchGraphRead();
restore();
assert.deepEqual(read, { enabled: true, chunkTokens: 8192 });
});
it("the owner repro shape — graph section present, budget never written — is 8192", async () => {
const restore = stub({ settings: { version: 1, graph: { enabled: true } } });
const read = await fetchGraphRead();
restore();
assert.equal(read?.chunkTokens, 8192, "the record lacks the key: factory, not the stale 4096");
});
it("first boot (settings null) resolves factory — the ring shows, at the true budget", async () => {
const restore = stub({ settings: null });
const read = await fetchGraphRead();
restore();
assert.deepEqual(read, { enabled: true, chunkTokens: 8192 });
});
it("a custom budget rides through verbatim", async () => {
const restore = stub({ settings: { version: 1, graph: { enabled: true, extractionChunkTokens: 2000 } } });
const read = await fetchGraphRead();
restore();
assert.equal(read?.chunkTokens, 2000);
});
it("fetch failure → null → no ring", async () => {
const restore = stub({}, false);
const read = await fetchGraphRead();
restore();
assert.equal(read, null);
});
});
describe("ringFill (the donut's fold, pure)", () => {
it("fills uncovered/chunk, clamped to [0,1]", () => {
assert.equal(ringFill(0, 4096), 0);