Skip to content

Commit 63aa363

Browse files
authored
test(dashboard): catch up with the plugin Pages to Views rename (#10307) (#10319)
The rename merged without updating the suites that assert the old names, leaving the pytest matrix red on master: - test_plugin_manager: assert StarMetadata.views; the metadata.yaml case now uses the views: key, plus a new test for the pages: alias the rename kept for compatibility - test_dashboard: the injected bridge snippet now reads window.AstrBotPluginView?.__setInitialContext; the served bridge keeps the AstrBotPluginPage alias, so that assertion stays - regenerate docs/public/openapi.json (and the two openapi-scopes tables) with docs/scripts/update_openapi_json.py so the public spec matches the runtime spec again after the six /plugins/view(s) alias routes Fixes #10318
1 parent 9d4f523 commit 63aa363

5 files changed

Lines changed: 221 additions & 16 deletions

File tree

‎docs/en/dev/openapi-scopes.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,14 @@ Manage plugins, plugin configuration, plugin sources, and marketplace data.
256256
| `GET` | `/api/v1/plugins/page-bridge-sdk.js` | — |
257257
| `GET` | `/api/v1/plugins/page/assets` | — |
258258
| `GET` | `/api/v1/plugins/pages` | — |
259-
| `GET` | `/api/v1/plugins/views` | — |
260-
| `GET` | `/api/v1/plugins/view` | — |
261-
| `GET` | `/api/v1/plugins/view/assets` | — |
262259
| `GET` | `/api/v1/plugins/readme` | — |
263260
| `POST` | `/api/v1/plugins/reload` | — |
264261
| `POST` | `/api/v1/plugins/update` | — |
265262
| `POST` | `/api/v1/plugins/validate/repo` | — |
266263
| `POST` | `/api/v1/plugins/version-support/check` | — |
264+
| `GET` | `/api/v1/plugins/view` | — |
265+
| `GET` | `/api/v1/plugins/view/assets` | — |
266+
| `GET` | `/api/v1/plugins/views` | — |
267267
| `GET` | `/api/v1/plugins/{plugin_id}` | — |
268268
| `DELETE` | `/api/v1/plugins/{plugin_id}` | — |
269269
| `GET` | `/api/v1/plugins/{plugin_id}/changelog` | — |
@@ -278,13 +278,13 @@ Manage plugins, plugin configuration, plugin sources, and marketplace data.
278278
| `GET` | `/api/v1/plugins/{plugin_id}/pages` | — |
279279
| `GET` | `/api/v1/plugins/{plugin_id}/pages/{page_name}` | — |
280280
| `GET` | `/api/v1/plugins/{plugin_id}/pages/{page_name}/assets/{asset_path}` | — |
281-
| `GET` | `/api/v1/plugins/{plugin_id}/views` | — |
282-
| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}` | — |
283-
| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}` | — |
284281
| `GET` | `/api/v1/plugins/{plugin_id}/readme` | — |
285282
| `POST` | `/api/v1/plugins/{plugin_id}/reload` | — |
286283
| `POST` | `/api/v1/plugins/{plugin_id}/source` | — |
287284
| `POST` | `/api/v1/plugins/{plugin_id}/update` | — |
285+
| `GET` | `/api/v1/plugins/{plugin_id}/views` | — |
286+
| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}` | — |
287+
| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}` | — |
288288

289289
## `mcp`
290290

‎docs/public/openapi.json‎

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4398,6 +4398,196 @@
43984398
"description": "**Required scope:** `plugin`"
43994399
}
44004400
},
4401+
"/api/v1/plugins/views": {
4402+
"get": {
4403+
"tags": [
4404+
"Plugin Pages"
4405+
],
4406+
"summary": "List plugin views by query ID (alias of /plugins/pages)",
4407+
"operationId": "listPluginViewsById",
4408+
"x-astrbot-scope": "plugin",
4409+
"parameters": [
4410+
{
4411+
"name": "plugin_id",
4412+
"in": "query",
4413+
"required": true,
4414+
"schema": {
4415+
"type": "string"
4416+
}
4417+
}
4418+
],
4419+
"responses": {
4420+
"200": {
4421+
"$ref": "#/components/responses/Ok"
4422+
}
4423+
},
4424+
"description": "**Required scope:** `plugin`"
4425+
}
4426+
},
4427+
"/api/v1/plugins/view": {
4428+
"get": {
4429+
"tags": [
4430+
"Plugin Pages"
4431+
],
4432+
"summary": "Get plugin view entry HTML by query ID (alias of /plugins/page)",
4433+
"operationId": "getPluginViewById",
4434+
"x-astrbot-scope": "plugin",
4435+
"parameters": [
4436+
{
4437+
"name": "plugin_id",
4438+
"in": "query",
4439+
"required": true,
4440+
"schema": {
4441+
"type": "string"
4442+
}
4443+
},
4444+
{
4445+
"name": "page_name",
4446+
"in": "query",
4447+
"required": true,
4448+
"schema": {
4449+
"type": "string"
4450+
}
4451+
}
4452+
],
4453+
"responses": {
4454+
"200": {
4455+
"$ref": "#/components/responses/Html"
4456+
}
4457+
},
4458+
"description": "**Required scope:** `plugin`"
4459+
}
4460+
},
4461+
"/api/v1/plugins/view/assets": {
4462+
"get": {
4463+
"tags": [
4464+
"Plugin Pages"
4465+
],
4466+
"summary": "Get a plugin view asset by query ID (alias of /plugins/page/assets)",
4467+
"operationId": "getPluginViewAssetById",
4468+
"x-astrbot-scope": "plugin",
4469+
"parameters": [
4470+
{
4471+
"name": "plugin_id",
4472+
"in": "query",
4473+
"required": true,
4474+
"schema": {
4475+
"type": "string"
4476+
}
4477+
},
4478+
{
4479+
"name": "page_name",
4480+
"in": "query",
4481+
"required": true,
4482+
"schema": {
4483+
"type": "string"
4484+
}
4485+
},
4486+
{
4487+
"name": "asset_path",
4488+
"in": "query",
4489+
"required": true,
4490+
"schema": {
4491+
"type": "string"
4492+
}
4493+
}
4494+
],
4495+
"responses": {
4496+
"200": {
4497+
"description": "Plugin asset content"
4498+
}
4499+
},
4500+
"description": "**Required scope:** `plugin`"
4501+
}
4502+
},
4503+
"/api/v1/plugins/{plugin_id}/views": {
4504+
"get": {
4505+
"tags": [
4506+
"Plugin Pages"
4507+
],
4508+
"summary": "List plugin views (alias of /plugins/{plugin_id}/pages)",
4509+
"operationId": "listPluginViews",
4510+
"x-astrbot-scope": "plugin",
4511+
"parameters": [
4512+
{
4513+
"$ref": "#/components/parameters/PluginId"
4514+
}
4515+
],
4516+
"responses": {
4517+
"200": {
4518+
"$ref": "#/components/responses/Ok"
4519+
}
4520+
},
4521+
"description": "**Required scope:** `plugin`"
4522+
}
4523+
},
4524+
"/api/v1/plugins/{plugin_id}/views/{page_name}": {
4525+
"get": {
4526+
"tags": [
4527+
"Plugin Pages"
4528+
],
4529+
"summary": "Get plugin view entry HTML (alias of /plugins/{plugin_id}/pages/{page_name})",
4530+
"operationId": "getPluginView",
4531+
"x-astrbot-scope": "plugin",
4532+
"parameters": [
4533+
{
4534+
"$ref": "#/components/parameters/PluginId"
4535+
},
4536+
{
4537+
"name": "page_name",
4538+
"in": "path",
4539+
"required": true,
4540+
"schema": {
4541+
"type": "string"
4542+
}
4543+
}
4544+
],
4545+
"responses": {
4546+
"200": {
4547+
"$ref": "#/components/responses/Html"
4548+
}
4549+
},
4550+
"description": "**Required scope:** `plugin`"
4551+
}
4552+
},
4553+
"/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}": {
4554+
"get": {
4555+
"tags": [
4556+
"Plugin Pages"
4557+
],
4558+
"summary": "Get a plugin view asset (alias of /plugins/{plugin_id}/pages/{page_name}/assets/{asset_path})",
4559+
"operationId": "getPluginViewAsset",
4560+
"x-astrbot-scope": "plugin",
4561+
"parameters": [
4562+
{
4563+
"$ref": "#/components/parameters/PluginId"
4564+
},
4565+
{
4566+
"name": "page_name",
4567+
"in": "path",
4568+
"required": true,
4569+
"schema": {
4570+
"type": "string"
4571+
}
4572+
},
4573+
{
4574+
"name": "asset_path",
4575+
"in": "path",
4576+
"required": true,
4577+
"description": "URL-encoded relative asset path.",
4578+
"schema": {
4579+
"type": "string"
4580+
}
4581+
}
4582+
],
4583+
"responses": {
4584+
"200": {
4585+
"description": "Plugin asset content"
4586+
}
4587+
},
4588+
"description": "**Required scope:** `plugin`"
4589+
}
4590+
},
44014591
"/api/v1/plugins/page-bridge-sdk.js": {
44024592
"get": {
44034593
"tags": [

‎docs/zh/dev/openapi-scopes.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,14 @@ outline: deep
256256
| `GET` | `/api/v1/plugins/page-bridge-sdk.js` | — |
257257
| `GET` | `/api/v1/plugins/page/assets` | — |
258258
| `GET` | `/api/v1/plugins/pages` | — |
259-
| `GET` | `/api/v1/plugins/views` | — |
260-
| `GET` | `/api/v1/plugins/view` | — |
261-
| `GET` | `/api/v1/plugins/view/assets` | — |
262259
| `GET` | `/api/v1/plugins/readme` | — |
263260
| `POST` | `/api/v1/plugins/reload` | — |
264261
| `POST` | `/api/v1/plugins/update` | — |
265262
| `POST` | `/api/v1/plugins/validate/repo` | — |
266263
| `POST` | `/api/v1/plugins/version-support/check` | — |
264+
| `GET` | `/api/v1/plugins/view` | — |
265+
| `GET` | `/api/v1/plugins/view/assets` | — |
266+
| `GET` | `/api/v1/plugins/views` | — |
267267
| `GET` | `/api/v1/plugins/{plugin_id}` | — |
268268
| `DELETE` | `/api/v1/plugins/{plugin_id}` | — |
269269
| `GET` | `/api/v1/plugins/{plugin_id}/changelog` | — |
@@ -278,13 +278,13 @@ outline: deep
278278
| `GET` | `/api/v1/plugins/{plugin_id}/pages` | — |
279279
| `GET` | `/api/v1/plugins/{plugin_id}/pages/{page_name}` | — |
280280
| `GET` | `/api/v1/plugins/{plugin_id}/pages/{page_name}/assets/{asset_path}` | — |
281-
| `GET` | `/api/v1/plugins/{plugin_id}/views` | — |
282-
| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}` | — |
283-
| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}` | — |
284281
| `GET` | `/api/v1/plugins/{plugin_id}/readme` | — |
285282
| `POST` | `/api/v1/plugins/{plugin_id}/reload` | — |
286283
| `POST` | `/api/v1/plugins/{plugin_id}/source` | — |
287284
| `POST` | `/api/v1/plugins/{plugin_id}/update` | — |
285+
| `GET` | `/api/v1/plugins/{plugin_id}/views` | — |
286+
| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}` | — |
287+
| `GET` | `/api/v1/plugins/{plugin_id}/views/{page_name}/assets/{asset_path}` | — |
288288

289289
## `mcp`
290290

‎tests/test_dashboard.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ async def test_plugin_page_content_issues_scoped_asset_token(
20582058
bridge_response = await anonymous_client.get(bridge_sdk_url.group(1))
20592059
assert bridge_response.status_code == 200
20602060
bridge_js = (await bridge_response.get_data()).decode("utf-8")
2061-
assert "window.AstrBotPluginPage?.__setInitialContext" in bridge_js
2061+
assert "window.AstrBotPluginView?.__setInitialContext" in bridge_js
20622062
assert '"locale": "zh-CN"' in bridge_js
20632063
assert '"displayName": "插件页面演示"' in bridge_js
20642064
assert '"pageTitle": "Bridge 演示页"' in bridge_js

‎tests/test_plugin_manager.py‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,26 @@ def test_load_plugin_metadata_includes_i18n(tmp_path: Path):
141141

142142
assert metadata is not None
143143
assert metadata.short_desc == "Local test short description"
144-
assert metadata.pages == []
144+
assert metadata.views == []
145145
assert metadata.i18n == {"zh-CN": {"metadata": {"display_name": "你好世界"}}}
146146

147147

148-
def test_load_plugin_metadata_includes_pages(tmp_path: Path):
148+
def test_load_plugin_metadata_includes_views(tmp_path: Path):
149+
plugin_path = tmp_path / "helloworld"
150+
_write_local_test_plugin(plugin_path, TEST_PLUGIN_REPO)
151+
metadata_path = plugin_path / "metadata.yaml"
152+
metadata = yaml.safe_load(metadata_path.read_text(encoding="utf-8"))
153+
metadata["views"] = [{"name": "dashboard", "title": "Dashboard"}]
154+
metadata_path.write_text(yaml.dump(metadata), encoding="utf-8")
155+
156+
loaded_metadata = PluginManager._load_plugin_metadata(str(plugin_path))
157+
158+
assert loaded_metadata is not None
159+
assert loaded_metadata.views == [{"name": "dashboard", "title": "Dashboard"}]
160+
161+
162+
def test_load_plugin_metadata_pages_alias_maps_to_views(tmp_path: Path):
163+
# "pages" stays a compatible alias for "views" in metadata.yaml.
149164
plugin_path = tmp_path / "helloworld"
150165
_write_local_test_plugin(plugin_path, TEST_PLUGIN_REPO)
151166
metadata_path = plugin_path / "metadata.yaml"
@@ -156,7 +171,7 @@ def test_load_plugin_metadata_includes_pages(tmp_path: Path):
156171
loaded_metadata = PluginManager._load_plugin_metadata(str(plugin_path))
157172

158173
assert loaded_metadata is not None
159-
assert loaded_metadata.pages == [{"name": "dashboard", "title": "Dashboard"}]
174+
assert loaded_metadata.views == [{"name": "dashboard", "title": "Dashboard"}]
160175

161176

162177
def test_load_plugin_metadata_accepts_yml_suffix(tmp_path: Path):

0 commit comments

Comments
 (0)