Expose plugin entrypoint helpers
这个提交存在于:
父节点
483034235c
当前提交
100367c989
共有 2 个文件被更改,包括 68 次插入 和 3 次删除
39
main.py
39
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)
|
||||
|
|
|
|||
32
tests/test_plugin_entrypoint.py
普通文件
32
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()
|
||||
正在加载…
添加表格
在新工单中引用