Skip to content

fix(approve): refuse a still-denied bundle approve before writing (#4933) - #4934

Merged
Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
fix-4933-bundle-approve-deny
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
fix-4933-bundle-approve-deny

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

apm approve "<bundle key>" saved the bundle grant to apm.yml (or the --user store), then exited 1 with <key> is still denied by another trust layer when an org deny or a deny in the other store still blocked the key. A failed command changed durable state (I7, transaction.failed_command_preserves_state). This is the bundle-path sibling of #4923 / #4928.

Fix at the approve owner (commands/approve.py::_approve_bundles): _bundles_still_denied decides the deny BEFORE any write. It reads package_type_verdicts (the trust owner) over the trust context, with the written store's deny map replaced by the one approve would save (same-store denies on the named keys are lifted). Neither the store load nor the preflight read persists a legacy approvals.yml migration; a successful --user save retires that file. A still-denied key keeps the [x] <key> is still denied by another trust layer text, now naming the layer and how to lift it (as a named package does), then prints Nothing written., exits 1, and leaves every store unchanged. If any named key is still denied, no grant is written for the other keys either. A non-denied bundle approve behaves as before, including Cleared deny for <key> for a same-store deny.

Docs: the reference/cli/approve.md "Local bundles" section and the apm-usage guide list "another layer still denies the key" among the refusals that write nothing.

promise: P-LAW-transaction.failed_command_preserves_state (I7) -- a failed bundle approve leaves apm.yml, config.json and approvals.yml unchanged (source: docs/src/content/docs/reference/cli/approve.md "Local bundles")
cell: OP=approve SRC=local-bundle GATE=org-deny|user-deny SCOPE=project   owner: src/apm_cli/commands/approve.py::_approve_bundles
instrument: today test -> tests/unit/commands/test_approve_deny.py::test_bundle_approve_refuses_before_any_write_when_another_layer_denies[org|user|org-user-store|project-user-store] (new); control test_bundle_approve_records_a_grant_no_layer_denies[fresh|clears-own-deny]
oracles: [I7, I8, snapshot-unchanged]  decisive: store bytes after == before
failing-before: pytest -k bundle_approve (fix stashed) -> 2 failed (store bytes differ), 2 passed (controls)
passing-after: pytest tests/unit/commands/test_approve_deny.py -> 70 passed
guard+mutation: n/a     ledger: tests/fixtures/lifecycle_bug_ledger/bugs/4933.json
hints executed: none new printed

Conflicts with #4928 in approve.py, test_approve_deny.py and the two doc files (different hunks). Whichever lands second rebases.

Issue and approved scope

Issue: Fixes #4933

Human scope-approval comment: #4933 (comment)

Completes the issue.

Type of change

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

Testing

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

Run locally (CI runs the full suite):

  • uv run --extra dev pytest tests/unit/commands/test_approve_deny.py -q -> 70 passed (the refusal cases fail without the fix)
  • Neighbours: APM_BINARY_PATH=$(uv run which apm) APM_E2E_TESTS=1 uv run --extra dev pytest tests/integration/test_install_local_bundle_e2e.py tests/integration/test_local_bundle_hooks_lifecycle.py tests/integration/test_local_bundle_mcp_lifecycle.py tests/integration/test_local_bundle_mcp_retire_lifecycle.py tests/integration/test_bundle_deny_retires_lsp_lifecycle.py tests/integration/test_executables_gate_integration.py tests/integration/test_local_bundle_canvas_gate_lifecycle.py tests/lifecycle/test_local_bundle_lost_lock_mcp.py -n 4 -> 166 passed
  • uv run --extra dev pytest tests/quality/test_lifecycle_bug_ledger.py -q -> 2 passed
  • ruff 0.15.12 check + format --check on changed Python files -> clean
  • python scripts/check_test_assertions.py -> ratchet clean
  • python scripts/lint_architecture_boundaries.py --root . -> exit 0
  • python -m tests.lifecycle.generator --check -> up to date
  • python scripts/check_complexity_ratchet.py --base-ref origin/main -> clean; pylint R0801 -> 10.00
  • python -m tests.quality.taxonomy --changed -> clean
  • bash tests/spec_conformance/mode_b_detector.sh -> no critical-path diff

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

)

apm approve <bundle key> saved the grant, then exited 1 when an org or
other-store deny still blocked the key. Decide that deny against the deny
map approve would save, through the trust owner, before any write, so a
failed bundle approve leaves apm.yml and the user store unchanged (I7).

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 23, 2026
Copilot AI balanced review requested due to automatic review settings November 23, 2026 06:34
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

The user approval path can delete approvals.yml and rewrite config.json before policy preflight rejects a bundle, changing durable state despite reporting “Nothing written.”

1 open issue
What changed in this PR

This PR addresses #4933, the local-bundle counterpart to #4923/#4928, by checking remaining trust-layer denies before saving bundle approvals.

Changes:

  • Adds a pre-write deny check that refuses the entire bundle selection if any key remains denied.
  • Adds state-preservation regression tests, successful-approval controls, and a lifecycle bug-ledger entry.
  • Updates approval documentation and the changelog to describe the refusal behavior.
File Description
tests/​unit/​commands/​test_approve_deny.py Adds refusal snapshots and successful bundle-approval controls.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4933.json Records the failed-command state-preservation regression.
src/​apm_cli/​commands/​approve.py Moves remaining-deny checks before bundle approval writes.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents refusal when another layer denies a bundle.
docs/​src/​content/​docs/​reference/​cli/​approve.md Updates the local-bundle refusal contract.
changelog.d/​4934.fixed.md Adds the user-facing fix entry.

Review effort: Balanced

Comment thread src/apm_cli/commands/approve.py Resolved
…approve

Matches the #4933 scope record: the refusal keeps the 'still denied by
another trust layer' text and adds the layer and how to lift it.

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.

🔵 Needs a closer look

The initial user-store read can migrate and delete legacy approvals before an org- or project-denied bundle is refused, changing durable state despite reporting “Nothing written.”

1 open issue

Review effort: Balanced

…undle approve

approve loads its store without persisting the legacy approvals.yml
migration; a successful --user save retires that file.

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.

🟢 Approval recommended

The bundle-approval state-preservation fix has no active review issues.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 3da1112 into main Nov 23, 2026
75 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the fix-4933-bundle-approve-deny branch November 23, 2026 07:50
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Move the #4678, #4890, #4892, #4912 and #4934 lines into [0.38.1]: they merged before the v0.38.1 tag and shipped in it. [0.38.2] keeps #4920.

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.

[BUG] apm approve <key> for a bundle saves the grant, then exits 1 when another trust layer still denies it

2 participants