`scan` with a glob PATH reads `--cwd` as part of the pattern: under a `--cwd` that holds `[` it scans another directory's projects, or says the PATH matches no directory
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
crates/socket-patch-cli/src/commands/scan/mod.rs の project_dirs を読み、glob の処理を crates/socket-patch-cli/src/path_scope.rs の PathScope::parse および BoundScope::matches と比較してください。[, *, ? を含む --cwd パスと、一致するおとりディレクトリを対象とする単体テストを追加してください。ユーザーの PATH に一致するディレクトリだけが選択されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
[agent] Found by the architecture refactor routine on main at cfc870f. Gate: a drifted duplicate (two readers of "a PATH glob relative to --cwd" that disagree on a --cwd holding [, * or ?). Low harm: it needs such a --cwd and a glob PATH together.
Problem
In hosted and vendored mode, scan PATH… takes each PATH as a project directory or a glob of them. The contract (crates/socket-patch-cli/CLI_CONTRACT.md, line 450):
Each PATH is a directory, or a glob (
*?[) matching directories, relative to--cwd
project_dirs joins --cwd and the PATH and hands the whole string to glob::glob, so the characters of --cwd are read as pattern syntax too. With a --cwd (or SOCKET_CWD) that holds [, the run either says the PATH matches no directory, or scans the directories the misread pattern matches: another directory's projects.
Evidence on main
The binary built from main. --offline stops each run before any request, after the directories are chosen; the == <dir> == headings show the choice.
$ find /work/repo -name package.json | sort
/work/repo/sites/[brand]/packages/a/package.json
/work/repo/sites/[brand]/packages/b2/package.json
/work/repo/sites/b/packages/other/package.json
/work/repo/sites/b/packages/other2/package.json
$ socket-patch scan --mode hosted --offline --cwd "/work/repo/sites/[brand]" "packages/*"
== /work/repo/sites/b/packages/other ==
Error: scan requires network access to query the patch API and cannot run with --offline/SOCKET_OFFLINE (strict airgap)
== /work/repo/sites/b/packages/other2 ==
Error: scan requires network access to query the patch API and cannot run with --offline/SOCKET_OFFLINE (strict airgap)
# exit 1
$ (cd "/work/repo/sites/[brand]" && socket-patch scan --mode hosted --offline "packages/*")
== packages/a ==
Error: scan requires network access […]
== packages/b2 ==
Error: scan requires network access […]
# exit 1
[brand] is read as "one of b, r, a, n, d", so the pattern matches sites/b/packages/*. A wet hosted or vendored scan would rewrite the lockfiles of those two projects and leave the two that were named.
With no directory for the misread pattern to match:
$ socket-patch scan --mode hosted --offline --cwd "/work/app [v2]" "packages/*"
Error: `packages/*` matches no directory
# exit 2
$ socket-patch scan --mode hosted --offline --cwd "/work/plain" "packages/*"
== packages/a ==
== packages/b ==
/work/app [v2]/packages/a and /packages/b exist. --mode vendored gives the same, a relative --cwd "app [v2]" gives the same, and --json gives the same message in its error. The literal PATH packages/a under the same --cwd works, as does the glob from inside the directory, where --cwd is ..
A match outside the repository is refused before anything runs (path_outside_repo: with a sibling /work/app v/packages/a, the run says that directory "is outside /work/app [v2]"). So the wrong scan needs the misread pattern to match inside the same repository.
The other reader is right. Agent mode's PATH globs go through PathScope, which compiles only what the user typed and strips --cwd as a literal prefix. Over a real npm install of left-pad with an applied patch, the same pattern selects the same package under both spellings:
$ socket-patch rollback --dry-run --offline --cwd /work/pplain 'node_modules/left-*'
Rollback verification complete: 1 package can be rolled back
$ socket-patch rollback --dry-run --offline --cwd '/work/proj[ab]' 'node_modules/left-*'
Rollback verification complete: 1 package can be rolled back
Where
crates/socket-patch-cli/src/commands/scan/mod.rs, lines 1705 to 1745,project_dirs:let joined = cwd.join(raw);thenglob::glob(&joined.to_string_lossy())(lines 1711 to 1714). Its one caller is at line 2280. The call has been there since #277.crates/socket-patch-cli/src/path_scope.rs, lines 72 to 92 (PathScope::parsecompiles the pattern alone) and 141 to 165 (BoundScope::matchesstrips the absolute or the given--cwd).
Planned fix
In project_dirs, escape the --cwd part with glob::Pattern::escape before the PATH is appended, so only the user's PATH is a pattern. Add a unit test over a --cwd holding each of [, * and ? beside a decoy directory the misread pattern would match, and show it failing on main. No flag, message or exit code changes; a --cwd without those characters behaves as now.
Not run: Windows, where * and ? cannot be in a path and [ can.
Generated by Claude Code
- 主要言語
- Rust
- スター
- 9
- フォーク
- 2
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 251
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SocketDev/socket-patch のほかの issue
-
agent:triaged arch-audit bug priority:p1
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
SocketDev/socket-patch#2364 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
agent:triaged bug bughunt pm:bundler priority:p1 ux
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
SocketDev/socket-patch#2326 ·
メンテナーはふだん 1 日以内に返信
-
agent:triaged arch-audit priority:p3 refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
SocketDev/socket-patch#2319 ·
メンテナーはふだん 1 日以内に返信
-
agent:triaged arch-audit bug priority:p2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
SocketDev/socket-patch#2306 ·
メンテナーはふだん 1 日以内に返信
-
agent:triaged arch-audit bug priority:p3
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
SocketDev/socket-patch#2296 ·
メンテナーはふだん 1 日以内に返信
SocketDev/socket-patch の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
tamatebako/tebako#1155 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
swc-project/swc-next-issues#1148 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
registrystack/registry-stack#2828 ·
メンテナーはふだん 1 日以内に返信
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信