Skip to content

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
Copilot AI review requested due to automatic review settings January 22, 2026 12:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves unit test coverage for the Microsoft.Agents.AI.OpenAI project from 66.6% line / 50% branch to meet the 85% target. The PR adds 47 new unit tests (increasing from 43 to 90 total tests) targeting previously uncovered code paths in internal streaming classes and extension methods.

Changes:

  • Created 4 new test files for testing internal streaming classes and extension methods
  • Extended 2 existing test files with additional test cases for tool conversions and ResponseItem overloads
  • Added InternalsVisibleTo attribute to expose internal types to the test project

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
AgentResponseExtensionsTests.cs New test file covering AsOpenAIChatCompletion and AsOpenAIResponse extension methods with null checks and conversion paths
AsyncStreamingChatCompletionUpdateCollectionResultTests.cs New test file testing GetContinuationToken, GetRawPagesAsync, and iteration behavior for streaming chat completion updates
AsyncStreamingResponseUpdateCollectionResultTests.cs New test file covering streaming response update filtering logic including RawRepresentation and ChatResponseUpdate handling
StreamingUpdatePipelineResponseTests.cs New test file testing PipelineResponse properties, content handling, and unsupported buffering operations
AIAgentWithOpenAIExtensionsTests.cs Extended with ResponseItem overload tests covering null argument validation and method invocation
OpenAIAssistantClientExtensionsTests.cs Extended with tool conversion tests for HostedCodeInterpreterTool, HostedFileSearchTool, HostedFileContent, and HostedVectorStoreContent
Microsoft.Agents.AI.OpenAI.csproj Added InternalsVisibleTo attribute to expose internal types to unit tests

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