Skip to content

fix(policy): dry-run previews an org policy block when policy cannot be resolved - #4466

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-s20-dry-run-policy-block
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-s20-dry-run-policy-block

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

With policy.fetch_failure_default: block and no enforceable org policy, apm install refuses, but apm install --dry-run printed nothing about it. The policy-outcome routing owner (policy/outcome_routing.route_discovery_outcome) now emits Would be blocked by policy: <reason> when a dry run suppresses the blocking error. Every dry-run caller (install preflight, local bundle) goes through it. The exit code is unchanged (0) and nothing is written.

Issue and approved scope

Issue: Fixes #4455

Human scope-approval comment: see #4455.

Does this PR complete the issue, or what remains? It completes it.

Type of change

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

Testing

  • Tested locally

  • All existing tests pass

  • Added tests for new functionality (if applicable)

  • tests/unit/policy/test_pr_832_findings.py::TestOutcomeRoutingTable::test_dry_run_previews_the_fetch_failure_default_block: fails before the change (no warning emitted) and passes after.

  • The strict lifecycle cell test_policy_outcomes.py::test_site_routes_the_outcome[install-dry-run-preflight|cache_miss_fetch_fail/block] is now required (witnesses regenerated: 925 required).

  • tests/unit/policy/: 1407 passed. Ledger tests pass; ruff and architecture boundaries are 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.

Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:37
Co-authored-by: Copilot App <[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

Blocking previews raise AttributeError because the logger adapters lack warning(), breaking default trust-policy resolution with raise_blocking_errors=False and the lifecycle preview tests.

1 open issue
What changed in this PR

This PR addresses #4455 by adding blocked-policy previews to the shared policy-outcome router, so dry runs explain when an unresolved org policy would block installation without changing exit status or writing state.

Changes:

  • Emit a warning when a dry run suppresses a blocking policy error.
  • Add a unit regression and enable the existing lifecycle check.
  • Update generated coverage obligations, the bug ledger, and changelog.
File Description
tests/​unit/​policy/​test_pr_832_findings.py Adds an assertion for the blocked-policy preview warning.
tests/​quality/​generated_obligations.json Refreshes required lifecycle coverage mappings.
tests/​lifecycle/​security/​test_policy_outcomes.py Removes the expected-failure marker from the dry-run block check.
tests/​fixtures/​lifecycle_bug_ledger.json Records #4455 and its regression coverage.
src/​apm_cli/​policy/​outcome_routing.py Emits a warning for suppressed blocking outcomes.
CHANGELOG.md Documents the dry-run preview fix.

Review effort: Balanced

)
if route.blocks and logger is not None:
# A dry run previews the block the real command applies (#4455).
logger.warning(f"Would be blocked by policy: {route.block_reason}")
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit f490fdb into main Nov 21, 2026
41 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-s20-dry-run-policy-block 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.

install --dry-run does not preview the blocked outcome when org policy cannot be fetched

2 participants