Skip to content

refactor(install): split lockfile phase helpers to restore the module size budget - #4155

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-lockfile-phase-split
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-lockfile-phase-split

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

main is red: install/phases/lockfile.py is 1017 lines, over the 1000-line install module budget in tests/unit/install/test_architecture_invariants.py::test_no_install_module_exceeds_loc_budget. It got there when #4021 (orphan owner) and #4023 (receipt plumbing) landed together. Every PR based on main fails this test.

This PR restores the budget without raising it. It moves one cohesive block of existing code out of LockfileBuilder: the three best-effort .apm-pin cache pin marker syncs.

Moved from LockfileBuilder (phases/lockfile.py) To install/phases/lockfile_cache_pins.py
_sync_cache_pin_markers(self, lockfile) sync_cache_pin_markers(ctx, lockfile)
_sync_cache_pin_markers_from_existing(self) sync_cache_pin_markers_from_existing(ctx)
_sync_cache_pin_markers_from_disk(self) sync_cache_pin_markers_from_disk(ctx)
  • No behavior change: the bodies are verbatim, with self.ctx changed to ctx. build_and_save calls them at the same three points. The lazy install.cache_pin imports stay, so existing patches of sync_markers_for_lockfile still apply.
  • phases/lockfile.py goes from 1017 to 940 lines; the new module has 100.
  • Owner registry: the new module is a selector of locked-copy-validity in .apm/architecture/owners/install-deployment.json. That owner already holds install/cache_pin.py and the .apm-pin marker contract. No architecture guard names the moved methods.
  • Test: tests/unit/install/phases/test_lockfile_orphan_prune.py now monkeypatches the module-level functions instead of the removed methods.

Issue and approved scope

Issue: Refs #3701 (Part of #3701). This unblocks #4049, which finishes #3701.

Human scope-approval comment: #3701 (comment). The 0.37 Stream H lead requested this split to restore main.

Does this PR complete the issue, or what remains? No. #4049 completes #3701.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally. Static gates only: ruff check and ruff format --check pass on the touched files. The host is overloaded, so CI validates the rest.
  • All existing tests pass (CI)
  • Added tests for new functionality (if applicable). N/A: this is a pure move.

Changelog

  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

… size budget

Move the three best-effort cache pin marker syncs out of LockfileBuilder
into install/phases/lockfile_cache_pins.py, owned with install/cache_pin.py
(locked-copy-validity). No behavior change; phases/lockfile.py drops from
1017 to 940 lines, back under the 1000-line install module budget.

Part of #3701

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
apm-spec-waiver: pure code move of cache-pin helpers to restore the install module size budget, no behavior change

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Landing over one known flake, per the 0.37 Hardening PM decision (steward-accepted root cause): Build & Test Shard 2 fails only on tests/unit/deps/test_git_reference_resolver.py::TestResolveCommitShaForRef::test_best_effort_rate_limit_falls_through_without_retry_wait (the test patches the global time.sleep and counts other threads' polls; 1 failed, 14871 passed). The fix is P-3 (e401b1fb), in flight. The flake is unrelated to this diff (lockfile.py 1017 -> 940 plus the new lockfile_cache_pins.py, no behavior change). All other checks pass, including Spec conformance (waiver accepted).

Copilot AI balanced review requested due to automatic review settings November 20, 2026 09:18
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 7f21fb1 into main Nov 20, 2026
52 of 55 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-lockfile-phase-split branch November 20, 2026 09:19
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the cache pin helper extraction.

No open issues 🎉

What changed in this PR

This refactor restores the install module size budget by extracting cache pin marker synchronization from LockfileBuilder, supporting the follow-up cleanup work for #3701 without changing behavior.

Changes:

  • Moves three best-effort cache pin helpers into a dedicated module, preserving call order and lazy imports.
  • Reduces lockfile.py to 940 lines, below the 1,000-line install module limit.
  • Updates test patch targets and registers the extracted module under the existing architecture owner.
File Description
tests/​unit/​install/​phases/​test_lockfile_orphan_prune.py Patches the extracted functions at their lockfile-phase call sites.
src/​apm_cli/​install/​phases/​lockfile.py Delegates marker synchronization to the extracted helpers.
src/​apm_cli/​install/​phases/​lockfile_cache_pins.py Contains the three existing best-effort marker synchronization helpers.
.apm/​architecture/​owners/​install-deployment.json Adds the helper module to the locked-copy-validity selectors.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants