Repository navigation
Closed
Labels
agent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)Filed by a scheduled architecture audit routine (see the architecture review discussion)priority:p1refactorStructural change: duplicated code or logic, missing abstraction, layering, dead codeStructural change: duplicated code or logic, missing abstraction, layering, dead code
Description
[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_testsandbatch_equivalence_testsexist in both files, and the "fragments changed shape" test exists three times (lock_fragmentsL595,pdm_lockL921,poetry_lock).
The _steps loops have already drifted:
- PDM calls
rewrite.edits()?before its Unchanged check: pdm_lock.rs L333-L340. - Poetry compares the text first: poetry_lock.rs L710-L719.
- This looks unreachable today, but nothing stops it from becoming reachable.
Inside lock_fragments itself, fragment pairing is written three times, and the copies disagree on how uniqueness is counted:
pair_fragmentsL191-L210 counts non-overlapping matches on both sides.- the
finishloop L316-L336 checksoldin the text andnewin the spliced result. rewrite_batchL473-L495 counts overlappingsole_occurrences.- The shape-change length check is repeated at L198, L322 and L477.
Proposed change
- Move the
_steps,_alland_with_editsdrivers intolock_fragments, generic over a small per-format value:plan,mutate,fragments_in. - Delete the per-format wrappers and the
PoetryLockRewrite/PoetryLockParsealiases. - Have
finishandrewrite_batchcall 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.
Metadata
Metadata
Assignees
Labels
agent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)Filed by a scheduled architecture audit routine (see the architecture review discussion)priority:p1refactorStructural change: duplicated code or logic, missing abstraction, layering, dead codeStructural change: duplicated code or logic, missing abstraction, layering, dead code
Activity
audit-core: rest of utils/ (20 files, 16.4K lines); file #1844-#1848;…
mikolalysenko commentedon Oct 29, 2026
[agent] Triaged: priority:p1 (PyPI-family: poetry/pdm), refactor with no user-visible change. It overlaps with #1847, which also touches
utils/poetry_lock.rs, but the two have different causes, so they're not clustered.Generated by Claude Code
mikolalysenko commentedon Nov 1, 2026
[agent] Claiming this issue (single-issue cluster; root cause: pdm_lock and poetry_lock each carry a mirrored driver around lock_fragments, and lock_fragments pairs fragments three ways). Branch: agent/fix-lock-fragments-driver. Claim-ID: 2026-11-01T00:21:01Z-6da843
Generated by Claude Code
mikolalysenko commentedon Nov 1, 2026
[agent] Draft PR: #1898
Generated by Claude Code