From 04032d704ecf5e87309cc97355bc0da60d79358a Mon Sep 17 00:00:00 2001 From: HeavyGee <133152184+heavygee@users.noreply.github.com> Date: Fri, 13 Nov 2026 00:40:19 +0000 Subject: [PATCH] fix(cli): isolate claude.test.ts resume-identity tests from HAPI_INVOKED_CWD (#2396) --- cli/src/commands/claude.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cli/src/commands/claude.test.ts b/cli/src/commands/claude.test.ts index 91e1d262..239d8d2f 100644 --- a/cli/src/commands/claude.test.ts +++ b/cli/src/commands/claude.test.ts @@ -162,6 +162,13 @@ describe('claudeCommand resume identity', () => { // Resume targets need a local transcript; give each test its own Claude config dir. const originalClaudeConfigDir = process.env.CLAUDE_CONFIG_DIR + // getInvokedCwd() prefers HAPI_INVOKED_CWD over process.cwd() — running + // this suite itself inside a HAPI-wrapped session (this one included) + // leaks that var in, so the fixture written under process.cwd() below + // would silently resolve against a different directory than the command + // actually looks in. Clear it for the duration so resolution matches + // where `directory` points, same as CI (where the var is unset). + const originalHapiInvokedCwd = process.env.HAPI_INVOKED_CWD let claudeConfigDir = '' beforeEach(() => { @@ -169,6 +176,7 @@ describe('claudeCommand resume identity', () => { getLocalResumeTargetByAgentSessionIdMock.mockReset() handoffSessionToLocalMock.mockClear() prepareSessionForLocalResumeMock.mockClear() + delete process.env.HAPI_INVOKED_CWD claudeConfigDir = mkdtempSync(join(tmpdir(), 'hapi-claude-resume-')) process.env.CLAUDE_CONFIG_DIR = claudeConfigDir const projectDir = getProjectPath(directory) @@ -179,6 +187,8 @@ describe('claudeCommand resume identity', () => { afterEach(() => { if (originalClaudeConfigDir === undefined) delete process.env.CLAUDE_CONFIG_DIR else process.env.CLAUDE_CONFIG_DIR = originalClaudeConfigDir + if (originalHapiInvokedCwd === undefined) delete process.env.HAPI_INVOKED_CWD + else process.env.HAPI_INVOKED_CWD = originalHapiInvokedCwd rmSync(claudeConfigDir, { recursive: true, force: true }) })