Skip to content

fix(policy): route the org policy fetch-failure remedy through the remediation catalog - #4500

Merged
Daniel Meppiel (danielmeppiel) merged 1 commit into
mainfrom
p-4450-policy-remedy-catalog
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 1 commit into
mainfrom
p-4450-policy-remedy-catalog

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

The policy.fetch_failure_default: block refusal printed a free-text remedy literal from policy/outcome_routing.py. It now renders from a new core/remediation.py catalog entry, policy-fetch-failure-blocked (command apm policy status), so the single remediation owner holds it and an executed proof backs it.

  • Old: Check that the org policy source is reachable (apm policy status) and retry, or ask your org admin.
  • New: Run 'apm policy status' to check that the org policy source (org:contoso/.github) is reachable, then retry, or ask your org admin.

The source is named when discovery reports one. For outcomes that carry no source (absent, no_git_remote), the source is omitted: Run 'apm policy status' to check that the org policy source is reachable, then retry, or ask your org admin. The advice never suggests --no-policy.

Tests:

  • tests/integration/test_remediation_advice_lifecycle.py::test_policy_fetch_failure_remediation_clears_the_block: executed proof on the installed CLI. The install is blocked with no reachable org policy and prints the catalog sentence. The test then makes the source reachable, runs the advised apm policy status (exit 0), and retries the install, which succeeds without the advice.
  • tests/integration/test_mcp_policy_block_reason_lifecycle.py: asserts that the refusal ends with the catalog sentence instead of a hard-coded copy.
  • tests/unit/policy/test_pr_832_findings.py: asserts that the routed block reason ends with the bound catalog sentence and contains no --no-policy.

Issue and approved scope

Issue: Fixes #4450

Human scope-approval comment: #4450 (comment)

Does this PR complete the issue, or what remains? It completes the issue. One limitation: the source is named only when discovery reports one. The absent and no_git_remote outcomes carry no source today, so their sentence omits it and keeps the same meaning.

Type of change

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

Testing

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

Validation evidence (each run alone through the host load guard; full suites not run locally, so CI covers them):

  • APM_E2E_TESTS=1 APM_BINARY_PATH=<wrapper running python -m apm_cli.cli from this tree> python -m pytest tests/integration/test_remediation_advice_lifecycle.py -k policy_fetch_failure -n 0: passed (1 passed)
  • APM_E2E_TESTS=1 APM_BINARY_PATH=<same> python -m pytest tests/integration/test_mcp_policy_block_reason_lifecycle.py -n 0: passed (2 passed)
  • python -m pytest tests/unit/policy/test_pr_832_findings.py -n 0: passed (15 passed)
  • python scripts/lint_architecture_boundaries.py --root <worktree>: passed (exit 0)
  • uvx -q [email protected] check <5 changed .py files>: passed
  • uvx -q [email protected] format --check <5 changed .py files>: passed

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md:
    user-visible effect first, 25 words or fewer, ending with (#PR);
    breaking changes only under upgrade notes; no Highlights; see
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

If this PR changes behaviour that an OpenAPM v0.1 req-XXX covers,
confirm the three-step ritual in the
development guide:

  • 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.

@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
Copilot AI balanced review requested due to automatic review settings November 20, 2026 20:00
…mediation catalog

The fetch_failure_default=block refusal now renders its remedy from the
policy-fetch-failure-blocked catalog entry (apm policy status), naming the
org policy source when discovery reports one. Adds an executed proof in
test_remediation_advice_lifecycle.py and a unit check on the routing owner.

Fixes #4450

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

A missing proof registration breaks a frozen-policy test, while brace-containing paths crash refusal handling, wording departs from approved scope, and lifecycle coverage misses key outcomes.

5 open issues
What changed in this PR

This PR addresses #4450 by moving the org-policy fetch-failure remedy into APM's shared remediation catalog, keeping advice centralized without changing the fail-closed decision.

Changes:

  • Adds catalog-based apm policy status advice that names the policy source when available and never suggests a bypass.
  • Updates unit and installed-CLI tests to check catalog-backed advice and exercise recovery.
  • Adds a changelog entry for the user-visible message change.
File Description
tests/​unit/​policy/​test_pr_832_findings.py Checks catalog-backed block advice and absence of bypass guidance.
tests/​integration/​test_remediation_advice_lifecycle.py Adds a blocked-install, policy-status, and retry recovery scenario.
tests/​integration/​test_mcp_policy_block_reason_lifecycle.py Replaces literal expected advice with the catalog sentence.
src/​apm_cli/​policy/​outcome_routing.py Renders the remedy through the catalog with an optional source.
src/​apm_cli/​core/​remediation.py Defines the policy fetch-failure remediation entry.
CHANGELOG.md Records the updated policy-refusal advice.

Review effort: Balanced

# The way out of an org-enforced fail-closed block; never advertise a bypass.
# {source} binds to " (<source>)" when discovery named the source it tried, else "".
POLICY_FETCH_FAILURE_BLOCKED = _entry(
"policy-fetch-failure-blocked",
Comment on lines +1130 to +1132
"apm policy status",
"check that the org policy source{source} is reachable",
then="retry, or ask your org admin",
sentences.append(hint.rstrip("."))
reason = ". ".join([*sentences, _FETCH_FAILURE_BLOCK_REMEDY])
named = f" ({source})" if source != "unknown" else ""
remedy = POLICY_FETCH_FAILURE_BLOCKED.bind(source=named).sentence()
Comment on lines +1065 to +1067
with local_github_https_fixture(
tmp_path / "certs-unreachable", world.served_repositories()
) as fx:
Comment on lines +1086 to +1087
advised = run(env, entry.argv()[1:], "remediation-run-policy-fetch-failure-blocked")
assert advised.returncode == 0, _result_evidence(advised)
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit ca3071b into main Nov 21, 2026
40 of 42 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the p-4450-policy-remedy-catalog 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.

Route the org policy fetch-failure remedy through the remediation catalog

2 participants