Skip to content

fix(approve): refuse an org-denied approve before writing apm.yml (#4923) - #4928

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-jubilant-potato
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-jubilant-potato

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

apm approve <pkg> under an org executables.deny recorded the grant in apm.yml (and cleared any same-store deny), saved the store, and only then reported is still denied (org-deny) and exited 1. A failed command changed durable state (I7, transaction.failed_command_preserves_state).

Fix at the approve owner (commands/approve.py::_record_and_save): for named packages, _refuse_still_denied decides the other-layer deny BEFORE any record or save. It reads the trust ladder through the existing _still_denied / package_type_verdicts path, with the written store's deny map replaced by the map approve would save (same-store denies it lifts removed), so the decision is not duplicated. A still-denied package prints the same error naming the layer and how to lift it, plus Nothing written., and exits 1 with every store unchanged. If any named package is still denied, nothing is written for the others either. The preflight runs in approve_cmd before the local-bundle approval path saves, so a mixed bundle-key/package approve also writes nothing. Trust reads before the write no longer persist the legacy approvals.yml migration; a successful --user save retires that file. The old post-save check is removed. Bulk --all / --recommended are unchanged (they already skip denied packages before writing). A non-denied approve behaves as before.

Docs: reference/cli/approve.md and the apm-usage guide now say a still-denied approve writes nothing.

Lands after #4924 (strict Known cell gate-cell-approve-org-deny). After #4924 merges, this branch is rebased, the Known marker is removed so the cell is required, and the snapshots are regenerated.

promise: P-LAW-transaction.failed_command_preserves_state (I7) -- a failed approve leaves apm.yml and the user store unchanged (source: docs/src/content/docs/reference/cli/approve.md "Approving a denied package")
cell: OP=approve GATE=org-deny|user-deny SCOPE=project   owner: src/apm_cli/commands/approve.py::_record_and_save
instrument: today test -> tests/unit/commands/test_approve_deny.py::test_approve_refuses_an_org_denied_package_before_any_write (new, 3 cases: org-deny, with-an-allowed-one, project-deny-kept); tests/integration/test_deny_remediation_lifecycle.py::test_approve_exits_1_when_another_layer_still_denies (extends: bytes oracle on apm.yml, apm.lock.yaml, user config.json)
oracles: [I7, I8, snapshot-unchanged]  decisive: store bytes after == before
failing-before: pytest <both nodes> -> unit: 3 failed (AssertionError on manifest bytes); integration: 1 failed (apm.yml bytes differ)
passing-after: same -> 67 passed (unit module); 3 passed (integration module)
guard+mutation: n/a     ledger: tests/fixtures/lifecycle_bug_ledger/bugs/4923.json
hints executed: none new printed

Issue and approved scope

Issue: Fixes #4923

Human scope-approval comment: #4923 carries status/accepted (milestone 0.38.0); assigned through the P2 Install & Harness lead.

Completes the issue: the refusal now happens before any write (option 1 in 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 -> 71 passed (new refusal cases, including mixed bundle+package and legacy approvals.yml, fail without the fix)
  • APM_BINARY_PATH=$(uv run which apm) uv run --extra dev pytest tests/integration/test_deny_remediation_lifecycle.py -n 0 -q -> 3 passed (extended case fails without the fix)
  • Neighbours: test_pinned_hook_policy_deny_lifecycle, test_user_scope_exec_trust_lifecycle, test_executables_gate_integration, test_approval_identity_lifecycle, test_lsp_denied_package_wording_lifecycle, test_frozen_deny_preflight_lifecycle, tests/lifecycle/machines/test_m_gate.py, test_remediation_gate9_call_sites -> 140 passed; after the review fold, the deny/user-scope/identity/local-bundle/gate neighbours -> 158 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
  • python -m tests.quality.taxonomy --changed -> clean
  • bash tests/spec_conformance/mode_b_detector.sh -> no critical-path diff

Inherited reds on main (not from this PR): Lint deployment_ledger.py line count (2101 > 2100); Windows #4876 failure.

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 recorded the grant (and cleared a same-store deny), saved the
store, and only then exited 1 when an org or other-store deny still blocked
the package. Decide that deny before any write, against the store as approve
would save it, so a failed 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 05:38
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

Critical refusal paths can migrate personal consent stores or persist bundle grants before rejecting an org-denied package, changing stored data despite reporting “Nothing written.”

2 open issues
What changed in this PR

This PR addresses #4923 by moving named-package deny checks before approval writes, aiming to preserve durable state when apm approve fails because another trust layer denies the package.

Changes:

  • Adds a preflight check using the existing trust evaluation, accounting for same-store denies that approval would clear.
  • Adds regression coverage for denied approvals and unchanged store bytes.
  • Updates command documentation and records the fix in the changelog and lifecycle bug ledger.
File Description
tests/​unit/​commands/​test_approve_deny.py Adds refusal, mixed-package, and successful-approval cases.
tests/​integration/​test_deny_remediation_lifecycle.py Checks store bytes remain unchanged after refusal.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4923.json Links the failed-command invariant to regression tests.
src/​apm_cli/​commands/​approve.py Moves named-package deny evaluation before recording and saving.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents that still-denied approvals write nothing.
docs/​src/​content/​docs/​reference/​cli/​approve.md Clarifies the no-write refusal behavior.
changelog.d/​4928.fixed.md Adds the user-facing fix entry.

Review effort: Balanced

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

Select named packages and refuse a still-denied one before the local-bundle
approval path saves, so a mixed bundle-key/package approve writes nothing.
Trust reads that run before the write no longer persist 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

No active review issues remain for the change that prevents denied package approvals from writing approval stores.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

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

No active review issues block the approval state-preservation change.

No open issues 🎉

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 11cd107 into main Nov 23, 2026
75 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-jubilant-potato branch November 23, 2026 13:14
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 writes the grant to apm.yml and then exits 1 when an org deny still blocks the package

2 participants