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

未关闭
#1,889 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@mikolalysenko 已经在做这个了。

开始于 2026年10月30日。

  • #1891 来自 @mikolalysenko —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
Rust
星标
8
派生
2
平均合并
19 小时 24 分钟
30 天内合并 PR
669

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SocketDev/socket-patch 的其他 Issue

查看 SocketDev/socket-patch 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。