NuGet crawler test crawls the host's ~/.nuget/packages and fails on dev machines

オープン 初心者向け
#2,023 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
devtools, testing

調査の方向性

crates/socket-patch-core/src/crawlers/nuget_crawler.rsを読み、特にテストsolution_roots_and_unrestored_projects_keep_the_walkと、1450行目付近のNUGET_PACKAGESテストを確認します。既存の環境分離パターンを確認するため、crate::test_env::EnvGuardを調べます。問題を再現し、修正を検証するため、issueにあるcargo testコマンドを実行します。両方のテストで環境設定をガードし、ホストのNuGetパッケージフォルダーを読み込まずに成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug pm:nuget

LLM Description written by Claude Code:claude-opus-5-5

Summary

crawlers::nuget_crawler::tests::solution_roots_and_unrestored_projects_keep_the_walk (crates/socket-patch-core/src/crawlers/nuget_crawler.rs:1978) is not hermetic. It crawls the real global packages folder of the machine running it, so it fails on any developer machine whose ~/.nuget/packages holds a package. It passes in CI only because the runners' NuGet cache is empty.

Repro

On main (7bde3ba5), on a machine with any package in ~/.nuget/packages:

cargo test --locked -p socket-patch-core --lib solution_roots_and_unrestored_projects_keep_the_walk
panicked at crates/socket-patch-core/src/crawlers/nuget_crawler.rs:1994:9:
  left: ["pkg:nuget/[email protected]", "pkg:nuget/[email protected]", "pkg:nuget/[email protected]", "pkg:nuget/[email protected]"]
 right: ["pkg:nuget/[email protected]", "pkg:nuget/[email protected]", "pkg:nuget/[email protected]"]

The extra purl comes from the host's ~/.nuget/packages/socketsecurity.socketpatch/3.3.0. The test fails every time on such a machine, and passes with an isolated home:

HOME=$(mktemp -d) CARGO_HOME=~/.cargo RUSTUP_HOME=~/.rustup \
  cargo test --locked -p socket-patch-core --lib solution_roots_and_unrestored_projects_keep_the_walk
# test result: ok. 1 passed

Root cause

In project mode, crawl_roots always adds the global packages folder NuGet would restore into as search root 3 (nuget_crawler.rs:626-630, via global_packages_folder → nuget_home(), which falls back to $DOTNET_CLI_HOME or ~/.nuget/packages). A solution root, or a project that hasn't been restored, has no restore scope (roots.scope is set only for DotnetRoot::Project), so every package in that folder is crawled.

The test builds its packages in a temp shared-cache named by packageFolders, but leaves NUGET_PACKAGES and DOTNET_CLI_HOME unset. Its expected list (every) therefore assumes the host's default folder is empty or missing.

Suggested fix

Run the crawl under the existing crate::test_env::EnvGuard, with NUGET_PACKAGES pointed at an empty directory inside the test's tempdir (and DOTNET_CLI_HOME cleared). That makes root 3 hermetic without changing the crawler.

The NUGET_PACKAGES test around nuget_crawler.rs:1450 sets and removes the variable with bare std::env::set_var/remove_var, outside the guard. It should move onto EnvGuard too, so a parallel crawl test can't observe the variable while it's set.

Note

The product behavior the test pins, where a solution-root or unrestored-project crawl includes every package in the user's global folder, is the unscoped "today's walk" that #427 / #1183 deliberately kept for those roots. This issue is only about the test's isolation.

Found while validating #2015.

主要言語
Rust
スター
9
フォーク
2
平均マージ
20時間 9分
マージ済み PR(30日)
629

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SocketDev/socket-patch のほかの issue

SocketDev/socket-patch の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。