Skip to content

Fix env var state leakage in tests via Drop-based EnvGuard#80

Merged
vsilent merged 2 commits intocopilot/analyze-test-coveragefrom
copilot/sub-pr-79
Mar 25, 2026
Merged

Fix env var state leakage in tests via Drop-based EnvGuard#80
vsilent merged 2 commits intocopilot/analyze-test-coveragefrom
copilot/sub-pr-79

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

Tests mutating env vars (AGENT_SCOPES, UPDATE_SERVER_URL, UPDATE_STORAGE_PATH) used unconditional remove_var cleanup, leaking state into other tests on panic and clobbering any pre-existing env values. load_manifest_nonexistent_returns_default also used a hard-coded /tmp path that could become flaky if that path existed from a prior run.

Changes

  • src/test_utils.rs (new) — shared EnvGuard drop-based restore helper; saves the original value before mutation and restores it on Drop regardless of panic:
let _env = EnvGuard::set("AGENT_SCOPES", "docker:restart,admin");
// original value restored automatically when _env drops, even on panic
  • src/lib.rs — registers test_utils as #[cfg(test)] pub(crate) mod test_utils

  • src/security/scopes.rs, src/commands/version_check.rs, src/commands/deploy.rs — replace all manual set_var/remove_var pairs with EnvGuard::set()/EnvGuard::remove() imported from the shared module

  • src/commands/deploy.rsload_manifest_nonexistent_returns_default now uses tempfile::tempdir() instead of /tmp/status-test-nonexistent-path for guaranteed isolation


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add unit tests to increase confidence and coverage Fix env var state leakage in tests via Drop-based EnvGuard Mar 25, 2026
Copilot AI requested a review from vsilent March 25, 2026 14:14
@vsilent vsilent marked this pull request as ready for review March 25, 2026 14:44
@vsilent vsilent merged commit 5116081 into copilot/analyze-test-coverage Mar 25, 2026
1 check 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