refactor: reduce complexity of execute_impl in upload_build_attachment.rs - #1909
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
…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: 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Clippy's
too_many_lineslint flaggedUploadBuildAttachmentResult::execute_implat 267/100 lines — the highest-complexity function insrc/safe_outputs/not already addressed in a prior refactor pass (per cache-memory history:create_pull_request.rs::execute_implat 349/100 was already tackled across two prior PRs and remains the single largest outlier, but two other executors — this one andupload_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-suppliedbuild_idresolve_final_artifact_name— appliesname-prefixand validates charset/length/allow-listcheck_extension_allowed— validates the file extension againstallowed-extensionsresolve_attachment_type(free fn) — resolves/validates theattachment-typeconfig valueresolve_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-sizeresolve_ado_upload_context(free fn) — resolves org URL, project, token, project id, plan id, timeline id, record id fromExecutionContextbuild_attachment_url(free fn) — builds the DistributedTask timeline-attachment URLupload_attachment— sends the PUT request and maps the response to anExecutionResultexecute_implitself is now a short, linear sequence of calls to these helpers, unwrapping theResult<T, ExecutionResult>pattern used throughout the codebase for validation short-circuits.Verification
cargo build— cleancargo test— 3118 tests pass (including all 42upload_build_attachmenttests), 0 failurescargo clippy --all-targets --all-features— cleantoo_many_linesclippy check scoped to this file: the lint no longer fires forexecute_implNo 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.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.