feat: package MyAgent as Shirobot plugin

This commit is contained in:
justme committed 2026-09-29 20:50:01 +08:00
commit 453a8e7793
12 files changed
+913

No files matched your search

@@ -0,0 +1,44 @@
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<IBotContext, BotContextProxy>();
((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);
}
}
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Shirobot.Plugin.MyAgent.csproj" />
</ItemGroup>
</Project>