Files
VolcanicAgenticCore/tests/Volcanic.AgenticCore.Extensions.Tests/A2A/AgentsFileTests.cs

60 lines
2.0 KiB
C#

using Volcanic.AgenticCore.Extensions.A2A;
namespace Volcanic.AgenticCore.Extensions.Tests.A2A;
public sealed class AgentsFileTests : IDisposable
{
private readonly string _ws = Path.Combine(Path.GetTempPath(), "a2a-agents", Guid.NewGuid().ToString("N"));
private void Write(string json)
{
Directory.CreateDirectory(Path.GetDirectoryName(AgentsFile.PathFor(_ws))!);
File.WriteAllText(AgentsFile.PathFor(_ws), json);
}
[Fact]
public void Missing_NoAgentsNoError()
{
var r = AgentsFile.Read(_ws);
Assert.Empty(r.Agents);
Assert.Null(r.Error);
}
[Fact]
public void Agents_MalformedFile_ReportsFile()
{
Write("{ nope");
var r = AgentsFile.Read(_ws);
Assert.Empty(r.Agents);
Assert.Contains("agents.json", r.Error);
}
[Fact]
public void Read_ValidatesEntries_AndNeverEchoesKeys()
{
Write("""
[ { "name": "travel-bot", "url": "https://travel.example/", "key": "secret-1", "description": "Trips" },
{ "name": "Bad Name", "url": "https://x.example/", "key": "secret-2" },
{ "name": "no-url" },
{ "name": "ftp", "url": "ftp://x.example/" },
{ "name": "travel-bot", "url": "https://dup.example/" } ]
""");
var r = AgentsFile.Read(_ws);
var agent = Assert.Single(r.Agents);
Assert.Equal(new RemoteAgentEntry("travel-bot", "https://travel.example/", "secret-1", "Trips"), agent);
Assert.Equal(4, r.Problems.Count);
Assert.DoesNotContain(r.Problems, p => p.Contains("secret"));
}
[Fact]
public void Agents_FileEdited_AppliesToNextCall()
{
Write("""[ { "name": "a", "url": "https://a.example/" } ]""");
Assert.NotNull(AgentsFile.Find(_ws, "a"));
Write("[]");
Assert.Null(AgentsFile.Find(_ws, "a"));
}
public void Dispose() { try { Directory.Delete(_ws, true); } catch (IOException) { } }
}