mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-18 18:10:37 +08:00
test: align imports with PKGBUILD check(), add AUR startup chain tests
This commit is contained in:
@@ -1,58 +1,44 @@
|
||||
"""Lightweight import smoke test — runs in CI and PKGBUILD check().
|
||||
"""Lightweight import smoke test.
|
||||
|
||||
Catches missing symbols, undefined names, and abstract methods that are not
|
||||
implemented — the kind of breakage that ``git merge -X theirs`` or a botched
|
||||
cherry-pick silently introduces.
|
||||
Matches the checks in ``PKGBUILD check()`` plus extra guards for imports
|
||||
that have broken in past merges.
|
||||
"""
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Layer 1 — symbol-level imports (曾炸过的 import 路径)
|
||||
# PKGBUILD check() — mirrors ``python -c "from ... import ..."`` verbatim
|
||||
# ---------------------------------------------------------------------------
|
||||
from astrbot.core.astr_main_agent_resources import (
|
||||
BACKGROUND_TASK_RESULT_WOKE_SYSTEM_PROMPT,
|
||||
BACKGROUND_TASK_WOKE_USER_PROMPT,
|
||||
CONVERSATION_HISTORY_INJECT_PREFIX,
|
||||
BACKGROUND_TASK_RESULT_WOKE_SYSTEM_PROMPT, # noqa: F401
|
||||
BACKGROUND_TASK_WOKE_USER_PROMPT, # noqa: F401
|
||||
CONVERSATION_HISTORY_INJECT_PREFIX, # noqa: F401
|
||||
)
|
||||
from astrbot.core.astr_agent_tool_exec import FunctionToolExecutor
|
||||
from astrbot.core.pipeline.process_stage.stage import ProcessStage # noqa: F401
|
||||
from astrbot.dashboard.server import AstrBotDashboard # noqa: F401
|
||||
import astrbot.core.pipeline.process_stage.stage # noqa: F401
|
||||
|
||||
# Dashboard routes (曾炸过 sentinel class / import 丢失)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Extra guards —曾炸过的 import 路径
|
||||
# ---------------------------------------------------------------------------
|
||||
from astrbot.core.astr_agent_tool_exec import FunctionToolExecutor # noqa: F401
|
||||
from astrbot.dashboard.routes.live_chat import LiveChatRoute # noqa: F401
|
||||
from astrbot.dashboard.routes.chat import ChatRoute # noqa: F401
|
||||
from astrbot.dashboard.server import AstrBotDashboard # noqa: F401
|
||||
|
||||
# Pipeline scheduler
|
||||
from astrbot.core.pipeline.scheduler import PipelineScheduler # noqa: F401
|
||||
|
||||
# Auth password utilities
|
||||
from astrbot.core.utils.auth_password import (
|
||||
hash_dashboard_password,
|
||||
validate_dashboard_password,
|
||||
verify_dashboard_password,
|
||||
is_default_dashboard_password,
|
||||
) # noqa: F401
|
||||
hash_dashboard_password, # noqa: F401
|
||||
validate_dashboard_password, # noqa: F401
|
||||
verify_dashboard_password, # noqa: F401
|
||||
is_default_dashboard_password, # noqa: F401
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Layer 2 — abstract-method completeness
|
||||
# Abstract-method completeness
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_platform_abstract_methods():
|
||||
"""Platform (ABC) should not crash on import and its abstract methods
|
||||
should be introspectable.
|
||||
|
||||
Concrete subclasses that can be instantiated without network/external
|
||||
dependencies should also be verified here.
|
||||
"""
|
||||
"""Platform (ABC) has abstract methods (catches missing implementations)."""
|
||||
from astrbot.core.platform.platform import Platform
|
||||
import inspect
|
||||
|
||||
# Introspect abstract methods — this caught SQLiteDatabase missing 5 methods
|
||||
abstract_methods = set(
|
||||
meth
|
||||
for meth in Platform.__abstractmethods__ # type: ignore[attr-defined]
|
||||
)
|
||||
assert isinstance(abstract_methods, set)
|
||||
assert len(abstract_methods) > 0
|
||||
assert len(Platform.__abstractmethods__) > 0 # type: ignore[attr-defined]
|
||||
|
||||
|
||||
def test_live_chat_route():
|
||||
|
||||
@@ -66,6 +66,23 @@ def test_cli_entry():
|
||||
assert cli is not None, "astrbot.cli.__main__.cli must exist"
|
||||
|
||||
|
||||
def test_run_command_import():
|
||||
"""``astrbot run`` subcommand can be imported (AUR systemd startup path)."""
|
||||
from astrbot.cli.commands.cmd_run import run
|
||||
|
||||
assert run is not None
|
||||
|
||||
|
||||
def test_pkgbuild_aliases():
|
||||
"""PKGBUILD check() references the correct class names."""
|
||||
# The PKGBUILD had ``from astrbot.dashboard.server import DashboardServer``
|
||||
# which is wrong — the actual class is AstrBotDashboard.
|
||||
# This test ensures the rename sticks.
|
||||
from astrbot.dashboard.server import AstrBotDashboard
|
||||
|
||||
assert AstrBotDashboard is not None
|
||||
|
||||
|
||||
def test_sqlite_implements_all_abstract():
|
||||
"""SQLiteDatabase implements every abstract method of BaseDatabase."""
|
||||
from astrbot.core.db import BaseDatabase
|
||||
|
||||
Reference in New Issue
Block a user