Skip to content

refactor: reduce complexity of execute_impl in upload_build_attachment.rs - #1909

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-upload-build-attachment-execute-impl-39e4985c6ed0bfba
Draft

refactor: reduce complexity of execute_impl in upload_build_attachment.rs#1909
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-upload-build-attachment-execute-impl-39e4985c6ed0bfba

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Clippy's too_many_lines lint flagged UploadBuildAttachmentResult::execute_impl at 267/100 lines — the highest-complexity function in src/safe_outputs/ not already addressed in a prior refactor pass (per cache-memory history: create_pull_request.rs::execute_impl at 349/100 was already tackled across two prior PRs and remains the single largest outlier, but two other executors — this one and upload_workitem_attachment.rs — were the next biggest and this one was still unaddressed).

The function mixed together: build-id resolution/validation, artifact-name prefixing and allow-list checks, extension allow-list checks, attachment-type validation, staged-file path/size/directory verification, SHA-256 integrity checking, ADO context resolution (org/project/token/plan/timeline/record), URL construction, and the actual HTTP PUT + response handling — all inline in one async fn.

Changes

Extracted the following helpers (all private, no public API changes):

  • resolve_effective_build_id — resolves/validates the current-run build id against the agent-supplied build_id
  • resolve_final_artifact_name — applies name-prefix and validates charset/length/allow-list
  • check_extension_allowed — validates the file extension against allowed-extensions
  • resolve_attachment_type (free fn) — resolves/validates the attachment-type config value
  • resolve_and_verify_staged_file — canonicalizes the staged path, verifies it's within the working directory, isn't a directory, and matches the recorded size/max-size
  • resolve_ado_upload_context (free fn) — resolves org URL, project, token, project id, plan id, timeline id, record id from ExecutionContext
  • build_attachment_url (free fn) — builds the DistributedTask timeline-attachment URL
  • upload_attachment — sends the PUT request and maps the response to an ExecutionResult

execute_impl itself is now a short, linear sequence of calls to these helpers, unwrapping the Result<T, ExecutionResult> pattern used throughout the codebase for validation short-circuits.

Verification

  • cargo build — clean
  • cargo test3118 tests pass (including all 42 upload_build_attachment tests), 0 failures
  • cargo clippy --all-targets --all-features — clean
  • Re-ran the too_many_lines clippy check scoped to this file: the lint no longer fires for execute_impl

No behavior or public API changes — this is a pure internal restructuring for readability/testability.

Warning

Firewall blocked 1 domain

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

  • spsprodeus21.vssps.visualstudio.com

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

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · auto · 106.6 AIC · ⌖ 8.12 AIC · ⊞ 11.3K ·

…t.rs

Extract UploadBuildAttachmentResult::execute_impl (267/100 too_many_lines)
into focused helpers:
- resolve_effective_build_id: current-run build_id resolution/validation
- resolve_final_artifact_name: name-prefix application + allow-list check
- check_extension_allowed: allowed-extensions check
- resolve_attachment_type (free fn): attachment-type resolution/validation
- resolve_and_verify_staged_file: staged-file path/size/dir checks
- resolve_ado_upload_context (free fn): ADO org/project/token/plan/timeline/record resolution
- build_attachment_url (free fn): timeline-attachment URL construction
- upload_attachment: PUT request + response handling

No public API or behavior changes. All 42 upload_build_attachment tests plus
the full workspace test suite (3118 tests) pass; clippy is clean; the
too_many_lines lint no longer fires for this function.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
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.

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.

0 participants