using FluentAssertions; using IBKRTrader.Modules.Supervisor.Agent; namespace IBKRTrader.Tests.Modules.Supervisor; [Trait("cat", "unit")] public class SupervisorToolRegistryTests { private static SupervisorToolRegistry WithEcho() { var reg = new SupervisorToolRegistry(); reg.Register(new SupervisorTool("echo", "Echo", """{"type":"object","properties":{"x":{"type":"string"}}}""", args => SupervisorToolRegistry.GetString(args, "x") ?? "(leer)")); return reg; } [Fact] public void UnknownTool_ReturnsErrorText_DoesNotThrow() { var reg = WithEcho(); reg.Execute("nope", "{}").Should().StartWith("FEHLER: Unbekanntes Tool"); } [Fact] public void InvalidJsonArgs_ReturnsErrorText() { var reg = WithEcho(); reg.Execute("echo", "{ kaputt").Should().StartWith("FEHLER: Ungültige Tool-Argumente"); } [Fact] public void ExecutesRegisteredTool() { var reg = WithEcho(); reg.Execute("echo", """{"x":"hallo"}""").Should().Be("hallo"); } [Fact] public void ToolException_IsCaught_AsErrorText() { var reg = new SupervisorToolRegistry(); reg.Register(new SupervisorTool("boom", "Boom", """{"type":"object"}""", _ => throw new InvalidOperationException("geplatzt"))); reg.Execute("boom", "{}").Should().Contain("geplatzt"); } }