From cddf5d5a53a4b34fc2cb2f4401a2b60c14fd6085 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Tue, 18 Aug 2026 08:27:22 -0700 Subject: [PATCH] test(optimize): pin per-session MCP schema charging without connectors The rewritten cost pass charges each session only for the schemas that session loaded, which changes local-only estimates too (on a real corpus the mcp-low-coverage estimate roughly halves). Pin it so the change is deliberate rather than a side effect of the connector split. --- tests/mcp-coverage.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/mcp-coverage.test.ts b/tests/mcp-coverage.test.ts index 0dc7f36c..49d94cd6 100644 --- a/tests/mcp-coverage.test.ts +++ b/tests/mcp-coverage.test.ts @@ -970,6 +970,25 @@ describe('connector findings and finding class', () => { expect(classTotals([finding!], 0.00002).fix.tokensSaved).toBe(finding!.tokensSaved) }) + it('charges each session only for the local schemas it actually loaded', () => { + // Same per-session scoping the connector split relies on, with no + // connector in play: two flagged local servers in disjoint sessions are + // charged one schema each, not both schemas everywhere. + const sessions = ['filesystem', 'playwright'].flatMap(server => + ['a', 'b'].map(suffix => makeSession({ + sessionId: `${server}-${suffix}`, + inventory: inventoryFor([server]), + turns: [makeTurn([makeCall({ cacheCreation: 50_000 })])], + })), + ) + + const finding = detectMcpToolCoverage([project(sessions)]) + + expect(finding).toMatchObject({ tokensSaved: 40_000 }) + expect(finding!.applyTokensSaved).toBeUndefined() + expect(classTotals([finding!], 0.00002).fix.tokensSaved).toBe(40_000) + }) + it('treats a local server named like a connector namespace as manual only', () => { // Known limitation: the namespace prefix is the only connector signal in // the transcript, so a local server literally named claude_ai_* gets the