원클릭으로
testing
Write and run tests for Copex. Use this when asked to write tests, fix tests, improve coverage, or debug test failures.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Write and run tests for Copex. Use this when asked to write tests, fix tests, improve coverage, or debug test failures.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Review code changes in Copex for bugs, style issues, and best practices. Use this when reviewing PRs or code changes.
Debug issues in Copex, especially streaming, content display, and event handling bugs. Use this when investigating bugs, unexpected behavior, or errors.
Add new features to Copex. Use this when asked to implement new functionality, add CLI commands, or extend the client.
Release and publish Copex to PyPI. Use this when asked to release, publish, bump version, or create a new version.
| name | testing |
| description | Write and run tests for Copex. Use this when asked to write tests, fix tests, improve coverage, or debug test failures. |
# Run all tests
python -m pytest tests/ -v
# Run with coverage
python -m pytest tests/ --cov=copex --cov-report=term-missing
# Run single test file
python -m pytest tests/test_client_streaming.py -v
# Run single test
python -m pytest tests/test_client_streaming.py::test_name -v
Tests are in tests/ directory:
conftest.py - Shared fixturestest_client_streaming.py - Client streaming and event handlingfrom types import SimpleNamespace
from copex.client import Copex, StreamChunk
from copex.config import CopexConfig
from copex.models import EventType
class FakeSession:
def __init__(self, events, messages=None):
self._events = events
self._messages = messages or []
self._handler = None
def on(self, handler):
self._handler = handler
return lambda: None # unsubscribe
async def send(self, _options):
for event in self._events:
if self._handler:
self._handler(event)
async def get_messages(self):
return self._messages
def build_event(event_type: str, **data):
return SimpleNamespace(type=event_type, data=SimpleNamespace(**data))
def test_example():
# Arrange - create events that simulate SDK behavior
events = [
build_event(EventType.ASSISTANT_MESSAGE_DELTA.value, delta_content="Hello"),
build_event(EventType.ASSISTANT_MESSAGE.value, content="Hello"),
build_event(EventType.SESSION_IDLE.value),
]
session = FakeSession(events)
# Setup client with fake session
client = Copex(CopexConfig())
client._started = True
client._client = DummyClient()
client._session = session
# Act
chunks: list[StreamChunk] = []
response = asyncio.run(client.send("prompt", on_chunk=chunks.append))
# Assert
assert response.content == "Hello"
| Event | Purpose |
|---|---|
ASSISTANT_MESSAGE_DELTA | Streaming content |
ASSISTANT_MESSAGE | Final content |
ASSISTANT_REASONING_DELTA | Streaming reasoning |
ASSISTANT_REASONING | Final reasoning |
TOOL_EXECUTION_START | Tool call started |
TOOL_EXECUTION_COMPLETE | Tool finished |
SESSION_IDLE | Turn complete |
SESSION_ERROR | Error occurred |
import pytest
def test_error_raises():
events = [build_event(EventType.SESSION_ERROR.value, message="boom")]
session = FakeSession(events)
client = Copex(CopexConfig())
client._started = True
client._session = session
with pytest.raises(RuntimeError, match="boom"):
asyncio.run(client.send("prompt"))
Important: History fallback behavior differs:
on_chunk (streaming): Does NOT use history fallbackon_chunk: Uses history fallback if no content receiveddef test_streaming_no_history_fallback():
# Streaming should NOT use stale history
events = [build_event(EventType.ASSISTANT_TURN_END.value)]
stale = SimpleNamespace(type=EventType.ASSISTANT_MESSAGE.value,
data=SimpleNamespace(content="Stale"))
session = FakeSession(events, messages=[stale])
chunks = []
response = asyncio.run(client.send("x", on_chunk=chunks.append))
assert response.content != "Stale" # Should NOT use history