feat(config-audit): TOK consumes readActiveConfig (v5 F1)

Removes the v4 'void readActiveConfig' placeholder and wires the
active-config snapshot into the TOK scanner.

Per-turn behavior changes:
- Each enabled MCP server becomes its own hotspot entry (richer than
  the parent .mcp.json file alone)
- total_estimated_tokens now includes MCP server cost
- result.activeConfig exposes a small summary
  (claudeMdEstimatedTokens, mcpServerCount, pluginCount, skillCount)

Failures of readActiveConfig are non-fatal — the scanner falls back
to the discovery-only path used in v4.

Tests: +3 cases on the new tok-active-config fixture
(.mcp.json with 2 servers, CLAUDE.md, plugin skeleton).
This commit is contained in:
Kjell Tore Guttormsen 2026-05-01 06:27:34 +02:00
commit 34669d596c
6 changed files with 115 additions and 9 deletions

View file

@ -0,0 +1,5 @@
{
"name": "tok-active-config",
"description": "Fixture plugin for TOK scanner active-config integration test",
"version": "0.0.1"
}

View file

@ -0,0 +1,12 @@
{
"mcpServers": {
"alpha": {
"command": "npx",
"args": ["alpha-server"]
},
"beta": {
"command": "npx",
"args": ["beta-server"]
}
}
}

View file

@ -0,0 +1,14 @@
# Tok Active-Config Fixture
A small Claude Code-shaped project used by the TOK scanner integration test.
## Purpose
Verify that the TOK scanner consumes `readActiveConfig` output: MCP servers
appear in hotspots and the CLAUDE.md cascade contributes a non-zero token
estimate when active-config integration is wired up (v5 F1).
## Notes
This file is intentionally larger than a one-liner so the cascade contributes
visible tokens to `activeConfig.claudeMd.estimatedTokens`.

View file

@ -0,0 +1,11 @@
---
name: sample
description: Sample command in the tok-active-config fixture
model: sonnet
---
# /sample
A trivial command body so the file has both frontmatter and content. The TOK
scanner ranks command sources by their estimated tokens; this is bigger than
zero, smaller than CLAUDE.md.

View file

@ -112,6 +112,35 @@ describe('TOK scanner — marketplace scale ordering', () => {
});
});
describe('TOK scanner — readActiveConfig integration (v5 F1)', () => {
let result;
beforeEach(async () => {
result = await runScanner('tok-active-config');
});
it('exposes activeConfig summary on the result (proves readActiveConfig was called)', () => {
assert.ok(result.activeConfig, 'expected result.activeConfig to be set');
assert.equal(typeof result.activeConfig.claudeMdEstimatedTokens, 'number');
assert.ok(result.activeConfig.claudeMdEstimatedTokens > 0,
`expected claudeMd cascade > 0 tokens, got ${result.activeConfig.claudeMdEstimatedTokens}`);
});
it('hotspots include at least one MCP-source entry', () => {
const hasMcp = result.hotspots.some(h => /mcp/i.test(h.source));
assert.ok(hasMcp,
`expected hotspots to include an MCP source; got: ${result.hotspots.map(h => h.source).join(', ')}`);
});
it('total_estimated_tokens exceeds the minimal sonnet-era baseline', async () => {
// sonnet-era has no .mcp.json — the activeConfig MCP entries from this
// fixture should push its total above sonnet-era's even when both fixtures
// share the user's ambient cascade/plugin state.
const baseline = await runScanner('opus-47/sonnet-era');
assert.ok(result.total_estimated_tokens > baseline.total_estimated_tokens,
`expected ${result.total_estimated_tokens} > ${baseline.total_estimated_tokens}`);
});
});
describe('TOK scanner — hotspots contract', () => {
let result;
beforeEach(async () => {