astrbot_plugin_imagestudio/tests/test_docs_packaging.py

90 行
3.7 KiB
Python

2026-07-06 04:33:14 +08:00
from __future__ import annotations
import json
import re
2026-07-06 04:33:14 +08:00
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
PLUGIN_NAME = "astrbot_plugin_imagestudio"
DATA_ROOT = f"data/plugin_data/{PLUGIN_NAME}"
CURRENT_API = f"/api/v1/plugins/extensions/{PLUGIN_NAME}/<endpoint>"
LEGACY_API = f"/api/plug/{PLUGIN_NAME}/<endpoint>"
def read(path: str) -> str:
return (ROOT / path).read_text(encoding="utf-8")
2026-07-06 04:33:14 +08:00
class PackagingDocsTests(unittest.TestCase):
def test_install_docs_cover_smoke_pg_and_archive_commands(self):
install = read("INSTALL.md")
readme = read("README.md")
2026-07-06 04:33:14 +08:00
self.assertIn("python scripts/imagestudio_non_ui_smoke.py", install)
self.assertIn("python scripts/imagestudio_pg_smoke.py --dry-run", install)
self.assertIn("git archive --format=zip", install)
self.assertIn("psycopg2", install)
self.assertIn("[INSTALL.md](INSTALL.md)", readme)
def test_docs_describe_official_astrbot_discovery_and_lifecycle(self):
docs = "\n".join(read(path) for path in ("README.md", "INSTALL.md", "DEVELOPMENT.md", "backend/README.md"))
self.assertIn("pages/imagestudio/index.html", docs)
self.assertIn("context.register_web_api", docs)
self.assertIn("initialize()", docs)
self.assertIn("terminate()", docs)
self.assertIn("相对 endpoint", docs)
self.assertIn("4.25.0", docs)
def test_docs_cover_legacy_bridge_and_current_direct_api(self):
docs = "\n".join(read(path) for path in ("README.md", "INSTALL.md", "DEVELOPMENT.md", "backend/README.md"))
self.assertIn(LEGACY_API, docs)
self.assertIn(CURRENT_API, docs)
self.assertIn('apiGet("ui/bootstrap")', docs)
def test_docs_do_not_claim_custom_helpers_are_astrbot_callbacks(self):
docs = "\n".join(read(path) for path in ("README.md", "INSTALL.md", "DEVELOPMENT.md", "backend/README.md"))
self.assertNotIn("get_plugin_manifest", docs)
self.assertNotIn("register_plugin", docs)
def test_runtime_data_paths_use_astrbot_plugin_data_directory(self):
config = read("config.yaml")
schema = json.loads(read("_conf_schema.json"))
docs = "\n".join(read(path) for path in ("README.md", "INSTALL.md", "DEVELOPMENT.md", "backend/README.md"))
self.assertIn(DATA_ROOT, config)
self.assertEqual(schema["sqlite_path"]["default"], "data/db/imagestudio.db")
self.assertIn(DATA_ROOT, docs)
self.assertIn("path: data/db/imagestudio.db", config)
self.assertNotIn(f"path: {DATA_ROOT}/db/imagestudio.db", config)
def test_plugin_page_build_is_packaged(self):
self.assertTrue((ROOT / "pages" / "imagestudio" / "index.html").is_file())
self.assertTrue((ROOT / "metadata.yaml").is_file())
self.assertTrue((ROOT / "main.py").is_file())
metadata = read("metadata.yaml")
self.assertRegex(metadata, re.compile(rf"^name:\s*{PLUGIN_NAME}$", re.MULTILINE))
self.assertRegex(metadata, re.compile(r"^display_name:\s*ImageStudio$", re.MULTILINE))
self.assertRegex(metadata, re.compile(r'^astrbot_version:\s*["\']>=4\.25\.0,<5["\']$', re.MULTILINE))
def test_postgresql_drivers_are_documented_but_not_forced(self):
requirements = read("requirements.txt")
active_requirements = [
line.strip()
for line in requirements.splitlines()
if line.strip() and not line.lstrip().startswith("#")
]
self.assertEqual(active_requirements, [])
self.assertRegex(requirements, re.compile(r"^# psycopg\[binary\]", re.MULTILINE))
self.assertRegex(requirements, re.compile(r"^# psycopg2-binary", re.MULTILINE))
2026-07-06 04:33:14 +08:00
if __name__ == "__main__":
unittest.main()