A failed `npm root -g` probe reads as "no global install": scan -g reports nothing to scan, and rollback drops the record of a copy that is still patched
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 53/100
Hướng nghiên cứu
Start with get_npm_global_prefix and get_global_node_modules_paths in crates/socket-patch-core/src/crawlers/npm_crawler.rs, comparing the Bun probe and warning behavior nearby. Then trace patched_in_other_scope in crates/socket-patch-cli/src/commands/rollback.rs and read the rollback contract in CLI_CONTRACT.md. Run the proposed injected CommandRunner cases and rollback CLI test; done means failed npm probes warn during global scans and project rollback preserves records and blobs when the global copy cannot be checked.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
[agent] Filed by the architecture refactor routine (lead L33, run on main at cfc870f).
Kind: bug, an error that lies. A package manager's global-directory probe that fails is read as "this manager has no global install". Bun's probe was taught the difference in #1009 (for #443); npm's was not.
Problem
The npm crawler asks each manager where its global packages are (npm root -g, pnpm root -g, yarn global dir, bun pm ls -g). For npm, pnpm and yarn a probe that gives no answer is dropped without a word ([npm_crawler.rs L3401-L3426](https://github.com/SocketDev/socket-patch/blob/cfc870f55f5910e48e331ae460585ac2dea878a4/crates/socket-patch-core/src/crawlers/npm_crawler.rs#L3401-L3426)): get_npm_global_prefix returns Err, and the caller's if let Ok(..) skips it. "No answer" covers a manager that is not installed, one that exits non-zero, and one that is still running at the 10 s probe budget. On Linux there is no other discovery path for npm's directory.
Bun's probe already tells these apart. resolve_bun_global_prefix returns Ok(None) for "Bun is not in use" and Err for "Bun is in use but its global dir can't be told", "so a global scan can say so instead of reporting a clean, empty result" ([L2500-L2535](https://github.com/SocketDev/socket-patch/blob/cfc870f55f5910e48e331ae460585ac2dea878a4/crates/socket-patch-core/src/crawlers/npm_crawler.rs#L2500-L2535)), and the caller prints Warning: could not determine Bun's global package directory (…), so Bun's global packages were not scanned. That came with 2044d9ee (git log -S'fn resolve_bun_global_prefix').
Two things follow for npm.
1. A global scan reports a clean, empty result. scan -g prints No global packages found. and exits 0, with status: success and scannedPackages: 0 under --json and no warning.
2. A project rollback drops the record of a copy that is still patched. The contract says that before a rollback drops a record it checks the other scope, and that "a copy there that still holds the patch's afterHash bytes, or has a patched file that exists but cannot be hashed, keeps the record (with its variant group) and its blobs" (CLI_CONTRACT.md L2494). patched_in_other_scope (rollback.rs L341-L390) crawls the default global install for that. When the probe fails, the crawl finds no copy, so the record leaves the manifest and its blobs are freed. The run says nothing, and the rollback -g the user would run next finds no record.
apply -g and rollback -g are honest over the same failure: apply -g exits 1 (package_not_installed), and rollback -g warns that "a copy this run did not find stays patched until the package is reinstalled".
Evidence
The binary built from main. A project whose [email protected] holds its original files, a manifest record and blobs for a patch of it, and a global node_modules whose [email protected] holds the patched files. PATH holds one npm:
- answers: a script that prints the global
node_modulesforroot -g; - fails:
echo "npm ERR! code EACCES" >&2; exit 1; - hangs:
exec sleep 600.
socket-patch rollback --offline --yes in the project, then socket-patch rollback -g --offline --yes:
=== npm answers
Rolled back 1 package:
pkg:npm/[email protected] (already original)
Warning: pkg:npm/[email protected]: its copy in the global install (…/os-global/lib/node_modules/left-pad) is still patched or could not be verified, so its manifest record was kept; run `socket-patch rollback pkg:npm/[email protected] -g --cwd …/os-proj` to restore it
exit=0 (0s)
manifest records: 1 blobs left: 4 global index.js: module.exports = 2
then: rollback -g
Rolled back 1 package:
pkg:npm/[email protected]
exit=0 global index.js: module.exports = 1
=== npm fails
Rolled back 1 package:
pkg:npm/[email protected] (already original)
Removed 1 patch from manifest.
Freed 66 B of unused blobs and archives
exit=0 (0s)
manifest records: 0 blobs left: 0 global index.js: module.exports = 2
then: rollback -g
No patches in this project; nothing to roll back.
exit=0 global index.js: module.exports = 2
=== npm hangs
(the same output as "npm fails")
exit=0 (10s)
manifest records: 0 blobs left: 0 global index.js: module.exports = 2
Under --json the first run carries warnings: ["patched_in_other_scope"], removed: 0. The other two carry no warning, removed: 1, bytesFreed: 66, and nothing on stderr.
A global scan on this machine, against a local stand-in for the patch API that offers no patch (--proxy-url, left out below with the token notice), with its real npm (199 global packages) and then with a failing npm, pnpm and yarn first on PATH:
$ socket-patch scan -g --ecosystems npm --mode agent --dry-run
Found 199 packages (199 npm)
No patches available for installed packages.
$ PATH=<failing npm, pnpm, yarn>:$PATH socket-patch scan -g --ecosystems npm --mode agent --dry-run
No global packages found. (exit 0)
scan -g --ecosystems gem gives the same pair with a failing gem and ruby (17 packages, then No global packages found.). I did not trace the gem crawler's probe.
Not checked: how often npm root -g fails or takes over 10 s on a machine whose global install is otherwise in use. The cases run here are a script that exits 1 and one that never returns.
Planned fix
- Give npm's probe Bun's shape:
Ok(None)whennpmis not onPATH,Err(why)when it is andnpm root -ggave no usable answer.get_global_node_modules_pathsthen warns once, as it does for Bun, that npm's global packages were not scanned and names--global-prefix. - In
patched_in_other_scope, when the other scope is the global install and npm's directory could not be determined, keep the npm records it was asked about, and say so. That is the rule the function already follows for a file it cannot hash: "keep the record rather than strand it". - Tests: a unit test over an injected
CommandRunnerfor the three answers, and a CLI test that runs the rollback above with a failingnpmonPATHand expects the record and blobs to stay.
Two things to settle in the PR:
- pnpm and yarn.
yarn global dirfails for every Yarn Berry install, which has noglobalcommand, so a warning on any failed yarn probe would be noise. The first slice is npm alone; pnpm and yarn need their benign failures told from real ones first. - The
--jsoncode for step 2.patched_in_other_scopenames a copy's path, and here no path is known. Reusing it with a different detail, or adding a code, is an addition towarnings[]that the contract does not name yet.
Generated by Claude Code
- Ngôn ngữ chính
- Rust
- Star
- 9
- Fork
- 2
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 313
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SocketDev/socket-patch
-
agent:triaged arch-audit bug priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
SocketDev/socket-patch#2306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit bug priority:p3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
SocketDev/socket-patch#2296 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:needs-human agent:triaged ci-janitor priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SocketDev/socket-patch#2270 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit bug priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
SocketDev/socket-patch#2259 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit priority:p3 refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
SocketDev/socket-patch#1860 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của SocketDev/socket-patch
Issue tương tự
-
Find/Replace panel: "Previous/Next occurrence" labels overlap and overflow their buttons (French)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
obi1kenobi/cargo-semver-checks#1839 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Có thể đã có người làm @iliqiliev đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ajeetdsouza/zoxide#1381 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
kornia/kornia-rs#1416 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày