Repository navigation
fix(config): stop loading the developer's real config in default tests - #375
Merged
Merged
Conversation
`Config::load` merges the trusted user layer from `~/.../forge/config.toml` before anything else, but `EnvGuard` only cleared the `FORGE_*` env vars. Every assertion in this module about default values was therefore layered over whatever the developer running the suite happened to have in their own config, while CI — which has no user config — stayed green. A personal `[tui] theme = "system"` was enough to fail `defaults_workspace_to_cwd` locally with `left: "system", right: "forge-dark"`. The test was not wrong about the default; it was reading someone's settings. `EnvGuard` now also redirects the platform config dir into a temp dir it owns (clearing `XDG_CONFIG_HOME` and pointing `HOME` at it, covering Linux and macOS), so all 21 tests that use it are hermetic rather than just the one that happened to trip. This mirrors `permissions.rs`'s existing `IsolatedUserConfig` and shares the same crate-wide `ENV_LOCK`, since rustc runs tests in parallel threads. That makes `XdgEnvGuard` redundant — its sole user now takes the isolated config dir from the unified guard via `user_config_dir()`. Adds a test that pins the guard itself: it seeds a user config that changes a default, proves it is merged, then proves a separate guarded load does not see it. Without the positive half, a guard that isolated nothing would still pass.
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
#375) `Config::load` merges the trusted user layer from `~/.../forge/config.toml` before anything else, but `EnvGuard` only cleared the `FORGE_*` env vars. Every assertion in this module about default values was therefore layered over whatever the developer running the suite happened to have in their own config, while CI — which has no user config — stayed green. A personal `[tui] theme = "system"` was enough to fail `defaults_workspace_to_cwd` locally with `left: "system", right: "forge-dark"`. The test was not wrong about the default; it was reading someone's settings. `EnvGuard` now also redirects the platform config dir into a temp dir it owns (clearing `XDG_CONFIG_HOME` and pointing `HOME` at it, covering Linux and macOS), so all 21 tests that use it are hermetic rather than just the one that happened to trip. This mirrors `permissions.rs`'s existing `IsolatedUserConfig` and shares the same crate-wide `ENV_LOCK`, since rustc runs tests in parallel threads. That makes `XdgEnvGuard` redundant — its sole user now takes the isolated config dir from the unified guard via `user_config_dir()`. Adds a test that pins the guard itself: it seeds a user config that changes a default, proves it is merged, then proves a separate guarded load does not see it. Without the positive half, a guard that isolated nothing would still pass.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
#375) `Config::load` merges the trusted user layer from `~/.../forge/config.toml` before anything else, but `EnvGuard` only cleared the `FORGE_*` env vars. Every assertion in this module about default values was therefore layered over whatever the developer running the suite happened to have in their own config, while CI — which has no user config — stayed green. A personal `[tui] theme = "system"` was enough to fail `defaults_workspace_to_cwd` locally with `left: "system", right: "forge-dark"`. The test was not wrong about the default; it was reading someone's settings. `EnvGuard` now also redirects the platform config dir into a temp dir it owns (clearing `XDG_CONFIG_HOME` and pointing `HOME` at it, covering Linux and macOS), so all 21 tests that use it are hermetic rather than just the one that happened to trip. This mirrors `permissions.rs`'s existing `IsolatedUserConfig` and shares the same crate-wide `ENV_LOCK`, since rustc runs tests in parallel threads. That makes `XdgEnvGuard` redundant — its sole user now takes the isolated config dir from the unified guard via `user_config_dir()`. Adds a test that pins the guard itself: it seeds a user config that changes a default, proves it is merged, then proves a separate guarded load does not see it. Without the positive half, a guard that isolated nothing would still pass.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
#375) `Config::load` merges the trusted user layer from `~/.../forge/config.toml` before anything else, but `EnvGuard` only cleared the `FORGE_*` env vars. Every assertion in this module about default values was therefore layered over whatever the developer running the suite happened to have in their own config, while CI — which has no user config — stayed green. A personal `[tui] theme = "system"` was enough to fail `defaults_workspace_to_cwd` locally with `left: "system", right: "forge-dark"`. The test was not wrong about the default; it was reading someone's settings. `EnvGuard` now also redirects the platform config dir into a temp dir it owns (clearing `XDG_CONFIG_HOME` and pointing `HOME` at it, covering Linux and macOS), so all 21 tests that use it are hermetic rather than just the one that happened to trip. This mirrors `permissions.rs`'s existing `IsolatedUserConfig` and shares the same crate-wide `ENV_LOCK`, since rustc runs tests in parallel threads. That makes `XdgEnvGuard` redundant — its sole user now takes the isolated config dir from the unified guard via `user_config_dir()`. Adds a test that pins the guard itself: it seeds a user config that changes a default, proves it is merged, then proves a separate guarded load does not see it. Without the positive half, a guard that isolated nothing would still pass.
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.
The bug
crates/forge-config'stests::defaults_workspace_to_cwdfails on any machine where the developer has a personal Forge config:It is not an environment quirk — the test is non-hermetic by construction.
Config::loadmerges the trusted user layer from~/.../forge/config.tomlfirst:…but
EnvGuard::clear_forge_env()only cleared theFORGE_*variables. So every assertion about default values in this module was silently layered over the developer's own settings. A two-line[tui] theme = "system"in my config dir was enough to trip it. CI has no user config, so it stayed green and the failure looked local-only.21 tests use this guard. Only one happened to assert a value my config overrode; the rest were passing by luck.
The fix
EnvGuardnow isolates everythingConfig::loadreads from outside the repository — theFORGE_*vars and the platform config dir. It owns aTempDir, clearsXDG_CONFIG_HOME, and pointsHOMEat it, which landsdirs::config_dir()inside the temp dir on both Linux and macOS. All 21 tests become hermetic, not just the one that broke.This is not a new pattern:
permissions.rsalready hasIsolatedUserConfigdoing exactly this, with a comment explaining that it shares the crate-wideENV_LOCKwithlib.rs's guards because rustc runs tests in parallel threads. The unified guard takes the same lock, so the two remain safe against each other.That also makes
XdgEnvGuardredundant — it existed solely to widenEnvGuardwithHOME/XDG_CONFIG_HOMEfor one test. Removed; its sole user now gets the isolated directory fromEnvGuard::user_config_dir().Guarding the guard
A guard that isolated nothing would make every test pass, so the new test pins both directions:
One detail worth recording: the first draft seeded
theme = "not-the-default"and failed, becausenormalize_theme_idmaps an unknown id back toDEFAULT_THEME_ID. The seed has to be a real alternate theme (THEME_SOLARIZED_DARK) for the positive half to mean anything.Verification
cargo test --workspace— fully green, zero failures. This was the last failing test in the workspace on this machine.cargo fmt --allandcargo clippy --all-targetsclean.defaults_workspace_to_cwdpasses with the offending~/Library/Application Support/forge/config.tomlstill on disk, so the fix is the isolation and not a cleaned-up environment.No production code changed — this is test isolation only.