Skip to content

restore CCP_CONFIG_DIR after the config accessor tests - #159

Merged
raine merged 1 commit into
raine:mainfrom
rikbrown:rik/config-test-isolation
Sep 19, 2026
Merged

raine merged 1 commit into
raine:mainfrom
rikbrown:rik/config-test-isolation

Conversation

@rikbrown

Copy link
Copy Markdown
Contributor

Problem

The config accessor tests in src/config.rs start with clear_env(), which removes CCP_CONFIG_DIR with a plain remove_var and never restores it. The EnvGuard each test sets afterwards 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.

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_DIR at an empty dir for the whole run — is silently defeated.

This is the same hazard #033ecdc fixed for the codex_transport tests, but that only isolated the five tests that call the accessor directly. The clear_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.json setting non-default codex options (effort, reasoningSummary, serviceTier), eight tests fail:

providers::codex::chat_completions::request::tests::none_effort_retains_context
providers::codex::chat_completions::request::tests::translates_messages_and_responses_lite_fields
providers::codex::chat_completions::tests::buffered_request_translates_upstream_and_downstream
providers::codex::translate::request::tests::responses_lite_without_effort_uses_all_turns_context
providers::codex::translate::request::tests::translate_effort_max_maps_to_max
providers::codex::translate::request::tests::translate_effort_xhigh_maps_to_xhigh
providers::codex::translate::request::tests::translate_omits_reasoning_when_not_enabled
providers::codex::translate::request::tests::translate_includes_reasoning_when_enabled

They fail the same way with CCP_CONFIG_DIR=<empty dir> cargo test --lib. Add --skip config::tests and all eight pass — the config tests are what strip the variable.

Fix

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, CCP_CONFIG_DIR is set to the temp dir, and all of it is restored when the guards drop. EnvGuard::unset is added to match. The 14 call sites collapse from clear_env() + TempDir + EnvGuard::set to TempDir + isolated_env. Assertions are unchanged.

Verification

  • isolated_env_restores_an_exported_config_dir — exports a config dir, runs isolated_env in an inner scope, asserts paths::config_dir() points at the temp dir inside and returns to the exported dir after
  • The repro above with CCP_CONFIG_DIR exported: 907/907 lib tests pass with the fix, 898/906 without
  • cargo clippy --locked --all-targets -- -D warnings clean, cargo fmt --check clean, full suite green

Scope

The eight tests above still read the real config when CCP_CONFIG_DIR is 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

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
raine force-pushed the rik/config-test-isolation branch from 312c839 to b925bda Compare September 19, 2026 13:36
@raine
raine merged commit 84434db into raine:main Sep 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants