Skip to content

Commit 66a1aca

Browse files
committed
test: add coverage for get_agent_card content handling and local mode
- Test JSON and markdown content handling in _get_agent_card - Test local mode delegates to _local_search - Test local mode ImportError returns error dict
1 parent af21cac commit 66a1aca

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

tests/unittests/tools/ardhf/test_ardhf_toolset.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,82 @@ async def test_connect_agent_rejects_file_url(self):
327327
assert "error" in result
328328

329329

330+
class TestGetAgentCard:
331+
"""Tests for the get_agent_card tool's content handling."""
332+
333+
@pytest.mark.asyncio
334+
async def test_returns_parsed_json_for_json_content(self):
335+
"""JSON content is parsed and returned as a dict."""
336+
toolset = AgentFinderToolset()
337+
json_content = '{"name": "test-tool", "version": "1.0"}'
338+
339+
with patch(
340+
"google.adk_community.tools.ardhf.ardhf_toolset"
341+
"._remote_fetch",
342+
return_value=json_content,
343+
):
344+
mock_context = AsyncMock()
345+
result = await toolset._get_agent_card(
346+
mock_context, url="https://example.com/tool.json"
347+
)
348+
349+
assert result["name"] == "test-tool"
350+
assert result["version"] == "1.0"
351+
352+
@pytest.mark.asyncio
353+
async def test_returns_markdown_for_non_json_content(self):
354+
"""Non-JSON content is returned as raw text under 'content'."""
355+
toolset = AgentFinderToolset()
356+
md_content = "# Skill\n\nThis is a skill."
357+
358+
with patch(
359+
"google.adk_community.tools.ardhf.ardhf_toolset"
360+
"._remote_fetch",
361+
return_value=md_content,
362+
):
363+
mock_context = AsyncMock()
364+
result = await toolset._get_agent_card(
365+
mock_context,
366+
url="https://example.com/SKILL.md",
367+
)
368+
369+
assert result["content"] == md_content
370+
assert result["content_type"] == "text/markdown"
371+
372+
@pytest.mark.asyncio
373+
async def test_local_mode_delegates_to_local_search(self):
374+
"""Local mode calls _local_search instead of _remote_search."""
375+
toolset = AgentFinderToolset(local=True)
376+
377+
with patch(
378+
"google.adk_community.tools.ardhf.ardhf_toolset"
379+
"._local_search",
380+
return_value={"results": []},
381+
) as mock_local:
382+
await toolset._do_search("test query", limit=5)
383+
384+
mock_local.assert_called_once_with(
385+
"test query",
386+
artifact_type=None,
387+
limit=5,
388+
token=None,
389+
)
390+
391+
@pytest.mark.asyncio
392+
async def test_local_mode_import_error_returns_error(self):
393+
"""Local mode returns error when agentfinder is not installed."""
394+
toolset = AgentFinderToolset(local=True)
395+
396+
with patch(
397+
"google.adk_community.tools.ardhf.ardhf_toolset"
398+
"._local_search",
399+
side_effect=ImportError("agentfinder not installed"),
400+
):
401+
result = await toolset._do_search("test query")
402+
403+
assert "error" in result
404+
405+
330406
class TestExtractTextFromA2aResponse:
331407
"""Tests for the _extract_text_from_a2a_response helper."""
332408

0 commit comments

Comments
 (0)