Repository navigation
Fix crawlers missing parent dirs under --cwd . (#1902) - #1906
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
Conversation
Assisted-by: Claude Code:claude-opus-5-5
Run from a project or yarn workspace member without --cwd, scan and apply never looked above the working directory. A parent .yarnrc --modules-folder was ignored, so packages installed there were reported missing. From a member, the root's relocated yarn pnpm store was never walked, so transitive packages read as not installed. The npm crawler now walks up from the absolute path while keeping the relative spelling of the paths it reports. Fixes #1902. Assisted-by: Claude Code:claude-opus-5-5
Review follow-up. A store reached from two node_modules roots could be reported under two spellings (./store and store) and walked twice; the walk now keeps the lexical spelling and only adds .. above the working directory, so each directory has one spelling. pnpm's modulesDir lookup had the same bug: from a workspace member under the default --cwd, the root pnpm-workspace.yaml was never read. It now walks from the absolute path too. The helpers move to utils::relpath, and the cwd-changing tests move to the crawler_npm_e2e suite, which already serializes cwd changes. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 378c581. Configure here.
|
Burn-down agent: labeled Ready for review at head
Generated by Claude Code |
Final review briefWhat it does: Under the default Risk: low. The fix is confined to three lookup helpers. With an absolute Look here
Verified
Changes I made: none. Open questions: none blocking. Note that, as with an absolute Auto-merge is armed, so approving sends it straight to the merge queue. Generated by Claude Code |
LLM Description written by Claude Code:claude-opus-5-5
Fixes #1902
Summary
If you run
socket-patchfrom a project or workspace member without--cwd, scan, apply and vex now read the config files in parent directories, just as they do with an absolute--cwd. Before this fix, three lookups never looked above the working directory:.yarnrcwith--modules-folder: the packages installed there were reported as not installed.pnpmStoreFolder), when run from a member: its transitive packages were reported as not installed.modulesDirset in the workspace root'spnpm-workspace.yamlor.npmrc, when run from a member: the same symptom. This one isn't listed in Under the default --cwd ".", the npm crawler never sees a parent .yarnrc --modules-folder or a parent yarn pnpm store, because it walks lexical ancestors of "." #1902. The review found it, and it has the same cause.Root cause
--cwddefaults to.and reaches the crawlers as typed. Upward config lookups walkedPath::ancestors(), which for.yields only.and"". So they never reached a real parent directory.pkg_managers(std::path::absolute) andenclosing_pnpm_modules_yaml_sync(canonicalize) already worked around this. The three lookups above didn't.Fix
utils::relpath::absolute_lexically: makes a path absolute against the working directory and folds./... It doesn't resolve symlinks, and it treats the empty path (the parent of a barenode_modules) as the working directory.yarnrc_modules_folderandpnpm_layout::modules_dir_settingnow walk from it. Both return only a project-relative string, so their output keeps the same spelling.utils::relpath::ancestors_keeping_spelling: a lazy upward walk that pairs each absolute level with a spelling in the start path's own terms. It keeps the lexical ancestors and spells each level above the working directory with..(./..).relocated_yarn_pnpm_store_syncuses it, so a store found from./packages/a/node_modulesand one found from./node_modulesget the same spelling. The store is still read from the absolute project path.Why not make
--cwdabsolute inGlobalArgs::crawler_options, as the issue proposes?The CLI depends on crawler paths keeping the relative spelling under the default
--cwd ..ui::display_copy_pathstrips the rawcwdprefix to printnode_modules/x, andpath_scope::BoundScopedocuments that "crawler paths are NOT absolutized". Absolute crawler paths would change every relative path the CLI prints or matches. Fixing the lookups that walk upward keeps those outputs the same.Tests
New regression tests in
crates/socket-patch-core/tests/crawler_npm_e2e.rsare#[serial]and use a sharedCwdGuard, which replaces the inline copy that was there. Each test crawls once with an absolute cwd as a control, then again with.from inside the project:.yarnrc --modules-folderabove cwdparent_yarnrc_modules_folder_is_read_from_a_relative_cwd[], want["./deps"]parent_yarn_pnpm_store_is_found_from_a_relative_member_cwd(unix)is-odd, transitiveis-numbermissingmodulesDirin the root yamlparent_pnpm_modules_dir_is_read_from_a_relative_member_cwd[]utils::relpath::tests::ancestors_keeping_spelling_climbs_past_the_working_directoryTo get the "without the fix" column, I made
absolute_lexicallyreturn its input unchanged and reran the tests.Local runs:
cargo fmt --all -- --check: okcargo clippy --workspace --all-features -- -D warnings: okcargo test -p socket-patch-core --all-features --no-fail-fast: 7657 passed. 4 failed, all permission-denial tests in other modules (copy_tree,vlt_heal,pypi_poetry,pypi_requirements). They can't fail closed when run as root, which is how this container runs. CI runs them as a normal user.cargo test -p socket-patch-cli --all-features --lib: 940 passedSOCKET_PATCH_NPM_E2E_REQUIRED=1 cargo test -p socket-patch-cli --all-features --test e2e_redirect_npm_build -- --ignored: 9 passed (run on the first commit)cargo test --workspaceran out of disk in this container, so CI is the check for the remaining CLI suites.No wrapper changes are needed:
npm/,pypi/andgem/only forward--cwd.Review notes (/code-review high)
Fixed:
./storeandstore). The walk now keeps the lexical spelling.modulesDirlookup had the same bug.Not changed, with reasons:
--cwdfor ayarn.lock. An absolute--cwdhas always done this. It's how a member finds its workspace root's store, and the store must still lie inside that project. This brings.in line with the absolute spelling.--cwdthat contains..still walks its lexical ancestors. That's unchanged behaviour and outside Under the default --cwd ".", the npm crawler never sees a parent .yarnrc --modules-folder or a parent yarn pnpm store, because it walks lexical ancestors of "." #1902.enclosing_pnpm_modules_yaml_syncstill canonicalizes. It reads only the absolute file, and swapping its helper isn't needed for this fix.https://claude.ai/code/session_011f9aeS6qCCCE8PZfZcJW4k
Generated by Claude Code