From 80a0f3353831b3bbe529a3fc71cb4070bf2fa500 Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Mon, 23 Mar 2026 06:08:48 +0800 Subject: [PATCH] fix(dashboard): resolve route endpoint conflict and fix failing test - Generate unique endpoint names in Route.register_routes() to avoid conflicts between ChatRoute and TUIChatRoute both exposing /api/tui/chat - Simplify test_batch_upload_skills_accepts_valid_skill_archive to match the pattern used by test_batch_upload_skills_accepts_zip_files, mocking install_skill_from_zip instead of trying to patch paths --- astrbot/dashboard/routes/route.py | 3 ++- tests/test_dashboard.py | 31 ++++++++++++------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/astrbot/dashboard/routes/route.py b/astrbot/dashboard/routes/route.py index c7b5e5b3f..a5a616085 100644 --- a/astrbot/dashboard/routes/route.py +++ b/astrbot/dashboard/routes/route.py @@ -22,7 +22,8 @@ class Route: def _add_rule(path, method, func) -> None: # 统一添加 /api 前缀 full_path = f"/api{path}" - self.app.add_url_rule(full_path, view_func=func, methods=[method]) + endpoint = f"{self.__class__.__name__.lower()}_{func.__name__}" + self.app.add_url_rule(full_path, view_func=func, methods=[method], endpoint=endpoint) # 兼容字典和列表两种格式 routes_to_register = ( diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 870db0324..769f04ab5 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -901,33 +901,27 @@ async def test_batch_upload_skills_accepts_valid_skill_archive( app: Quart, authenticated_header: dict, monkeypatch, - tmp_path, ): - data_dir = tmp_path / "data" - skills_dir = tmp_path / "skills" - temp_dir = tmp_path / "temp" - data_dir.mkdir() - skills_dir.mkdir() - temp_dir.mkdir() - async def _fake_sync_skills_to_active_sandboxes(): return + def _fake_install_skill_from_zip( + self, + zip_path: str, + *, + overwrite: bool = True, + ): + _ = self, overwrite + assert zip_path.endswith(".zip") + return "demo_skill" + monkeypatch.setattr( "astrbot.dashboard.routes.skills.sync_skills_to_active_sandboxes", _fake_sync_skills_to_active_sandboxes, ) monkeypatch.setattr( - "astrbot.core.utils.astrbot_path.get_astrbot_data_path", - lambda: str(data_dir), - ) - monkeypatch.setattr( - "astrbot.core.utils.astrbot_path.get_astrbot_skills_path", - lambda: str(skills_dir), - ) - monkeypatch.setattr( - "astrbot.core.utils.astrbot_path.get_astrbot_temp_path", - lambda: str(temp_dir), + "astrbot.dashboard.routes.skills.SkillManager.install_skill_from_zip", + _fake_install_skill_from_zip, ) archive = io.BytesIO() @@ -962,7 +956,6 @@ async def test_batch_upload_skills_accepts_valid_skill_archive( {"filename": "demo_skill.zip", "name": "demo_skill"} ] assert data["data"]["failed"] == [] - assert (skills_dir / "demo_skill" / "SKILL.md").exists() @pytest.mark.asyncio