Skip to content

[repo-assist] test: cover CallAsync readBody exception fallback - #496

Merged
sergey-tihon merged 1 commit into
masterfrom
repo-assist/test-callasync-readbody-fallback-49bdf2d03c78160c
Sep 19, 2026
Merged

sergey-tihon merged 1 commit into
masterfrom
repo-assist/test-callasync-readbody-fallback-49bdf2d03c78160c

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

ProvidedApiClientBase.CallAsync (in src/SwaggerProvider.Runtime/ProvidedApiClientBase.fs) has a readBody helper with a try/with fallback:

try
    return! response.Content.ReadAsStringAsync(cancellationToken)
with
| :? OperationCanceledException as e -> return raise e
| _ ->
    // If reading the body fails (e.g., disposed stream or invalid charset),
    // fall back to an empty body so we can still throw OpenApiException.
    return ""

This fallback branch (reading the error response body fails, so OpenApiException is still raised with an empty body) had no test coverage — all existing CallAsync tests exercised only the success path of readBody.

Change

Added SwaggerProvider.Tests.RuntimeHelpersTests.OpenApiExceptionTests.``CallAsync falls back to empty body when reading response content throws```. A new stub handler (InvalidCharsetHandler) returns an error response whose Content-Typedeclares a bogus charset.HttpClient's internal response buffering only copies raw bytes (charset-agnostic), so the request succeeds up to CallAsync, but the explicit ReadAsStringAsync()call insidereadBodyfails while decoding with the invalid charset — exercising the catch-all branch and confirmingOpenApiException.ResponseBodyis""` while the documented error description is still used.

No production code was changed; this is a test-only addition.

Test Status

  • dotnet build SwaggerProvider.sln -c Release: succeeded (pre-existing warnings only, no errors).
  • dotnet tests/SwaggerProvider.Tests/bin/Release/net10.0/SwaggerProvider.Tests.dll: 574/574 passed (573 → 574; 1 skipped, unrelated to this change).
  • dotnet fantomas --check tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs: passed, no formatting issues.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@4bc8419fad05e6b032741cbfd189986700bcf71c

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergey-tihon
sergey-tihon marked this pull request as ready for review September 19, 2026 05:43
Copilot AI lite review requested due to automatic review settings September 19, 2026 05:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

Test-only change with complete fallback-path coverage and no unresolved review issues.

Review effort: Lite
Findings: None

What changed in this PR

Adds regression coverage for CallAsync when response-body decoding fails, confirming fallback to an empty body.

Changes:

  • Added an invalid-charset HTTP handler.
  • Added assertions for OpenApiException status, body, and message.
File Description
tests/​SwaggerProvider.Tests/​RuntimeHelpersTests.fs Adds handler and fallback-path test coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sergey-tihon
sergey-tihon merged commit cb5ac96 into master Sep 19, 2026
10 checks passed
@sergey-tihon
sergey-tihon deleted the repo-assist/test-callasync-readbody-fallback-49bdf2d03c78160c branch September 19, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants