refactor: reduce complexity of generate_mcpg_config in compile/common.rs#322
Conversation
Extract helper functions to reduce cognitive complexity from 31 to below 25: - nonempty_vec / nonempty_map: eliminate 7 repetitive if-is-empty patterns - validate_stdio_mcp: groups all validation calls for container MCPs - build_stdio_mcpg_server: constructs McpgServerConfig for container MCPs - build_http_mcpg_server: constructs McpgServerConfig for HTTP MCPs - try_add_user_mcp: handles the full lifecycle of one user-defined MCP entry (reserved-name check, name validation, enabled check, dispatch to stdio/http) generate_mcpg_config itself now contains only the top-level orchestration loop calling try_add_user_mcp per entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/rust-review |
|
✅ Rust PR Reviewer completed successfully! |
🔍 Rust PR ReviewSummary: Looks good — clean, correct refactoring with no behavioral changes. Findings
|
|
@copilot address suggestions |
…pers Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/014d0c8a-864f-4cd0-89c3-c6be88598ad2 Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
Addressed both suggestions in d61a010:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Summary
Reduces the cognitive complexity of
generate_mcpg_configfrom 31 (flagged byclippy::cognitive_complexity) to below 25 (no longer flagged) by extracting focused helper functions.What was complex
The original function contained a large
for (name, config) in &front_matter.mcp_serversloop with:if let Some(opts) = options { if let Some(container) = ... { ... } else if let Some(url) = ... { ... } }branchingif vec.is_empty() { None } else { Some(vec.clone()) }patterns spread across the container and HTTP branchesvalidate_container_image,validate_mount_source,validate_docker_args,warn_potential_secrets) mixed with construction logicWhat changed
Five private helpers were extracted:
nonempty_vec/nonempty_mapvalidate_stdio_mcpbuild_stdio_mcpg_serverMcpgServerConfigfor container (stdio) MCPsbuild_http_mcpg_serverMcpgServerConfigfor HTTP MCPstry_add_user_mcpgenerate_mcpg_configitself now contains only the top-level orchestration — iterating extensions, then callingtry_add_user_mcponce per entry.Verification
cargo test— all tests passcargo clippy --all-targets --all-features— clean (no new warnings)cargo clippy ... -W clippy::cognitive_complexity—generate_mcpg_configno longer appears in outputNo public API signatures or observable behaviour changed.
Warning
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.