Skip to content

[0.38] fix(unpack): keep a tracked apm.lock.yaml unchanged when the lock already records the unpacked files (#4556) - #4580

Merged
Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-fuzzy-dollop
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-fuzzy-dollop

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

apm unpack <bundle> -o <checkout> into a project whose committed apm.lock.yaml already records the bundle's files no longer rewrites the lockfile, so a restore-style unpack (the microsoft/apm-action restore step) leaves tracked apm.yml and apm.lock.yaml byte-unchanged.

record_unpacked_files (src/apm_cli/install/bundle_admission.py) is the canonical owner and the only unpack lockfile writer. It now asks the deployment ledger (DeploymentLedgerCodec.deployed_file_hashes) which written files the existing lock already claims with the same content hash. Those files stay with their recorded owner: no ./local-bundle owners and no local_deployed_* rows are added. When nothing is left to record, the lockfile is neither migrated nor written. Files the lock does not claim, or claims with a different hash, are recorded exactly as before (#4157), so apm audit --ci still checks them.

Decisions (worker defaults, no open questions):

  • Ownership is checked against the canonical deployments rows through the existing codec projection. No new codec method was added because core/deployment_ledger.py is at the file-length cap.
  • A project with only a legacy apm.lock is read before migration, so a restore that adds nothing does not rename it either (the record says "not migrated or written").
  • The different-hash control alters both the canonical deployments row and the legacy deployed_file_hashes view, because the ledger reads the canonical row.

Issue and approved scope

Issue: Fixes #4556

Human scope-approval comment: #4556 (comment)

This PR completes the issue. Out of scope, per the record: apm install <bundle> recording, new flags, git-tracking detection, bundle/pack and lockfile schema changes, and apm-action changes.

Landing order

  • Dependencies: none (independent of other open 0.38 PRs).

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

New in tests/integration/test_trust_integrity_consistency_lifecycle.py (installed CLI):

  • test_unpack_restore_leaves_a_tracked_lockfile_unchanged[untracked|committed]: the producer installs contoso/pkg-a and runs apm pack --format apm. A git checkout holding only the committed apm.yml and apm.lock.yaml (plus the skill when it is committed) runs apm unpack <bundle> -o <checkout>. The test asserts that the skill bytes match the bundle, the lock bytes are identical, git status --porcelain -- apm.yml apm.lock.yaml is empty, and apm audit --ci --no-drift exits 0.
  • test_unpack_records_a_file_the_tracked_lockfile_claims_with_another_hash (control): when the committed lock claims the path with a different hash, the file is recorded as local_deployed_files as today.
  • Existing controls unchanged and green: test_unpack_records_deployed_files_in_the_project_lockfile and test_unpack_into_a_non_project_dir_announces_and_writes_no_lockfile.

Red on main (src/apm_cli/install/bundle_admission.py checked out from origin/main, new tests kept):

  • APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm uv run --frozen --extra dev pytest -n 4 tests/integration/test_trust_integrity_consistency_lifecycle.py -k "restore or another_hash" -> 2 failed, 1 passed. Both restore[untracked] and restore[committed] fail on assert (checkout / "apm.lock.yaml").read_bytes() == lock_before. The control passes, which pins today's behavior.

Green on head:

  • APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm uv run --frozen --extra dev pytest -n 8 tests/integration/test_trust_integrity_consistency_lifecycle.py -> 57 passed, plus the control after its fix: -k unpack -> 20 passed.
  • uv run --frozen --extra dev pytest -n 8 tests/unit/commands/test_pack.py tests/unit/commands/test_unpack_deprecation.py tests/unit/test_unpacker.py tests/unit/test_unpack_security.py -> 148 passed.
  • APM_E2E_TESTS=1 ... pytest -n 8 tests/integration/test_pack_unpack_e2e.py tests/integration/test_install_local_bundle_e2e.py tests/integration/test_lockfile_writer_mapping.py tests/integration/test_architecture_lockfile_write_authority.py -> 71 passed. The 3 lockfile_write_authority failures were xdist workers killed on a shared 2-core/7 GB host. Those tests pass when run alone (for example [2-entry-point-scope]: 1 passed).
  • Gates: ruff check and ruff format --check (clean), pylint R0801 (clean), lint-auth-signals.sh (clean), lint_architecture_boundaries.py --root . (exit 0, before the rebase), complexity ratchet --base-ref origin/main (clean), check_test_assertions.py (clean), tests.quality.taxonomy --changed (clean), check_taxonomy_allowances.py (clean), tests.spec_conformance.gen_statement (no diff).
  • Not completed locally: the full tests/integration/test_architecture_owner_rule_mutations.py was OOM-killed (exit 137) at about 80% with no failures, because the host is shared with other runs of that suite. CI covers it. This change adds no guard or owner edge.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md:
    user-visible effect first, 25 words or fewer, ending with (#PR);
    breaking changes only under upgrade notes; no Highlights; see
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…4556)

record_unpacked_files now asks the deployment ledger which written files
the existing apm.lock.yaml already claims with the same content hash and
records only the rest as local-bundle. When nothing is left to record, the
lockfile is neither migrated nor written, so a restore-style
`apm unpack <bundle> -o <checkout>` keeps a tracked lockfile unchanged.

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

Bundle admission duplicates lockfile selection instead of using the shared resolver’s symlink-aware precedence rules, and its lockfile-read guard needs to cover this caller.

1 open issue
What changed in this PR

This PR addresses #4556 by preserving the project lockfile during restore-style apm unpack when it already records every written file with the same content hash.

Changes:

  • Skip redundant deployment records and avoid lockfile migration or writes when nothing needs recording.
  • Add lifecycle tests for tracked-lockfile restores and different-hash recording.
  • Update unpack documentation and the changelog.
File Description
tests/​integration/​test_trust_integrity_consistency_lifecycle.py Tests clean restores and different-hash recording.
src/​apm_cli/​install/​bundle_admission.py Filters matching deployment hashes before updating the lockfile.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents the matching-content recording exception.
docs/​src/​content/​docs/​reference/​cli/​unpack.md Describes restore behavior and retained ownership.
CHANGELOG.md Records the unpack lockfile-preservation fix.

Review effort: Balanced

Comment thread src/apm_cli/install/bundle_admission.py Resolved
…_read (#4556)

Review: record_unpacked_files re-derived current-versus-legacy lockfile
selection. It now reads through the read-only owner (symlink-aware) and
migrates only when it writes; the lockfile-read guard covers this caller.

Co-authored-by: Copilot App <[email protected]>
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.

apm unpack into a project with a tracked lockfile modifies apm.lock.yaml

2 participants