Skip to content

refactor(audit): split add_ado_proxy_findings into per-condition helpers - #2119

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-findings-ado-proxy-370e5426b354fc3f
Draft

refactor(audit): split add_ado_proxy_findings into per-condition helpers#2119
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-findings-ado-proxy-370e5426b354fc3f

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

What was complex

add_ado_proxy_findings in src/audit/findings.rs was flagged by Clippy's too_many_lines lint at 219/100 lines (measured over the whole findings.rs before this run; the function itself spanned ~230 lines). It handled seven independent proxy-diagnostic conditions (lifecycle health, credential-unavailable, upstream-failed, out-of-scope-response, prompt conflicts, prohibited requests, malformed records) inline as a sequence of if blocks each constructing a Finding + Recommendation, making the function long and hard to scan or test in isolation.

What changed

Extracted each condition into its own single-purpose helper function, each taking &AdoProxyAnalysis plus the shared findings/recommendations accumulators and using an early-return guard clause instead of a large wrapping if:

  • check_proxy_lifecycle
  • check_proxy_credential_unavailable
  • check_proxy_upstream_failed
  • check_proxy_out_of_scope_response
  • check_proxy_prompt_conflicts
  • check_proxy_prohibited_requests
  • check_proxy_malformed_records

add_ado_proxy_findings now just early-returns when there's no proxy analysis and calls each helper in the original order — so the aggregation order (and thus emitted finding order) is unchanged.

No public API changed, no behaviour changed, no comments removed.

Before / after

  • Before: Clippy too_many_lines reported add_ado_proxy_findings well over the 100-line threshold.
  • After: cargo clippy --all-targets --all-features -- -W clippy::cognitive_complexity reports no warnings for src/audit/findings.rs.

Verification

  • cargo check --all-targets — clean
  • cargo clippy --all-targets --all-features — clean
  • cargo test --bin ado-aw audit::154 passed, 0 failed (including all audit::findings::tests::* cases covering each proxy condition)

Generated by Cyclomatic Complexity Reducer · auto · 60.3 AIC · ⌖ 10.9 AIC · ⊞ 11.4K ·

Reduces cognitive complexity / too-many-lines by extracting seven
independent check_proxy_* helpers (lifecycle, credential-unavailable,
upstream-failed, out-of-scope-response, prompt-conflicts, prohibited
requests, malformed-records) out of add_ado_proxy_findings, each with
an early-return guard clause. No behaviour change; all 154 audit unit
tests continue to pass.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

0 participants