Skip to content

Respect unavailable AI chat client providers#8453

Merged
Evangelink merged 3 commits into
mainfrom
copilot/mtp-diagnostic-analysis-fix-ichatclientprovider
May 21, 2026
Merged

Respect unavailable AI chat client providers#8453
Evangelink merged 3 commits into
mainfrom
copilot/mtp-diagnostic-analysis-fix-ichatclientprovider

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 21, 2026

IChatClientProvider.IsAvailable documented that providers can be registered but unusable, but GetChatClientAsync() ignored it and still invoked client creation. Unavailable providers could therefore throw instead of behaving like no usable provider exists.

  • Availability gate
    • GetChatClientAsync() now returns null when the registered provider reports IsAvailable == false.
    • Available providers continue to create clients as before.
return provider is null || !provider.IsAvailable
    ? null
    : await provider.CreateChatClientAsync(cancellationToken).ConfigureAwait(false);
  • Regression coverage
    • Added unit coverage verifying an unavailable provider returns null and does not call CreateChatClientAsync().

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 08:24
Copilot AI changed the title [WIP] Fix IChatClientProvider.IsAvailable behavior during provider retrieval Respect unavailable AI chat client providers May 21, 2026
Copilot AI requested a review from Evangelink May 21, 2026 08:25
@Evangelink Evangelink marked this pull request as ready for review May 21, 2026 09:23
Copilot AI review requested due to automatic review settings May 21, 2026 09:23
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

This PR updates the Microsoft.Testing.Platform AI integration to honor IChatClientProvider.IsAvailable, ensuring that registered-but-unusable providers behave the same as “no provider registered” (i.e., GetChatClientAsync() returns null rather than attempting client creation and potentially throwing).

Changes:

  • Gate GetChatClientAsync() on IChatClientProvider.IsAvailable to return null when unavailable.
  • Add a unit test covering the “unavailable provider” scenario.
  • Add a unit test project reference to Microsoft.Testing.Platform.AI to enable compiling the new AI-related unit test.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj Adds a project reference to the AI project (with netstandard targeting for non-.NETCoreApp TFMs) so unit tests can compile against AI types.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/AI/ChatClientProviderExtensionsTests.cs Introduces a regression test ensuring an unavailable provider results in null.
src/Platform/Microsoft.Testing.Platform.AI/ChatClientProviderExtensions.cs Updates GetChatClientAsync() to return null when a provider exists but reports IsAvailable == false.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

@Evangelink
Copy link
Copy Markdown
Member

@copilot address review comments

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 21, 2026

@copilot address review comments

Addressed in e854d72: updated the XML docs for the nullable result and strengthened the regression test to assert the provider is resolved via IsAvailable and CreateChatClientAsync is not invoked.

@Evangelink Evangelink merged commit 643c819 into main May 21, 2026
10 of 12 checks passed
@Evangelink Evangelink deleted the copilot/mtp-diagnostic-analysis-fix-ichatclientprovider branch May 21, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MTP Diagnostic Analysis] IChatClientProvider.IsAvailable is never honored by provider registration or retrieval

3 participants