mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
test: comprehensive test coverage and type fixes
- Add 100+ new test files covering provider sources, platform adapters, agent runners, star/plugin system, knowledge base, core utils, pipeline, computer tools, builtin commands, and dashboard routes - Fix Python type errors in sqlite.py (col() wrappers for SQLModel), astr_agent_tool_exec, core_lifecycle, star context/manager - Fix TypeScript strict mode errors across 30+ dashboard Vue files - Add import smoke tests, auth roundtrip, startup tests - Add compile-all check and CLI entry test for AUR compatibility - Restore BotMessageAccumulator and helpers lost in merge
This commit is contained in:
@@ -20,7 +20,7 @@ def _get_open_api_route(app: Quart):
|
||||
(
|
||||
item
|
||||
for item in app.url_map.iter_rules()
|
||||
if item.rule == "/api/v1/chat" and "POST" in item.methods
|
||||
if item.rule == "/api/v1/chat" and item.methods is not None and "POST" in item.methods
|
||||
),
|
||||
None,
|
||||
)
|
||||
@@ -49,14 +49,29 @@ async def _create_api_key(
|
||||
|
||||
@pytest_asyncio.fixture(scope="module")
|
||||
async def core_lifecycle_td(tmp_path_factory):
|
||||
from astrbot.core import astrbot_config as _astrbot_config
|
||||
from astrbot.core.utils.auth_password import hash_dashboard_password
|
||||
|
||||
tmp_db_path = tmp_path_factory.mktemp("data") / "test_data_api_key.db"
|
||||
db = SQLiteDatabase(str(tmp_db_path))
|
||||
log_broker = LogBroker()
|
||||
|
||||
# Override the dashboard password to a known test value so the login
|
||||
# credential resolution works during test. _resolve_dashboard_password
|
||||
# detects the hash prefix and sends back "astrbot-test-password" as
|
||||
# the plaintext credential.
|
||||
orig_password = _astrbot_config.get("dashboard", {}).get("password")
|
||||
_astrbot_config["dashboard"]["password"] = hash_dashboard_password(
|
||||
"astrbot-test-password"
|
||||
)
|
||||
|
||||
core_lifecycle = AstrBotCoreLifecycle(log_broker, db)
|
||||
await core_lifecycle.initialize()
|
||||
try:
|
||||
yield core_lifecycle
|
||||
finally:
|
||||
if orig_password is not None:
|
||||
_astrbot_config["dashboard"]["password"] = orig_password
|
||||
try:
|
||||
stop_result = core_lifecycle.stop()
|
||||
if asyncio.iscoroutine(stop_result):
|
||||
@@ -74,9 +89,9 @@ def app(core_lifecycle_td: AstrBotCoreLifecycle):
|
||||
|
||||
def _resolve_dashboard_password(core_lifecycle_td: AstrBotCoreLifecycle) -> str:
|
||||
password = core_lifecycle_td.astrbot_config["dashboard"]["password"]
|
||||
if isinstance(password, str) and ((password.startswith("pbkdf2_sha256$") or password.startswith("$argon2")) or password.startswith("$argon2")):
|
||||
if isinstance(password, str) and (password.startswith("pbkdf2_sha256$") or password.startswith("$argon2")):
|
||||
return "astrbot-test-password"
|
||||
return password
|
||||
return str(password)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="module")
|
||||
@@ -495,13 +510,14 @@ async def test_open_chat_send_config_resolution(
|
||||
|
||||
update_route = AsyncMock()
|
||||
delete_route = AsyncMock()
|
||||
config_router = getattr(open_api_route.core_lifecycle, 'umop_config_router')
|
||||
monkeypatch.setattr(
|
||||
open_api_route.core_lifecycle.umop_config_router,
|
||||
config_router,
|
||||
"update_route",
|
||||
update_route,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
open_api_route.core_lifecycle.umop_config_router,
|
||||
config_router,
|
||||
"delete_route",
|
||||
delete_route,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user