From c5cfc285b11424ac7728c735c1dd1180fc719b86 Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Mon, 6 Jul 2026 09:37:00 +0800 Subject: [PATCH] =?UTF-8?q?S123=20AstrBot=E9=A1=B5=E9=9D=A2=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E4=B8=8E=E8=B7=AF=E7=94=B1=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 3 +++ pages/imagestudio/index.html | 4 ++-- tests/test_plugin_entrypoint.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index a45c178..87d6749 100644 --- a/main.py +++ b/main.py @@ -100,8 +100,11 @@ class Main(AstrBotStar): except TypeError: super().__init__() self.context = context + self.registration_result: dict[str, Any] | None = None async def initialize(self) -> None: + if self.context is not None: + self.registration_result = register_plugin(self.context) return None async def terminate(self) -> None: diff --git a/pages/imagestudio/index.html b/pages/imagestudio/index.html index 343929b..b415461 100644 --- a/pages/imagestudio/index.html +++ b/pages/imagestudio/index.html @@ -1,3 +1,3 @@ - - + +
diff --git a/tests/test_plugin_entrypoint.py b/tests/test_plugin_entrypoint.py index 9152dd4..e831db1 100644 --- a/tests/test_plugin_entrypoint.py +++ b/tests/test_plugin_entrypoint.py @@ -1,6 +1,8 @@ from __future__ import annotations +import asyncio import unittest +from pathlib import Path from backend.route_registry import ROUTES from core.identity import RequestContext @@ -59,6 +61,36 @@ class PluginEntrypointTests(unittest.TestCase): self.assertEqual(manifest["plugin_name"], PLUGIN_NAME) self.assertTrue(manifest["runtime"]["health"]["ok"]) + def test_astrbot_main_initialize_registers_routes_when_supported(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() + plugin = Main(context=runtime) + + asyncio.run(plugin.initialize()) + + self.assertTrue(plugin.registration_result["registered"]) + self.assertEqual(len(runtime.routes), len(ROUTES)) + self.assertEqual(len(runtime.mounts), 1) + + def test_plugin_page_uses_relative_assets(self): + page = Path(__file__).resolve().parents[1] / "pages" / "imagestudio" / "index.html" + html = page.read_text(encoding="utf-8") + + self.assertIn('src="assets/', html) + self.assertIn('href="assets/', html) + self.assertNotIn('src="/assets/', html) + self.assertNotIn('href="/assets/', html) + if __name__ == "__main__": unittest.main()