|
16 | 16 |
|
17 | 17 | import asyncio |
18 | 18 | from pathlib import Path |
| 19 | +from unittest.mock import Mock |
19 | 20 |
|
20 | 21 | import pytest |
21 | 22 |
|
22 | | -from veadk.skills import VeSkillRegistry |
| 23 | +from veadk.skills import VeSkillRegistry, utils |
23 | 24 | from veadk.skills import registry as registry_module |
24 | 25 | from veadk.skills.skill import Skill as VeADKSkill |
25 | 26 |
|
@@ -70,7 +71,10 @@ def test_registry_search_ignores_query_and_fetches_all_remote_skills( |
70 | 71 | ), |
71 | 72 | ] |
72 | 73 |
|
73 | | - def load_skills_from_cloud(skill_source_id: str) -> list[VeADKSkill]: |
| 74 | + def load_skills_from_cloud( |
| 75 | + skill_source_id: str, *, search_filter=None |
| 76 | + ) -> list[VeADKSkill]: |
| 77 | + assert search_filter is None |
74 | 78 | calls.append(skill_source_id) |
75 | 79 | return remote_skills |
76 | 80 |
|
@@ -296,3 +300,59 @@ def test_registry_get_skill_raises_when_name_is_missing( |
296 | 300 |
|
297 | 301 | with pytest.raises(ValueError, match="Skill 'missing' not found"): |
298 | 302 | asyncio.run(registry.get_skill(name="missing")) |
| 303 | + |
| 304 | + |
| 305 | +@pytest.mark.parametrize("mode", [None, "all", "exact", "semantic", "rrf"]) |
| 306 | +@pytest.mark.parametrize("query", ["", " find skill "]) |
| 307 | +def test_space_search_request(monkeypatch, mode, query): |
| 308 | + monkeypatch.delenv("SKILL_SPACE_POLICY", raising=False) |
| 309 | + monkeypatch.setattr(utils, "_get_cloud_credentials", lambda: ("", "", "")) |
| 310 | + request = Mock( |
| 311 | + return_value={ |
| 312 | + "Items": [ |
| 313 | + {"Name": "beta", "Description": "Beta skill"}, |
| 314 | + {"Name": "alpha", "Description": "Alpha skill"}, |
| 315 | + ] |
| 316 | + } |
| 317 | + ) |
| 318 | + monkeypatch.setattr(utils, "ve_request", request) |
| 319 | + options = {"search_mode": mode} if mode is not None else {} |
| 320 | + registry = VeSkillRegistry(skill_source_id="ss-test", **options) |
| 321 | + |
| 322 | + skills = asyncio.run(registry.search_skills(query=query)) |
| 323 | + assert [skill.name for skill in skills] == ["beta", "alpha"] |
| 324 | + body = {"SkillSpaceId": "ss-test", "InnerTags": {"source": "sandbox"}} |
| 325 | + if mode not in (None, "all"): |
| 326 | + body["Filter"] = {"Query": query, "QueryMode": mode} |
| 327 | + assert request.call_args.kwargs["request_body"] == body |
| 328 | + |
| 329 | + with pytest.raises(ValueError, match="not found"): |
| 330 | + asyncio.run(registry.get_skill(name="missing")) |
| 331 | + assert "Filter" not in request.call_args.kwargs["request_body"] |
| 332 | + |
| 333 | + |
| 334 | +@pytest.mark.parametrize("mode", ["all", "exact", "semantic", "rrf"]) |
| 335 | +def test_skillhub_search_request_ignores_mode(monkeypatch, mode): |
| 336 | + monkeypatch.delenv("SKILL_SPACE_POLICY", raising=False) |
| 337 | + request = Mock(return_value={"Items": [], "TotalCount": 0}) |
| 338 | + monkeypatch.setattr(utils, "_skillhub_request", request) |
| 339 | + registry = VeSkillRegistry(skill_source_id="sp-test", search_mode=mode) |
| 340 | + asyncio.run(registry.search_skills(query="hello")) |
| 341 | + assert request.call_args.args[1]["Filter"] == {"SkillSpaceId": "sp-test"} |
| 342 | + assert "query is ignored" in registry.search_tool_description() |
| 343 | + |
| 344 | + |
| 345 | +def test_registry_rejects_unknown_search_mode(): |
| 346 | + with pytest.raises(ValueError, match="unknown"): |
| 347 | + VeSkillRegistry(skill_source_id="ss-test", search_mode="unknown") |
| 348 | + |
| 349 | + |
| 350 | +def test_filtered_search_returns_empty_on_request_error(monkeypatch): |
| 351 | + monkeypatch.delenv("SKILL_SPACE_POLICY", raising=False) |
| 352 | + monkeypatch.setattr(utils, "_get_cloud_credentials", lambda: ("", "", "")) |
| 353 | + request = Mock(side_effect=RuntimeError("offline")) |
| 354 | + monkeypatch.setattr(utils, "ve_request", request) |
| 355 | + registry = VeSkillRegistry(skill_source_id="ss-test", search_mode="exact") |
| 356 | + |
| 357 | + assert asyncio.run(registry.search_skills(query="hello")) == [] |
| 358 | + request.assert_called_once() |
0 commit comments