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
This commit is contained in:
LIghtJUNction
2026-03-23 06:08:48 +08:00
parent a05f9eba7d
commit 80a0f33538
2 changed files with 14 additions and 20 deletions

View File

@@ -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 = (

View File

@@ -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