Repository navigation
restore CCP_CONFIG_DIR after the config accessor tests - #159
Merged
Merged
Conversation
The config accessor tests start with clear_env(), which removes CCP_CONFIG_DIR with a plain remove_var and never puts it back. The EnvGuard each test then sets restores to "absent" on drop, so once the first config test has run, CCP_CONFIG_DIR is gone for the rest of the process. Every later test in the lib binary that reads config through paths::config_dir() falls back to the real ~/.config/claude-code-proxy/config.json, and the only escape hatch a developer has, exporting CCP_CONFIG_DIR at an empty dir for the whole run, is silently defeated. With a config.json that sets non-default codex options (effort, reasoningSummary, serviceTier), eight tests under providers::codex::translate::request and providers::codex::chat_completions fail on upstream even with CCP_CONFIG_DIR exported. Skip config::tests and the same eight pass. Replace clear_env() with isolated_env(&TempDir) -> Vec<EnvGuard>, the shape tests/codex_compact_effort.rs already uses: every knob is unset through an EnvGuard and CCP_CONFIG_DIR is set to the temp dir, so all of it is restored when the guards drop. Add EnvGuard::unset to match, and a regression test that exports a config dir, runs isolated_env in an inner scope, and asserts paths::config_dir() returns to the exported value. The existing assertions are unchanged.
raine
force-pushed
the
rik/config-test-isolation
branch
from
September 19, 2026 13:36
312c839 to
b925bda
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The config accessor tests in
src/config.rsstart withclear_env(), which removesCCP_CONFIG_DIRwith a plainremove_varand never restores it. TheEnvGuardeach test sets afterwards restores to "absent" on drop, so once the first config test has run,CCP_CONFIG_DIRis gone for the rest of the process. Every later test in the lib binary that reads config throughpaths::config_dir()falls back to the real~/.config/claude-code-proxy/config.json.The practical effect: tests pass or fail depending on what the person running them has in their own config file, and the one escape hatch a developer has — exporting
CCP_CONFIG_DIRat an empty dir for the whole run — is silently defeated.This is the same hazard #033ecdc fixed for the
codex_transporttests, but that only isolated the five tests that call the accessor directly. Theclear_env()that strips the variable is untouched, so any other test in the process that reads config is still exposed.Repro (on
main)With
$HOME/.config/claude-code-proxy/config.jsonsetting non-default codex options (effort,reasoningSummary,serviceTier), eight tests fail:They fail the same way with
CCP_CONFIG_DIR=<empty dir> cargo test --lib. Add--skip config::testsand all eight pass — the config tests are what strip the variable.Fix
Replace
clear_env()withisolated_env(&TempDir) -> Vec<EnvGuard>, the shapetests/codex_compact_effort.rsalready uses: every knob is unset through anEnvGuard,CCP_CONFIG_DIRis set to the temp dir, and all of it is restored when the guards drop.EnvGuard::unsetis added to match. The 14 call sites collapse fromclear_env()+TempDir+EnvGuard::settoTempDir+isolated_env. Assertions are unchanged.Verification
isolated_env_restores_an_exported_config_dir— exports a config dir, runsisolated_envin an inner scope, assertspaths::config_dir()points at the temp dir inside and returns to the exported dir afterCCP_CONFIG_DIRexported: 907/907 lib tests pass with the fix, 898/906 withoutcargo clippy --locked --all-targets -- -D warningsclean,cargo fmt --checkclean, full suite greenScope
The eight tests above still read the real config when
CCP_CONFIG_DIRis not exported at all, because they do not pin a config dir themselves. Doing that needs an env lock shared across modules, which felt like a separate change — happy to follow up if you want it.🤖 Generated with Claude Code