From c1409ae9b93524e9316331a0b23a00e521a0b321 Mon Sep 17 00:00:00 2001 From: Kjell Tore Guttormsen Date: Sun, 21 Jun 2026 13:45:53 +0200 Subject: [PATCH] =?UTF-8?q?test(tok):=20hermetic=20HOME=20in=20runScanner?= =?UTF-8?q?=20=E2=80=94=20deterministic=20on=20populated=20~/.claude?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit token-hotspots.test.mjs ran scan() under the developer's real HOME, so readActiveConfig leaked ~/.claude (user CLAUDE.md cascade + ambient MCP/ plugins) into every fixture result. This made assertions machine-dependent: green on a clean HOME, red on a populated one (small-cascade tipped past the 10k-token threshold; sonnet-era gained ambient MCP findings). Wrap the HOME-dependent scan() call in the shared withHermeticHome helper — same isolation the OST test and the snapshot/byte-stability suite already use. Full suite (1055) now green on BOTH real and clean HOME. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/scanners/token-hotspots.test.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/scanners/token-hotspots.test.mjs b/tests/scanners/token-hotspots.test.mjs index 4c29eda..4b19523 100644 --- a/tests/scanners/token-hotspots.test.mjs +++ b/tests/scanners/token-hotspots.test.mjs @@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'; import { resetCounter } from '../../scanners/lib/output.mjs'; import { scan } from '../../scanners/token-hotspots.mjs'; import { discoverConfigFiles } from '../../scanners/lib/file-discovery.mjs'; +import { withHermeticHome } from '../helpers/hermetic-home.mjs'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); const FIXTURES = resolve(__dirname, '../fixtures'); @@ -17,7 +18,16 @@ async function runScanner(fixtureName) { resetCounter(); const path = resolve(FIXTURES, fixtureName); const discovery = await fixtureDiscovery(fixtureName); - return scan(path, discovery); + // Hermetic HOME: scan() calls readActiveConfig, which resolves the user + // ~/.claude/CLAUDE.md cascade + plugins/MCP from process.env.HOME. Without + // this override the developer's real ~/.claude leaks into every fixture + // result — small-cascade tips past the 10k-token threshold and sonnet-era + // picks up ambient MCP findings — making assertions machine-dependent + // (green on a clean HOME, red on a populated one). Mirrors the OST test. + // NOTE: residual coupling — the cascade's ancestor walk still climbs from + // the fixture path through the real repo CLAUDE.md (an ancestor of tests/), + // but that contribution is deterministic per-checkout, not user-dependent. + return withHermeticHome(() => scan(path, discovery)); } describe('TOK scanner — healthy-project', () => {