Skip to content

refactor: reduce complexity of copilot_args and configure::run#324

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-configure-engine-4ff0a97fb753ff9d
Closed

refactor: reduce complexity of copilot_args and configure::run#324
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-configure-engine-4ff0a97fb753ff9d

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Both src/engine.rs::copilot_args and src/configure.rs::run were flagged by clippy::cognitive_complexity at 27/25.

What was complex

copilot_args (src/engine.rs):

  • A large if !use_allow_all_tools { ... } block (~85 lines) mixing three nested loops: extension tools, user MCP server scanning (with match config inside), and bash command collection.
  • A for arg in engine.args() { for blocked in BLOCKED_ARG_PREFIXES { ... } } double loop at the bottom.

configure::run (src/configure.rs):

  • A nested match pat { None => match try_azure_cli_token() { ... } } auth resolution block.
  • An and_then(|url| { match parse_ado_remote { ... } }) closure inside the ADO context block.
  • A large for m in matched { match update_pipeline_variable { Ok => ..., Err => ... } } update loop with counter tracking.

What changed

src/engine.rs

  • collect_allowed_tools(front_matter, extensions, edit_enabled) -> Result<Vec<String>> — moves the entire restricted-tools collection block out of copilot_args. Handles extension tool names, user MCP server names, "write", and shell(<cmd>) entries.
  • push_user_args(params, engine) -> Result<()> — moves the engine.args() validation + blocked-prefix check loop out of copilot_args.

src/configure.rs

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

File Function Before After
src/engine.rs copilot_args 27 below 25 (no longer flagged)
src/configure.rs run 27 below 25 (no longer flagged)

Only tests/compiler_tests.rs (complexity 29, a test helper with many assertion branches) remains — deferred as lower priority.

Verification

  • All tests pass (cargo test)
  • No new Clippy warnings introduced
  • cargo clippy --all-targets --all-features -- -W clippy::cognitive_complexity no longer flags either file

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • dev.azure.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "dev.azure.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · ● 2.4M ·

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