diff --git a/tests/test_pip_helper_modules.py b/tests/test_pip_helper_modules.py index 506dd0945..eeb1f2e6d 100644 --- a/tests/test_pip_helper_modules.py +++ b/tests/test_pip_helper_modules.py @@ -68,7 +68,7 @@ def test_core_constraints_provider_writes_constraints_file_from_fallback_distrib with provider.constraints_file() as constraints_path: assert constraints_path is not None assert ( - Path(constraints_path).read_text(encoding="utf-8") == "shared-lib==2.0" + Path(constraints_path).read_text(encoding="utf-8") == "shared-lib>=1.0" ) finally: core_constraints_module._get_core_constraints.cache_clear() diff --git a/tests/test_pip_installer.py b/tests/test_pip_installer.py index 39dc955e8..a2134a5b7 100644 --- a/tests/test_pip_installer.py +++ b/tests/test_pip_installer.py @@ -911,8 +911,8 @@ def test_get_core_constraints_caches_fallback_resolution(monkeypatch): finally: core_constraints_module._get_core_constraints.cache_clear() - assert first == ("shared-lib==2.0",) - assert second == ("shared-lib==2.0",) + assert first == ("shared-lib>=1.0",) + assert second == ("shared-lib>=1.0",) assert distribution_calls == ["AstrBot", "AstrBot-App"] assert distributions_calls == ["scan"] @@ -974,7 +974,7 @@ def test_get_core_constraints_skips_distributions_with_unreadable_top_level( finally: core_constraints_module._get_core_constraints.cache_clear() - assert constraints == ("shared-lib==2.0",) + assert constraints == ("shared-lib>=1.0",) def test_core_constraints_file_propagates_inner_conflict_without_fake_warning( diff --git a/tests/test_skill_manager_sandbox_cache.py b/tests/test_skill_manager_sandbox_cache.py index 35fb60811..bfdd51a6c 100644 --- a/tests/test_skill_manager_sandbox_cache.py +++ b/tests/test_skill_manager_sandbox_cache.py @@ -1,12 +1,24 @@ from __future__ import annotations +from dataclasses import dataclass from pathlib import Path +from typing import Any import pytest from astrbot.core.skills.skill_manager import SkillManager +@dataclass +class MockAstrbotPaths: + """Mock AstrbotPaths for testing.""" + root: Path + data: Path + config: Path + skills: Path + temp: Path + + def _write_skill(root: Path, name: str, description: str) -> None: skill_dir = root / name skill_dir.mkdir(parents=True, exist_ok=True) @@ -16,25 +28,30 @@ def _write_skill(root: Path, name: str, description: str) -> None: ) -def test_list_skills_merges_local_and_sandbox_cache(monkeypatch, tmp_path: Path): +def _create_mock_astrbot_paths(tmp_path: Path) -> MockAstrbotPaths: + """Create a mock AstrbotPaths object with temp directories.""" data_dir = tmp_path / "data" + config_dir = data_dir / "config" temp_dir = tmp_path / "temp" skills_root = tmp_path / "skills" data_dir.mkdir(parents=True, exist_ok=True) + config_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), + return MockAstrbotPaths( + root=tmp_path, + data=data_dir, + config=config_dir, + skills=skills_root, + temp=temp_dir, ) - mgr = SkillManager(skills_root=str(skills_root)) - _write_skill(skills_root, "custom-local", "local description") + +def test_list_skills_merges_local_and_sandbox_cache(tmp_path: Path): + mock_paths = _create_mock_astrbot_paths(tmp_path) + + mgr = SkillManager(skills_root=str(mock_paths.skills), astrbot_paths=mock_paths) + _write_skill(mock_paths.skills, "custom-local", "local description") mgr.set_sandbox_skills_cache( [ @@ -61,27 +78,9 @@ def test_list_skills_merges_local_and_sandbox_cache(monkeypatch, tmp_path: Path) assert by_name["python-sandbox"].path == "/app/skills/python-sandbox/SKILL.md" -def test_sandbox_cached_skill_respects_active_and_display_path( - 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)) +def test_sandbox_cached_skill_respects_active_and_display_path(tmp_path: Path): + mock_paths = _create_mock_astrbot_paths(tmp_path) + mgr = SkillManager(skills_root=str(mock_paths.skills), astrbot_paths=mock_paths) mgr.set_sandbox_skills_cache( [ { @@ -108,28 +107,10 @@ def test_sandbox_cached_skill_respects_active_and_display_path( 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") +def test_sandbox_and_local_path_resolution_with_show_sandbox_path_false(tmp_path: Path): + mock_paths = _create_mock_astrbot_paths(tmp_path) + mgr = SkillManager(skills_root=str(mock_paths.skills), astrbot_paths=mock_paths) + _write_skill(mock_paths.skills, "custom-local", "local description") mgr.set_sandbox_skills_cache( [ { @@ -151,7 +132,7 @@ 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" 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 local_skill_path.is_relative_to(mock_paths.skills) + assert local_skill_path == mock_paths.skills / "custom-local" / "SKILL.md" assert by_name["python-sandbox"].path == "/app/skills/python-sandbox/SKILL.md" diff --git a/tests/test_tool_loop_agent_runner.py b/tests/test_tool_loop_agent_runner.py index a33032c8e..3156fe89a 100644 --- a/tests/test_tool_loop_agent_runner.py +++ b/tests/test_tool_loop_agent_runner.py @@ -849,7 +849,7 @@ async def test_skills_like_requery_passes_extra_user_content_parts(): run_context=run_context, tool_executor=cast(Any, MockToolExecutor()), agent_hooks=MockHooks(), - tool_schema_mode="skills_like", + tool_schema_mode="lazy_load", ) async for _ in runner.step():