Skip to content

Share one scoped env-var test guard: EnvGuard is copy-pasted 11 times across core unit and integration tests #1889

Open

Description

[agent] Filed by the scheduled architecture audit (audit-core). Register: register.

Kind: refactor (tests). Register ID: A37.

Problem

Tests that mutate process env each define their own restore-on-drop guard.

These three copies are byte-identical:

  • go_crawler.rs L1518-L1542
  • deno_crawler.rs L945-L969
  • maven_crawler.rs L2508-L2532

These are variants:

  • npm_crawler.rs L5880, which takes an OsStr value
  • python_crawler.rs L7878 and L8107
  • vendor/maven_repo.rs L2649
  • patch/jvm_jar.rs L837
  • tests/upstream_restore_golden.rs L188
  • tests/crawler_deno_e2e.rs L24
  • tests/crawler_npm_e2e.rs L357

There are also closure-style twins: utils/socket_cli_config.rs with_env (L311) and utils/fs.rs with_home_env (L1489).

grep -rn "struct EnvGuard" crates finds 11 definitions.

Proposed change

  • Add one #[cfg(test)] pub(crate) mod test_env in core, beside test_rng. It holds EnvGuard::set(key, value), ::unset(key) and a multi-key form taking OsStr values, plus with_env(pairs, f).
  • Unit tests use it.
  • The three integration-test files share one copy in tests/common/, or through a test-support feature if one already exists.
  • Where a function under test already takes injected env (*_with variants), switch the test to that and drop the guard.

Size

About 12 files, about −150 lines. Tests only.

Acceptance criteria

  • No production code changes.
  • Every touched test still runs under #[serial] where it did before and passes.
  • grep -rn "struct EnvGuard" crates/socket-patch-core/src finds one definition.

Activity

  1. added
    arch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)
    refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code
    on Oct 30, 2026
  2. mikolalysenko commented on Oct 30, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue (CI/test-infra lane). Branch: agent/fix-ci-test-env-guard. Claim-ID: 2026-10-30T06:51:13Z-66005a


    Generated by Claude Code

  3. mikolalysenko commented on Oct 30, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Draft PR: #1891


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:claimedagent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)priority:p3refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions