Skip to content

Commit 7ba94b9

Browse files
committed
fix: isolate session and plugin-data env vars in tests
Three tests fail when CODEX_COMPANION_SESSION_ID is set in the environment (e.g., inside a Claude Code session). The session filter drops all test jobs because they lack a sessionId field. Similarly, the resolveStateDir tmpdir test fails when CLAUDE_PLUGIN_DATA is set. Strip CODEX_COMPANION_SESSION_ID from the subprocess env for tests that don't exercise session filtering, and isolate CLAUDE_PLUGIN_DATA in the state directory test. Fixes 4 pre-existing test failures that appear when running tests inside a Claude Code session.
1 parent 594fd1e commit 7ba94b9

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

tests/runtime.test.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,11 @@ test("status shows phases, hints, and the latest finished job", () => {
750750
"utf8"
751751
);
752752

753+
const env = { ...process.env };
754+
delete env.CODEX_COMPANION_SESSION_ID;
753755
const result = run("node", [SCRIPT, "status"], {
754-
cwd: workspace
756+
cwd: workspace,
757+
env
755758
});
756759

757760
assert.equal(result.status, 0, result.stderr);
@@ -894,8 +897,11 @@ test("status preserves adversarial review kind labels", () => {
894897
"utf8"
895898
);
896899

900+
const env = { ...process.env };
901+
delete env.CODEX_COMPANION_SESSION_ID;
897902
const result = run("node", [SCRIPT, "status"], {
898-
cwd: workspace
903+
cwd: workspace,
904+
env
899905
});
900906

901907
assert.equal(result.status, 0, result.stderr);
@@ -1017,8 +1023,11 @@ test("result returns the stored output for the latest finished job by default",
10171023
"utf8"
10181024
);
10191025

1026+
const env = { ...process.env };
1027+
delete env.CODEX_COMPANION_SESSION_ID;
10201028
const result = run("node", [SCRIPT, "result"], {
1021-
cwd: workspace
1029+
cwd: workspace,
1030+
env
10221031
});
10231032

10241033
assert.equal(result.status, 0, result.stderr);

tests/state.test.mjs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,22 @@ import { resolveJobFile, resolveJobLogFile, resolveStateDir, resolveStateFile, s
99

1010
test("resolveStateDir uses a temp-backed per-workspace directory", () => {
1111
const workspace = makeTempDir();
12-
const stateDir = resolveStateDir(workspace);
12+
const previousPluginDataDir = process.env.CLAUDE_PLUGIN_DATA;
13+
delete process.env.CLAUDE_PLUGIN_DATA;
14+
15+
try {
16+
const stateDir = resolveStateDir(workspace);
1317

14-
assert.equal(stateDir.startsWith(os.tmpdir()), true);
15-
assert.match(path.basename(stateDir), /.+-[a-f0-9]{16}$/);
16-
assert.match(stateDir, new RegExp(`^${os.tmpdir().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
18+
assert.equal(stateDir.startsWith(os.tmpdir()), true);
19+
assert.match(path.basename(stateDir), /.+-[a-f0-9]{16}$/);
20+
assert.match(stateDir, new RegExp(`^${os.tmpdir().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
21+
} finally {
22+
if (previousPluginDataDir == null) {
23+
delete process.env.CLAUDE_PLUGIN_DATA;
24+
} else {
25+
process.env.CLAUDE_PLUGIN_DATA = previousPluginDataDir;
26+
}
27+
}
1728
});
1829

1930
test("resolveStateDir uses CLAUDE_PLUGIN_DATA when it is provided", () => {

0 commit comments

Comments
 (0)