refactor: reduce complexity of copilot_args and configure::run#324
Closed
github-actions[bot] wants to merge 1 commit into
Closed
refactor: reduce complexity of copilot_args and configure::run#324github-actions[bot] wants to merge 1 commit into
copilot_args and configure::run#324github-actions[bot] wants to merge 1 commit into
Conversation
Extract helper functions to bring both below the cognitive complexity threshold (25): src/engine.rs - copilot_args (27 → below 25): - collect_allowed_tools(): extracts the entire restricted-tools collection block (MCP names from extensions + user servers + bash shell() entries) - push_user_args(): extracts the validated engine.args append loop (removes nested for-in-for-in with blocked prefix checks) src/configure.rs - run (27 → below 25): - resolve_auth(): extracts PAT / Azure CLI / interactive prompt flow - resolve_ado_context(): extracts git remote parsing + CLI override logic - apply_token_updates(): extracts the per-definition update loop with success/failure counting All existing tests pass. No behaviour changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both
src/engine.rs::copilot_argsandsrc/configure.rs::runwere flagged byclippy::cognitive_complexityat 27/25.What was complex
copilot_args(src/engine.rs):if !use_allow_all_tools { ... }block (~85 lines) mixing three nested loops: extension tools, user MCP server scanning (withmatch configinside), and bash command collection.for arg in engine.args() { for blocked in BLOCKED_ARG_PREFIXES { ... } }double loop at the bottom.configure::run(src/configure.rs):match pat { None => match try_azure_cli_token() { ... } }auth resolution block.and_then(|url| { match parse_ado_remote { ... } })closure inside the ADO context block.for m in matched { match update_pipeline_variable { Ok => ..., Err => ... } }update loop with counter tracking.What changed
src/engine.rscollect_allowed_tools(front_matter, extensions, edit_enabled) -> Result<Vec<String>>— moves the entire restricted-tools collection block out ofcopilot_args. Handles extension tool names, user MCP server names,"write", andshell(<cmd>)entries.push_user_args(params, engine) -> Result<()>— moves theengine.args()validation + blocked-prefix check loop out ofcopilot_args.src/configure.rsresolve_auth(pat) -> Result<AdoAuth>— extracts the PAT / Azure CLI / interactive-prompt fallback chain.resolve_ado_context(repo_path, org, project) -> Result<AdoContext>— extracts the git-remote parsing + CLI override logic.apply_token_updates(client, ado_ctx, auth, matched, token) -> Result<()>— extracts the per-definition update loop with success/failure counting and final error reporting.Results
src/engine.rscopilot_argssrc/configure.rsrunOnly
tests/compiler_tests.rs(complexity 29, a test helper with many assertion branches) remains — deferred as lower priority.Verification
cargo test)cargo clippy --all-targets --all-features -- -W clippy::cognitive_complexityno longer flags either fileWarning
The following domain was blocked by the firewall during workflow execution:
dev.azure.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.