Add test infrastructure for agent conformance tests (#77)

* Add test infrastructure for agent conformance tests

* Address PR comments.

* Switch TargetFrameworks to have inline condition
This commit is contained in:
westey
2025-06-16 11:32:20 +01:00
committed by GitHub
parent 4d3b17eb27
commit 293cdb1846
16 changed files with 268 additions and 20 deletions
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(ProjectsTargetFrameworks)</TargetFrameworks>
<TargetFrameworks Condition="'$(Configuration)' == 'Debug'">$(ProjectsDebugTargetFrameworks)</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AgentConformance.IntegrationTests\AgentConformance.IntegrationTests.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
using System.Threading.Tasks;
using AgentConformance.IntegrationTests;
using AgentConformanceTests;
using Microsoft.Agents;
using Microsoft.Extensions.AI;
using OpenAI;
namespace OpenAIChatCompletion.IntegrationTests;
public class OpenAIChatCompletionFixture : AgentFixture
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
private IChatClient _chatClient;
private Agent _agent;
private AgentThread _agentThread;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
public override Agent Agent => this._agent;
public override AgentThread AgentThread => this._agentThread;
public override Task<List<ChatMessage>> GetChatHistory()
{
throw new System.NotImplementedException();
}
public override Task InitializeAsync()
{
var config = TestConfiguration.LoadSection<OpenAIConfiguration>();
this._chatClient = new OpenAIClient(config.ApiKey)
.GetChatClient(config.ChatModelId)
.AsIChatClient();
this._agentThread = new ChatClientAgentThread();
this._agent =
new ChatClientAgent(this._chatClient, new()
{
Name = "HelpfulAssistant",
Instructions = "You are a helpful assistant.",
});
return Task.CompletedTask;
}
public override Task DisposeAsync()
{
this._chatClient.Dispose();
return Task.CompletedTask;
}
}
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.
using AgentConformance.IntegrationTests;
namespace OpenAIChatCompletion.IntegrationTests;
public class OpenAIChatCompletionInvokeTests() : RunAsyncTests<OpenAIChatCompletionFixture>(() => new())
{
}
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
namespace OpenAIChatCompletion.IntegrationTests;
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
#pragma warning disable CA1812 // Internal class that is apparently never instantiated.
internal sealed class OpenAIConfiguration
{
public string? ServiceId { get; set; }
public string ChatModelId { get; set; }
public string ApiKey { get; set; }
}