Skip to content

fix(lockfile): rewrites keep lockfile_version 2 or later (req-lk-002) - #4372

Merged
Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
danielmeppiel-4232-lock-version-monotonic
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 8 commits into
mainfrom
danielmeppiel-4232-lock-version-monotonic

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

A rewrite of an existing lockfile at lockfile_version 2 or later never writes version 1 (OpenAPM req-lk-002), for registry and git-semver entries alike. LockFile.write reads the existing lockfile it replaces and applies a version-2 floor before the semantic-equivalence check. Versions 3 and 4 follow their own requirements: version 4 still tracks framed package content hashes, so the floor is 2, not the previous maximum.

Issue and approved scope

Issue: Fixes #4232

Human scope-approval comment: #4232 (apm-scope:v1 record by Daniel Meppiel (@danielmeppiel))

Completes the issue. Starts from Daniel Meppiel (@danielmeppiel)'s unit slice (9582695).

Type of change

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

Testing

  • Tested locally

  • All existing tests pass

  • Added tests for new functionality (if applicable)

  • tests/unit/test_lockfile_v2_bump.py::TestSchemaBumpOpportunistic::test_rewrite_keeps_v2_after_the_v2_entry_is_removed[registry|git-semver] -- registry and git-semver triggers.

  • tests/unit/test_lockfile_v2_bump.py::TestSchemaBumpOpportunistic::test_v4_marker_follows_framed_content_hashes_not_the_floor -- version 4 follows framed hashes; the floor only excludes version 1.

  • tests/integration/test_lockfile_version_monotonic_lifecycle.py::test_lockfile_version_is_kept_after_the_v2_dependency_is_removed -- installed CLI: install a git-semver dependency into a version 2 lockfile, uninstall it, reinstall; the version is never 1.

Commands run:

  • APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest tests/integration/test_lockfile_version_monotonic_lifecycle.py tests/unit/test_lockfile_v2_bump.py -n0 -q -- 35 passed.
  • uv run --extra dev pytest tests/unit -k "lockfile or lock_" -n 8 -q -- 1292 passed; 3 failures are environment-only (gpg-signed fixture commits, root-run installer) and fail identically on main.
  • uv run --extra dev ruff check / ruff format --check over src/ tests/ scripts -- clean. python -m tests.quality.taxonomy --changed -- clean.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit: @pytest.mark.req("req-lk-002") on the installed-CLI test.
  • CONFORMANCE.{md,json} regenerated; no change on this base.
  • N/A

req-lk-002: LockFile.write reads the existing lockfile's version, and a
rewrite of a lockfile at version 2 or later never emits version 1.
Versions 3 and 4 stay content-derived.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
A rewrite of an existing lockfile at version 2 or later never writes version
1, for registry and git-semver entries alike. Versions 3 and 4 follow their
own rules: version 4 still tracks framed package content hashes.

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

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.

🟡 Changes recommended

The three filesystem-based tests are in a unit-marked module that requires pure logic without filesystem access and must be moved to a component-marked module.

1 open issue
What changed in this PR

This PR fixes #4232 by preserving the version-2 boundary when rewriting an existing lockfile, as required by OpenAPM req-lk-002, while retaining the separate rules for versions 3 and 4.

Changes:

  • Applies a version-2 floor before comparing an existing lockfile for semantic equivalence.
  • Adds regression coverage for dependency removal, framed-hash version handling, and new version-1 lockfiles.
  • Documents the user-visible fix in the changelog.
File Description
tests/​unit/​test_lockfile_v2_bump.py Adds rewrite and version-boundary regression tests.
tests/​integration/​test_lockfile_version_monotonic_lifecycle.py Checks version preservation through CLI install, uninstall, and reinstall.
src/​apm_cli/​deps/​lockfile.py Prevents rewrites of existing version-2-or-later lockfiles from emitting version 1.
CHANGELOG.md Records the lockfile rewrite fix.

Review effort: Balanced

Comment thread tests/unit/test_lockfile_v2_bump.py Resolved
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit d7fc711 into main Nov 21, 2026
37 of 42 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4232-lock-version-monotonic branch November 21, 2026 05:24
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.

Lockfile version is lowered when a registry dependency is removed

2 participants