66 行
2.4 KiB
Python
66 行
2.4 KiB
Python
|
|
"""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())
|