From 06c6ec052e622663362a1257d27f161fb9ce1753 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 15:15:26 +0000 Subject: [PATCH] .NET: Fix failing vision integration tests by using local test files (#4128) * Initial plan * Fix failing vision integration tests by using local test files Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> * Fix net472 build error: replace File.ReadAllBytesAsync with compatible helper using AppContext.BaseDirectory Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> * Simplify ReadLocalFile: return byte[] directly instead of Task Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> --- .../MediaInputTest.cs | 35 ++++++++-------- ...kflows.Declarative.IntegrationTests.csproj | 3 ++ .../TestFiles/basic-text.pdf | 39 ++++++++++++++++++ .../TestFiles/test-image.jpg | Bin 0 -> 148 bytes 4 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/basic-text.pdf create mode 100644 dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/test-image.jpg diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs index 5400628ba3..da30db6f98 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs @@ -2,7 +2,6 @@ using System; using System.IO; -using System.Net.Http; using System.Threading.Tasks; using Azure.AI.Projects; using Azure.Identity; @@ -21,12 +20,13 @@ public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(o { private const string WorkflowWithConversationFileName = "MediaInputConversation.yaml"; private const string WorkflowWithAutoSendFileName = "MediaInputAutoSend.yaml"; - private const string ImageReference = "https://sample-files.com/downloads/images/jpg/web_optimized_1200x800_97kb.jpg"; - private const string PdfReference = "https://sample-files.com/downloads/documents/pdf/basic-text.pdf"; + private const string ImageReferenceUrl = "https://sample-files.com/downloads/images/jpg/web_optimized_1200x800_97kb.jpg"; + private const string PdfLocalFile = "TestFiles/basic-text.pdf"; + private const string ImageLocalFile = "TestFiles/test-image.jpg"; [Theory] - [InlineData(ImageReference, "image/jpeg", true)] - [InlineData(ImageReference, "image/jpeg", false)] + [InlineData(ImageReferenceUrl, "image/jpeg", true)] + [InlineData(ImageReferenceUrl, "image/jpeg", false)] public async Task ValidateFileUrlAsync(string fileSource, string mediaType, bool useConversation) { // Arrange @@ -39,12 +39,12 @@ public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(o // Temporarily disabled [Theory] [Trait("Category", "IntegrationDisabled")] - [InlineData(ImageReference, "image/jpeg", true)] - [InlineData(ImageReference, "image/jpeg", false)] + [InlineData(ImageLocalFile, "image/jpeg", true)] + [InlineData(ImageLocalFile, "image/jpeg", false)] public async Task ValidateImageFileDataAsync(string fileSource, string mediaType, bool useConversation) { // Arrange - byte[] fileData = await DownloadFileAsync(fileSource); + byte[] fileData = ReadLocalFile(fileSource); string encodedData = Convert.ToBase64String(fileData); string fileUrl = $"data:{mediaType};base64,{encodedData}"; this.Output.WriteLine($"Content: {fileUrl.Substring(0, Math.Min(112, fileUrl.Length))}..."); @@ -54,12 +54,12 @@ public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(o } [Theory] - [InlineData(PdfReference, "application/pdf", true)] - [InlineData(PdfReference, "application/pdf", false)] + [InlineData(PdfLocalFile, "application/pdf", true)] + [InlineData(PdfLocalFile, "application/pdf", false)] public async Task ValidateFileDataAsync(string fileSource, string mediaType, bool useConversation) { // Arrange - byte[] fileData = await DownloadFileAsync(fileSource); + byte[] fileData = ReadLocalFile(fileSource); string encodedData = Convert.ToBase64String(fileData); string fileUrl = $"data:{mediaType};base64,{encodedData}"; this.Output.WriteLine($"Content: {fileUrl.Substring(0, Math.Min(112, fileUrl.Length))}..."); @@ -71,12 +71,12 @@ public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(o // Temporarily disabled [Theory] [Trait("Category", "IntegrationDisabled")] - [InlineData(PdfReference, "doc.pdf", true)] - [InlineData(PdfReference, "doc.pdf", false)] + [InlineData(PdfLocalFile, "doc.pdf", true)] + [InlineData(PdfLocalFile, "doc.pdf", false)] public async Task ValidateFileUploadAsync(string fileSource, string documentName, bool useConversation) { // Arrange - byte[] fileData = await DownloadFileAsync(fileSource); + byte[] fileData = ReadLocalFile(fileSource); AIProjectClient client = new(this.TestEndpoint, new AzureCliCredential()); using MemoryStream contentStream = new(fileData); OpenAIFileClient fileClient = client.GetProjectOpenAIClient().GetOpenAIFileClient(); @@ -94,11 +94,10 @@ public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(o } } - private static async Task DownloadFileAsync(string uri) + private static byte[] ReadLocalFile(string relativePath) { - using HttpClient client = new(); - client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0"); - return await client.GetByteArrayAsync(new Uri(uri)); + string fullPath = Path.Combine(AppContext.BaseDirectory, relativePath); + return File.ReadAllBytes(fullPath); } private async Task ValidateFileAsync(AIContent fileContent, bool useConversation) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj index 985086a56e..309a590b83 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj @@ -36,6 +36,9 @@ Always + + Always + diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/basic-text.pdf b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/basic-text.pdf new file mode 100644 index 0000000000..a4fb8a4509 --- /dev/null +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/basic-text.pdf @@ -0,0 +1,39 @@ +%PDF-1.4 +%âãÏÓ +1 0 obj +<< /Type /Catalog /Pages 2 0 R >> +endobj + +2 0 obj +<< /Type /Pages /Kids [3 0 R] /Count 1 >> +endobj + +3 0 obj +<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >> +endobj + +4 0 obj +<< /Length 44 >> +stream +BT /F1 12 Tf 100 700 Td (Hello World) Tj ET + +endstream +endobj + +5 0 obj +<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> +endobj + +xref +0 6 +0000000000 65535 f +0000000015 00000 n +0000000065 00000 n +0000000123 00000 n +0000000250 00000 n +0000000345 00000 n +trailer +<< /Size 6 /Root 1 0 R >> +startxref +416 +%%EOF diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/test-image.jpg b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/test-image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8bb5fc31c4b221a3f69ad88d93e0aefd22247747 GIT binary patch literal 148 zcmex=)Zf(-wU mFvtT9X9aSAfB^~^nV4Bv+1NQaxw!w|V&DKt*fae2e-i*tgC2MQ literal 0 HcmV?d00001