mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
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:
@@ -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 = (
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user