Skip to content

fix(config): isolate permissions tests from real user config - #285

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/permissions-test-home-isolation
Aug 6, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/permissions-test-home-isolation

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Summary

Three forge-config permissions tests (missing_files_merge_to_empty_without_diagnostics, malformed_repo_file_is_skipped_with_a_diagnostic, repo_allow_entries_are_ignored_but_deny_entries_are_honored) failed on any machine that has a real personal permissions.toml: load_permissions merges user_permissions_path() (resolved via dirs::config_dir()), so merged.allow/merged.deny were never empty.

Fix

  • Point HOME/XDG_CONFIG_HOME at an empty temp dir for those tests via a new IsolatedUserConfig guard that restores the environment on drop (including assertion failure).
  • Hoisted the crate's test ENV_LOCK to the crate root so the permissions module shares one lock with lib.rs's EnvGuard/XdgEnvGuard — both modules mutate HOME in the same parallel test binary, so a single lock prevents a new race.
  • Added user_scope_file_is_still_loaded_under_isolation proving a seeded user-scope file still loads and merges, so the guard can't silently over-isolate.

Validation

  • cargo test --package forge-config --all-targets --locked: 59/59 pass (was 3 failures).
  • Ran the env-race-prone forge-config lib suite 3x: stable.
  • cargo fmt --all -- --check clean; cargo clippy --workspace --all-targets --locked -- -D warnings clean.
  • Full workspace: green except a pre-existing flaky forge-connect::anthropic::verify_falls_back_to_messages_endpoint_on_missing_models_route (macOS socket EINVAL race in its mock_server harness, ~3/8 with parallel ephemeral-port listeners) — reproduced on main, unrelated to this PR.

The three `load_permissions` tests read `user_permissions_path()` (via
`dirs::config_dir()`) and so merged the developer's real personal
permissions file when the suite runs on a machine that has one, making
`merged.allow`/`merged.deny` non-empty. Point `HOME`/`XDG_CONFIG_HOME` at
an empty temp dir for those tests and restore on drop.

- Hoist the crate's test `ENV_LOCK` to the crate root so the `permissions`
  module shares one lock with `lib.rs`'s env guards (rustc runs tests in
  parallel threads; both mutate `HOME`).
- Add an `IsolatedUserConfig` guard and apply it to the three tests that
  depend on the user scope being absent.
- Add a positive test proving a seeded user-scope file still loads and is
  merged under isolation, so the guard can't silently over-isolate.
@github-actions
github-actions Bot enabled auto-merge (squash) August 6, 2026 07:35
@github-actions
github-actions Bot merged commit fef6bf9 into main Aug 6, 2026
7 checks passed
mohitranka added a commit that referenced this pull request Aug 21, 2026
The three `load_permissions` tests read `user_permissions_path()` (via
`dirs::config_dir()`) and so merged the developer's real personal
permissions file when the suite runs on a machine that has one, making
`merged.allow`/`merged.deny` non-empty. Point `HOME`/`XDG_CONFIG_HOME` at
an empty temp dir for those tests and restore on drop.

- Hoist the crate's test `ENV_LOCK` to the crate root so the `permissions`
  module shares one lock with `lib.rs`'s env guards (rustc runs tests in
  parallel threads; both mutate `HOME`).
- Add an `IsolatedUserConfig` guard and apply it to the three tests that
  depend on the user scope being absent.
- Add a positive test proving a seeded user-scope file still loads and is
  merged under isolation, so the guard can't silently over-isolate.
mohitranka added a commit that referenced this pull request Sep 11, 2026
The three `load_permissions` tests read `user_permissions_path()` (via
`dirs::config_dir()`) and so merged the developer's real personal
permissions file when the suite runs on a machine that has one, making
`merged.allow`/`merged.deny` non-empty. Point `HOME`/`XDG_CONFIG_HOME` at
an empty temp dir for those tests and restore on drop.

- Hoist the crate's test `ENV_LOCK` to the crate root so the `permissions`
  module shares one lock with `lib.rs`'s env guards (rustc runs tests in
  parallel threads; both mutate `HOME`).
- Add an `IsolatedUserConfig` guard and apply it to the three tests that
  depend on the user scope being absent.
- Add a positive test proving a seeded user-scope file still loads and is
  merged under isolation, so the guard can't silently over-isolate.
mohitranka added a commit that referenced this pull request Sep 11, 2026
The three `load_permissions` tests read `user_permissions_path()` (via
`dirs::config_dir()`) and so merged the developer's real personal
permissions file when the suite runs on a machine that has one, making
`merged.allow`/`merged.deny` non-empty. Point `HOME`/`XDG_CONFIG_HOME` at
an empty temp dir for those tests and restore on drop.

- Hoist the crate's test `ENV_LOCK` to the crate root so the `permissions`
  module shares one lock with `lib.rs`'s env guards (rustc runs tests in
  parallel threads; both mutate `HOME`).
- Add an `IsolatedUserConfig` guard and apply it to the three tests that
  depend on the user scope being absent.
- Add a positive test proving a seeded user-scope file still loads and is
  merged under isolation, so the guard can't silently over-isolate.
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.

1 participant