Skip to content

Replace the deprecated WebHostBuilder with WebApplication - #9468

Merged
glen-84 merged 22 commits into
mainfrom
mst/webhostbuilder-migration
Oct 25, 2026
Merged

glen-84 merged 22 commits into
mainfrom
mst/webhostbuilder-migration

Conversation

@michaelstaib

@michaelstaib michaelstaib commented Mar 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Replaces the deprecated WebHostBuilder and IWebHost with WebApplication in the test infrastructure and in the Nitro CLI (nitro fusion run and the nitro login callback listener), and removes ASPDEPR004 and ASPDEPR008 from WarningsNotAsErrors, so any new use fails the build.
  • Test hosts are built with WebApplication.CreateEmptyBuilder and UseTestServer(). The shared server factories and sessions stop each app before disposing it, asynchronously: disposing a WebApplication does not stop it, while disposing the old TestServer stopped the host it owned.
  • nitro fusion run uses CreateEmptyBuilder with Kestrel, so it reads no appsettings.json from the working directory and writes no framework log output. It still honors ASPNETCORE_ENVIRONMENT. After its own Starting server at … line it no longer prints the hosting status lines (Hosting environment, Content root path, Now listening on).
  • The subscription protocol tests run each test once (RunTest instead of the retrying TryTest) and wait for the server's close frame before asserting the close status.

Test timing

Run durations on net10.0, measured locally against main at 10721ce with the same configuration on both sides, three runs per side unless noted.

Project main This PR
AspNetCore.Tests 287–295 s total test time, 144 ms median test 280 s total test time, 137 ms median test (one run)
Fusion.AspNetCore.Tests 28.1–29.2 s 28.1–29.5 s
Adapters.OpenApi.Tests 10.9–11.3 s 10.7–11.4 s
Diagnostics.Tests 10.5–11.2 s 10.6–11.4 s
CodeGeneration.CSharp.Tests 23.6–27.6 s 26.2 s
Transport.Sockets.Client.Tests 2.0–2.2 s 2.5–2.6 s
Transport.WebSocket.Tests 1.2–1.3 s 1.3 s

AspNetCore.Tests runs at most two test classes in parallel, and the order xUnit picks depends on the path of the test assembly, so its wall-clock time varies with where the 140 s GraphQLOverHttpSpecTests class lands in the run. Total test time is the comparable figure.

Test plan

  • src/All.slnx builds with ASPDEPR004 and ASPDEPR008 treated as errors.
  • The test projects that use the changed hosts pass: AspNetCore, AspNetCore.Authorization, Transport.Sockets.Client, Transport.Http, Caching, Adapters.Mcp, Adapters.OpenApi, Data.Sorting.InMemory, Diagnostics, Utilities.Introspection, Fusion.AspNetCore, Fusion.Execution, Fusion.Diagnostics, Fusion.Connectors.InMemory, Fusion.Caching, the StrawberryShake transport and C# code generation tests, and the Nitro CLI tests.
  • nitro fusion run serves queries with Access-Control-Allow-Origin: * and the Nitro tool page, allows introspection only with ASPNETCORE_ENVIRONMENT=Development as before, and exits with code 0 on Ctrl+C and on SIGTERM.
  • The nitro login callback listener answers the redirect with the identity server's close page and hands the callback to the OIDC client, as before.

Copilot AI review requested due to automatic review settings April 8, 2026 12:45

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.

Pull request overview

This PR migrates the test hosting infrastructure from WebHostBuilder/IWebHost patterns to WebApplication (minimal hosting) across multiple test projects, and updates several HTTP streaming tests/snapshots to use GraphQLHttpResponse.

Changes:

  • Replace WebHostBuilder/TestServer setup with WebApplication.CreateSlimBuilder() + UseTestServer() / UseUrls() in multiple test helpers/sessions.
  • Update StrawberryShake integration tests to dispose the new WebApplication hosts (await using) and adjust client helper signatures.
  • Update GraphQL-over-HTTP/defer streaming tests to wrap responses with GraphQLHttpResponse and enhance snapshot formatting for jsonl/SSE streaming payloads.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.cs Switch server lifetime handling to WebApplication and async disposal.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UnsignedTypesTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsUnionListTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnUnionsTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnInterfacesTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsOnReviewSubNoStoreTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsOnReviewSubGraphQLSSETest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsOnReviewSubCompletionTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsIntrospectionTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroWithFragmentIncludeAndSkipDirectiveTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroTraitsTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetHeroTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetFriendsTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetFriendsNoStoreTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetFriendsDeferredTest.cs Update commented template snippet to new server creation style.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsGetFriendsDeferInListTest.cs Update commented template snippet to new server creation style.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/LocalTypesTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/AnyScalarDefaultSerializationTest.cs Use async disposal for server created via updated helper.
src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/resources/TestTemplate.txt Update generated test template to new hosting pattern.
src/StrawberryShake/Client/test/Transport.WebSocket.Tests/TestHelper/TestServerHelper.cs Re-implement server creation using WebApplication + Kestrel/URLs.
src/StrawberryShake/Client/test/Transport.WebSocket.Tests/IntegrationTests.cs Dispose updated WebApplication server via await using.
src/HotChocolate/Fusion/test/Fusion.Execution.Tests/TestServerSession.cs Replace WebHostBuilder/TestServer lifecycle with WebApplication-based lifecycle.
src/HotChocolate/Fusion/test/Fusion.Diagnostics.Tests/ActivityTestHelper.cs Improve activity parent correlation using span-id lookup.
src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/TestServerSession.cs Replace WebHostBuilder/TestServer lifecycle with WebApplication-based lifecycle.
src/HotChocolate/Diagnostics/test/Diagnostics.Tests/ActivityTestHelper.cs Improve activity parent correlation using span-id lookup.
src/HotChocolate/Data/test/Data.Sorting.InMemory.Tests/QueryableSortVisitorVariablesTests.cs Switch to WebApplication+UseTestServer() for in-memory sorting test server.
src/HotChocolate/Caching/test/Caching.Tests/TestServerFactory.cs Switch test server factory to WebApplication instances and GetTestServer().
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/GraphQLOverHttpSpecTests.cs Use GraphQLHttpResponse to read SSE result streams; adjust timeouts/assertions.
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/DeferOverHttpTests.cs Wrap streaming responses in GraphQLHttpResponse and snapshot the patched result.
src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/TestServerFactory.cs Switch shared test server factory to WebApplication instances and GetTestServer().
src/HotChocolate/AspNetCore/test/AspNetCore.Tests.Utilities/Subscriptions/GraphQLOverWebSocket/SubscriptionTestBase.cs Increase retry/timeout window for flaky subscription tests.
src/HotChocolate/AspNetCore/test/AspNetCore.Authorization.Tests/AuthorizationPolicyProviderTests.cs Implement fallback policy method to return null instead of throwing.
src/HotChocolate/Adapters/test/Adapters.OpenApi.Tests/TestServerSession.cs Replace WebHostBuilder/TestServer lifecycle with WebApplication-based lifecycle.
src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/FusionIntegrationTests.cs Switch gateway/subgraph test servers to WebApplication + UseTestServer().
src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/CoreIntegrationTests.cs Switch MCP test servers to WebApplication + UseTestServer().
src/CookieCrumble/src/CookieCrumble.HotChocolate/Formatters/GraphQLHttpResponseFormatter.cs Add formatting support for SSE/jsonl result streams by patching incremental payloads.
src/CookieCrumble/src/CookieCrumble.HotChocolate/Formatters/ExecutionResultSnapshotValueFormatter.cs Add legacy incremental patch handling when path is present without id.
Comments suppressed due to low confidence (1)

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/UploadScalarTest.cs:219

  • CreateClient takes a WebApplication host parameter but never uses it. Since callers already keep host alive in the test scope, consider removing this parameter (and updating call sites) to avoid confusion and keep the helper focused on what it actually needs (the port/base address).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

michaelstaib and others added 2 commits April 16, 2026 07:14
Resolve conflict in TestServerSession.cs by keeping WebApplication
migration and incorporating environmentName support from main.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

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.

🟡 Changes recommended

One or more issues must be addressed before approval.

1 open issue

Review effort: Lite

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

0.0% of changed lines covered (0/36)

File Covered Changed Patch %
…/src/CommandLine/Commands/Fusion/FusionRunCommand.cs 0 28 0.0% 🔴
…/Nitro/CommandLine/src/CommandLine/Helpers/SystemBrowser.cs 0 8 0.0% 🔴
Uncovered changed lines (JSON)
{
  "sha": "a67761d3f75b75e4c65419d6f0649ddd80f8f845",
  "files": [
    { "path": "src/Nitro/CommandLine/src/CommandLine/Commands/Fusion/FusionRunCommand.cs", "ranges": [[54, 55], [57, 60], [62, 64], [66, 68], [70, 72], [74, 79], [81, 85], [87, 87], [120, 120]] },
    { "path": "src/Nitro/CommandLine/src/CommandLine/Helpers/SystemBrowser.cs", "ranges": [[131, 133], [135, 137], [149, 150]] }
  ]
}

Project coverage: 59.4% (316794/533313 lines)

@glen-84 glen-84 changed the title Migrate test infrastructure from WebHostBuilder to Replace the deprecated WebHostBuilder with WebApplication Oct 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Nitro CLI E2E snapshots: no flow recordings changed vs main.

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.

🟡 Changes recommended

Unresolved application lifecycle leaks and reduced SSE response-contract coverage must be addressed before approval.

2 open issues
1 resolved since last review

Review effort: Lite

Comment thread src/Nitro/CommandLine/src/CommandLine/Helpers/SystemBrowser.cs

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.

🟡 Changes recommended

The MCP integration hosts are not retained by test-owned cleanup, leaving gateway and subgraph applications running after tests.

1 open issue
2 resolved since last review

Review effort: Lite

@glen-84
glen-84 merged commit a1eb52e into main Oct 25, 2026
160 checks passed
@glen-84
glen-84 deleted the mst/webhostbuilder-migration branch October 25, 2026 18:09
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.

3 participants