spoonos-testing-patterns
БесплатноЗапускает вложенные скриптыНе проверенTest SpoonOS agents effectively. Use when writing unit tests, integration tests, mocking LLM responses, or debugging agent behavior.
от jiayaoqijia★ 81 звезда на GitHubОб этом скилле
Testing Patterns
Comprehensive testing strategies for SpoonOS agents.
Testing Pyramid
/\
/ \ E2E Tests (few)
/----\
/ \ Integration Tests (some)
/--------\
/ \ Unit Tests (many)
/------------\
Unit Testing Tools
Testing a Custom Tool
# tests/test_tools.py
import pytest
from unittest.mock import AsyncMock, patch
from my_agent.tools import PriceTool, WalletTool
@pytest.mark.asyncio
async def test_price_tool_success():
"""Test successful price fetch."""
tool = PriceTool()
# Mock the HTTP response
with patch('aiohttp.ClientSession.get') as mock_get:
mock_response = AsyncMock()
mock_response.status = 200
mock_response.json = AsyncMock(return_value={
"bitcoin": {"usd": 50000, "usd_24h_change": 2.5}
})
mock_get.return_value.__aenter__.return_value = mock_response
result = await tool.execute(coin_id="bitcoin", currency="usd")
assert "50,000" in result
assert "2.50%" in result
@pytest.mark.asyncio
async def test_price_tool_not_found():
"""Test handling of unknown coin."""
tool = PriceTool()
with patch('aiohttp.ClientSession.get') as mock_get:
mock_response = AsyncMock()
mock_response.status = 200
mock_response.json = AsyncMock(return_value={})
mock_get.return_value.__aenter__.return_value = mock_response
result = await tool.execute(coin_id="unknown_coin")
assert "not found" in result.lower()
@pytest.mark.asyncio
async def test_wallet_tool_validation():
"""Test address validation."""
tool = WalletTool()
# Invalid address
result = await tool.execute(address="invalid", chain="ethereum")
assert "Error" in result
# Valid address format
result = await tool.execute(
address="0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7",
chain="ethereum"
)
# Should not have validation error
assert "Invalid" not in result or "validation" not in result.lower()
Testing Tool Parameters
def test_tool_parameters_schema():
"""Verify tool parameter schema."""
tool = PriceTool()
params = tool.parameters
assert params["type"] == "object"
assert "coin_id" in params["properties"]
assert "required" in params
assert "coin_id" in params["required"]
def test_tool_to_param():
"""Test OpenAI-compatible conversion."""
tool = PriceTool()
param = tool.to_param()
assert param["type"] == "function"
assert param["function"]["name"] == "get_price"
assert "description" in param["function"]
Mocking LLM Responses
Mock ChatBot
# tests/conftest.py
import pytest
from unittest.mock import AsyncMock, MagicMock
from spoon_ai.chat import ChatBot
@pytest.fixture
def mock_chatbot():
"""Create a mock ChatBot that returns predefined responses."""
chatbot = MagicMock(spec=ChatBot)
async def mock_chat(messages, tools=None, **kwargs):
# Return a mock response based on input
last_message = messages[-1]["content"]
if "price" in last_message.lower():
return MagicMock(
content="I'll check the price for you.",
tool_calls=[{
"id": "call_123",
"function": {
"name": "get_price",
"arguments": '{"coin_id": "bitcoin"}'
}
}]
)
else:
return MagicMock(
content="I don't understand that request.",
tool_calls=None
)
chatbot.chat = AsyncMock(side_effect=mock_chat)
return chatbot
@pytest.fixture
def mock_tool_response():
"""Fixture for mocking tool execution."""
async def _mock_response(tool_name, expected_result):
tool = MagicMock()
tool.execute = AsyncMock(return_value=expected_result)
return tool
return _mock_response
Using Mock in Tests
# tests/test_agent.py
import pytest
from my_agent import TradingAgent
@pytest.mark.asyncio
async def test_agent_price_query(mock_chatbot):
"""Test agent handles price queries."""
agent = TradingAgent()
agent.llm = mock_chatbot
# Mock tool execution
agent.tools["get_price"].execute = AsyncMock(
return_value="BTC: $50,000 USD"
)
result = await agent.run("What's the Bitcoin price?")
# Verify tool was called
agent.tools["get_price"].execute.assert_called_once()
assert "50,000" in result
@pytest.mark.asyncio
async def test_agent_max_steps():
"""Test agent respects max_steps limit."""
agent = TradingAgent()
agent.max_steps = 2
# Mock LLM to always request tool calls
agent.llm.chat = AsyncMock(return_value=MagicMock(
content="",
tool_calls=[{"id": "1", "function": {"name": "get_price", "arguments": "{}"}}]
))
result = await a
Установить spoonos-testing-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл spoonos-testing-patterns?
Test SpoonOS agents effectively. Use when writing unit tests, integration tests, mocking LLM responses, or debugging agent behavior.
Как установить скилл spoonos-testing-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл spoonos-testing-patterns запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic