"""Tests for agent skill registry.""" from __future__ import annotations import os from pathlib import Path os.environ.setdefault("SECRET_KEY", "test-secret-key-for-unit-tests-only") _test_dir = Path(__file__).resolve().parent _backend_root = _test_dir.parent _skills_dir = _backend_root.parent / "skills" if not _skills_dir.is_dir(): _skills_dir = _backend_root / "skills" os.environ["SKILLS_PATH"] = str(_skills_dir) from app.services.skill_registry import ( # noqa: E402 invalidate_skills_cache, load_skills, match_skills, skill_guidance_block, ) def test_load_skills_finds_seeded_skills(): invalidate_skills_cache() skills = load_skills(force=True) assert "vessel-voip" in skills assert "vessel-dns-portal" in skills assert skills["vessel-voip"]["body"] def test_match_voip_skill_by_keywords(): invalidate_skills_cache() matched = match_skills("VoIP issue", "one-way audio on SIP calls") ids = [s.id for s in matched] assert "vessel-voip" in ids def test_match_skill_by_rule_id_boost(): invalidate_skills_cache() matched = match_skills("Mystery", "something vague", matched_rule_id="crew-dns-slow") ids = [s.id for s in matched] assert "vessel-dns-portal" in ids def test_match_respects_max_skills(): invalidate_skills_cache() matched = match_skills( "VoIP DNS portal", "slow dns captive portal sip registration one-way audio", max_skills=1, ) assert len(matched) == 1 def test_skill_guidance_block_includes_body(): invalidate_skills_cache() matched = match_skills("VoIP", "one-way audio rtp") block = skill_guidance_block(matched) assert "Agent skills" in block assert "One-way audio playbook" in block