using System.Reflection; using ShiroBot.SDK.Plugin; using Shirobot.Plugin.MyAgent; using Xunit; namespace Shirobot.Plugin.MyAgent.Tests; public sealed class ManagementServerTests { [Fact] public async Task StartsManagementApiWithoutIndependentMessageEndpoint() { var root = Path.Combine(Path.GetTempPath(), "myagent-test-" + Guid.NewGuid().ToString("n")); Directory.CreateDirectory(root); var context = DispatchProxy.Create(); ((BotContextProxy)(object)context).PluginDirectory = root; try { await using var app = AgentManagementServer.Build(context, "http://127.0.0.1:0"); await app.StartAsync(); var address = app.Urls.Single(); using var client = new HttpClient { BaseAddress = new Uri(address) }; using var health = await client.GetAsync("/api/health"); Assert.True(health.IsSuccessStatusCode); using var oldIngress = await client.PostAsync("/api/group-chat/send", new StringContent("{}")); Assert.False(oldIngress.IsSuccessStatusCode); await app.StopAsync(); } finally { var full = Path.GetFullPath(root); if (full.StartsWith(Path.GetFullPath(Path.GetTempPath()), StringComparison.OrdinalIgnoreCase)) Directory.Delete(full, recursive: true); } } public class BotContextProxy : DispatchProxy { public string PluginDirectory { get; set; } = ""; protected override object? Invoke(MethodInfo? targetMethod, object?[]? args) => targetMethod?.Name == "get_PluginDirectory" ? PluginDirectory : throw new NotSupportedException(targetMethod?.Name); } }