Drive pdm.lock and poetry.lock rewrites through one lock_fragments driver instead of two mirrored triads

已关闭
#1,844 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #1898 来自 @mikolalysenko —— 已合并

评估

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

调研方向

Start by reading crates/socket-patch-core/src/utils/lock_fragments.rs, pdm_lock.rs, and poetry_lock.rs, especially the driver, pairing, and equivalence test sections cited in the issue. Then trace the listed call sites in redirect/pdm.rs, redirect/poetry.rs, vendor/pypi_pdm.rs, and vendor/pypi_poetry.rs. Done means one shared driver and pairing helper, equivalence coverage for both formats, and all exact byte tests passing unchanged.

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

描述

agent:claimed agent:triaged arch-audit priority:p1 refactor

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

Kind: refactor. Register ID: A05.

Problem

utils/pdm_lock.rs and utils/poetry_lock.rs each carry the same driver around utils::lock_fragments:

  • Poetry has rewrite_poetry_lock / _with_edits / _in / _all / _all_with_version / _batch / _steps: poetry_lock.rs L426-L731.
  • PDM has the mirror: pdm_lock.rs L136-L353.
  • The test modules are mirrored too. parse_reuse_equivalence_tests and batch_equivalence_tests exist in both files, and the "fragments changed shape" test exists three times (lock_fragments L595, pdm_lock L921, poetry_lock).

The _steps loops have already drifted:

Inside lock_fragments itself, fragment pairing is written three times, and the copies disagree on how uniqueness is counted:

  • pair_fragments L191-L210 counts non-overlapping matches on both sides.
  • the finish loop L316-L336 checks old in the text and new in the spliced result.
  • rewrite_batch L473-L495 counts overlapping sole_occurrences.
  • The shape-change length check is repeated at L198, L322 and L477.
Proposed change
  • Move the _steps, _all and _with_edits drivers into lock_fragments, generic over a small per-format value: plan, mutate, fragments_in.
  • Delete the per-format wrappers and the PoetryLockRewrite/PoetryLockParse aliases.
  • Have finish and rewrite_batch call one pairing helper.
  • Keep one copy of each equivalence test, parameterized over both formats.
Size

Three files (lock_fragments.rs, pdm_lock.rs, poetry_lock.rs), plus call-site renames in redirect/pdm.rs, redirect/poetry.rs, vendor/pypi_pdm.rs and vendor/pypi_poetry.rs. About −250 net lines.

Acceptance criteria
  • Every pdm/poetry exact-bytes test passes unchanged, including the batch and parse-reuse equivalence tests (kept once, run for both formats).
  • The duplicated shape-change test is kept once, in lock_fragments.
  • No user-visible change.
主要语言
Rust
星标
9
派生
2
平均合并
20 小时 47 分钟
30 天内合并 PR
681

环境准备

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