npm_crawler classifies node_modules store children three times, and the copies drifted on store entries and legacy/global stores

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start in crates/socket-patch-core/src/crawlers/npm_crawler.rs, comparing the three store-classification walks: nested_node_modules_of (the find_by_purls resolver), gather_node_modules (the scan) and find_store_peer_variant_copies_reusing. Run crawl_all, find_by_purls and find_store_peer_variant_copies on the existing tests in that file and tests/crawler_npm_e2e.rs to capture current results. Done means a shared StoreKind classifier with the same results on those tests, plus a new test pinning the store-entry rule. Settle the intended store-entry behaviour with maintainers before changing it.

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

描述

agent:triaged arch-audit priority:p1 refactor

[agent] Filed by the scheduled architecture audit (audit-core). Register: register comment.

Kind: refactor. Register ID: A41.

Problem

crawlers/npm_crawler.rs decides which child of a node_modules is a package-manager store (pnpm-shaped .pnpm/.store, vlt .vlt, npm-linked .store, .modules.yaml, legacy pnpm store names) in three hand-written copies:

  • the find_by_purls resolver, nested_node_modules_of: L3166-L3225
  • the scan, gather_node_modules: L3576-L3624
  • the peer-variant finder, find_store_peer_variant_copies_reusing: L4478-L4520

The copies have drifted:

  • Store entries. Every arm of the scan is gated on !store_entry, so a store entry's own node_modules/.pnpm (or .vlt, .store, .modules.yaml, a legacy name) is never treated as a store. The resolver has no store_entry parameter and walks such a child as a store. apply can therefore resolve copies that scan never reports. This is unexecuted and an edge case.
  • Missing kinds. The peer finder handles neither legacy pnpm stores nor the pnpm global virtual store.
  • Empty .modules.yaml arm. The resolver's arm pushes an empty entry list (L3207), and visit_resolver_dir then has to guard against it (L3037).

The same file also has:

  • four shapes for one store entry: StoreEntryDir, StoreEntry, (String, PathBuf) and (OsString, PathBuf). They are converted at L1751-L1788, L3673, L3692, L4087 and L4131, and list_npm_store_entries decodes each name, discards the result, and decodes it again (L4243, then L4619);
  • about 7 copies of the "package-dir child" filter (not hidden, not node_modules, a real dir): L3082, L3226-L3241, L3508, L3772, L4153, L4200, L600. They drift on whether is_dir follows symlinks (L4077 vs L4160/L4226) and on whether a scoped child named node_modules is excluded (L3238);
  • 5 copies of the @scope/name expansion: L3088-L3102, L3234-L3245, L3645/L3762, L4213-L4222, L4719.

Proposed change

  • Add one StoreKind enum with a classify(name, file_type, in_store_entry) -> Option<StoreKind> and use it in all three walks. The resolver passes in_store_entry the way the scan does.
  • Keep one store-entry type (StoreEntryDir), drop the tuple shapes, and decode each name once.
  • Add one package_children(dir, listing) iterator that yields unscoped and @scope/name package dirs, and use it for the filter and expansion copies.

The peer-variant section (L4391-L4791) can then move to crawlers/npm_crawler/store.rs.

Size: 1 file (plus a new submodule), about −300/+150 lines.

Acceptance criteria

  • crawl_all, find_by_purls and find_store_peer_variant_copies return the same results on every existing test in npm_crawler.rs and tests/crawler_npm_e2e.rs.
  • A new test pins the store-entry rule: a store entry holding a nested node_modules/.pnpm is neither reported by crawl_all nor resolved by find_by_purls. Alternatively, if both are meant to walk it, the test asserts that both do.
主要语言
Rust
星标
9
派生
2
平均合并
1 天 8 小时
30 天内合并 PR
309

环境准备

  • 没有 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 摘要。