From 24f1c75be39f00397c8219a3fe1a2042c19a871a Mon Sep 17 00:00:00 2001 From: Baptiste LAFOURCADE Date: Tue, 20 Oct 2026 07:17:31 +0200 Subject: [PATCH] test(cli): keep the runner's own session out of the telemetry sandbox's git A test that set its fixture's Claude Code session got the runner's CODEX_THREAD_ID in its commit trailer instead, since the sandbox's git environment inherited it. The sandbox now hands git no ambient session. Closes #1050 Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01TnCgcujM2xi6T6dkmVogVw --- .../telemetry-sandbox.integration.test.ts | 28 +++++++++++++++++++ cli/tests/helpers/telemetry-sandbox.ts | 7 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 cli/tests/helpers/telemetry-sandbox.integration.test.ts diff --git a/cli/tests/helpers/telemetry-sandbox.integration.test.ts b/cli/tests/helpers/telemetry-sandbox.integration.test.ts new file mode 100644 index 000000000..094340fb1 --- /dev/null +++ b/cli/tests/helpers/telemetry-sandbox.integration.test.ts @@ -0,0 +1,28 @@ +import { rmSync } from "node:fs"; +import { afterEach, describe, expect, it } from "vitest"; +import { createTelemetrySandbox } from "./telemetry-sandbox.js"; + +describe("the telemetry sandbox's git environment", () => { + const saved = { claude: process.env.CLAUDE_CODE_SESSION_ID, codex: process.env.CODEX_THREAD_ID }; + afterEach(() => { + for (const [name, value] of [ + ["CLAUDE_CODE_SESSION_ID", saved.claude], + ["CODEX_THREAD_ID", saved.codex], + ] as const) { + if (value === undefined) delete process.env[name]; + else process.env[name] = value; + } + }); + + it("hands a git hook no session of the process running the tests", () => { + process.env.CLAUDE_CODE_SESSION_ID = "runner-claude-session"; + process.env.CODEX_THREAD_ID = "runner-codex-thread"; + const box = createTelemetrySandbox(); + try { + expect(box.gitEnv.CLAUDE_CODE_SESSION_ID).toBe(""); + expect(box.gitEnv.CODEX_THREAD_ID).toBe(""); + } finally { + rmSync(box.root, { recursive: true, force: true }); + } + }); +}); diff --git a/cli/tests/helpers/telemetry-sandbox.ts b/cli/tests/helpers/telemetry-sandbox.ts index f943e5f8a..1f2dfa547 100644 --- a/cli/tests/helpers/telemetry-sandbox.ts +++ b/cli/tests/helpers/telemetry-sandbox.ts @@ -41,7 +41,12 @@ export function createTelemetrySandbox(): TelemetrySandbox { for (const dir of [home, claude]) mkdirSync(dir, { recursive: true }); assertUnderTemporaryDirectory([root, home, telemetry, claude]); writeFileSync(join(home, ".gitconfig"), ""); - const gitEnv = sandboxGitEnv(home, { GIT_CONFIG_GLOBAL: join(home, ".gitconfig") }); + // A hook git runs reads the session from these: the runner's own must not reach a commit. + const gitEnv = sandboxGitEnv(home, { + GIT_CONFIG_GLOBAL: join(home, ".gitconfig"), + CLAUDE_CODE_SESSION_ID: "", + CODEX_THREAD_ID: "", + }); return { root, home,