test_banner_skills.py
1 """Tests for banner get_available_skills() — disabled and platform filtering.""" 2 3 from unittest.mock import patch 4 5 import pytest 6 7 8 _MOCK_SKILLS = [ 9 {"name": "skill-a", "description": "A skill", "category": "tools"}, 10 {"name": "skill-b", "description": "B skill", "category": "tools"}, 11 {"name": "skill-c", "description": "C skill", "category": "creative"}, 12 ] 13 14 15 def test_get_available_skills_delegates_to_find_all_skills(): 16 """get_available_skills should call _find_all_skills (which handles filtering).""" 17 with patch("tools.skills_tool._find_all_skills", return_value=list(_MOCK_SKILLS)): 18 from hermes_cli.banner import get_available_skills 19 result = get_available_skills() 20 21 assert "tools" in result 22 assert "creative" in result 23 assert sorted(result["tools"]) == ["skill-a", "skill-b"] 24 assert result["creative"] == ["skill-c"] 25 26 27 def test_get_available_skills_excludes_disabled(): 28 """Disabled skills should not appear in the banner count.""" 29 # _find_all_skills already filters disabled skills, so if we give it 30 # a filtered list, get_available_skills should reflect that. 31 filtered = [s for s in _MOCK_SKILLS if s["name"] != "skill-b"] 32 with patch("tools.skills_tool._find_all_skills", return_value=filtered): 33 from hermes_cli.banner import get_available_skills 34 result = get_available_skills() 35 36 all_names = [n for names in result.values() for n in names] 37 assert "skill-b" not in all_names 38 assert "skill-a" in all_names 39 assert len(all_names) == 2 40 41 42 def test_get_available_skills_empty_when_no_skills(): 43 """No skills installed returns empty dict.""" 44 with patch("tools.skills_tool._find_all_skills", return_value=[]): 45 from hermes_cli.banner import get_available_skills 46 result = get_available_skills() 47 48 assert result == {} 49 50 51 def test_get_available_skills_handles_import_failure(): 52 """If _find_all_skills import fails, return empty dict gracefully.""" 53 with patch("tools.skills_tool._find_all_skills", side_effect=ImportError("boom")): 54 from hermes_cli.banner import get_available_skills 55 result = get_available_skills() 56 57 assert result == {} 58 59 60 def test_get_available_skills_null_category_becomes_general(): 61 """Skills with None category should be grouped under 'general'.""" 62 skills = [{"name": "orphan-skill", "description": "No cat", "category": None}] 63 with patch("tools.skills_tool._find_all_skills", return_value=skills): 64 from hermes_cli.banner import get_available_skills 65 result = get_available_skills() 66 67 assert "general" in result 68 assert result["general"] == ["orphan-skill"]