Repository navigation
[0.38] fix(unpack): keep a tracked apm.lock.yaml unchanged when the lock already records the unpacked files (#4556) - #4580
Merged
Conversation
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-fuzzy-dollop
branch
from
November 21, 2026 09:57
bb92669 to
5401a2c
Compare
…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]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…#4556) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-fuzzy-dollop
branch
from
November 21, 2026 10:05
5401a2c to
8cfa2f5
Compare
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 21, 2026 10:33
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 21, 2026 10:33
Contributor
There was a problem hiding this comment.
🟡 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
…_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]>
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-fuzzy-dollop
branch
November 21, 2026 15:31
Merged
3 of 10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
apm unpack <bundle> -o <checkout>into a project whose committedapm.lock.yamlalready records the bundle's files no longer rewrites the lockfile, so a restore-style unpack (themicrosoft/apm-actionrestore step) leaves trackedapm.ymlandapm.lock.yamlbyte-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-bundleowners and nolocal_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), soapm audit --cistill checks them.Decisions (worker defaults, no open questions):
deploymentsrows through the existing codec projection. No new codec method was added becausecore/deployment_ledger.pyis at the file-length cap.apm.lockis read before migration, so a restore that adds nothing does not rename it either (the record says "not migrated or written").deploymentsrow and the legacydeployed_file_hashesview, 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
Type of change
Testing
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 runsapm pack --format apm. A git checkout holding only the committedapm.ymlandapm.lock.yaml(plus the skill when it iscommitted) runsapm 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.yamlis empty, andapm audit --ci --no-driftexits 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 aslocal_deployed_filesas today.test_unpack_records_deployed_files_in_the_project_lockfileandtest_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. Bothrestore[untracked]andrestore[committed]fail onassert (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 3lockfile_write_authorityfailures 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).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).tests/integration/test_architecture_owner_rule_mutations.pywas 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
## [Unreleased]inCHANGELOG.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.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated