Skip to content

[0.38] test(registry): enterprise registry lifecycle stage 1 (#3299) - #4015

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-fluffy-garbanzo
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-fluffy-garbanzo

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

TL;DR

Stage 1 of #3299: one APMLifecycle scenario family drives the installed CLI through the enterprise registry path — producer publish, employee install, cold-CI install --frozen, audit --ci, uninstall, and browsing a public HTTPS catalog. It runs against an APM-controlled loopback implementation of the documented Registry HTTP API, not a vendor service. The duplicated registry handlers in three existing lifecycle tests now use one shared fixture that serves exactly the uploaded PUT bytes, keyed by package and version.

Refs #3299 — stage 1 only; the remaining stages are listed below. Passing stage 1 does not complete #3299.

Note

Lifecycle smoke runs on Linux PRs and in the merge queue. macOS ARM release validation selects lifecycle_smoke through MACOS_MARK_EXPR, so the new markers enroll the scenario in all three. No workflow file changes.

Problem (WHY)

  • No executable test showed that a company can publish to an API-compliant registry, install on a developer machine, and reproduce the install on a cold CI runner. [TEST] Cover enterprise marketplace lifecycle with APMLifecycle against the APM API #3299 asks for "executable APMLifecycle coverage, not a vendor deployment guide".
  • Three lifecycle tests (test_registry_redirect_origin_lifecycle.py, test_registry_redirect_location_hardening_lifecycle.py, test_auth_upgrade_lock_replay_lifecycle.py) each hand-rolled /versions and /download handlers for one hard-coded package, and none served the bytes from a real PUT.
  • [!] The record requires each killed mutant to fail at the guard it targets. The archive-hash check against resolved_hash sits on top of a second tree-hash check (content_hash). If the archive hash is bypassed, the tree hash still rejects wrong bytes, so a test that only checks the exit code cannot tell the two apart.

Approach (WHAT)

# Change
1 Extract tests/utils/local_package_registry.py: the three documented endpoints with immutable versions (409), optional bearer auth, and outage / wrong-bytes download faults.
2 Move the three existing registry tests onto it without changing behavior: same assertions and byte-identical archives.
3 Add tests/integration/test_enterprise_registry_lifecycle.py, marked integration, requires_apm_binary and lifecycle_smoke. It uses isolated producer, employee and cold-CI environments.
4 Every networked step checks egress before the exit code: any request to the producer Git hosts, or to any host except the one under test, fails the step. Fault steps pin the guard that rejected the artifact (registry HTTP 503, archive sha256 mismatch).
5 Add a short workflow note to the registry guide and one CHANGELOG line.

Implementation (HOW)

  • tests/utils/local_package_registry.py (new): LocalPackageRegistry.handle() is a ScriptedHttpsProxy origin handler. It stores RegistryArtifact(package, version, data, content_type), /versions returns spec-shaped digests (sha256:<hex>), and /download returns the stored bytes. It also provides flat_registry_archive() (a deterministic zip builder) and sha256_digest().
  • test_registry_redirect_origin_lifecycle.py, ..._location_hardening_..., test_auth_upgrade_lock_replay_lifecycle.py: the gateways keep their redirect logic and delegate payloads to the shared registry. The consumer seeds acme/widget, and publish scenarios start empty, so a PUT still returns 201. The auth-upgrade archive is byte-identical to the old one, which the pinned fixture lock hashes require.
  • tests/integration/test_enterprise_registry_lifecycle.py (new, 2 tests):
    • The producer publishes acme/base and then acme/widget, which depends on acme/base#1.0.0.
    • The employee installs acme/widget#1.0.0 with registry.corp.url set. The test asserts source: registry, version, resolved_url, resolved_hash (the PUT digest), resolved_by, and that the deployed bytes equal the archive members.
    • Cold CI copies only apm.yml, apm.lock.yaml and the sentinel file. It runs --frozen three times: artifact outage (fails), wrong bytes (fails), healthy (passes). After each failure the lockfile is unchanged and nothing is deployed. Then audit --ci -f json must pass every check. The employee uninstalls and the unrelated sentinel must survive.
    • A separate test registers https://catalog.corp.example/apm/marketplace.json and browses it. No registry token reaches the catalog host.
  • docs/.../guides/registries.md: adds a ~25-line "Enterprise workflow" subsection in section 5.
  • CHANGELOG.md: one line at the bottom of ### Added.

Diagrams

Legend: the actors and hosts in the main scenario. Dashed arrows are requests that must never happen; the egress check catches them.

sequenceDiagram
    participant P as Producer env
    participant E as Employee env
    participant C as Cold-CI env
    participant R as registry.corp.example (LocalPackageRegistry)
    participant G as github.com (producer Git, 503 recorder)
    P->>R: PUT acme/base 1.0.0, then acme/widget 1.0.0
    E->>R: GET versions + download (install acme/widget#1.0.0)
    Note over E: lock pins resolved_url + resolved_hash
    E->>C: copy apm.yml, apm.lock.yaml, sentinel only
    C->>R: GET download (outage 503 -> fail, nothing deployed)
    C->>R: GET download (wrong bytes -> archive sha256 mismatch)
    C->>R: GET download x2 (frozen replay passes, lock byte-identical)
    C--xG: any request fails the step
    Note over C: apm audit --ci -f json, all checks pass
    Note over E: apm uninstall keeps the unrelated sentinel
Loading

Trade-offs

  • Pinning the rejection reason with --verbose. Without it, the default output for both an outage and a hash mismatch reads --frozen: restored MCP declarations differ from apm.lock.yaml ... package manifest not found, which is misleading. I pinned the verbose reason so the hash-bypass mutant cannot be hidden by the tree-hash check. I did not fix the default wording: it is outside this test-only scope and is reported to the coordinator for a separate issue.
  • Git may use HTTPS in this scenario (GIT_ALLOW_PROTOCOL=file:https). If git were limited to file, a Git fallback would be blocked locally and never reach the recorder. With HTTPS allowed, it is observed as a producer-Git request. A sanity mutant that routes registry dependencies to Git hit github.com as expected.
  • APM_E2E_TESTS=1 in the child environment turns off the CLI's own update check, which would otherwise call api.github.com and look like egress.
  • The catalog test is separate from the main chain. The catalog entry's github source is not installable from a registry until Registry-backed marketplace entries cannot install by name or replay with --frozen #4009, so the test only registers and browses.
  • No skipped or xfail placeholders for later stages, per the record. They are listed below instead.

Benefits

  1. The full enterprise path (publish → install → cold --frozen → audit → uninstall) runs through the installed CLI on every Linux PR, in the merge queue, and in macOS ARM release validation. It takes about 11s locally.
  2. One fixture replaces three copies of the registry handlers, and it serves the bytes that were actually PUT, not a pre-baked archive.
  3. Three recorded mutants each fail at the intended guard (evidence below).
  4. Later stages have a concrete place to add their assertions (EnterpriseRegistryWorld).

Follow-up after #4022

Pending stages (proposed text for the #3299 body)

Important

This PR does not edit #3299. The block below is the proposed issue-body text for the coordinator to apply.

### Stage status (APMLifecycle: tests/integration/test_enterprise_registry_lifecycle.py)

- [x] Stage 1 (#4015): registries enabled in isolated producer, employee and cold-CI environments; producer `apm publish` (dependency first); direct registry install with the URL mapping provisioned; lockfile URL/hash/version; cold-CI `install --frozen` with producer Git unreachable; artifact outage and wrong bytes fail closed; `apm audit --ci`; uninstall preserves unrelated files; register and browse a public HTTPS catalog.
- [ ] Catalog-identity registry install and `--frozen` replay (`plugin@catalog` for a registry-backed entry) -- #4009
- [ ] Protected (authenticated) hosted catalogs; denied/expired credentials; wrong-origin isolation -- #3300
- [ ] Committed catalog origins in `apm.yml` and alias rebinding (D1/D3) -- #2903 (PR #4006)
- [ ] Registry-backed catalog authoring -- #3298
- [ ] Catalog-following update (company catalog advertises v2 while v3 exists elsewhere) -- depends on #4009; owner to be assigned
- [ ] User scope (`-g`) variant -- owner to be assigned
- [ ] Native consent in the correct scope -- #3094

Passing stage 1 does not complete #3299. Later stages are added by their owning PRs, never as skipped or expected-failure tests.

Rebase onto v0.37.0 main (decision log)

  • CHANGELOG.md: the line moved under the new ## [Unreleased] -> ### Added above [0.37.0] (this is 0.38 work), reworded "registries guide" -> "registries reference".
  • Main's test-taxonomy ratchet now requires one behavioral marker and promise ids per new module. Taken default: pytest.mark.e2e (installed CLI, like the sibling registry tests) and promise("req-rg-001", "P-LAW-lockfile.frozen_preserves_bytes", "P-OWN-credential-origin-scope"), the archive-hash trust anchor, frozen replay keeping lock bytes, and the registry token staying on its origin -- each asserted by the scenario. Folded into the scenario commit so the docs commit stays last.

Docs re-home after #3996

Edit in this PR (current main layout) Location after #3996
docs/src/content/docs/guides/registries.md, section 5, new "Enterprise workflow: publish, install, replay in CI" subsection Done: #3996 merged, and the rebase carried it to docs/src/content/docs/reference/registries.md section 5 (links match that page)

All docs/** edits are in the last commit (docs(registries): ...), so the rebase or re-home touches only that commit.

Issue and approved scope

Issue: Refs #3299

Human scope-approval comment: #3299 (comment) (apm-scope:v1; scripts/governance/eligibility.cjs → state: record-present, trusted sha 67936cd)

Does this PR complete the issue, or what remains? No. It delivers stage 1. The pending stages and their owning issues are listed above.

Type of change

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

Testing

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

Scenario evidence

# Scenario (user promise) Principle(s) Test Type
1 A producer publishes a package and its registry dependency to any Registry-HTTP-API server Vendor-neutral test_enterprise_registry_lifecycle.py::test_enterprise_registry_publish_install_frozen_replay_audit_uninstall integration (installed CLI)
2 A developer installs from the registry; the lock pins URL, hash and version; deployed bytes equal the published bytes Governed by policy, Secure by default same integration
3 Cold CI replays the lockfile without contacting the producer's Git host; an outage or wrong bytes fail closed and deploy nothing Secure by default same integration
4 apm audit --ci passes after the frozen replay; uninstall keeps unrelated files Governed by policy, DevX same integration
5 A public HTTPS catalog can be registered and browsed; no registry credential reaches it Secure by default, DevX ...::test_employee_registers_and_browses_public_https_catalog integration
6 Existing registry redirect and upgrade-replay contracts are unchanged Secure by default test_registry_redirect_origin_lifecycle.py, test_registry_redirect_location_hardening_lifecycle.py, test_auth_upgrade_lock_replay_lifecycle.py integration

Killed-mutant runs (recorded)

Each mutant was applied to src/, the scenario was run with APM_BINARY_PATH=.venv/bin/apm (editable install), and the file was reverted with git checkout.

Mutant Patch Result Guard that fired
Producer-Git request install/phases/resolve.py, in the lockfile-replay branch: requests.get("https://github.com/{repo}.git/info/refs?service=git-upload-pack"), errors swallowed (install otherwise succeeds) 1 failed step=ci-frozen-outage reached hosts other than registry.corp.example: [('github.com', 'GET', '/acme/widget.git/info/refs')]
Bypassed hash verification deps/registry/extractor.py::verify_sha256: if actual != expected → if False and actual != expected 1 failed ci-frozen-wrong-bytes: archive sha256 mismatch missing; the tree-hash check rejected the bytes instead
Deletes the unrelated sentinel integration/cleanup.py: stale_target.unlink() → unlink every file in the stale file's directory 1 failed AssertionError: uninstall deleted the unrelated sentinel file
Registry token leaked to the catalog on add (peer-review follow-up) marketplace/client.py URL-catalog fetch: add Authorization: Bearer $APM_REGISTRY_TOKEN_CORP when add is in argv 1 failed (the previous test version passed: the add step was never checked) step=add sent the registry token to {'catalog.corp.example'}

A non-recorded sanity mutant (resolve.py: if False and dep_ref.source == "registry") sent the employee install to https://github.com/acme/widget.git through the recorder, which confirms that a real Git fallback is observable.

Local validation commands
$ APM_BINARY_PATH=.venv/bin/apm uv run --extra dev python -m pytest -q -p no:cacheprovider tests/integration/test_enterprise_registry_lifecycle.py
..                                                                       [100%]
2 passed in 11.27s

$ APM_BINARY_PATH=.venv/bin/apm APM_E2E_TESTS=1 uv run --extra dev python -m pytest -q -p no:cacheprovider -n 4 \
    tests/integration/test_registry_redirect_origin_lifecycle.py \
    tests/integration/test_registry_redirect_location_hardening_lifecycle.py \
    tests/integration/test_auth_upgrade_lock_replay_lifecycle.py
24 passed in 31.58s

$ uv run --extra dev python -m pytest -q -p no:cacheprovider -n 4 tests/quality \
    tests/integration/test_marker_registry_sync.py tests/integration/test_apm_lifecycle_runner_contract.py \
    tests/unit/test_platform_contract_workflow.py
304 passed in 114.25s

$ uv run --extra dev ruff check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/   -> clean
$ uv run --extra dev ruff format --check (same paths)                                                            -> clean
$ uv run --extra dev python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ ...
Your code has been rated at 10.00/10
$ bash scripts/lint-auth-signals.sh
[+] auth-signal lint clean

CI on dd4404fa4 (rebased on main bfc09299f, after v0.37.0): see the checks tab; results are reported to the program manager.

How to test

  • uv sync --frozen --extra dev
  • APM_BINARY_PATH=.venv/bin/apm uv run --extra dev python -m pytest -q tests/integration/test_enterprise_registry_lifecycle.py → 2 passed
  • Apply any mutant from the table, re-run, and see it fail at the named guard; then git checkout -- src/
  • uv run --extra dev python -m pytest -q -m 'lifecycle_smoke and not lifecycle_merge_group' tests/integration --collect-only -q | grep enterprise_registry → test_enterprise_registry_lifecycle.py: 2

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.

Co-authored-by: Copilot [email protected]

Move the duplicated Registry HTTP API handlers from the registry redirect
and upgrade replay lifecycle tests into tests/utils/local_package_registry.py.
The fixture serves exactly the PUT (or seeded) bytes keyed by package and
version, enforces immutability, and can simulate an artifact outage or wrong
bytes. Existing tests keep their assertions unchanged.

Refs #3299

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Drive the installed CLI through producer publish (dependency first),
employee direct registry install, cold-CI frozen replay with the producer
Git host unreachable, artifact outage and wrong-bytes fail-closed, audit
--ci, uninstall preserving an unrelated file, and registering and
browsing a public HTTPS catalog against the shared loopback Registry HTTP
API fixture. Marked integration, requires_apm_binary and lifecycle_smoke.

Refs #3299

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Each networked step now asserts no request reached the producer Git host
before its exit code, git may speak HTTPS so a Git fallback is observed
rather than blocked locally, and the fault steps pin the archive-hash and
HTTP 503 reasons so a bypassed archive hash is not masked by the tree hash.

Refs #3299

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

egress_step clears observations per step, so the add step's credential
egress was never asserted. Steps now take token_hosts and both catalog
steps require that no host receives the registry token.

Refs #3299

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) marked this pull request as ready for review November 21, 2026 08:48
Copilot AI balanced review requested due to automatic review settings November 21, 2026 08:48
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit f8c31a5 into main Nov 21, 2026
47 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fluffy-garbanzo branch November 21, 2026 08:52

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 registry fixture rejects valid encoded package/version requests and accepts invalid archives as successful uploads, allowing tests to diverge from the Registry HTTP API contract.

2 open issues
What changed in this PR

Adds stage 1 of #3299: installed-CLI coverage for enterprise package distribution through APM’s Registry HTTP API, using a local fixture rather than an external vendor service. Later marketplace lifecycle stages remain separate.

Changes:

  • Introduces a shared registry fixture and migrates three existing lifecycle suites to it.
  • Adds publish, install, cold frozen replay, failure, audit, uninstall and public catalog browsing scenarios.
  • Documents the enterprise workflow and adds a changelog entry.
File Description
tests/​utils/​local_package_registry.py Adds an in-memory registry with stored uploads, authentication and download faults.
tests/​integration/​test_registry_redirect_origin_lifecycle.py Delegates registry responses to the shared fixture.
tests/​integration/​test_registry_redirect_location_hardening_lifecycle.py Reuses the fixture while retaining redirect scenarios.
tests/​integration/​test_enterprise_registry_lifecycle.py Adds producer, employee and cold-CI lifecycle coverage.
tests/​integration/​test_auth_upgrade_lock_replay_lifecycle.py Reuses registry and deterministic archive helpers.
docs/​src/​content/​docs/​reference/​registries.md Documents enterprise publishing, installation and CI replay.
CHANGELOG.md Notes the documented and tested enterprise workflow.

Review effort: Balanced

Comment on lines +116 to +122
tail = unquote(path[len(prefix) :])
package, separator, rest = tail.partition("/versions")
if not separator or not package:
return _problem(404, "Not found", path)
if rest == "" and request.method in ("GET", "HEAD"):
return self._versions(package, path)
version, _, action = rest.lstrip("/").partition("/")
Comment on lines +154 to +157
if not request.body:
return _problem(400, "Empty archive", path)
artifact = RegistryArtifact(package, version, request.body, content_type)
self.artifacts[(package, version)] = artifact
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…log replay

The scripted Registry HTTP API gateway now serves only seeded packages
(#4015 extracted it into tests/utils/local_package_registry.py), so the
scenario seeds acme/widget 1.0.0 and simulates changed bytes with the
registry's wrong-bytes download fault instead of swapping a served archive.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…log replay

The scripted Registry HTTP API gateway now serves only seeded packages
(#4015 extracted it into tests/utils/local_package_registry.py), so the
scenario seeds acme/widget 1.0.0 and simulates changed bytes with the
registry's wrong-bytes download fault instead of swapping a served archive.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…log replay

The scripted Registry HTTP API gateway now serves only seeded packages
(#4015 extracted it into tests/utils/local_package_registry.py), so the
scenario seeds acme/widget 1.0.0 and simulates changed bytes with the
registry's wrong-bytes download fault instead of swapping a served archive.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
…log replay

The scripted Registry HTTP API gateway now serves only seeded packages
(#4015 extracted it into tests/utils/local_package_registry.py), so the
scenario seeds acme/widget 1.0.0 and simulates changed bytes with the
registry's wrong-bytes download fault instead of swapping a served archive.

Co-authored-by: copilot-swe-agent[bot] <[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.

2 participants