Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#1,889 2 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@mikolalysenko já está trabalhando nisso.

Desde 30/10/2026.

  • #1891 de @mikolalysenko — aberto

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
55/100
Tipo de issue
Refatoração
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
rust

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.
Linguagem predominante
Rust
Estrelas
8
Forks
2
Merge médio
19h 12min
PRs com merge (30d)
709

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de SocketDev/socket-patch

Todas as issues de SocketDev/socket-patch

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.