Skip to content

fix(prune): keep package removal when the local bundle hook re-check cannot resolve targets - #4141

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-4027-prune-recheck
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
mainfrom
danielmeppiel-4027-prune-recheck

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

apm prune exited 1 with "Failed to parse apm.yml: ..." when target resolution failed during the local-bundle hook re-check, a step #4061 added. The re-check ran inside the apm.yml parse try, so its error was reported as a parse failure and package removal stopped.

The re-check now runs after the parse:

  • If it cannot resolve targets (BundleHookTargetsUnresolved, raised only around target resolution), prune warns that local bundle hooks were NOT re-checked, points to apm install, and continues. The re-check writes nothing before targets resolve, so the zero-write guarantee holds.
  • The exception scope is narrow, so unrelated re-check failures stay fatal: policy, lockfile and integrator errors make apm prune exit 1.

The lockfile is read after the re-check, so prune's own lockfile write keeps the rows the re-check retired; tests/integration/test_trust_integrity_consistency_lifecycle.py::test_one_prune_retires_revoked_bundle_hooks_and_removes_an_orphan covers one prune that does both. No test was relaxed. New unit tests in tests/unit/test_prune_command.py::TestPruneLocalBundleHookRecheck cover the warn path and the fail-closed path. Mutation-break: broadening the catch to Exception fails the fail-closed test. tests/integration/test_hook_wipe_target_scope_e2e.py::test_zero_write_abort_before_destructive_wipe_on_prune keeps its zero-write and exit-0 assertions.

Issue and approved scope

Issue: Refs #4027

Human scope-approval comment: #4027 (comment) (regression repair for item 5, #4061)

Does this PR complete the issue, or what remains? #4027 is already closed (milestone 0.37.0); this repairs a regression in its merged part 2 (#4061). No open issue to close.

Type of change

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

Testing

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

The existing e2e test fails on main and passes with this fix. Each command below was run with APM_E2E_TESTS=1 APM_RUN_INTEGRATION_TESTS=1.

  • pytest tests/integration/test_hook_wipe_target_scope_e2e.py -k zero_write on main: failed (Failed to parse apm.yml: simulated target resolution failure, exit 1).
  • pytest -n 2 tests/integration/test_hook_wipe_target_scope_e2e.py tests/unit/test_prune_command.py tests/integration/test_trust_integrity_consistency_lifecycle.py::test_revoked_bundle_grant_retires_its_hooks with this fix: 100 passed.
  • ruff check and ruff format --check on src/ tests/, pylint R0801, lint-auth-signals.sh and lint-architecture-boundaries.sh: 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)

No req-XXX behaviour changes.

…cannot resolve targets

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 08:27

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

Prune can restore stale deployment records after hook revocation and suppress trust or retirement failures, potentially leaving an unapproved hook executable while exiting successfully.

2 open issues
What changed in this PR

This PR addresses a regression introduced by #4061 where a local-bundle hook target-resolution failure stopped apm prune and was reported as an apm.yml parse error.

Changes:

  • Moves the hook trust re-check outside manifest parsing.
  • Logs non-policy re-check failures as warnings so package removal can continue, while retaining failure behavior for PolicyViolationError.
  • Adds an Unreleased changelog entry for the prune fix.
File Description
src/​apm_cli/​commands/​prune.py Separates hook re-check error handling from manifest parsing.
CHANGELOG.md Documents continued package removal when hook target resolution fails.

Review effort: Balanced

Comment thread src/apm_cli/commands/prune.py Resolved
Comment thread src/apm_cli/commands/prune.py Resolved
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit b13e84f into main Nov 20, 2026
36 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-4027-prune-recheck branch November 20, 2026 10:19
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