refactor(compile): reduce complexity of build_pipeline_context in agentic_pipeline.rs - #1874
Conversation
Extracts four cohesive blocks from the 258-line build_pipeline_context into named helper functions to reduce clippy::too_many_lines from 258/100 to 192/100: - validate_pipeline_front_matter: the sequence of shared front-matter validators. - collect_extension_declarations: the per-extension Declarations collection loop (with warning surfacing). - fanout_extension_declarations: fan-out of Declarations into Agent setup steps, prepare steps, and conditions. - build_engine_setup: engine invocation, install-steps, composed env, and BYOM/BYOK exclusion-key computation for both Agent and Detection engines (returns a small EngineSetup struct). No public API or observable behavior changes. Verified with the full test suite (2948 tests, all passing) and a clean cargo clippy run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Preserve the current main pipeline behavior while retaining the build_pipeline_context helper extraction and its complete validation sequence. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a791be18-ce7e-40f4-80a1-f03d6eceba6c
Bring the PR branch through the current canonical merge wave without rewriting its existing history. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a791be18-ce7e-40f4-80a1-f03d6eceba6c
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
✅ PR Security Reviewer completed the security review.
|
|
✅ Rust Code Quality Reviewer completed the Rust code quality review.
|
|
✅ Test Quality Sentinel completed the test quality analysis. Reviewed PR #1874: a pure internal refactor of src/compile/agentic_pipeline.rs that extracts four helper functions from build_pipeline_context to reduce cyclomatic complexity. No public API or observable behavior changes, and no test files are touched in this diff. As the Test Quality Sentinel, there is no test code in scope to review here — existing test coverage should already exercise this logic unchanged. No inline comments or review needed.
|
|
✅ Compiler Contract Reviewer completed the compiler contract review.
|
There was a problem hiding this comment.
Compiler contract review
This is a pure internal function-extraction refactor confined to src/compile/agentic_pipeline.rs (build_pipeline_context split into validate_pipeline_front_matter, collect_extension_declarations, fanout_extension_declarations, build_engine_setup). No front-matter grammar, safe-output schema, typed IR, extension registration, generated-shell, or documentation contracts are touched, and no other files changed — so none of the drift/registry checks in this review apply.
Signatures, control flow, and error propagation are preserved 1:1 in the diff (confirmed by inspection). No findings.
🏗️ Compiler contract review by Compiler Contract Reviewer · auto · 20.2 AIC · ⌖ 2.7 AIC · ⊞ 12.7K
Comment /review to run again
There was a problem hiding this comment.
Reviewed. This is a pure mechanical refactor extracting four helper functions (validate_pipeline_front_matter, collect_extension_declarations, fanout_extension_declarations, build_engine_setup) out of build_pipeline_context in src/compile/agentic_pipeline.rs. I traced the diff end to end against the security-relevant concerns for this trust boundary (Stage 1/2/3 token isolation, generated-YAML injection, validation strength, network allowlist, safe-output integrity):
- Validation call order and arguments are unchanged (
validate_pipeline_front_mattercalls the exact same validators in the same sequence). - Extension declaration collection/fan-out logic (setup steps, agent-prepare steps, conditions, prompt supplements) is copied verbatim, only relocated.
- Engine/token handling (
SYSTEM_ACCESSTOKENprojection viaado_bundle.rs, BYOM/BYOK exclusion keys, detection engine env) is untouched — no new token reaches a new step type, and Copilot BYOM exclusion gating (is_copilotmatch) is preserved unchanged. - No new raw
Stringfields replace validated newtypes fromsrc/secure.rs; no new external inputs are introduced. - No changes to
src/allowed_hosts.rs,src/sanitize.rs, orsrc/validate.rs.
No security regression found — this diff is security-neutral (internal decomposition only, no behavior change per the PR description and confirmed by inspection).
🔒 Security review by PR Security Reviewer · auto · 27.5 AIC · ⌖ 2.99 AIC · ⊞ 11.7K
Comment /review to run again
There was a problem hiding this comment.
Rust review: no blocking issues
This is a clean, purely mechanical extraction of build_pipeline_context into four helpers (validate_pipeline_front_matter, collect_extension_declarations, fanout_extension_declarations, build_engine_setup). I traced each extracted block against the original and confirmed:
- Parameter/return threading is correct (e.g.
threat_detection/detection_engine_configpassed by reference,extension_declarationsmoved intofanout_extension_declarationsafter being borrowed bybuild_engine_setup— no double-move or borrow conflict since the borrow ends before the move). - Error propagation (
?) is preserved at every call site; nounwrap/expectintroduced. EngineSetupstruct destructuring reproduces the original local bindings exactly, no fields dropped or renamed incorrectly.- No behavioral or ordering changes to validation, extension iteration, or engine env composition.
The rust-critic sub-agent ran but returned no response after the blocking wait, so I relied on my own pass only.
💡 Minor, non-blocking observation
The new free functions use fully-qualified paths like crate::compile::types::ThreatDetectionConfig instead of the module's existing use imports — harmless but slightly inconsistent with the surrounding style. Not worth blocking on.
🦀 Rust code quality review by Rust Code Quality Reviewer · auto · 36 AIC · ⌖ 3.74 AIC · ⊞ 11.5K
Comment /review to run again
What was complex
build_pipeline_contextinsrc/compile/agentic_pipeline.rswas flagged bycargo clippy -W clippy::too_many_linesat 258/100 lines — the highest of any function in the crate. It mixed several independent concerns inline: front-matter validation, extension declaration collection, engine invocation/env/install-steps computation, and extension declaration fan-out into Agent job steps/conditions.What changed
Extracted four cohesive blocks into named helper functions, each with a doc comment noting it exists purely to reduce cognitive complexity:
validate_pipeline_front_matter— the sequence of shared front-matter validators (identity, permissions, timeout, variable groups, safe-outputs keys, threat detection, require-approval, staged, GitHub issue outputs, comment target, work-item target, PR review events/votes, PR thread statuses, ado-aw-debug config, supply-chain).collect_extension_declarations— the per-extensionDeclarationscollection loop, including warning surfacing.fanout_extension_declarations— fan-out of collectedDeclarationsinto Agent setup steps, prepare steps, and conditions (plus prompt-supplement raw-YAML steps).build_engine_setup— engine invocation, install-steps, composed env block, and Copilot BYOM/BYOK exclusion-key computation for both the Agent and Detection engines (returns a smallEngineSetupstruct).Before / after
too_many_lines (258/100)too_many_lines (192/100)build_pipeline_contextis still above the lint's threshold; the remaining body (network/MCPG config generation and paths/tokens/prompt content assembly) is a natural next target for a follow-up refactor.Verification
cargo test— 2948 passed, 0 failed.cargo clippy --all-targets --all-features— clean, no warnings.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
spsprodeus21.vssps.visualstudio.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.