From 48a34e6355bb0e60881ec36d278d88de8cb5b13d Mon Sep 17 00:00:00 2001 From: RC-CHN <1051989940@qq.com> Date: Tue, 3 Mar 2026 16:24:07 +0800 Subject: [PATCH 1/2] test(skill_manager): update sandbox cache path expectations adjust sandbox cache tests to match absolute path resolution in list_skills for sandbox runtime. verify sandbox-cached skills cannot be deactivated via set_skill_active by asserting a PermissionError, and keep active-only listing behavior intact. add coverage for show_sandbox_path=false to ensure local skills still override cached metadata while sandbox-only skills retain cached paths. --- tests/test_skill_manager_sandbox_cache.py | 57 +++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/tests/test_skill_manager_sandbox_cache.py b/tests/test_skill_manager_sandbox_cache.py index 88923ec10b..eb7b2644b8 100644 --- a/tests/test_skill_manager_sandbox_cache.py +++ b/tests/test_skill_manager_sandbox_cache.py @@ -2,6 +2,8 @@ from pathlib import Path +import pytest + from astrbot.core.skills.skill_manager import SkillManager @@ -56,7 +58,7 @@ def test_list_skills_merges_local_and_sandbox_cache(monkeypatch, tmp_path: Path) assert by_name["custom-local"].description == "local description" assert by_name["custom-local"].path == "skills/custom-local/SKILL.md" assert by_name["python-sandbox"].description == "ship built-in" - assert by_name["python-sandbox"].path == "skills/python-sandbox/SKILL.md" + assert by_name["python-sandbox"].path == "/workspace/skills/python-sandbox/SKILL.md" def test_sandbox_cached_skill_respects_active_and_display_path( @@ -98,7 +100,56 @@ def test_sandbox_cached_skill_respects_active_and_display_path( assert len(all_skills) == 1 assert all_skills[0].path == "/app/skills/browser-automation/SKILL.md" - mgr.set_skill_active("browser-automation", False) + with pytest.raises(PermissionError): + mgr.set_skill_active("browser-automation", False) + active_skills = mgr.list_skills(runtime="sandbox", active_only=True) - assert active_skills == [] + assert len(active_skills) == 1 + assert active_skills[0].name == "browser-automation" + + +def test_sandbox_and_local_path_resolution_with_show_sandbox_path_false( + monkeypatch, + tmp_path: Path, +): + data_dir = tmp_path / "data" + temp_dir = tmp_path / "temp" + skills_root = tmp_path / "skills" + data_dir.mkdir(parents=True, exist_ok=True) + temp_dir.mkdir(parents=True, exist_ok=True) + skills_root.mkdir(parents=True, exist_ok=True) + + monkeypatch.setattr( + "astrbot.core.skills.skill_manager.get_astrbot_data_path", + lambda: str(data_dir), + ) + monkeypatch.setattr( + "astrbot.core.skills.skill_manager.get_astrbot_temp_path", + lambda: str(temp_dir), + ) + + mgr = SkillManager(skills_root=str(skills_root)) + _write_skill(skills_root, "custom-local", "local description") + mgr.set_sandbox_skills_cache( + [ + { + "name": "custom-local", + "description": "cached description should be overridden", + "path": "/app/skills/custom-local/SKILL.md", + }, + { + "name": "python-sandbox", + "description": "ship built-in", + "path": "/app/skills/python-sandbox/SKILL.md", + }, + ] + ) + + skills = mgr.list_skills(runtime="sandbox", show_sandbox_path=False) + by_name = {item.name: item for item in skills} + + assert sorted(by_name) == ["custom-local", "python-sandbox"] + assert by_name["custom-local"].description == "local description" + assert by_name["custom-local"].path.endswith("/skills/custom-local/SKILL.md") + assert by_name["python-sandbox"].path == "/app/skills/python-sandbox/SKILL.md" From c76572525518e971974fe82c3755725013173104 Mon Sep 17 00:00:00 2001 From: RC-CHN <1051989940@qq.com> Date: Tue, 3 Mar 2026 16:41:05 +0800 Subject: [PATCH 2/2] test(skill_manager): tighten local skill path assertions --- tests/test_skill_manager_sandbox_cache.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_skill_manager_sandbox_cache.py b/tests/test_skill_manager_sandbox_cache.py index eb7b2644b8..145420156b 100644 --- a/tests/test_skill_manager_sandbox_cache.py +++ b/tests/test_skill_manager_sandbox_cache.py @@ -150,6 +150,8 @@ def test_sandbox_and_local_path_resolution_with_show_sandbox_path_false( assert sorted(by_name) == ["custom-local", "python-sandbox"] assert by_name["custom-local"].description == "local description" - assert by_name["custom-local"].path.endswith("/skills/custom-local/SKILL.md") + local_skill_path = Path(by_name["custom-local"].path) + assert local_skill_path.is_relative_to(skills_root) + assert local_skill_path == skills_root / "custom-local" / "SKILL.md" assert by_name["python-sandbox"].path == "/app/skills/python-sandbox/SKILL.md"