mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.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<byte[]> 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>
This commit is contained in:
committed by
GitHub
Unverified
parent
b3ac4777ba
commit
06c6ec052e
+17
-18
@@ -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<byte[]> 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)
|
||||
|
||||
+3
@@ -36,6 +36,9 @@
|
||||
<None Update="Workflows\*.yaml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="TestFiles\*">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
+39
@@ -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
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 148 B |
Reference in New Issue
Block a user