fix(config): prevent base_path from flipping to ~/.forge when ~/forge still holds user data#2925
Merged
tusharmath merged 3 commits intomainfrom Apr 10, 2026
Merged
fix(config): prevent base_path from flipping to ~/.forge when ~/forge still holds user data#2925tusharmath merged 3 commits intomainfrom
tusharmath merged 3 commits intomainfrom
Conversation
Comment on lines
+205
to
+212
| // Without FORGE_CONFIG set the path must be either ".forge" (new) or | ||
| // "forge" (legacy fallback when ~/forge exists on this machine). | ||
| let name = actual.file_name().unwrap(); | ||
| assert!( | ||
| name == ".forge" || name == "forge", | ||
| "Expected base_path to end with '.forge' or 'forge', got: {:?}", | ||
| name | ||
| ); |
Contributor
There was a problem hiding this comment.
Test is now non-deterministic and depends on the host filesystem state. If ~/forge exists on the CI/CD runner or developer's machine, the test validates different behavior than if it doesn't exist. This makes test results non-reproducible and can hide regressions.
Impact: Different environments will test different code paths, reducing test reliability.
Fix: Use filesystem isolation for deterministic testing:
#[test]
fn test_base_path_prefers_legacy_when_it_exists() {
let temp = TempDir::new().unwrap();
env::set_var("HOME", temp.path());
fs::create_dir(temp.path().join("forge")).unwrap();
let actual = ConfigReader::base_path();
assert_eq!(actual.file_name().unwrap(), "forge");
}Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
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.
Summary
Fix
ProviderNotAvailableerrors caused bybase_path()silently switching from~/forgeto~/.forgewhen an empty~/.forgedirectory was created as a side effect of the shell plugin's config-edit action.Context
After adding the
forge config migratecommand (which teaches users to move from~/forgeto~/.forge), the shell plugin's_forge_action_config_editfunction was updated to callforge config pathdynamically and then runmkdir -p <config_dir>to ensure the config directory exists.The problem:
forge config pathreturns~/.forge/.forge.tomlas the new default (since26badbaacchangedbase_path()to prefer~/.forge). So for users who still have their data in~/forge, the shell plugin would eagerly create an empty~/.forgedirectory. This causedbase_path()to flip:With
base_path()now returning~/.forge,credentials_path()pointed to~/.forge/.credentials.json— a file that doesn't exist because all credentials are in~/forge/.credentials.json.read_credentials()returned an empty list, every provider appeared unconfigured, and every provider lookup raisedProviderNotAvailable.Changes
crates/forge_config/src/reader.rs—base_path()now returns~/forgewhenever that directory exists, regardless of whether~/.forgealso exists. The legacy path takes priority untilforge config migrateremoves it, at which point the fallback stops applying and~/.forgeis used correctly.shell-plugin/lib/actions/config.zsh— fixed hardcodedforgebinary name to use$FORGE_BINvariable (so the correct binary is invoked in environments where forge is installed under a different name or path).~/.forgeor~/forgeas validbase_pathresults depending on the test machine's state.Testing
Reproduce and verify the fix: