Skip to content

refactor: reduce complexity of test_compiled_yaml_structure in compiler_tests.rs#325

Merged
jamesadevine merged 1 commit into
mainfrom
refactor/test-compiled-yaml-structure-complexity-98fb44fd28427a3c
Apr 27, 2026
Merged

refactor: reduce complexity of test_compiled_yaml_structure in compiler_tests.rs#325
jamesadevine merged 1 commit into
mainfrom
refactor/test-compiled-yaml-structure-complexity-98fb44fd28427a3c

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

test_compiled_yaml_structure in tests/compiler_tests.rs was flagged by clippy::cognitive_complexity at 29/25.

The function was a single monolithic block of ~30 individual assert! calls grouped only by comments. Clippy counts each macro invocation (which expands to an if !(condition) { panic! } branch) as a complexity increment, so the score grew linearly with the number of assertions.

What changed

Five focused helper functions were extracted from the assertion body:

Helper Responsibility
assert_required_markers Data-driven loop over all \{\{ marker }} placeholders — a single for loop replaces 13 identical assert!(content.contains(...)) calls. Also consolidates firewall_version, mcpg_config, and mcpg_version markers that were previously checked in separate sections.
assert_pool_config Pool marker count + no-hardcoded-pool-name guards
assert_compiler_download ado-aw GitHub Releases fetch + targeted checksum verification
assert_awf_download AWF GitHub Releases fetch + absence of legacy ADO artifact tasks
assert_mcpg_integration MCPG flags + absence of legacy mcp-firewall artefacts

The main test now reads as a clear five-step checklist:

fn test_compiled_yaml_structure() {
    // ...load template...
    assert_required_markers(&content);
    assert_pool_config(&content);
    assert_compiler_download(&content);
    assert_awf_download(&content);
    assert_mcpg_integration(&content);
}

No assertions were removed — the data-driven loop in assert_required_markers actually adds coverage for firewall_version, mcpg_config, and mcpg_version to the unified marker list.

Results

File Function Before After
tests/compiler_tests.rs test_compiled_yaml_structure 29 below 25 (no longer flagged)

Verification

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 · ● 1.2M ·

…er_tests.rs

Extract four focused helper functions from the monolithic assertion body:
- assert_required_markers: data-driven loop over all {{ marker }} placeholders
- assert_pool_config: pool marker count and no-hardcode checks
- assert_compiler_download: ado-aw GitHub Releases fetch + checksum assertions
- assert_awf_download: AWF GitHub Releases fetch + no legacy artifact tasks
- assert_mcpg_integration: MCPG flags + no legacy mcp-firewall artefacts

Moving firewall_version, mcpg_config, and mcpg_version into the markers loop
in assert_required_markers also removes three duplicated assert! calls.

Complexity: 29 → below 25 (no longer flagged by clippy::cognitive_complexity).
All tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jamesadevine jamesadevine marked this pull request as ready for review April 27, 2026 09:49
@jamesadevine jamesadevine merged commit 28c23e8 into main Apr 27, 2026
@jamesadevine jamesadevine deleted the refactor/test-compiled-yaml-structure-complexity-98fb44fd28427a3c branch April 27, 2026 09:49
@github-actions github-actions Bot mentioned this pull request Apr 27, 2026
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