Skip to content

fix(approve): accept the content-bound local-bundle key install prints (#4437) - #4490

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
bug-sweep/p4437
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
bug-sweep/p4437

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Fixes #4437 (scope record: #4437 (comment))

Description

apm approve now accepts the content-bound local-bundle key that apm install <bundle> prints (name#version@sha256:<digest>). It approves the bundle's executables by writing the same executables.allow grant the install diagnostic tells you to add, so both paths are equivalent. There is one store and one owner for the decision:

  • install/local_bundle_pending.py is the single record of installed local bundles. It now keeps every installed bundle's exact key and executable types, not only the parked ones. --pending still re-checks trust, so approved bundles stay hidden. The new recorded_bundle(key) is the only lookup.
  • commands/approve.py splits content-bound keys out before spec canonicalization. _resolve_bundle_keys refuses any key that no install recorded (wrong digest, or the bundle bytes changed since the key was printed): exit 1, an [x] line, nothing written. _approve_bundles writes allow[key] = {type: true} through _save_store (the executables.allow writer) and clears a same-store deny. It reports [x] and exits 1 if another layer still denies the key.
  • apm approve --pending prints a runnable apm approve [-g] '<key>' per parked bundle, rendered by the security/trust.approve_command owner (architecture rule install-deployment-approve-command is clean).
  • Docs: reference/cli/approve.md gains a "Local bundles" section, and the apm-usage commands.md now says apm approve "<key>" works, with executables.allow kept as the equivalent path. This supersedes the docs: local bundle executables are approved in apm.yml executables.allow #4463 line saying approve does not accept bundle keys.

Issue and approved scope

Issue: Fixes #4437

Human scope-approval comment: #4437 (comment)

This PR completes the issue. Out of scope, per the record: new key formats beyond the printed one.

Type of change

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

Testing

  • Tested locally (one guarded targeted run, PM-approved). Commit order shows the fails-before proof:
    • SHA1 603b31efa97c6eb4cd0d69af90eacac01cc1cdaf (test only, on train c8dbec8): RED expected and observed.
    • SHA2 e20abf85ecdcb672a240e56e9a9667ab47d7a124 (fix, docs, ledger, CHANGELOG): GREEN.
  • All existing tests pass (pending train CI)
  • Added tests for new functionality (if applicable)

New lifecycle test: tests/integration/test_local_bundle_hooks_lifecycle.py::test_approve_grants_the_printed_local_bundle_key (installed CLI, lifecycle_smoke). It covers:

  • Install a bundle with executables: {}: hooks are parked and the key is printed.
  • A wrong-digest key is refused: exit 1, [x] line, project tree bytes unchanged.
  • apm approve <printed key> writes exactly executables.allow: {key: {hooks: true}}. Rerunning the install registers the hook and runs it, the lock matches disk, and --pending is clean.
  • Re-approving converges with no byte change.
  • Changed bundle bytes park again under a new key. The old key is now refused with no state change. Approving the new key and reinstalling runs the new script.

Expected red on the parent: apm approve <key> exits 1 with "not found" at the first approve step. The test also refuses a wrong-digest key, a key for a bundle that isn't installed, and a stale key (project tree and $APM_HOME/config.json byte-identical), and runs the exact apm approve '<key>' line --pending prints.

Red/green evidence (.venv/bin/python -m pytest tests/integration/test_local_bundle_hooks_lifecycle.py::test_approve_grants_the_printed_local_bundle_key -n 1 -p no:cacheprovider -q, APM_BINARY_PATH=.venv/bin/apm):

  • SHA1 (parent src): 1 failed -- AssertionError: assert '[x]hookpkg#1.0.0@sha256:000...:noinstalledlocalbundlehasthisexactcontent' in 'hookpkg#1.0.0@sha256:000...:notfoundininstalledpackages.Review:apmapprove--pending' (approve has no local-bundle key path).
  • SHA2: 1 passed in 58.94s.

Lint run locally: uvx [email protected] check and format --check on the touched files, scripts/lint-auth-signals.sh, check_complexity_ratchet.py --base-ref origin/train/0.37-final (clean), lint_architecture_boundaries.py --root . (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)

  • N/A -- this PR does not change OpenAPM-observable behaviour (the local-bundle approval record is CLI-internal; spec waiver in the commit message).

@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
apm-spec-waiver: local-bundle approval record is CLI-internal; no OpenAPM-observable behaviour change.

Co-authored-by: Copilot App <[email protected]>
#4437)

apm approve <key> matches the key against the bundle the last install
recorded and writes the same executables.allow grant; a wrong, stale or
uninstalled content binding is refused (exit 1, [x]) before any write. The
install record now keeps every installed bundle's key, not only parked ones.
apm approve --pending prints a runnable approve command per parked bundle.

apm-spec-waiver: local-bundle approval record is CLI-internal; no OpenAPM-observable behaviour change.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Fails-before evidence for tests/integration/test_local_bundle_hooks_lifecycle.py::test_approve_grants_the_printed_local_bundle_key (-n 1, installed CLI via APM_BINARY_PATH=.venv/bin/apm, guarded local run):

  • RED at 603b31efa9 (test only, on train c8dbec8cd2): 1 failed. The wrong-digest key prints ...: not found in installed packages. Review: apm approve --pending, with no [x] line and no local-bundle key path.
  • GREEN at e20abf85ec (fix + docs + ledger + CHANGELOG): 1 passed in 58.94s.

The tree at e20abf85ec is byte-identical to the previous head df69dc81a7; only the commit order changed.

@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Binary provenance for the red/green run above: APM_BINARY_PATH was this worktree's own .venv/bin/apm, an editable install of this worktree's src/. $APM_BINARY_PATH --version -> Agent Package Manager (APM) CLI version 0.37.0 (e20abf85ec).

The red on the parent is the "not found" refusal, not a version-stamp or edited-lock refusal. Failing assertion at test_local_bundle_hooks_lifecycle.py:346 (in _assert_refused, first call, wrong-digest key):

E       AssertionError: assert '[x]hookpkg#1.0.0@sha256:0000000000000000000000000000000000000000000000000000000000000000:noinstalledlocalbundlehasthisexactcontent' in 'hookpkg#1.0.0@sha256:0000000000000000000000000000000000000000000000000000000000000000:notfoundininstalledpackages.Review:apmapprove--pending'

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…apm approve command

One remedy, one message: a parked local-bundle executable prints the
catalog entry local-bundle-executables-unapproved, 'apm approve <key>'
('-g' at user scope), then the reinstall, with the executables.allow entry
as the same grant. The executed-remedy test runs the printed approve
command and reinstalls; it needs apm approve for content-bound keys (#4490).

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…mmit

Keep #4490's record shape (key plus declared types, approve by recorded
key); add #4505's commit-only persistence as BundleRecordStage.

Co-authored-by: Copilot App <[email protected]>
Base automatically changed from train/0.37-final to main November 21, 2026 05:24
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 90c1bab into main Nov 21, 2026
6 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the bug-sweep/p4437 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.

apm approve does not accept content-bound local-bundle keys

1 participant