Files
AstrBot/tests/unit/test_openapi_scope_docs.py
Wei Chengqian fae2c120ef feat(chatui): paginate chat history (#9667)
* feat(dashboard): add chat history pagination and reasoning blocks (#9652)

* refactor(dashboard): remove reasoning char count and loading text

* feat(dashboard): load earlier messages on scroll up

* refactor(dashboard): remove reasoning retry label

* refactor(dashboard): remove thread panel pagination and lazy reasoning

Restore the thread panel to pre-#9652 behavior: full history without
pagination and inline reasoning content. Reverts the out-of-scope thread
additions while keeping main-session pagination and reasoning lazy-loading.

* chore: retrigger smoke test

* fix(dashboard): pause automatic history loading after failure

* feat(dashboard): show progress while loading earlier messages

* fix(dashboard): show reasoning loading errors and retry action

* style(dashboard): align chat loading errors with chat UI

* style(dashboard): make chat loading errors more compact

* refactor(chat): retain complete message content in history pages

* refactor(dashboard): expand reasoning directly from history pages

* refactor(api): remove lazy chat message retrieval endpoint
2026-09-12 13:56:22 +08:00

82 lines
3.1 KiB
Python

import json
from pathlib import Path
from docs.scripts.update_openapi_json import (
PUBLIC_OPEN_API_SCOPES,
filter_public_openapi,
load_yaml,
render_scope_reference,
)
SPEC_PATH = Path(__file__).resolve().parents[2] / "openspec" / "openapi-v1.yaml"
PUBLIC_SPEC_PATH = (
Path(__file__).resolve().parents[2] / "docs" / "public" / "openapi.json"
)
ZH_REFERENCE_PATH = (
Path(__file__).resolve().parents[2] / "docs" / "zh" / "dev" / "openapi-scopes.md"
)
EN_REFERENCE_PATH = (
Path(__file__).resolve().parents[2] / "docs" / "en" / "dev" / "openapi-scopes.md"
)
def test_public_openapi_is_filtered_by_supported_scope() -> None:
spec = filter_public_openapi(load_yaml(SPEC_PATH))
assert "/api/v1/conversations" in spec["paths"]
assert spec["paths"]["/api/v1/conversations"]["get"]["x-astrbot-scope"] == "data"
assert "/api/v1/commands" not in spec["paths"]
assert "/api/v1/files/tokens/{file_token}" not in spec["paths"]
assert "/api/v1/stats/versions" not in spec["paths"]
for methods in spec["paths"].values():
for operation in methods.values():
assert operation["x-astrbot-scope"] in PUBLIC_OPEN_API_SCOPES
assert "**Required scope:**" in operation["description"]
def test_public_openapi_documents_sensitive_subscopes() -> None:
spec = filter_public_openapi(load_yaml(SPEC_PATH))
chat_send = spec["paths"]["/api/v1/chat"]["post"]
assert chat_send["x-astrbot-sensitive-scopes"] == ["chat:admin"]
assert chat_send["description"] == (
"**Required scope:** `chat`\n\n**Conditional sensitive scope:** `chat:admin`"
)
system_config_update = spec["paths"]["/api/v1/system-config"]["put"]
assert system_config_update["x-astrbot-sensitive-scopes"] == ["config:edit_admin"]
assert "`config:edit_admin`" in system_config_update["description"]
def test_scope_reference_lists_every_supported_scope() -> None:
spec = filter_public_openapi(load_yaml(SPEC_PATH))
zh_reference = render_scope_reference(spec, language="zh")
en_reference = render_scope_reference(spec, language="en")
for scope in PUBLIC_OPEN_API_SCOPES:
assert f"## `{scope}`" in zh_reference
assert f"## `{scope}`" in en_reference
definition = spec["x-astrbot-scope-definitions"][scope]
assert definition["description_zh"] in zh_reference
assert definition["description"] in en_reference
assert "| `GET` | `/api/v1/conversations` | — |" in zh_reference
assert "| `POST` | `/api/v1/chat` | `chat:admin` |" in en_reference
assert "**包含权限:** `bot`、`provider`" in zh_reference
assert "**Sensitive sub-scope `chat:admin`:**" in en_reference
def test_generated_openapi_scope_artifacts_are_current() -> None:
spec = filter_public_openapi(load_yaml(SPEC_PATH))
assert json.loads(PUBLIC_SPEC_PATH.read_text(encoding="utf-8")) == spec
assert ZH_REFERENCE_PATH.read_text(encoding="utf-8") == render_scope_reference(
spec,
language="zh",
)
assert EN_REFERENCE_PATH.read_text(encoding="utf-8") == render_scope_reference(
spec,
language="en",
)