Skip to content

.NET: Add dedicated Foundry.Hosting UnitTest project#5592

Merged
rogerbarreto merged 7 commits intomicrosoft:mainfrom
rogerbarreto:features/foundry-hosting-unittests-split
Apr 30, 2026
Merged

.NET: Add dedicated Foundry.Hosting UnitTest project#5592
rogerbarreto merged 7 commits intomicrosoft:mainfrom
rogerbarreto:features/foundry-hosting-unittests-split

Conversation

@rogerbarreto
Copy link
Copy Markdown
Member

@rogerbarreto rogerbarreto commented Apr 30, 2026

Summary

Splits the Foundry-hosting unit tests out of Microsoft.Agents.AI.Foundry.UnitTests into a new dedicated Microsoft.Agents.AI.Foundry.Hosting.UnitTests project, mirroring the parallel src/Microsoft.Agents.AI.Foundrysrc/Microsoft.Agents.AI.Foundry.Hosting split.

Motivation

  • Foundry.UnitTests was carrying .NETCoreApp-only conditional packages, a ProjectReference to Foundry.Hosting, and a Compile Remove="Hosting\**" guard purely so the Hosting tests could live next to the Foundry tests on the multi-TFM matrix.
  • Hosting tests now run on the standard TargetFrameworksCore set (net10/9/8) without conditionals.
  • Each project owns exactly the test data and helpers it needs (no shared project, matching the repo convention).

What changed

Commit Scope
ed1e7866d Extract project: git mv 12 Hosting/*.cs files, copy FakeAuthenticationTokenProvider and HttpHandlerAssert, copy 3 toolbox JSONs, add a trimmed TestDataUtil (toolbox getters only). New csproj. slnx entry. InternalsVisibleTo granted from Foundry and Foundry.Hosting.
e04205804 Align namespaces to Microsoft.Agents.AI.Foundry.Hosting.UnitTests (also fixes a pre-existing inconsistency in FoundryToolboxTests).
4a0a768de Replace WorkflowIntegrationTests.cs (an IT-named file inside a UT project) with two SUT-focused files: AgentFrameworkResponseHandlerWorkflowTests + OutputConverterWorkflowTests, plus a shared WorkflowTestAgents.cs containing the test doubles.
e36d9054e Trim the parent Foundry.UnitTests csproj: drop the Hosting compile-remove guard, the four .NETCoreApp-only packages, the conditional Foundry.Hosting ProjectReference, the three toolbox JSONs, and the toolbox getters in TestDataUtil.
df8144a0d CI-parity format fix: drop the now-redundant using Microsoft.Agents.AI.Foundry.Hosting from the moved files (already in scope from the new namespace).

Verification

  • dotnet build agent-framework-dotnet.slnx --tl:off clean.
  • Test-count parity: parent was 198 (net10) + 172 (net472); after the split parent is unchanged at 198 + 172 and the new project adds 183 (net10/9/8). Total 381 net10. No tests dropped.
  • dotnet format --verify-no-changes clean on both csprojs (run on Linux against .NET 10.0.203).

Notes for reviewers

  • Two helper classes (FakeAuthenticationTokenProvider, HttpHandlerAssert) are duplicated between the two test projects intentionally, matching the repo convention of fully self-contained UnitTests projects (no shared helper project, no inter-test-project ProjectReferences).
  • A pre-existing CA1812 on AzureAIProjectChatClientExtensionsTests.TestChatClient shows up only when format runs against the Linux .NET 10 SDK; the file is not in this PR's diff.

Move all Hosting/* tests, three toolbox TestData JSONs, and the FakeAuthenticationTokenProvider/HttpHandlerAssert/TestDataUtil helpers (trimmed to toolbox getters) into a new Microsoft.Agents.AI.Foundry.Hosting.UnitTests project. Add it to the slnx and grant the new assembly InternalsVisibleTo from Microsoft.Agents.AI.Foundry and Microsoft.Agents.AI.Foundry.Hosting.
Rename namespaces from Microsoft.Agents.AI.Foundry.UnitTests(.Hosting) to Microsoft.Agents.AI.Foundry.Hosting.UnitTests across all moved tests, the duplicated helpers, and the trimmed TestDataUtil. Also fixes the prior namespace inconsistency in FoundryToolboxTests.
Replace the WorkflowIntegrationTests file (an IT-named file inside a UT project) with two SUT-focused files plus a shared test-doubles file:

- AgentFrameworkResponseHandlerWorkflowTests.cs - the 5 handler-driven tests that exercise AgentFrameworkResponseHandler with a real workflow agent.
- OutputConverterWorkflowTests.cs - the 5 OutputConverter tests driven by hand-crafted update sequences mirroring real workflow patterns.
- WorkflowTestAgents.cs - StreamingTextAgent and ThrowingStreamingAgent extracted as internal types used by both files.
Now that Hosting tests live in their own project:
- drop the Compile Remove guard for the Hosting subfolder,
- drop the .NETCoreApp-only PackageReferences (Azure.AI.AgentServer.Responses, Microsoft.AspNetCore.TestHost, OpenTelemetry, OpenTelemetry.Exporter.InMemory),
- drop the conditional ProjectReference to Microsoft.Agents.AI.Foundry.Hosting,
- delete the three Toolbox JSON files and the matching Toolbox getters in TestDataUtil.
…Foundry.Hosting'

The new project namespace is Microsoft.Agents.AI.Foundry.Hosting.UnitTests, which already brings the parent Microsoft.Agents.AI.Foundry.Hosting namespace into scope. The explicit using statement is therefore redundant (IDE0005). Caught by 'dotnet format --verify-no-changes' running on Linux against the .NET 10 SDK.
Copilot AI review requested due to automatic review settings April 30, 2026 17:41
@rogerbarreto rogerbarreto force-pushed the features/foundry-hosting-unittests-split branch from df8144a to cde10f0 Compare April 30, 2026 17:45
The non-hosting Foundry.UnitTests project no longer holds any Hosting tests after the split, so it doesn't need access to internal types in Microsoft.Agents.AI.Foundry.Hosting. Only Microsoft.Agents.AI.Foundry.Hosting.UnitTests needs it.
@rogerbarreto rogerbarreto changed the title Split Foundry.Hosting tests into Microsoft.Agents.AI.Foundry.Hosting.UnitTests .Net: Add dedicated UnitTest project Apr 30, 2026
@rogerbarreto rogerbarreto changed the title .Net: Add dedicated UnitTest project .Net: Add dedicated Foundry.Hosting UnitTest project Apr 30, 2026
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

Splits Foundry.Hosting-related unit tests out of Microsoft.Agents.AI.Foundry.UnitTests into a new dedicated Microsoft.Agents.AI.Foundry.Hosting.UnitTests project, aligning with the Foundry/Foundry.Hosting source split.

Changes:

  • Adds a new Microsoft.Agents.AI.Foundry.Hosting.UnitTests test project (csproj, helpers, workflow-focused tests, toolbox test data).
  • Trims Microsoft.Agents.AI.Foundry.UnitTests to remove Hosting-only dependencies and toolbox test data/getters.
  • Updates InternalsVisibleTo and solution membership for the new test project.

Reviewed changes

Copilot reviewed 24 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/TestDataUtil.cs Removes toolbox JSON loading/getters from the Foundry test utilities.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Microsoft.Agents.AI.Foundry.UnitTests.csproj Drops Hosting-only package refs/compile guards/toolbox data from the Foundry unit test project.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/WorkflowIntegrationTests.cs Removes the older large workflow integration test file (replaced by new workflow-focused tests).
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/ServiceCollectionExtensionsTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/OutputConverterTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/InputConverterTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/HostedOutboundUserAgentTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/FoundryToolboxTests.cs Updates namespace to Hosting test project namespace.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/FoundryToolboxServiceTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/FoundryToolboxBearerTokenHandlerTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/FoundryAIToolExtensionsTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/DelegatingResponsesClientTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/AgentFrameworkResponseHandlerTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/AgentFrameworkResponseHandlerTelemetryTests.cs Updates test namespace for Hosting test split.
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/WorkflowTestAgents.cs Adds shared workflow test doubles (streaming/throwing agents) used by new workflow tests.
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/TestDataUtil.cs Adds Hosting test utility for toolbox JSON test data.
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/OutputConverterWorkflowTests.cs Adds focused OutputConverter workflow-pattern tests (hand-crafted update sequences).
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests.csproj Adds new Hosting unit test project and its dependencies/test data.
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/HttpHandlerAssert.cs Duplicates helper HTTP handler assertion utility into the new Hosting test project.
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/FakeAuthenticationTokenProvider.cs Duplicates a fake token provider helper into the new Hosting test project.
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/AgentFrameworkResponseHandlerWorkflowTests.cs Adds focused workflow-backed agent tests for AgentFrameworkResponseHandler.
dotnet/src/Microsoft.Agents.AI.Foundry/Microsoft.Agents.AI.Foundry.csproj Grants internals visibility to the new Hosting unit test assembly.
dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/Microsoft.Agents.AI.Foundry.Hosting.csproj Grants internals visibility to the new Hosting unit test assembly.
dotnet/agent-framework-dotnet.slnx Adds the new Hosting unit test project to the solution.

@rogerbarreto rogerbarreto self-assigned this Apr 30, 2026
@rogerbarreto rogerbarreto moved this to In Review in Agent Framework Apr 30, 2026
@moonbox3 moonbox3 added the .NET label Apr 30, 2026
…esClient

Address westey-m's review feedback on PR microsoft#5453: `Delegating*` is conventionally reserved for inheritable base classes (mirroring `DelegatingHandler`) where consumers override one or two members. This polyfill is sealed and only injects the User-Agent supplement, so the new name reflects its actual purpose.

Renamed via `git mv` to preserve history:
* `src/Microsoft.Agents.AI.Foundry.Hosting/DelegatingResponsesClient.cs` to `UserAgentResponsesClient.cs`
* `tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/DelegatingResponsesClientTests.cs` to `UserAgentResponsesClientTests.cs`

Class, constructor, and all references updated across:
* `src/.../UserAgentResponsesClient.cs` (class + constructor + internal log message)
* `src/.../ServiceCollectionExtensions.cs` (cref + type check + instantiation)
* `src/.../HostedAgentUserAgentPolicy.cs` (cref)
* `tests/Foundry.UnitTests/RequestOptionsExtensionsTests.cs` (comment)
* `tests/Foundry.Hosting.UnitTests/UserAgentResponsesClientTests.cs` (class + cref + instantiations)
@github-actions github-actions Bot changed the title .Net: Add dedicated Foundry.Hosting UnitTest project .NET: Add dedicated Foundry.Hosting UnitTest project Apr 30, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 87%

✓ Correctness

This PR is a clean refactoring that splits hosting-specific tests from the Foundry.UnitTests project into a dedicated Foundry.Hosting.UnitTests project and renames DelegatingResponsesClient to UserAgentResponsesClient. The structural changes (file moves, namespace updates, InternalsVisibleTo adjustments, csproj restructuring) are correct. One correctness issue exists in the extracted test helpers: the StreamingTextAgent and ThrowingStreamingAgent classes use public new string Id to shadow the non-virtual base AIAgent.Id property, which means the custom IDs are invisible when the agents are accessed polymorphically through AIAgent — as the workflow execution machinery does. The intended fix is to override the virtual IdCore property instead.

✓ Security Reliability

This PR cleanly refactors DelegatingResponsesClientUserAgentResponsesClient and splits hosting-related unit tests from Microsoft.Agents.AI.Foundry.UnitTests into a new Microsoft.Agents.AI.Foundry.Hosting.UnitTests project. The production code changes are limited to doc-comment updates and type reference renames with no behavioral differences. Test files are moved via git renames (so the old Hosting/ directory will be empty post-merge) and the old csproj correctly removes its conditional Compile Remove and hosting project reference. All four previously-reviewed issues were resolved. No new security or reliability concerns were identified.

✓ Test Coverage

This PR is a well-executed structural refactoring that splits hosting-related tests into a separate Microsoft.Agents.AI.Foundry.Hosting.UnitTests project and renames DelegatingResponsesClient to UserAgentResponsesClient. All 167 test methods across 12 test files are preserved: the deleted WorkflowIntegrationTests.cs (10 tests) is cleanly split into AgentFrameworkResponseHandlerWorkflowTests.cs (5 handler-level tests) and OutputConverterWorkflowTests.cs (5 converter-level tests) with shared test agents extracted to WorkflowTestAgents.cs. Test data files and utilities are properly duplicated between projects since both FakeAuthenticationTokenProvider and HttpHandlerAssert are still needed by non-hosting tests in the original project. No test coverage gaps were found.

✓ Design Approach

I did not find a design-approach issue in this diff. The main changes are test-project extraction for hosting-specific coverage and a terminology rename from DelegatingResponsesClient to UserAgentResponsesClient; both appear aligned with the underlying architecture rather than masking a deeper problem.


Automated review by rogerbarreto's agents

@rogerbarreto rogerbarreto added this pull request to the merge queue Apr 30, 2026
Merged via the queue into microsoft:main with commit fb97e93 Apr 30, 2026
23 of 24 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants