From ac59813c55188e3c793d7c4ff801cd3b8774562b Mon Sep 17 00:00:00 2001 From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> Date: Wed, 21 Oct 2026 16:20:35 -0700 Subject: [PATCH] test(dotnet): remove legacy persistent tests Retire Azure Persistent v1 live integration coverage while preserving the product package, offline unit tests, and DeepResearch sample. Refs #9587 --- dotnet/agent-framework-dotnet.slnx | 1 - ...IAgentsChatClientAgentRunStreamingTests.cs | 10 - .../AzureAIAgentsChatClientAgentRunTests.cs | 10 - ...AIAgentsPersistent.IntegrationTests.csproj | 19 -- .../AzureAIAgentsPersistentCreateTests.cs | 285 ------------------ .../AzureAIAgentsPersistentFixture.cs | 104 ------- ...zureAIAgentsPersistentRunStreamingTests.cs | 10 - .../AzureAIAgentsPersistentRunTests.cs | 10 - ...gentsPersistentStructuredOutputRunTests.cs | 30 -- 9 files changed, 479 deletions(-) delete mode 100644 dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsChatClientAgentRunStreamingTests.cs delete mode 100644 dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsChatClientAgentRunTests.cs delete mode 100644 dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistent.IntegrationTests.csproj delete mode 100644 dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs delete mode 100644 dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentFixture.cs delete mode 100644 dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentRunStreamingTests.cs delete mode 100644 dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentRunTests.cs delete mode 100644 dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentStructuredOutputRunTests.cs diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx index 77e772cf214..33a360ee475 100644 --- a/dotnet/agent-framework-dotnet.slnx +++ b/dotnet/agent-framework-dotnet.slnx @@ -645,7 +645,6 @@ - diff --git a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsChatClientAgentRunStreamingTests.cs b/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsChatClientAgentRunStreamingTests.cs deleted file mode 100644 index 487dcd68788..00000000000 --- a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsChatClientAgentRunStreamingTests.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using AgentConformance.IntegrationTests; - -namespace AzureAIAgentsPersistent.IntegrationTests; - -[Trait("Category", "Integration")] -public class AzureAIAgentsChatClientAgentRunStreamingTests() : ChatClientAgentRunStreamingTests(() => new()) -{ -} diff --git a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsChatClientAgentRunTests.cs b/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsChatClientAgentRunTests.cs deleted file mode 100644 index 79a7c24c695..00000000000 --- a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsChatClientAgentRunTests.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using AgentConformance.IntegrationTests; - -namespace AzureAIAgentsPersistent.IntegrationTests; - -[Trait("Category", "Integration")] -public class AzureAIAgentsChatClientAgentRunTests() : ChatClientAgentRunTests(() => new()) -{ -} diff --git a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistent.IntegrationTests.csproj b/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistent.IntegrationTests.csproj deleted file mode 100644 index 0913d484e50..00000000000 --- a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistent.IntegrationTests.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - $(NoWarn);CS8793 - True - True - - - - - - - - - - - - - diff --git a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs b/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs deleted file mode 100644 index 971bf57cbcb..00000000000 --- a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentCreateTests.cs +++ /dev/null @@ -1,285 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -#pragma warning disable CS0618 // Type or member is obsolete - testing deprecated PersistentAgentsClientExtensions - -using System; -using System.Diagnostics; -using System.IO; -using System.Threading.Tasks; -using AgentConformance.IntegrationTests.Support; -using Azure.AI.Agents.Persistent; -using Microsoft.Agents.AI; -using Microsoft.Extensions.AI; -using Shared.IntegrationTests; - -namespace AzureAIAgentsPersistent.IntegrationTests; - -[Trait("Category", "Integration")] -public class AzureAIAgentsPersistentCreateTests -{ - private const string SkipCodeInterpreterReason = "Azure AI Code Interpreter intermittently fails to execute uploaded files in CI"; - - private readonly PersistentAgentsClient _persistentAgentsClient = new(TestConfiguration.GetRequiredValue(TestSettings.AzureAIProjectEndpoint), TestAzureCliCredentials.CreateAzureCliCredential()); - - [Theory] - [InlineData("CreateWithChatClientAgentOptionsAsync")] - [InlineData("CreateWithFoundryOptionsAsync")] - public async Task CreateAgent_CreatesAgentWithCorrectMetadataAsync(string createMechanism) - { - // Arrange. - const string AgentName = "IntegrationTestAgent"; - const string AgentDescription = "An agent created during integration tests"; - const string AgentInstructions = "You are an integration test agent"; - - // Act. - var agent = createMechanism switch - { - "CreateWithChatClientAgentOptionsAsync" => await this._persistentAgentsClient.CreateAIAgentAsync( - TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName), - options: new ChatClientAgentOptions() - { - ChatOptions = new() { Instructions = AgentInstructions }, - Name = AgentName, - Description = AgentDescription - }), - "CreateWithFoundryOptionsAsync" => await this._persistentAgentsClient.CreateAIAgentAsync( - TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName), - instructions: AgentInstructions, - name: AgentName, - description: AgentDescription), - _ => throw new InvalidOperationException($"Unknown create mechanism: {createMechanism}") - }; - - try - { - // Assert. - Assert.NotNull(agent); - Assert.Equal(AgentName, agent.Name); - Assert.Equal(AgentDescription, agent.Description); - Assert.Equal(AgentInstructions, agent.Instructions); - - var retrievedAgentMetadata = await this._persistentAgentsClient.Administration.GetAgentAsync(agent.Id); - Assert.NotNull(retrievedAgentMetadata); - Assert.Equal(AgentName, retrievedAgentMetadata.Value.Name); - Assert.Equal(AgentDescription, retrievedAgentMetadata.Value.Description); - Assert.Equal(AgentInstructions, retrievedAgentMetadata.Value.Instructions); - } - finally - { - // Cleanup. - await this._persistentAgentsClient.Administration.DeleteAgentAsync(agent.Id); - } - } - - [Theory(Skip = "For manual testing only")] - [InlineData("CreateWithChatClientAgentOptionsAsync")] - [InlineData("CreateWithFoundryOptionsAsync")] - public async Task CreateAgent_CreatesAgentWithVectorStoresAsync(string createMechanism) - { - // Arrange. - const string AgentInstructions = """ - You are a helpful agent that can help fetch data from files you know about. - Use the File Search Tool to look up codes for words. - Do not answer a question unless you can find the answer using the File Search Tool. - """; - - // Create a vector store. - var searchFilePath = Path.GetTempFileName() + "wordcodelookup.txt"; - File.WriteAllText( - path: searchFilePath, - contents: "The word 'apple' uses the code 442345, while the word 'banana' uses the code 673457." - ); - PersistentAgentFileInfo uploadedAgentFile = this._persistentAgentsClient.Files.UploadFile( - filePath: searchFilePath, - purpose: PersistentAgentFilePurpose.Agents - ); - var vectorStoreMetadata = await this._persistentAgentsClient.VectorStores.CreateVectorStoreAsync([uploadedAgentFile.Id], name: "WordCodeLookup_VectorStore"); - - // Wait for vector store indexing to complete before using it - await this.WaitForVectorStoreReadyAsync(this._persistentAgentsClient, vectorStoreMetadata.Value.Id); - - // Act. - var agent = createMechanism switch - { - "CreateWithChatClientAgentOptionsAsync" => await this._persistentAgentsClient.CreateAIAgentAsync( - TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName), - options: new ChatClientAgentOptions() - { - ChatOptions = new() - { - Instructions = AgentInstructions, - Tools = [new HostedFileSearchTool() { Inputs = [new HostedVectorStoreContent(vectorStoreMetadata.Value.Id)] }] - } - }), - "CreateWithFoundryOptionsAsync" => await this._persistentAgentsClient.CreateAIAgentAsync( - TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName), - instructions: AgentInstructions, - tools: [new FileSearchToolDefinition()], - toolResources: new ToolResources() { FileSearch = new([vectorStoreMetadata.Value.Id], null) }), - _ => throw new InvalidOperationException($"Unknown create mechanism: {createMechanism}") - }; - - try - { - // Assert. - // Verify that the agent can use the vector store to answer a question. - var result = await agent.RunAsync("Can you give me the documented code for 'banana'?"); - Assert.Contains("673457", result.ToString()); - } - finally - { - // Cleanup. - await this._persistentAgentsClient.Administration.DeleteAgentAsync(agent.Id); - await this._persistentAgentsClient.VectorStores.DeleteVectorStoreAsync(vectorStoreMetadata.Value.Id); - await this._persistentAgentsClient.Files.DeleteFileAsync(uploadedAgentFile.Id); - File.Delete(searchFilePath); - } - } - - [Fact(Skip = SkipCodeInterpreterReason)] - public Task CreateAgent_CreatesAgentWithCodeInterpreter_ChatClientAgentOptionsAsync() - => this.CreateAgent_CreatesAgentWithCodeInterpreterAsync("CreateWithChatClientAgentOptionsAsync"); - - [Fact(Skip = SkipCodeInterpreterReason)] - public Task CreateAgent_CreatesAgentWithCodeInterpreter_FoundryOptionsAsync() - => this.CreateAgent_CreatesAgentWithCodeInterpreterAsync("CreateWithFoundryOptionsAsync"); - - private async Task CreateAgent_CreatesAgentWithCodeInterpreterAsync(string createMechanism) - { - // Arrange. - const string AgentInstructions = """ - You are a helpful coding agent. A Python file is provided. Use the Code Interpreter Tool to run the file - and report the SECRET_NUMBER value it prints. Respond only with the number. - """; - - // Create a python file that prints a known value. - var codeFilePath = Path.GetTempFileName() + "secret_number.py"; - File.WriteAllText( - path: codeFilePath, - contents: "print(\"SECRET_NUMBER=24601\")" // Deterministic output we will look for. - ); - PersistentAgentFileInfo uploadedCodeFile = this._persistentAgentsClient.Files.UploadFile( - filePath: codeFilePath, - purpose: PersistentAgentFilePurpose.Agents - ); - CodeInterpreterToolResource toolResource = new(); - toolResource.FileIds.Add(uploadedCodeFile.Id); - - // Act. - var agent = createMechanism switch - { - // Hosted tool path (tools supplied via ChatClientAgentOptions) - "CreateWithChatClientAgentOptionsAsync" => await this._persistentAgentsClient.CreateAIAgentAsync( - TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName), - options: new ChatClientAgentOptions() - { - ChatOptions = new() - { - Instructions = AgentInstructions, - Tools = [new HostedCodeInterpreterTool() { Inputs = [new HostedFileContent(uploadedCodeFile.Id)] }] - } - }), - "CreateWithFoundryOptionsAsync" => await this._persistentAgentsClient.CreateAIAgentAsync( - TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName), - instructions: AgentInstructions, - tools: [new CodeInterpreterToolDefinition()], - toolResources: new ToolResources() { CodeInterpreter = toolResource }), - _ => throw new InvalidOperationException($"Unknown create mechanism: {createMechanism}") - }; - - try - { - // Assert. - var result = await agent.RunAsync("What is the SECRET_NUMBER?"); - // We expect the model to run the code and surface the number. - Assert.Contains("24601", result.ToString()); - } - finally - { - // Cleanup. - await this._persistentAgentsClient.Administration.DeleteAgentAsync(agent.Id); - await this._persistentAgentsClient.Files.DeleteFileAsync(uploadedCodeFile.Id); - File.Delete(codeFilePath); - } - } - - [Theory] - [InlineData("CreateWithChatClientAgentOptionsAsync")] - public async Task CreateAgent_CreatesAgentWithAIFunctionToolsAsync(string createMechanism) - { - // Arrange. - const string AgentInstructions = "You are a helpful weather assistant. Always call the GetWeather function to answer questions about weather."; - - static string GetWeather(string location) => $"The weather in {location} is sunny with a high of 23C."; - var weatherFunction = AIFunctionFactory.Create(GetWeather); - - ChatClientAgent agent = createMechanism switch - { - "CreateWithChatClientAgentOptionsAsync" => await this._persistentAgentsClient.CreateAIAgentAsync( - TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName), - options: new ChatClientAgentOptions() - { - ChatOptions = new() - { - Instructions = AgentInstructions, - Tools = [weatherFunction] - } - }), - _ => throw new InvalidOperationException($"Unknown create mechanism: {createMechanism}") - }; - - try - { - // Act. - var response = await agent.RunAsync("What is the weather like in Amsterdam?"); - - // Assert - ensure function was invoked and its output surfaced. - var text = response.Text; - Assert.Contains("Amsterdam", text, StringComparison.OrdinalIgnoreCase); - Assert.Contains("sunny", text, StringComparison.OrdinalIgnoreCase); - Assert.Contains("23", text, StringComparison.OrdinalIgnoreCase); - } - finally - { - await this._persistentAgentsClient.Administration.DeleteAgentAsync(agent.Id); - } - } - - /// - /// Waits for a vector store to complete indexing by polling its status. - /// - /// The persistent agents client. - /// The ID of the vector store. - /// Maximum time to wait in seconds (default: 30). - /// A task that completes when the vector store is ready or throws on timeout/failure. - private async Task WaitForVectorStoreReadyAsync( - PersistentAgentsClient client, - string vectorStoreId, - int maxWaitSeconds = 30) - { - Stopwatch sw = Stopwatch.StartNew(); - while (sw.Elapsed.TotalSeconds < maxWaitSeconds) - { - PersistentAgentsVectorStore vectorStore = await client.VectorStores.GetVectorStoreAsync(vectorStoreId); - - if (vectorStore.Status == VectorStoreStatus.Completed) - { - if (vectorStore.FileCounts.Failed > 0) - { - throw new InvalidOperationException("Vector store indexing failed for some files"); - } - - return; - } - - if (vectorStore.Status == VectorStoreStatus.Expired) - { - throw new InvalidOperationException("Vector store has expired"); - } - - await Task.Delay(1000); - } - - throw new TimeoutException($"Vector store did not complete indexing within {maxWaitSeconds}s"); - } -} diff --git a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentFixture.cs b/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentFixture.cs deleted file mode 100644 index e6446be1cfa..00000000000 --- a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentFixture.cs +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using AgentConformance.IntegrationTests; -using AgentConformance.IntegrationTests.Support; -using Azure; -using Azure.AI.Agents.Persistent; -using Microsoft.Agents.AI; -using Microsoft.Extensions.AI; -using Shared.IntegrationTests; - -namespace AzureAIAgentsPersistent.IntegrationTests; - -public class AzureAIAgentsPersistentFixture : IChatClientAgentFixture -{ - private ChatClientAgent _agent = null!; - private PersistentAgentsClient _persistentAgentsClient = null!; - - public IChatClient ChatClient => this._agent.ChatClient; - - public AIAgent Agent => this._agent; - - public async Task> GetChatHistoryAsync(AIAgent agent, AgentSession session) - { - List messages = []; - var typedSession = (ChatClientAgentSession)session; - - await foreach (var threadMessage in (AsyncPageable)this._persistentAgentsClient.Messages.GetMessagesAsync( - threadId: typedSession.ConversationId, order: ListSortOrder.Ascending)) - { - var message = new ChatMessage - { - Role = threadMessage.Role == MessageRole.User ? ChatRole.User : ChatRole.Assistant - }; - - foreach (var content in threadMessage.ContentItems) - { - if (content is MessageTextContent textContent) - { - message.Contents.Add(new TextContent(textContent.Text)); - } - } - - messages.Add(message); - } - - return messages; - } - - public async Task CreateChatClientAgentAsync( - string name = "HelpfulAssistant", - string instructions = "You are a helpful assistant.", - IList? aiTools = null) - { - var persistentAgentResponse = await this._persistentAgentsClient.Administration.CreateAgentAsync( - model: TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName), - name: name, - instructions: instructions); - - var persistentAgent = persistentAgentResponse.Value; - - return new ChatClientAgent( - this._persistentAgentsClient.AsIChatClient(persistentAgent.Id), - options: new() - { - Id = persistentAgent.Id, - ChatOptions = new() { Tools = aiTools } - }); - } - - public Task DeleteAgentAsync(ChatClientAgent agent) => - this._persistentAgentsClient.Administration.DeleteAgentAsync(agent.Id); - - public Task DeleteSessionAsync(AgentSession session) - { - var typedSession = (ChatClientAgentSession)session; - if (typedSession?.ConversationId is not null) - { - return this._persistentAgentsClient.Threads.DeleteThreadAsync(typedSession.ConversationId); - } - - return Task.CompletedTask; - } - - public ValueTask DisposeAsync() - { - GC.SuppressFinalize(this); - - if (this._persistentAgentsClient is not null && this._agent is not null) - { - return new ValueTask(this._persistentAgentsClient.Administration.DeleteAgentAsync(this._agent.Id)); - } - - return default; - } - - public async ValueTask InitializeAsync() - { - this._persistentAgentsClient = new(TestConfiguration.GetRequiredValue(TestSettings.AzureAIProjectEndpoint), TestAzureCliCredentials.CreateAzureCliCredential()); - this._agent = await this.CreateChatClientAgentAsync(); - } -} diff --git a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentRunStreamingTests.cs b/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentRunStreamingTests.cs deleted file mode 100644 index 1ba0ec991e9..00000000000 --- a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentRunStreamingTests.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using AgentConformance.IntegrationTests; - -namespace AzureAIAgentsPersistent.IntegrationTests; - -[Trait("Category", "Integration")] -public class AzureAIAgentsPersistentRunStreamingTests() : RunStreamingTests(() => new()) -{ -} diff --git a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentRunTests.cs b/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentRunTests.cs deleted file mode 100644 index 446b27b8176..00000000000 --- a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentRunTests.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using AgentConformance.IntegrationTests; - -namespace AzureAIAgentsPersistent.IntegrationTests; - -[Trait("Category", "Integration")] -public class AzureAIAgentsPersistentRunTests() : RunTests(() => new()) -{ -} diff --git a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentStructuredOutputRunTests.cs b/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentStructuredOutputRunTests.cs deleted file mode 100644 index 6ec4620ce32..00000000000 --- a/dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentStructuredOutputRunTests.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Threading.Tasks; -using AgentConformance.IntegrationTests; - -namespace AzureAIAgentsPersistent.IntegrationTests; - -[Trait("Category", "Integration")] -public class AzureAIAgentsPersistentStructuredOutputRunTests() : StructuredOutputRunTests(() => new()) -{ - private const string SkipReason = "Fails intermittently on the build agent/CI"; - - public override Task RunWithResponseFormatReturnsExpectedResultAsync() - { - Assert.SkipWhen(SkipReason is not null, SkipReason ?? string.Empty); - return base.RunWithResponseFormatReturnsExpectedResultAsync(); - } - - public override Task RunWithGenericTypeReturnsExpectedResultAsync() - { - Assert.SkipWhen(SkipReason is not null, SkipReason ?? string.Empty); - return base.RunWithGenericTypeReturnsExpectedResultAsync(); - } - - public override Task RunWithPrimitiveTypeReturnsExpectedResultAsync() - { - Assert.SkipWhen(SkipReason is not null, SkipReason ?? string.Empty); - return base.RunWithPrimitiveTypeReturnsExpectedResultAsync(); - } -}