61 lines
2.8 KiB
C#
61 lines
2.8 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.Extensions.Options;
|
|
using Volcanic.AgenticCore.A2A.Server.Callers;
|
|
using Volcanic.AgenticCore.A2A.Server.Hosting;
|
|
|
|
namespace Volcanic.AgenticCore.A2A.Server.Tests;
|
|
|
|
public sealed class CardTests : IDisposable
|
|
{
|
|
private readonly string _ws = Path.Combine(Path.GetTempPath(), "a2a-card", Guid.NewGuid().ToString("N"));
|
|
private A2ACaller Caller => new("x", "isolated", _ws, "p", "1");
|
|
private static A2ACardProvider Cards(string? publicUrl = null) =>
|
|
new(Options.Create(new A2AHostOptions { PublicUrl = publicUrl }), NullLogger<A2ACardProvider>.Instance);
|
|
|
|
public CardTests() => Directory.CreateDirectory(_ws);
|
|
|
|
[Fact]
|
|
public void Card_Public_IsGeneric_WithInterfacesAndApiKeyScheme()
|
|
{
|
|
var card = Cards("https://bot.example").Public(null);
|
|
Assert.Equal("Volcanic assistant", card.Name);
|
|
Assert.Contains(card.SupportedInterfaces, i => i.Url == "https://bot.example/a2a" && i.ProtocolBinding == "JSONRPC");
|
|
Assert.Contains(card.SupportedInterfaces, i => i.Url == "https://bot.example/a2a/v1" && i.ProtocolBinding == "HTTP+JSON");
|
|
Assert.True(card.Capabilities.ExtendedAgentCard);
|
|
Assert.Equal("X-API-Key", card.SecuritySchemes!["apiKey"].ApiKeySecurityScheme!.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void Card_Public_UsesRequestBaseUrlWithoutPublicUrl() =>
|
|
Assert.Equal("http://localhost:5000/a2a", Cards().Public("http://localhost:5000").SupportedInterfaces[0].Url);
|
|
|
|
[Fact]
|
|
public void Card_Public_BlankPublicUrlCountsAsUnset() =>
|
|
Assert.Equal("http://localhost:5000/a2a", Cards("").Public("http://localhost:5000").SupportedInterfaces[0].Url);
|
|
|
|
[Fact]
|
|
public void Card_Extended_FromCardJson()
|
|
{
|
|
Directory.CreateDirectory(Path.Combine(_ws, ".volcanic", "a2a"));
|
|
File.WriteAllText(A2ACardProvider.CardPath(_ws), """
|
|
{ "name": "Eugene's assistant", "description": "Schedules meetings.",
|
|
"skills": [ { "id": "scheduling", "name": "Scheduling", "description": "Books slots", "tags": ["calendar"], "examples": ["book 30 min"] } ] }
|
|
""");
|
|
var card = Cards().Extended(Caller, null);
|
|
Assert.Equal("Eugene's assistant", card.Name);
|
|
Assert.Equal("scheduling", Assert.Single(card.Skills).Id);
|
|
}
|
|
|
|
[Fact]
|
|
public void Card_Extended_FallsBackToPersona()
|
|
{
|
|
File.WriteAllText(Path.Combine(_ws, "PERSONA.md"), "\n# I am Eugene's secretary\nmore");
|
|
var card = Cards().Extended(Caller, null);
|
|
Assert.Equal("Volcanic assistant", card.Name);
|
|
Assert.Equal("I am Eugene's secretary", card.Description);
|
|
Assert.Equal("chat", Assert.Single(card.Skills).Id);
|
|
}
|
|
|
|
public void Dispose() { try { Directory.Delete(_ws, true); } catch (IOException) { } }
|
|
}
|