Integration tests should use a project-controlled CLAUDE_CONFIG_DIR, not the developer's #59
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
iterative-works/claude-code-query#59
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The integration tests spawn a real
claudeCLI, and almost none of them setCLAUDE_CONFIG_DIR. The spawned process therefore inherits the developer's own config directory (~/.claude, or whateverCLAUDE_CONFIG_DIRhappens to be exported in their shell).That makes the suite non-hermetic in both directions:
settings.json, permission mode, MCP servers, model selection, statusline. Two machines can produce different results from the same commit, and a failure may be caused by a setting no reviewer can see from the repo.Neither depends on what any particular configuration contains. A test suite that spawns a subprocess should decide that subprocess's environment.
Current state
Of 27 files under
*/itest, exactly one sets the variable —zio/itest/.../ConversationArchiveE2ETest.scala:21-29:So the pattern and the API (
QueryOptions.withEnvironmentVariables/SessionOptions.withEnvironmentVariables,core/src/.../QueryOptions.scala:158) already exist — they are simply not applied consistently. That test needed an isolated config dir to assert on the transcript tree; every other test gets the developer's by default.Observed instance
While debugging unrelated noise in another project we found ~225 real
claudesessions, spawned by this suite fromout/<module>/itest/testForked.dest/worker-N/sandbox, had triggered a globally-registeredSessionStart/Stophook belonging to that other project — one per test session, over months of test runs.Recording it only as evidence that the inbound/outbound coupling is real rather than theoretical. The other project has fixed its side; nothing here is a defect in
claude-code-query's behaviour, and this issue would stand even if that hook had never existed.Suggested direction
A shared itest helper that allocates a temp config dir per test (or per suite) and applies it to every
QueryOptions/SessionOptionsthe tests build, so isolation is the default rather than something each test remembers. Worth considering alongside it:withInheritEnvironment(false)where a test does not need the ambient environment at all, which would close the same gap for every other inherited variable rather than just this one.Naming the temp dirs (
os.temp.dir(prefix = ...)) would also make it obvious where a stray sandbox came from when one shows up somewhere unexpected.