Skip to content

.NET: Improve unit test coverage for Microsoft.Agents.AI.OpenAI#3349

Merged
rogerbarreto merged 6 commits intomainfrom
copilot/improve-unit-test-coverage
Jan 22, 2026
Merged

.NET: Improve unit test coverage for Microsoft.Agents.AI.OpenAI#3349
rogerbarreto merged 6 commits intomainfrom
copilot/improve-unit-test-coverage

Conversation

Copy link
Contributor

Copilot AI commented Jan 22, 2026

Motivation and Context

Code coverage for Microsoft.Agents.AI.OpenAI was at 66.6% line / 50% branch coverage, which is below the required 85% target. Several internal classes had 0-50% coverage including AsyncStreamingResponseUpdateCollectionResult (0%), StreamingUpdatePipelineResponse (13.3%), AgentResponseExtensions (50%), and AIAgentWithOpenAIExtensions (50%).

Description

This PR improves unit test coverage for the Microsoft.Agents.AI.OpenAI project by adding 47 new unit tests (43 → 90 total) targeting uncovered code paths.

New test files created:

  • AgentResponseExtensionsTests.cs - Tests for AsOpenAIChatCompletion and AsOpenAIResponse extension methods
  • AsyncStreamingChatCompletionUpdateCollectionResultTests.cs - Tests for internal streaming chat completion class
  • AsyncStreamingResponseUpdateCollectionResultTests.cs - Tests for internal streaming response class
  • StreamingUpdatePipelineResponseTests.cs - Tests for internal pipeline response class

Extended existing tests:

  • AIAgentWithOpenAIExtensionsTests.cs - Added ResponseItem overloads for RunAsync/RunStreamingAsync
  • OpenAIAssistantClientExtensionsTests.cs - Added tool conversion paths (HostedCodeInterpreterTool, HostedFileSearchTool, HostedFileContent, HostedVectorStoreContent)

Infrastructure changes:

  • Added InternalsVisibleTo attribute to expose internal types to the test project

Test Results: All 90 tests passing

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.
Original prompt

This section details on the original issue you should resolve

<issue_title>.NET: Improve unit test coverage for Microsoft.Agents.AI.OpenAI</issue_title>
<issue_description>Required code coverage is 85%

Image</issue_description>

<agent_instructions>Copilot please analyze the cobertura results for the Microsoft.Agents.AI.OpenAI Project and also the image provided in the issue and add the missing code path's into the UnitTests. Please follow the current pattern and testing patterns/cs files in the UnitTest project dedicated to the MA.AI.OpenAI package.

Ensure the added tests are not duplicated and focused in covering only the non-covered paths.
</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
@github-actions github-actions bot changed the title [WIP] Improve unit test coverage for Microsoft.Agents.AI.OpenAI .NET: [WIP] Improve unit test coverage for Microsoft.Agents.AI.OpenAI Jan 22, 2026
@rogerbarreto
Copy link
Member

@copilot Address format issues.

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Copilot AI changed the title .NET: [WIP] Improve unit test coverage for Microsoft.Agents.AI.OpenAI .NET: Improve unit test coverage for Microsoft.Agents.AI.OpenAI Jan 22, 2026
Copilot AI requested a review from rogerbarreto January 22, 2026 00:23
@rogerbarreto
Copy link
Member

@copilot

Formatting error still persists, getting:

Running formatters.
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/AsyncStreamingChatCompletionUpdateCollectionResultTests.cs(1,1): error CHARSET: Fix file encoding. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/AsyncStreamingResponseUpdateCollectionResultTests.cs(1,1): error CHARSET: Fix file encoding. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/StreamingUpdatePipelineResponseTests.cs(1,1): error CHARSET: Fix file encoding. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/AgentResponseExtensionsTests.cs(1,1): error CHARSET: Fix file encoding. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
Running Code Style analysis.
Determining diagnostics...
Running 30 analyzers on Microsoft.Agents.AI.OpenAI.UnitTests(net10.0).
Running 30 analyzers on Microsoft.Agents.AI.OpenAI.UnitTests(net472).
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIAssistantClientExtensionsTests.cs(848,39): error IDE0004: Cast is redundant. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/AsyncStreamingResponseUpdateCollectionResultTests.cs(6,1): error IDE0005: Using directive is unnecessary. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/AsyncStreamingChatCompletionUpdateCollectionResultTests.cs(5,1): error IDE0005: Using directive is unnecessary. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/StreamingUpdatePipelineResponseTests.cs(6,1): error IDE0005: Using directive is unnecessary. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/AgentResponseExtensionsTests.cs(4,1): error IDE0005: Using directive is unnecessary. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIAssistantClientExtensionsTests.cs(848,39): error IDE0004: Cast is redundant. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/AsyncStreamingChatCompletionUpdateCollectionResultTests.cs(5,1): error IDE0005: Using directive is unnecessary. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/StreamingUpdatePipelineResponseTests.cs(6,1): error IDE0005: Using directive is unnecessary. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/ChatClient/AsyncStreamingResponseUpdateCollectionResultTests.cs(6,1): error IDE0005: Using directive is unnecessary. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]
/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/AgentResponseExtensionsTests.cs(4,1): error IDE0005: Using directive is unnecessary. [/app/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Microsoft.Agents.AI.OpenAI.UnitTests.csproj]

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 22, 2026

@copilot Address format issues.

Fixed in 4d4160c. Ran dotnet format to address file encoding issues (CHARSET), remove unnecessary using directives (IDE0005), and remove redundant casts (IDE0004).

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 22, 2026

@copilot

Formatting error still persists, getting:
...

Fixed in 31fb3ab. Changed assistantClient.AsAIAgent(null!) to assistantClient.AsAIAgent(null!, chatOptions: null) to resolve the IDE0004 redundant cast error by using a named parameter to disambiguate the overload.

@rogerbarreto rogerbarreto marked this pull request as ready for review January 22, 2026 12:27
@rogerbarreto rogerbarreto added this pull request to the merge queue Jan 22, 2026
Merged via the queue into main with commit 958e6d2 Jan 22, 2026
14 checks passed
This was referenced Jan 27, 2026
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…osoft#3349)

* Initial plan

* Add unit tests for Microsoft.Agents.AI.OpenAI to improve code coverage

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>

* Address code review feedback: remove unused using directives

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>

* Fix format issues: file encoding and remove unused using directives

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>

* Fix redundant cast error by using named parameter

Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>

* Remove excessive inline comments per PR review feedback

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
@crickman crickman deleted the copilot/improve-unit-test-coverage branch February 4, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Improve unit test coverage for Microsoft.Agents.AI.OpenAI

5 participants