From 100367c989bdefa890f4bfea90aff222648b854c Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Sun, 5 Jul 2026 22:07:36 +0800 Subject: [PATCH] Expose plugin entrypoint helpers --- main.py | 39 ++++++++++++++++++++++++++++++--- tests/test_plugin_entrypoint.py | 32 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tests/test_plugin_entrypoint.py diff --git a/main.py b/main.py index 3812628..f74ad48 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,38 @@ -"""AstrBot ImageStudio plugin entrypoint. +"""AstrBot ImageStudio plugin entrypoint helpers. -Milestone S0 keeps this file lightweight. AstrBot web API registration and -runtime adapters will be connected in later P0 tasks. +The plugin is mounted inside AstrBot. This module exposes pure metadata and +dispatch helpers for the runtime layer without starting a standalone server. """ + +from __future__ import annotations + +from typing import Any + +from adapters.astrbot_adapter import dispatch_extension_request, runtime_route_table +from adapters.webui_adapter import get_web_mount_manifest +from backend.services.ui_service import API_BASE +from core.identity import RequestContext + + +PLUGIN_NAME = "astrbot_plugin_imagestudio" + + +def get_plugin_manifest() -> dict[str, Any]: + web_manifest = get_web_mount_manifest() + return { + "plugin_name": PLUGIN_NAME, + "api_base": API_BASE, + "web": web_manifest, + "routes": runtime_route_table(), + } + + +def dispatch_web_request( + ctx: RequestContext, + method: str, + path: str, + *, + query: dict[str, Any] | None = None, + payload: dict[str, Any] | None = None, +) -> dict[str, Any]: + return dispatch_extension_request(ctx, method, path, query=query, payload=payload) diff --git a/tests/test_plugin_entrypoint.py b/tests/test_plugin_entrypoint.py new file mode 100644 index 0000000..087015c --- /dev/null +++ b/tests/test_plugin_entrypoint.py @@ -0,0 +1,32 @@ +from __future__ import annotations + +import unittest + +from core.identity import RequestContext +from main import PLUGIN_NAME, dispatch_web_request, get_plugin_manifest + + +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")) + self.assertIn("web", manifest) + self.assertTrue(any(route["endpoint"] == "dashboard/summary" for route in manifest["routes"])) + + 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) + + +if __name__ == "__main__": + unittest.main()