Commit d19e71e
feat(migrate): --auto-apply mode for mechanically-rewritable codemod findings (#540)
* feat(migrate): --auto-apply mode for mechanically-rewritable codemod findings
Extends `python -m adcp.migrate v3-to-v4` with `--auto-apply`: rewrites
the ~78% of findings that are mechanically safe (flag_private + flag_numbered
with known aliases) while leaving flag_removed findings for human review.
- Add NUMBERED_ASSETS_RENAMES dict mapping Assets<N> to semantic aliases
- Add _AUTO_APPLY_PUBLIC_SYMBOLS frozenset for safe-rewrite eligibility
- Add auto_applied field to Report; route kind==auto_applied there
- Two-pass rewrite: (1) numbered asset substitution, (2) generated_poc
import path fix for lines where all symbols have public equivalents
- Fix pre-existing silent-drop bug: unknown symbols on mixed import lines
were silently discarded; now always emit flag_private
- --auto-apply implies --apply; enforced before dirty-tree guard
- JSON report gains auto_applied array (additive, no version bump)
- 16 new tests (total 49, all pass)
Closes #512
https://claude.ai/code/session_01MiPRbdJUEFBes5zzUGd5Vb
* fix(migrate): apply dx-expert review feedback on --auto-apply
- Text report hints at --auto-apply when flag_private/flag_numbered
findings remain and the flag was not used (discoverability)
- --apply help text cross-links --auto-apply
- Dirty-tree error shows --auto-apply when that flag was used
- Exit code semantics (0/1/2) documented in argparse description
- MIGRATION_v3_to_v4.md: add --auto-apply example + description
- 2 new tests for tip-line presence/absence (51 total, all pass)
https://claude.ai/code/session_01MiPRbdJUEFBes5zzUGd5Vb
* fix(migrate): address code-reviewer findings on --auto-apply
Two bugs found in pre-PR review:
1. apply_changes=False guard missing on auto-apply rewrite block.
run(apply_changes=False, auto_apply=True) was silently writing files
because the auto_apply block only checked `auto_apply and auto_apply_hits`
with no apply_changes guard. Fixed by requiring apply_changes too.
2. all_known check excluded numbered-asset symbols on mixed lines.
A line like `from ...generated_poc import Assets81, ContextObject`
got all_known=False (Assets81 not in GENERATED_POC_SYMBOL_MAP), so
ContextObject was flagged even though both symbols are auto-applicable.
Fixed: all_known now treats numbered assets as resolvable when auto_apply=True.
New tests:
- test_dry_run_with_auto_apply_does_not_write_files (regression guard)
- test_auto_apply_numbered_plus_known_symbol_same_line (mismatch case)
53 tests total, all pass.
https://claude.ai/code/session_01MiPRbdJUEFBes5zzUGd5Vb
* chore(migrate): fix orphaned test section header; document scan_file auto_apply contract
- Remove misplaced "Pre-existing silent-drop bug fix" section header
that sat above the discoverability tests; reattach it immediately
before test_mixed_line_unknown_symbol_not_silently_dropped
- scan_file docstring now documents that auto_apply=True without
apply_changes=True produces findings but never writes files
https://claude.ai/code/session_01MiPRbdJUEFBes5zzUGd5Vb
* fix(migrate): don't corrupt mixed numbered+unknown imports under --auto-apply
Per review on #540 — a generated_poc import mixing a known numbered
asset (Assets81) with an unknown one (Assets149) was getting
half-rewritten:
Input : from adcp.types.generated_poc.core.format import Assets81, Assets149
Output: from adcp.types.generated_poc.core.format import VideoFormatAsset, Assets149
leaving VideoFormatAsset imported from a private module path that
doesn't export it — guaranteed ImportError in adopter source.
Root cause: step 1 (file-wide Assets<N> substitution) ran before step 2
(import-path safety check) had a chance to veto the line.
Fix: line-by-line rewrite. For each generated_poc single-line import,
compute the post-numbered-substitution symbol set up-front; only run
both substitutions when every symbol on the line is in
``_AUTO_APPLY_PUBLIC_SYMBOLS``. Mixed-unsafe lines are left entirely
alone. Non-import lines still get free numbered substitution.
Scan-time also fixed: numbered references on a mixed-unsafe import line
now report ``flag_numbered`` instead of ``auto_applied`` so the report
matches the file content.
Adds regression test
``test_auto_apply_mixed_numbered_known_unknown_does_not_corrupt_import``.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8ea85ad commit d19e71e
3 files changed
Lines changed: 757 additions & 70 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
24 | | - | |
25 | | - | |
26 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
27 | 37 | | |
28 | 38 | | |
29 | 39 | | |
| |||
0 commit comments