S119 非UI冒烟脚本
这个提交存在于:
父节点
4c22966ed3
当前提交
94b7fc5b69
共有 2 个文件被更改,包括 88 次插入 和 0 次删除
|
|
@ -0,0 +1,65 @@
|
||||||
|
"""Non-UI backend smoke for ImageStudio."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
if str(REPO_ROOT) not in sys.path:
|
||||||
|
sys.path.insert(0, str(REPO_ROOT))
|
||||||
|
|
||||||
|
from adapters.astrbot_adapter import runtime_health
|
||||||
|
from backend.services.contract_service import ContractService
|
||||||
|
from database.db_helper import Database, DatabaseSettings, SqliteSettings
|
||||||
|
from database.seed import seed_default_material_categories
|
||||||
|
from main import get_plugin_manifest
|
||||||
|
from scripts.imagestudio_pg_smoke import run_pg_smoke
|
||||||
|
|
||||||
|
|
||||||
|
def run_non_ui_smoke(*, include_pg_dry_run: bool = True) -> dict[str, Any]:
|
||||||
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
database = Database(DatabaseSettings(sqlite=SqliteSettings(path=str(Path(tmp) / "imagestudio.db"))))
|
||||||
|
database.initialize()
|
||||||
|
seed = seed_default_material_categories(database)
|
||||||
|
conn = database.connect()
|
||||||
|
try:
|
||||||
|
migrations = conn.execute("SELECT COUNT(*) AS total FROM schema_migrations").fetchone()["total"]
|
||||||
|
categories = conn.execute("SELECT COUNT(*) AS total FROM material_categories").fetchone()["total"]
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
health = runtime_health()
|
||||||
|
contract = ContractService().get_contract()
|
||||||
|
manifest = get_plugin_manifest()
|
||||||
|
result = {
|
||||||
|
"ok": bool(health["ok"] and migrations and categories and contract["routes"]),
|
||||||
|
"checks": {
|
||||||
|
"runtime_health": health,
|
||||||
|
"sqlite_migrations": int(migrations),
|
||||||
|
"seed": seed,
|
||||||
|
"material_categories": int(categories),
|
||||||
|
"contract_routes": len(contract["routes"]),
|
||||||
|
"manifest_routes": len(manifest["routes"]),
|
||||||
|
"contract_url": manifest["contract_url"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if include_pg_dry_run:
|
||||||
|
result["checks"]["pg_dry_run"] = run_pg_smoke(dry_run=True)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv: list[str] | None = None) -> int:
|
||||||
|
parser = argparse.ArgumentParser(description="Run ImageStudio non-UI backend smoke.")
|
||||||
|
parser.add_argument("--no-pg-dry-run", action="store_true")
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
result = run_non_ui_smoke(include_pg_dry_run=not args.no_pg_dry_run)
|
||||||
|
print(json.dumps(result, ensure_ascii=False, sort_keys=True))
|
||||||
|
return 0 if result["ok"] else 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
23
tests/test_non_ui_smoke.py
普通文件
23
tests/test_non_ui_smoke.py
普通文件
|
|
@ -0,0 +1,23 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from scripts.imagestudio_non_ui_smoke import run_non_ui_smoke
|
||||||
|
|
||||||
|
|
||||||
|
class NonUiSmokeTests(unittest.TestCase):
|
||||||
|
def test_non_ui_smoke_runs_core_backend_checks(self):
|
||||||
|
result = run_non_ui_smoke()
|
||||||
|
|
||||||
|
self.assertTrue(result["ok"])
|
||||||
|
checks = result["checks"]
|
||||||
|
self.assertTrue(checks["runtime_health"]["ok"])
|
||||||
|
self.assertGreaterEqual(checks["sqlite_migrations"], 1)
|
||||||
|
self.assertGreaterEqual(checks["material_categories"], 1)
|
||||||
|
self.assertEqual(checks["contract_routes"], checks["manifest_routes"])
|
||||||
|
self.assertTrue(checks["contract_url"].endswith("/contract"))
|
||||||
|
self.assertTrue(checks["pg_dry_run"]["ok"])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
正在加载…
添加表格
在新工单中引用