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

Aperta
#1,889 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mikolalysenko ci sta già lavorando.

Dal 30/10/2026.

  • #1891 di @mikolalysenko — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start by reading the EnvGuard definitions named in the issue and the core test helper beside test_rng. Compare the unit-test and integration-test variants, including the OsStr and closure forms, then identify any existing injected-env helpers and test-support setup. Done means the touched tests share the guard, retain their existing #[serial] usage, and the stated grep finds one core definition.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

agent:claimed agent:triaged arch-audit priority:p3 refactor

[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.
Lingua principale
Rust
Stelle
8
Fork
2
Merge medio
19h 24m
PR unite (30g)
669

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SocketDev/socket-patch

Tutte le issue di SocketDev/socket-patch

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.