33# Copyright (C) 2026 Tencent. All rights reserved.
44#
55# tRPC-Agent-Python is licensed under Apache-2.0.
6- """Unit tests for trpc_agent_sdk.skills.tools._skill_list_tool.
7-
8- Covers:
9- - _extract_shell_examples_from_skill_body: Command section parsing
10- - skill_list_tools: returns tools and command examples
11- - skill_list_tools: handles missing skill / repository
12- """
6+ """Unit tests for trpc_agent_sdk.skills.tools._skill_list_tool."""
137
148from __future__ import annotations
159
1913
2014from trpc_agent_sdk .skills ._types import Skill , SkillSummary
2115from trpc_agent_sdk .skills .tools ._skill_list_tool import (
22- _extract_shell_examples_from_skill_body ,
2316 skill_list_tools ,
2417)
2518
2619
27- # ---------------------------------------------------------------------------
28- # _extract_shell_examples_from_skill_body
29- # ---------------------------------------------------------------------------
30-
31- class TestExtractShellExamples :
32- def test_empty_body (self ):
33- assert _extract_shell_examples_from_skill_body ("" ) == []
34-
35- def test_command_section (self ):
36- body = "Command:\n python scripts/run.py --input data.csv\n \n Overview"
37- result = _extract_shell_examples_from_skill_body (body )
38- assert len (result ) >= 1
39- assert "python scripts/run.py" in result [0 ]
40-
41- def test_limit (self ):
42- body = ""
43- for i in range (10 ):
44- body += f"Command:\n cmd_{ i } --arg\n \n "
45- result = _extract_shell_examples_from_skill_body (body , limit = 3 )
46- assert len (result ) <= 3
47-
48- def test_stops_at_section_break (self ):
49- body = "Command:\n python run.py\n \n Output files\n More content"
50- result = _extract_shell_examples_from_skill_body (body )
51- assert len (result ) == 1
52-
53- def test_multiline_command (self ):
54- body = "Command:\n python scripts/long.py \\ \n --arg1 val1 \\ \n --arg2 val2\n \n "
55- result = _extract_shell_examples_from_skill_body (body )
56- assert len (result ) >= 1
57-
58- def test_no_command_section (self ):
59- body = "# Overview\n Just a description.\n "
60- result = _extract_shell_examples_from_skill_body (body )
61- assert result == []
62-
63- def test_deduplication (self ):
64- body = "Command:\n python run.py\n \n Command:\n python run.py\n "
65- result = _extract_shell_examples_from_skill_body (body )
66- assert len (result ) == 1
67-
68- def test_rejects_non_command_starting_chars (self ):
69- body = "Command:\n !not_a_command\n \n "
70- result = _extract_shell_examples_from_skill_body (body )
71- assert result == []
72-
73- def test_command_with_numbered_break (self ):
74- body = "Command:\n python run.py\n \n 1) Next section\n "
75- result = _extract_shell_examples_from_skill_body (body )
76- assert len (result ) == 1
77-
78- def test_skips_empty_lines_before_command (self ):
79- body = "Command:\n \n \n python run.py\n \n End"
80- result = _extract_shell_examples_from_skill_body (body )
81- assert len (result ) >= 1
82-
83- def test_stops_at_tools_section (self ):
84- body = "Command:\n python run.py\n \n tools:\n - tool1"
85- result = _extract_shell_examples_from_skill_body (body )
86- assert len (result ) == 1
87-
88- def test_whitespace_normalization (self ):
89- body = "Command:\n python run.py --arg val\n \n "
90- result = _extract_shell_examples_from_skill_body (body )
91- assert len (result ) == 1
92- assert " " not in result [0 ]
93-
94-
9520# ---------------------------------------------------------------------------
9621# skill_list_tools
9722# ---------------------------------------------------------------------------
@@ -103,7 +28,7 @@ def _make_ctx(repository=None):
10328
10429
10530class TestSkillListTools :
106- def test_returns_tools_and_examples (self ):
31+ def test_returns_tools (self ):
10732 skill = Skill (
10833 summary = SkillSummary (name = "test" ),
10934 body = "Command:\n python run.py\n \n Overview" ,
@@ -114,16 +39,15 @@ def test_returns_tools_and_examples(self):
11439 ctx = _make_ctx (repository = repo )
11540
11641 result = skill_list_tools (ctx , "test" )
117- assert result ["tools" ] == ["get_weather" , "get_data" ]
118- assert len (result ["command_examples" ]) >= 1
42+ assert result ["available_tools" ] == ["get_weather" , "get_data" ]
11943
12044 def test_skill_not_found (self ):
12145 repo = MagicMock ()
12246 repo .get = MagicMock (return_value = None )
12347 ctx = _make_ctx (repository = repo )
12448
12549 result = skill_list_tools (ctx , "nonexistent" )
126- assert result == {"tools" : [], "command_examples " : []}
50+ assert result == {"available_tools " : []}
12751
12852 def test_no_repository_raises (self ):
12953 ctx = _make_ctx (repository = None )
@@ -137,4 +61,4 @@ def test_no_tools_or_examples(self):
13761 ctx = _make_ctx (repository = repo )
13862
13963 result = skill_list_tools (ctx , "test" )
140- assert result ["tools " ] == []
64+ assert result ["available_tools " ] == []
0 commit comments