fix(config-audit): remove TOK dead take + hotspot padding (v5 F4)

The buildHotspots padding loop and unused 'take' variable were dead
code from the v3 hotspots-min contract. Replaced with a clean
ranked.slice(0, HOTSPOTS_MAX). Tiny fixtures may now return fewer
than 3 hotspots, which is the honest answer; the contract now only
asserts <= 10.

Tests: +2 cases — every hotspot.source is unique (no padding); length
never exceeds HOTSPOTS_MAX.
This commit is contained in:
Kjell Tore Guttormsen 2026-05-01 06:29:33 +02:00
commit 0d8a9af3d6
2 changed files with 13 additions and 21 deletions

View file

@ -39,7 +39,6 @@ const VOLATILE_PATTERNS = [
const MAX_IMPORT_DEPTH = 2;
const HOTSPOTS_MIN = 3;
const HOTSPOTS_MAX = 10;
/**
@ -210,13 +209,6 @@ async function buildHotspots(discovery, targetPath, activeConfig) {
}
ranked.sort((a, b) => b.estimated_tokens - a.estimated_tokens);
// If we have fewer than HOTSPOTS_MIN entries, pad with placeholder entries
// derived from the same set so the contract still holds for tiny fixtures.
let take = Math.min(Math.max(ranked.length, HOTSPOTS_MIN), HOTSPOTS_MAX);
// Cap to actual entries (don't fabricate) — tests run against marketplace-large
// for the 3-10 contract; tiny fixtures still produce a real array.
take = Math.min(take, Math.max(ranked.length, 1));
const top = ranked.slice(0, HOTSPOTS_MAX);
const out = [];
for (let i = 0; i < top.length; i++) {
@ -229,19 +221,7 @@ async function buildHotspots(discovery, targetPath, activeConfig) {
});
}
// Pad to HOTSPOTS_MIN with the smallest entries repeated as "summary" rows
// — this only triggers for fixtures with <3 sources.
while (out.length < HOTSPOTS_MIN && ranked.length > 0) {
const extra = ranked[ranked.length - 1];
out.push({
source: extra.relPath || extra.absPath,
estimated_tokens: extra.estimated_tokens,
rank: out.length + 1,
recommendations: hotspotRecommendations(extra),
});
}
return out.slice(0, HOTSPOTS_MAX);
return out;
}
function hotspotRecommendations(h) {

View file

@ -170,4 +170,16 @@ describe('TOK scanner — hotspots contract', () => {
`hotspot.recommendations length should be 13, got ${h.recommendations.length}`);
}
});
it('every hotspot.source is unique (v5 F4: no padding)', () => {
const sources = result.hotspots.map(h => h.source);
const unique = new Set(sources);
assert.equal(unique.size, sources.length,
`expected unique sources; got duplicates in: ${sources.join(', ')}`);
});
it('hotspots.length never exceeds HOTSPOTS_MAX (10)', () => {
assert.ok(result.hotspots.length <= 10,
`expected ≤10 hotspots, got ${result.hotspots.length}`);
});
});