[repo-assist] refactor: deduplicate CallAsync error branch; add stream-array and HTTP-fallback tests#460
Merged
sergey-tihon merged 2 commits intoJun 13, 2026
Conversation
…TP-fallback tests
- Merge duplicate readBody()/raise(OpenApiException(...)) calls in
CallAsync into a single error path; description selection is now
the only branching point.
- Add test: toMultipartFormDataContent with IO.Stream[] input
- Add EmptyReasonPhraseHandler helper and test: CallAsync falls back
to 'HTTP {code}' description when ReasonPhrase is empty
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors ProvidedApiClientBase.CallAsync to remove duplicated error-handling code paths while keeping behavior the same, and it adds targeted runtime helper tests (including coverage for the stream-array multipart branch and an HTTP reason-phrase fallback).
Changes:
- Deduplicated
CallAsyncerror-response handling to read the body once and raiseOpenApiExceptionvia a single shared branch. - Added a test handler to force an empty
ReasonPhraseand a test asserting the"HTTP {code}"description fallback. - Added multipart form-data coverage for
IO.Stream[]inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/SwaggerProvider.Runtime/ProvidedApiClientBase.fs |
Refactors error handling in CallAsync to eliminate duplicated body-read/exception-raise logic. |
tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs |
Adds tests for empty reason-phrase fallback and Stream[] multipart parts (but currently needs a fix to separate two tests). |
Comments suppressed due to low confidence (1)
tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs:1314
- The new stream-array test accidentally includes the body of the (now-missing)
toMultipartFormDataContent skips values when toParam returns nulltest as a trailingtask { ... }expression. This makes the new test do two unrelated things and removes coverage for the null-skipping behavior as a standalone test. Split these into two separate[<Fact>]tests.
task {
let nestedNone = box(Some(None: string option))
use content =
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3 tasks
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
ProvidedApiClientBase.CallAsynchad two nearly identical error branches — both calledreadBody()and thenraise(OpenApiException(...))with different description strings. This PR merges them into a singlereadBody()call followed by a singleraise, with anif/elif/elseexpression selecting the description.Changes
src/SwaggerProvider.Runtime/ProvidedApiClientBase.fsreadBody()and theerrorIdxlookup before the description-selection branchraise(OpenApiException(...))from both branches, leaving onetests/SwaggerProvider.Tests/RuntimeHelpersTests.fsEmptyReasonPhraseHandler— a test helper that creates anHttpResponseMessagewithReasonPhraseexplicitly set to"", triggering the"HTTP {code}"fallback inCallAsynctoMultipartFormDataContent adds each stream in a Stream array as a separate part— covers the previously untestedIO.Stream[]match arm intoMultipartFormDataContentCallAsync uses HTTP status code in description when reason phrase is empty— verifies the"HTTP {code}"fallback path whenReasonPhraseis emptyTrade-offs
No behaviour change. The refactor makes the invariant explicit: the body is always read and the exception always raised; only the description varies.
Test Status
✅ Build: succeeded (0 errors, 12 warnings — all pre-existing)
✅ Tests: 512 passed, 0 failed, 1 skipped (pre-existing skip)
✅ Format:
dotnet fantomas --checkpasses after formatting both changed filesAdd this agentic workflows to your repo
To install this agentic workflow, run