Skip to content

refactor(audit): reduce complexity of add_ado_proxy_findings in src/audit/findings.rs - #2216

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-add-ado-proxy-findings-3f508cfd81a03d7b
Closed

github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-add-ado-proxy-findings-3f508cfd81a03d7b

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Clippy's too_many_lines lint flagged add_ado_proxy_findings in src/audit/findings.rs at 219/100 lines. The function was a single long sequence of seven independent if-blocks, each checking a different ado-proxy failure/policy signal (unhealthy lifecycle, unavailable credential, upstream failures, out-of-scope responses, prompt/policy conflicts, prohibited requests, malformed decision records) and pushing a matching Finding + Recommendation.

Change

Extracted each of the seven blocks into its own single-purpose helper function (e.g. add_ado_proxy_unhealthy_lifecycle_finding, add_ado_proxy_credential_unavailable_finding, ...), each taking &AdoProxyAnalysis plus the shared findings/recommendations vectors and early-returning when its condition does not apply. add_ado_proxy_findings now just calls each helper in the original order.

No behavioral change — the same findings and recommendations are produced in the same order for the same inputs, and the public API (derive_findings) is unchanged.

Verification

  • cargo build — passes
  • cargo test --bin ado-aw audit:: — 154 tests pass, including all audit::findings::tests::*
  • cargo clippy --all-targets --all-features — clean
  • Re-ran cargo clippy -- -W clippy::too_many_lines scoped to this file — no more warning for add_ado_proxy_findings

Before: this function has too many lines (219/100)
After: no too_many_lines warning remains for add_ado_proxy_findings

Generated by Cyclomatic Complexity Reducer · auto · 90.5 AIC · ⌖ 15.9 AIC · ⊞ 9.7K · ◷

Split the 219-line add_ado_proxy_findings function (clippy::too_many_lines)
into seven single-purpose helpers, one per proxy failure/policy signal:
lifecycle health, credential unavailability, upstream failures,
out-of-scope responses, prompt/policy conflicts, prohibited requests,
and malformed decision records.

Each helper takes the shared AdoProxyAnalysis plus the findings/
recommendations vectors and early-returns when its condition doesn't
apply, replacing the previous single function's long sequence of
if-blocks. No behavioral change: same findings/recommendations are
produced in the same order for the same inputs.

Before: this function has too many lines (219/100)
After: no too_many_lines warning remains for add_ado_proxy_findings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@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.

@jamesadevine

Copy link
Copy Markdown
Collaborator

The same audit findings refactor was already merged through #2189; #2238 records this duplicate disposition. Closing as superseded.

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.

1 participant