Repository navigation
fix(policy): keep optional policy discovery quiet when no policy exists - #3783
Daniel Meppiel (danielmeppiel) merged 11 commits into
Conversation
…ts (#3754) Auto-discovery logged a WARNING through the root logging handler whenever .github-private was absent on GitHub, even when the policy was then found in .github, and the secret redaction filter garbled it. Discovery now records the masked-404 hint as PolicyFetchResult data, only after every candidate is absent, worded so redaction leaves it readable. The output owner renders it only with --verbose, in apm policy status (table and JSON discovery_hint), and in the fail-closed error under policy.fetch_failure_default: block (install and audit --ci). A test guard keeps policy/discovery.py free of user-facing logger calls. apm-spec-waiver: diagnostic routing only; discovery order, outcomes and fetch_failure_default semantics are unchanged. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Cache-only misses can produce misleading HTTP 404 permission advice, while verbose CI audits omit the private-repository hint under the default warning policy.
2 open issues
What changed in this PR
This PR addresses #3754 by moving optional policy-discovery diagnostics into result data, keeping ordinary policy absence quiet while preserving troubleshooting details and fail-closed behavior.
Changes:
- Replace the mid-discovery warning with a hint recorded only after all candidates are absent.
- Surface hints in verbose logging, policy status, and block-mode errors.
- Add regression coverage and update policy documentation.
| File | Description |
|---|---|
| tests/unit/test_audit_ci_auto_discovery.py | Tests hint visibility in default and block modes. |
| tests/unit/policy/test_fetch_failure_knob.py | Tests hint propagation into blocking errors. |
| tests/unit/policy/test_discovery.py | Tests cascade behavior and guards against direct logging. |
| tests/unit/install/test_install_logger_policy.py | Tests verbose-only hint rendering. |
| tests/unit/commands/test_policy_status.py | Tests table and JSON hint output. |
| src/apm_cli/policy/outcome_routing.py | Passes hints to logging and blocking errors. |
| src/apm_cli/policy/discovery.py | Records the hint instead of emitting a warning. |
| src/apm_cli/core/command_logger.py | Adds verbose-only discovery hint output. |
| src/apm_cli/commands/policy.py | Exposes hints in policy status reports. |
| src/apm_cli/commands/audit.py | Includes hints in fail-closed CI errors. |
| packages/apm-guide/.apm/skills/apm-usage/governance.md | Documents quiet discovery and hint visibility. |
| docs/src/content/docs/reference/policy-schema.md | Explains absence diagnostics and block behavior. |
| docs/src/content/docs/enterprise/policy-reference.md | Documents policy status hints. |
| CHANGELOG.md | Records the warning-routing fix. |
Review effort: Balanced
Resolve the PR's DIRTY merge state against main; keep CHANGELOG Unreleased sections in Keep-a-Changelog order (Changed, Fixed). Co-authored-by: Copilot <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| CLI Logging Expert | 0 | 2 | 0 | Hint plumbing through CommandLogger is well-gated; two composition issues: cache_only emits false 404 hint, block-error lines bury the 190-char hint inline. |
| Test Coverage Expert | 0 | 2 | 0 | All five done-when cases have unit-tier regression traps (9/9 pass). cache_only path records misleading hint with no test; default-install silence lacks integration-tier trap. |
| Python Architect | 0 | 2 | 0 | Hint-as-data seam is architecturally sound; guard cache_only path to avoid false 404 claims; prefer direct attribute access over getattr on declared dataclass field. |
| Doc Writer | 0 | 3 | 0 | Docs and CHANGELOG match the fix. The hint is now explained in 3 places, the absent row in section 10 is stale, and the docs omit host and cache-only limits. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 5 follow-ups
- [Test Coverage Expert] Guard cache_only path: add
and result.not_foundto the hint condition (discovery.py:1002) and add test_cache_only_all_absent_does_not_record_http_hint. -- All four panelists converged on this. Evidence outcome: missing on a governed-by-policy surface. The hint text says 'returned 404' but cache_only mode never makes an HTTP request. One-line code fix plus one test. - [Python Architect] Replace getattr(fetch_result, 'discovery_hint', None) with fetch_result.discovery_hint in outcome_routing.py and audit.py. -- discovery_hint is a declared dataclass field with default None; getattr defeats type-checker narrowing. Every other field on PolicyFetchResult is accessed directly.
- [CLI Logging Expert] Split the block-error line in _audit_ci_gate into severity line + diagnostic line instead of concatenating the ~190-char hint inline. -- The [x] error + appended hint produces a ~300-char stderr line that buries the actionable fix. A two-line pattern ([x] then [i] hint) matches CommandLogger's existing convention.
- [Doc Writer] Update the section 10 outcomes-table absent row and consolidate the hint explanation to one canonical location with cross-links. -- The hint is explained in three pages but the outcomes table still says 'None required'. State the explanation once, link from the rest.
- [Doc Writer] Qualify the host scope: hint fires only on github.com, *.ghe.com, and $GITHUB_HOST -- not arbitrary GHES without GITHUB_HOST set. -- Docs currently imply every GitHub-compatible host. Users on GHES without GITHUB_HOST configured would look for a hint that never appears.
Recommendation
Fold the cache_only guard (and result.not_found on discovery.py) and its unit test before landing -- it is a one-line correctness fix that all four panelists converged on and the test-coverage-expert tagged as a missing regression trap on a governed-by-policy surface. The getattr cleanup and block-error line split are quick wins in the same pass. The doc consolidation can fold in the same run. With the cache_only guard folded, the PR is ready for maintainer sign-off.
Full per-persona findings
CLI Logging Expert
- [recommended] cache_only mode records 'returned 404' hint when no HTTP request was made at
src/apm_cli/policy/discovery.py:1002
In cache_only mode (local bundle install, audit replay), _auto_discover records the hint whenever result.outcome=='absent' for .github-private on a GitHub host. In cache_only the candidate is absent because there is no cache entry, not because GitHub answered 404, so the hint text is false. PolicyFetchResult.not_found is True only on the real 404 path.
Suggested: Guard with result.not_found. - [recommended] Block-error line in _audit_ci_gate concatenates the ~190-char hint inline, producing a ~300-char stderr line at
src/apm_cli/commands/audit.py:750
The hint appended as '. {hint}' to the [x] line buries the actionable fix; CommandLogger renders the same hint as a separate [i] line. Two-line pattern (error then diagnostic) keeps the severity signal scannable.
Suggested: Echo the [x] line, then if hint echo '[i] {hint}' on its own line.
Test Coverage Expert
- [recommended] cache_only=True path attaches misleading 'returned 404' hint when no HTTP request was made -- zero test coverage at
src/apm_cli/policy/discovery.py:1000
_auto_discover(cache_only=True) records masked_private_hint on cache-miss absent; grep confirmed no cache_only test in test_discovery.py.
Suggested: Add test_cache_only_all_absent_does_not_record_http_hint and gate the hint on result.not_found.
Proof (missing at):tests/unit/policy/test_discovery.py::TestAutoDiscover::test_cache_only_all_absent_does_not_record_http_hint-- proves: Offline discovery does not attach a misleading HTTP-based diagnostic hint [governed-by-policy,devx]
assert result.discovery_hint is None - [recommended] Default-install silence regression trap exists at unit tier only at
tests/unit/install/test_install_logger_policy.py
Defended by AST guard, assertNoLogs and mock-based InstallLogger silence tests; no test drives policy_gate.run in warn mode with absent discovery and asserts no output.
Suggested: Add a policy_gate.run warn-mode absent test with a real non-verbose InstallLogger asserting no _rich_warning/_rich_info.
Proof (passed):tests/unit/install/test_install_logger_policy.py::TestPolicyDiscoveryMiss::test_absent_hint_silent_in_non_verbose-- proves: Default-mode install with no org policy emits no policy warning on stderr [devx,governed-by-policy]
mock_info.assert_not_called(); mock_warning.assert_not_called()
Python Architect
- [recommended] cache_only path records a misleading '404' hint when no HTTP request was made at
src/apm_cli/policy/discovery.py:1003
_cache_only_policy_result returns absent on an empty cache; the hint says 'returned 404'. not_found (set only on the real HTTP 404 path) is the canonical signal and is future-proof against new non-HTTP absent paths.
Suggested: Add 'and result.not_found' to the hint guard. - [recommended] getattr on a declared dataclass field breaks type-checker narrowing and misrepresents the contract at
src/apm_cli/policy/outcome_routing.py:165
discovery_hint is a declared PolicyFetchResult field with default None; every other field is read directly in the same files.
Suggested: Use fetch_result.discovery_hint in outcome_routing.py and audit.py.
Doc Writer
- [recommended] The hint is explained in three pages, but the canonical absent row in the section 10 outcomes table was not updated at
docs/src/content/docs/enterprise/policy-reference.md:969
Section 10 Discovery outcomes table absent row still says 'None required'. policy-reference 9.7, policy-schema item 2 and apm-guide governance.md each restate the full explanation; state once and link.
Suggested: Put the explanation in the absent row; trim 9.7 to the Hint/discovery_hint field below the shell example; shorten policy-schema item 2 with a link; keep one clause in governance.md. - [recommended] The docs suggest the hint shows on every GitHub-compatible host, but the code limits it to github.com, *.ghe.com and $GITHUB_HOST at
packages/apm-guide/.apm/skills/apm-usage/governance.md:469
_is_github_host accepts github.com, *.ghe.com or GITHUB_HOST; GHES without GITHUB_HOST never sees the hint.
Suggested: Qualify the host scope once in the canonical location. - [recommended] Under cache-only discovery the hint says 'returned 404' even though no request was sent at
src/apm_cli/policy/discovery.py:1002
Docs repeat the 404 promise; code must gate on a real 404 for the docs to hold.
Suggested: Record the hint only when result.not_found is True.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
In cache_only mode a candidate is absent because no cache entry exists, not because GitHub answered 404, yet the hint said 'returned 404'. Gate it on PolicyFetchResult.not_found, which only the real 404 path sets. Addresses panel follow-up FU-1 (all four personas). Co-authored-by: Copilot <[email protected]>
discovery_hint is a declared PolicyFetchResult field with a None default; getattr implied it might be missing and defeated type narrowing. Addresses panel follow-up FU-2 (python-architect). Co-authored-by: Copilot <[email protected]>
Appending the ~190-char hint to the [x] line buried the actionable fix in a ~300-char line. Print the error, then the hint as an [i] line, matching CommandLogger. Addresses panel follow-up FU-3 (cli-logging-expert). Co-authored-by: Copilot <[email protected]>
Drive policy_gate.run with an absent result carrying a hint and a real non-verbose InstallLogger, asserting no warning or info output. Addresses panel finding from test-coverage-expert (default-install silence trap). Co-authored-by: Copilot <[email protected]>
Move the explanation into the canonical absent row of Discovery outcomes, link to it from policy status and the policy schema, and name the hosts where the hint applies (github.com, *.ghe.com, GITHUB_HOST). Addresses panel follow-ups FU-4 and FU-5 (doc-writer). Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
The fix collapses policy-discovery diagnostics onto the CommandLogger output owner (#3754). Extend the registry_delegation.output_diagnostics boundary rule so policy/discovery.py cannot regain a logger.info/warning/error call, and add the matching confirmed-bypass mutation to the architecture test. Dual guardrail for the split-authority repair. Co-authored-by: Copilot <[email protected]>
With the default fetch_failure_default=warn, apm audit --ci --verbose dropped the private-repo hint, so --verbose did not show it as the accepted scope requires. Print it as an [i] stderr line after the unchanged #1159 posture line; JSON/SARIF stdout is untouched. Addresses Copilot inline on src/apm_cli/commands/audit.py:752. Co-authored-by: Copilot <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| CLI Logging Expert | 0 | 0 | 0 | Both prior folds verified correct (cache_only 404 guard, block-error line split). New verbose warn-mode [i] hint follows all output rules; no findings. |
| Test Coverage Expert | 0 | 0 | 0 | Both prior findings folded and verified; delta adds architecture mutation guard and audit verbose warn-mode test, both passing. No new coverage gaps. |
| Python Architect | 0 | 0 | 0 | Delta guard extending registry_delegation.output_diagnostics to policy/discovery.py is the right home -- same owner decision (CommandLogger), dual guardrail complete, prior folds verified. |
| Doc Writer | 0 | 0 | 0 | Doc folds are accurate and concise; the absent row's --verbose wording covers audit --ci --verbose and the CHANGELOG line still matches. Ship. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Folded in this run
- (panel) FU-1: record the
.github-privatehint only after a real 404 (result.not_found), not on a cache-only miss; addstest_cache_only_miss_gets_no_masked_404_hint-- resolved in 5d59610. - (panel) FU-2: read
discovery_hintas a declared field instead ofgetattr-- resolved in fc0c801. - (panel) FU-3: block-mode
apm audit --ciprints the hint as its own[i]line after the[x]error -- resolved in 1754689. - (panel) Default-mode silence trapped through
policy_gate.runwith a real non-verboseInstallLogger-- resolved in 193fd83. - (panel) FU-4/FU-5: hint explained once in the
absentrow of Discovery outcomes, with host scope (github.com,*.ghe.com,GITHUB_HOST); other pages link to it -- resolved in d9d2d1d. - (panel) Dual guardrail for the output-owner repair:
registry_delegation.output_diagnosticsnow forbidslogger.<level>output inpolicy/discovery.py, plus the matching confirmed-bypass architecture test -- resolved in e44c3b8. - (copilot)
apm audit --ci --verbosein default warn mode now shows the hint as an[i]stderr line after the unchanged [BUG] _parse_remote_url fails for SSH remotes with non-git usernames #1159 posture line -- resolved in 21edf17. - (copilot) Exclude cache-only misses from the 404 hint -- resolved in 5d59610.
- Merged
mainto clear the conflict state (CHANGELOG Unreleased kept in Changed, Fixed order) -- b695b74, 36d9424.
Copilot signals reviewed
src/apm_cli/policy/discovery.py:1003-- LEGIT: cache-only "absent" is not a 404; hint gated onnot_found(resolved in 5d59610).src/apm_cli/commands/audit.py:752-- LEGIT: accepted scope says--verboseshows the hint; warn-mode audit now does (resolved in 21edf17).
Regression-trap evidence (mutation-break gate)
TestAutoDiscover::test_cache_only_miss_gets_no_masked_404_hint-- deletedand result.not_found; test FAILED as expected; guard restored.TestPolicyGateFailClosed::test_absent_with_hint_is_silent_by_default-- deleted theInstallLoggerverbose gate; test FAILED as expected; guard restored.TestMaskedPrivateRepoHint::test_hint_in_block_error-- re-concatenated the hint onto the[x]line; test FAILED as expected; guard restored.TestMaskedPrivateRepoHint::test_hint_shown_in_verbose_warn_mode-- disabled the verbose hint branch; test FAILED as expected; guard restored.- Discovery re-emitting
logger.warning-- behavioral test and AST unit guard FAILED, boundary lint exited 1 withregistry_delegation.output_diagnostics; restored. test_confirmed_bypass_is_rejected[policy-discovery-stdlib-warning]-- neutered the new static rule; test FAILED as expected; rule restored.
Lint contract
ruff check and ruff format --check (ruff 0.15.12) over src/ tests/ and the architecture-linter scripts: silent. pylint R0801: 10.00/10. lint-auth-signals.sh: clean. lint-architecture-boundaries.sh: exit 0.
CI
All 26 checks on 21edf17 finished: 23 SUCCESS, 2 NEUTRAL, 1 SKIPPED (after 0 CI fix iterations).
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3783 | 21edf17 |
ship_now | 2 | 8 | 0 | 2 | green | MERGEABLE | BLOCKED | pending required CODEOWNER review |
Convergence
2 outer iteration(s); 2 Copilot round(s). Final panel stance: ship_now. Ready for maintainer review; lands after v0.36.1 is tagged (milestone 0.37.0).
Recommendation
All five R1 follow-ups are folded, verified, and mutation-tested. The architecture-boundary lint guard adds a durable regression trap beyond what the panel asked for. No remaining findings from any panelist. The PR is ready for maintainer landing after the pending CODEOWNER review from Sergio Sisternes (@sergio-sisternes-epam); it can land as-is once that review completes and the milestone 0.37.0 sequencing (after the v0.36.1 tag) is met.
Full per-persona findings
CLI Logging Expert
No findings.
Test Coverage Expert
No findings.
Python Architect
No findings.
Doc Writer
No findings.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.
The #3775 and #3783 entries landed inside the [0.36.1] block when main was merged; they ship in 0.37.0. Move them, with #3777, under [Unreleased]. Co-authored-by: Copilot App <[email protected]>
The #3775 and #3783 entries landed inside the [0.36.1] block when main was merged; they ship in 0.37.0. Move them, with #3777, under [Unreleased]. Co-authored-by: Copilot App <[email protected]>
…d routes (#3777) * docs(registry-proxy): correct the range-resolution premise and name the supported routes (#3756) Registry proxies such as Artifactory do have listing APIs; APM simply fetches exact versions only through a proxy and does not call vendor listing APIs. registry-proxy.md now says so and names the two supported routes under PROXY_REGISTRY_ONLY: exact pins plus lockfile replay, or a server implementing the APM Registry HTTP API (GET /v1/packages/{owner}/{repo}/versions). The RegistryOnlySemverError hint names the same two routes; apm view versions and apm outdated drop the same false claim. No resolution behavior changes. apm-spec-waiver: message and documentation wording only; no resolver behavior change. Co-authored-by: Copilot App <[email protected]> * docs(changelog): note the registry-only range guidance (#3777) Co-authored-by: Copilot App <[email protected]> * fix(deps): keep the unset escape hatch in the registry-only range hint The reworded RegistryOnlySemverError hint dropped "unset PROXY_REGISTRY_ONLY", which the installed-CLI contract test_install_range_fails_with_remedy_without_contacting_source_host asserts. Restore it as the third option, tighten the hint so it no longer states the premise twice, and reflow the 111-char docstring line. A unit assertion now traps the escape hatch (mutation-break verified: removing the clause fails the unit and integration tests). Addresses panel follow-up 3 (doc-writer, hint verbosity) on #3777. Co-authored-by: Copilot App <[email protected]> * docs(registry-proxy): drop the remaining only-upstream-can-list claims registry-proxy.md still said a version listing is something only the upstream host can provide, contradicting the APM Registry HTTP API route named a few lines below. The apm-guide authentication resource still said the proxy has no tag listing. Both now state that APM does not list through the proxy by design and name the supported routes; the troubleshooting row matches the error hint. Addresses panel follow-ups 1 and 2 (doc-writer) on #3777. Co-authored-by: Copilot App <[email protected]> * docs(changelog): file 0.37 entries under [Unreleased] The #3775 and #3783 entries landed inside the [0.36.1] block when main was merged; they ship in 0.37.0. Move them, with #3777, under [Unreleased]. Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]>

Description
With no org policy,
apm install(and any command that auto-discovers policy) printed a stderr WARNING about.github-private, "not found (or [REDACTED] private-repo read scope)". It fired mid-cascade, so it also appeared when the org's policy lived in.githuband was found. It bypassed the output owner (CommandLogger), which deliberately keeps "no policy" verbose-only, and the secret redaction filter garbled its text.Fix at the owner boundary:
policy/discovery.py::_auto_discoverrecords the masked-404 hint asPolicyFetchResult.discovery_hint, only after every candidate is absent, worded so_redact_secretsleaves it unchanged. No logger output.CommandLogger.policy_discovery_miss(..., hint=)shows it withabsentin--verboseonly.outcome_routing.route_discovery_outcomepasses it to the logger and appends it to the fail-closed error underpolicy.fetch_failure_default: block;apm audit --cidoes the same in its block branch.apm policy statusshows it as aHintpanel (table) anddiscovery_hint(JSON).policy/discovery.pygains a user-facinglogger.warning/error/critical/infocall.Unchanged: discovery order and candidates, outcomes,
fetch_failure_defaultsemantics, policy-fetch auth (T1 owns it). Theapm audit --ci[!] No org policy found ...; enforcement skippedline from #1159 is a deliberate CI posture line, not this warning, and stays.Issue and approved scope
Issue: Fixes #3754
Human scope-approval comment: #3754 (comment)
Does this PR complete the issue, or what remains? Completes it.
Type of change
Testing
Validation evidence (local):
.venv/bin/python -m pytest tests/unit/policy/test_discovery.py tests/unit/install/test_install_logger_policy.py tests/unit/policy/test_fetch_failure_knob.py tests/unit/commands/test_policy_status.py -p no:xdist -q: 315 passed.tests/unit/test_audit_ci_auto_discovery.py: 16 passed..github(no hint),--verbose(hint shown),apm policy status(table + JSON), block mode (install andaudit --cifail closed with the hint), redaction-safe wording, static guard.discovery.pychange, the two new cascade tests fail.uvx [email protected] check/format --check: clean. pylint R0801: 10.00/10.bash scripts/lint-auth-signals.sh: clean.scripts/lint_architecture_boundaries.py --root .: no findings in tracked files.Spec conformance (OpenAPM v0.1)