2026-07-05 22:07:36 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
2026-07-06 04:00:59 +08:00
|
|
|
from backend.route_registry import ROUTES
|
2026-07-05 22:07:36 +08:00
|
|
|
from core.identity import RequestContext
|
2026-07-06 09:26:29 +08:00
|
|
|
from main import Main, PLUGIN_NAME, dispatch_web_request, get_plugin_manifest, get_runtime_health, register_plugin
|
2026-07-05 22:07:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PluginEntrypointTests(unittest.TestCase):
|
|
|
|
|
def test_plugin_manifest_exposes_astrbot_mounts(self):
|
|
|
|
|
manifest = get_plugin_manifest()
|
|
|
|
|
|
|
|
|
|
self.assertEqual(manifest["plugin_name"], PLUGIN_NAME)
|
|
|
|
|
self.assertTrue(manifest["api_base"].endswith("astrbot_plugin_imagestudio"))
|
2026-07-06 04:21:50 +08:00
|
|
|
self.assertTrue(manifest["contract_url"].endswith("/contract"))
|
2026-07-05 22:07:36 +08:00
|
|
|
self.assertIn("web", manifest)
|
|
|
|
|
self.assertTrue(any(route["endpoint"] == "dashboard/summary" for route in manifest["routes"]))
|
2026-07-06 04:00:59 +08:00
|
|
|
self.assertTrue(manifest["runtime"]["health"]["ok"])
|
|
|
|
|
self.assertEqual(manifest["health"]["route_count"], len(ROUTES))
|
2026-07-05 22:07:36 +08:00
|
|
|
|
|
|
|
|
def test_dispatch_web_request_delegates_to_adapter(self):
|
|
|
|
|
ctx = RequestContext.from_astrbot(username="admin", user_id="user_001")
|
|
|
|
|
|
|
|
|
|
response = dispatch_web_request(
|
|
|
|
|
ctx,
|
|
|
|
|
"GET",
|
|
|
|
|
"/api/v1/plugins/extensions/astrbot_plugin_imagestudio/ui/bootstrap",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.assertTrue(response["ok"])
|
|
|
|
|
self.assertEqual(response["data"]["plugin_name"], PLUGIN_NAME)
|
|
|
|
|
|
2026-07-06 04:00:59 +08:00
|
|
|
def test_register_plugin_delegates_to_runtime_registration(self):
|
|
|
|
|
class FakeRuntime:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.routes = []
|
|
|
|
|
self.mounts = []
|
|
|
|
|
|
|
|
|
|
def register_extension_route(self, **kwargs):
|
|
|
|
|
self.routes.append(kwargs)
|
|
|
|
|
|
|
|
|
|
def register_web_mount(self, **kwargs):
|
|
|
|
|
self.mounts.append(kwargs)
|
|
|
|
|
|
|
|
|
|
runtime = FakeRuntime()
|
|
|
|
|
result = register_plugin(runtime)
|
|
|
|
|
|
|
|
|
|
self.assertTrue(result["registered"])
|
|
|
|
|
self.assertEqual(len(runtime.routes), len(ROUTES))
|
|
|
|
|
self.assertEqual(len(runtime.mounts), 1)
|
|
|
|
|
self.assertTrue(get_runtime_health()["ok"])
|
|
|
|
|
|
2026-07-06 09:26:29 +08:00
|
|
|
def test_astrbot_main_class_exposes_manifest(self):
|
|
|
|
|
plugin = Main(context=object())
|
|
|
|
|
|
|
|
|
|
manifest = plugin.get_plugin_manifest()
|
|
|
|
|
|
|
|
|
|
self.assertEqual(manifest["plugin_name"], PLUGIN_NAME)
|
|
|
|
|
self.assertTrue(manifest["runtime"]["health"]["ok"])
|
|
|
|
|
|
2026-07-05 22:07:36 +08:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|