Repository navigation
[0.38] fix(registry): lockfile replay tolerates a mirror URL when the hash matches (#4013) - #4022
Merged
Daniel Meppiel (danielmeppiel) merged 2 commits intoNov 21, 2026
Conversation
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-registry-mirror-4013
branch
from
November 20, 2026 00:21
c54056b to
c60c462
Compare
This was referenced Nov 20, 2026
Closed
Merged
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-registry-mirror-4013
branch
2 times, most recently
from
November 21, 2026 08:03
94645d0 to
6cafcf8
Compare
…sh matches (#4013) Builds on the declared-mirror replay from #4278. When a registry declared in apm.yml serves the locked resolved_url, replay fetches it there, unchanged. When none does (the same registry name now points at a moved endpoint), the locked URL is never contacted: replay fetches the locked version from the dependency's configured registry and verifies the bytes against resolved_hash before the install target is touched (req-rs-009, req-lk-013). A match prints one [i] line naming both URLs and keeps the lockfile unchanged; a mismatch fails closed naming the package, both URLs and both hashes. Credentials still reach only each registry's own URL. A frozen install whose locked dependencies could not be restored now reports their cause through InstallService.enforce_frozen_restored instead of the MCP drift their missing manifests implied. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-registry-mirror-4013
branch
from
November 21, 2026 08:26
6cafcf8 to
fa08b53
Compare
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 21, 2026 08:39
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 21, 2026 08:39
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-registry-mirror-4013
branch
November 21, 2026 08:40
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Moved-registry replay can break cold audits, rewrite lockfiles, fail on unrelated registry configuration, and expose URL credentials, while acquisition failures can be masked during MCP validation.
6 open issues
Redact credentials from locked URLs in replay messages · New Avoid constructing clients for unrelated registry candidates · New Preserve registry selection during cold audit replay · New Keep the original resolved hash on moved-endpoint fallback · New Route acquisition failures into the restore gate · New Document updating user credentials when a registry moves · New
What changed in this PR
This PR fixes registry lockfile replay after an endpoint moves, using the locked content hash to verify archives from the dependency's configured registry while preserving existing declared-mirror support.
Changes:
- Adds a hash-verified fallback for moved endpoints without fetching an unconfigured locked URL.
- Adds a frozen-install restore-failure guard before hydrated MCP checks.
- Adds regression coverage and updates registry documentation, conformance records, and the changelog.
| File | Description |
|---|---|
tests/unit/registry/test_resolver.py |
Tests moved-endpoint replay and avoidance of foreign locked URLs. |
tests/spec_conformance/test_resolution_reqs.py |
Adds hash-match and mismatch cases for registry replay requirements. |
tests/integration/test_registry_mirror_replay_lifecycle.py |
Exercises plain and frozen replay against two local endpoints. |
src/apm_cli/install/service.py |
Adds the frozen restore-failure guard. |
src/apm_cli/install/phases/integrate.py |
Calls the restore guard before frozen MCP checks. |
src/apm_cli/deps/registry/resolver.py |
Adds configured-endpoint fallback, pre-extraction verification, and diagnostics. |
packages/apm-guide/.apm/skills/apm-usage/dependencies.md |
Documents moved-endpoint and mirror replay behavior. |
docs/src/content/docs/reference/registries.md |
Describes hash-based trust and endpoint migration. |
docs/src/content/docs/reference/lockfile-spec.md |
Clarifies the advisory role of resolved_url. |
CONFORMANCE.md |
Updates registry replay and integrity coverage counts. |
CONFORMANCE.json |
Records the added conformance tests. |
CHANGELOG.md |
Adds the user-visible registry replay fix. |
Review effort: Balanced
| Runs before the install target is touched, so a mismatch leaves nothing | ||
| extracted (req-lk-013). | ||
| """ | ||
| try: |
Comment on lines
+414
to
+415
| client = self._build_client(locked_name, locked_url) | ||
| return client, client.archive_url(owner, repo, version) |
Comment on lines
+414
to
+415
| client = self._build_client(locked_name, locked_url) | ||
| return client, client.archive_url(owner, repo, version) |
Comment on lines
+446
to
+449
| if fetch_url != resolved_url: | ||
| _verify_moved_archive( | ||
| dep_ref, version, archive_bytes, resolved_hash, resolved_url, fetch_url | ||
| ) |
| from apm_cli.install.template import effective_allow_map | ||
| from apm_cli.security.trust import McpAdmission | ||
|
|
||
| InstallService.enforce_frozen_restored(ctx.transitive_failures) |
| `resolved_hash` is the trust anchor for re-installs. On `apm install` and `apm install --frozen`, APM fetches the locked version through a registry declared in `apm.yml`, sending each registry's credentials only to its own URL, and verifies the bytes against `resolved_hash`. A hash mismatch aborts the install before extraction, and `apm update` re-resolves and records a new URL. | ||
|
|
||
| **Moved registries and mirrors.** If another declared registry serves the locked `resolved_url` (a mirror), APM fetches from it. If no declared registry serves it (you pointed the registry name at a new URL), APM never contacts the old URL: it fetches the locked version from the configured registry, prints one `[i]` line naming both URLs, and keeps the lockfile unchanged when the hash matches. A mismatch fails the install and names the package, both URLs and both hashes. | ||
|
|
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
Registry lockfile replay now accepts a moved or mirrored registry endpoint when the bytes match the locked hash, as OpenAPM req-rs-009 requires. Previously,
download_from_lockfilefailed with "lockfile registry URL does not match the configured registry endpoint" before it checked the hash. Pointing a registry name at a mirror or a new URL therefore broke every replay of that registry's dependencies.In
deps/registry/resolver.pydownload_from_lockfile:resolved_url, so credentials only go to a host the user configured.fetch_from_urlstill enforces the configured origin and base path.resolved_hashbefore the install target is touched.[i]line naming both URLs.resolved_urlandresolved_hashinapm.lock.yamlare not rewritten.--frozenfix (needed for "--frozenbehaves the same"). In a frozen install, a package that failed to download was masked by the later hydrated-MCP drift check ("restored MCP declarations differ ... package manifest not found"). The hash-mismatch cause never reached the user. The newInstallService.enforce_frozen_restoredreports restore failures with their real cause before the MCP check runs. It lives inInstallService, the owner of frozen decisions (architecture guardinstall-deployment-frozen-mutation-eligibility), and is called frominstall/phases/integrate.py. This touches neitherinstall/phases/resolve.py,install/sources.pynordeps/registry/auth.py(#4009's seam).Issue and approved scope
Issue: Fixes #4013
Human scope-approval comment: #4013 (comment)
This PR completes the issue. Out of scope per the record: policy-declared mirrors, fetching from a lockfile URL that no configured registry owns, registry-routed marketplace replay (#4009), lockfile schema changes, and
apm updatere-resolution.Rebase onto 0.37.0: composition with #4278 (decision log)
While this PR was waiting, main landed #4278 (
280e7d23d). Replay now accepts the lockedresolved_urlwhen any registry declared inapm.ymlserves it, and refuses otherwise. #4013's scenario still failed on main: the same registry name rebound to endpoint B, so A is no longer declared. It failed with "lockfile registry URL does not match any registry endpoint declared in apm.yml".Decision (S15 default, logged here): compose the two behaviours rather than replace either.
test_registry_mirror_lock_replay_lifecycle.pypasses here.[i]line naming both URLs. A mismatch fails closed with nothing extracted.Reasoning: req-rs-009 says a declared registry may satisfy the fetch and that a URL mismatch "MUST NOT fail the install when the hash matches". The #4013 record requires exactly this outcome.
One test outcome changed. Main's
test_rejects_lockfile_registry_origin_override(attacker.example locked URL) becomestest_foreign_locked_url_is_never_fetched. Its security assertion is kept: the attacker URL is never fetched, and only the configured registry is contacted with its own credentials. The expected outcome changes from "refused before any fetch" to "configured bytes fetched, then fail closed on the hash". If Daniel prefers main's refuse-before-fetch posture for an undeclared locked URL, revert that branch in_lockfile_replay_clientand this PR reduces toenforce_frozen_restored.Validation on
6cafcf82:lint-auth-signals.sh,lint_architecture_boundaries.py --root ., and the file guards are clean.test_architecture_owner_rule_mutations.pyrun: 1246 passed.orphan_checkis OK (149).test_unix_install_ownership, gpg signing, two install unit tests) fail identically on pristine main in this sandbox.Type of change
Testing
Lifecycle test
tests/integration/test_registry_mirror_replay_lifecycle.pyruns the installed CLI against two local registry endpoints. The steps:apm_modules. Plaininstallandinstall --frozenboth succeed with identical deployed bytes, an unchangedapm.lock.yaml, and the[i]line, with zero requests to A.--frozenboth fail closed with both URLs and both hashes, no request to A, no file written, and no extraction.The test was red on
mainat step 3, then at step 6 (the--frozenmismatch) until the frozen fix.Conformance (req-rs-009, req-lk-013) in
tests/spec_conformance/test_resolution_reqs.py: a mismatched locked URL is satisfied by the configured registry when the hash matches, and fails closed before extraction when it does not. Unit tests intests/unit/registry/test_resolver.py: the old "reject origin override" test becomes "a foreign locked URL is never fetched", plus moved-endpoint success that keeps the locked URL and hash.APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest -q tests/integration/test_registry_mirror_replay_lifecycle.pyAPM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest -q -n 4 tests/integration/test_frozen_remote_plugin_lifecycle.py tests/integration/test_frozen_cold_cache_apm_package_e2e.py tests/integration/test_auth_upgrade_lock_replay_lifecycle.py tests/integration/test_registry_redirect_location_hardening_lifecycle.py tests/integration/test_deps_registry_coverage.py tests/integration/test_registry_client_integration.py tests/unit/integration/test_frozen_mcp_evidence.py tests/unit/registry tests/unit/install/test_resolve_registry.pyuv run --extra dev pytest -q tests/spec_conformance/test_resolution_reqs.py tests/spec_conformance/test_lockfile_reqs.pytest_repository_identity_survives_full_install_and_persistent_cache, which fails identically onmainin this sandbox (commit signing)uv run --extra dev pytest -q -n auto tests/unit/registry tests/unit/install tests/unit/depstest_unix_install_ownership, git bare-cache tests,test_cache_pin,test_persistent_cache_ssh_transporterrors). They are identical onmainhere; CI is authoritative.uv run --extra dev python -m tests.spec_conformance.orphan_checkruff check/ruff format --check/pylint R0801/lint-auth-signals.sh/lint-architecture-boundaries.shChangelog
## [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)
This PR brings the implementation into line with the existing req-rs-009 and req-lk-013 (Mode A: code fixed, spec unchanged). There is no spec edit, so the manifest and anchors are unchanged. New
@pytest.mark.req("req-rs-009")andreq-lk-013tests cite them, andCONFORMANCE.{md,json}is regenerated.docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
Docs re-home after #3996
All
docs/**andpackages/apm-guide/**changes are in the last commit (docs: ...), written against the currentmainlayout:guides/registries.md, section 4 "What gets recorded in the lockfile"resolved_urlis the trust anchor" paragraph:resolved_hashis the anchor, replay fetches from the configured registry, and a new "Moved registries and mirrors" paragraphreference/registries.md, same section 4 (the page moves unchanged)reference/lockfile-spec.mdresolved_urlfield row now says advisory on replaypackages/apm-guide/.apm/skills/apm-usage/dependencies.md