Skip to content

Commit 09da2aa

Browse files
committed
simplify: Run example files directly in CI tests
- Remove custom e2e test files - Run examples/quick_start.py directly - Run examples/streaming_mode.py with 120s timeout - Remove || true to properly fail on errors
1 parent a277571 commit 09da2aa

File tree

5 files changed

+111
-180
lines changed

5 files changed

+111
-180
lines changed

.github/workflows/claude-code-integration.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,13 @@ jobs:
3737
- name: Run quickstart example
3838
run: |
3939
export PATH="$HOME/.local/bin:$PATH"
40-
cd examples
41-
python quick_start.py
40+
python examples/quick_start.py
4241
env:
4342
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
4443

45-
- name: Run basic integration tests
44+
- name: Run streaming mode examples
4645
run: |
4746
export PATH="$HOME/.local/bin:$PATH"
48-
python e2e-tests/test_basic_integration.py
49-
env:
50-
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
51-
52-
- name: Run file operation tests
53-
run: |
54-
export PATH="$HOME/.local/bin:$PATH"
55-
python e2e-tests/test_file_operations.py
47+
timeout 120 python examples/streaming_mode.py all
5648
env:
5749
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

e2e-tests/test_basic_integration.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

e2e-tests/test_file_operations.py

Lines changed: 0 additions & 96 deletions
This file was deleted.

e2e-tests/test_quickstart.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python3
2+
"""E2E test based on quickstart examples."""
3+
4+
import anyio
5+
6+
from claude_code_sdk import (
7+
AssistantMessage,
8+
ClaudeCodeOptions,
9+
ResultMessage,
10+
TextBlock,
11+
query,
12+
)
13+
14+
15+
async def test_basic_example():
16+
"""Test basic example - simple question."""
17+
print("Testing basic example...")
18+
19+
found_response = False
20+
async for message in query(prompt="What is 2 + 2?"):
21+
if isinstance(message, AssistantMessage):
22+
for block in message.content:
23+
if isinstance(block, TextBlock):
24+
print(f" Response: {block.text}")
25+
found_response = True
26+
27+
if not found_response:
28+
raise Exception("No response received for basic example")
29+
print("✅ Basic example test passed")
30+
31+
32+
async def test_with_options_example():
33+
"""Test example with custom options."""
34+
print("\nTesting with options example...")
35+
36+
options = ClaudeCodeOptions(
37+
system_prompt="You are a helpful assistant that explains things simply.",
38+
max_turns=1,
39+
)
40+
41+
found_response = False
42+
async for message in query(
43+
prompt="Explain what Python is in one sentence.", options=options
44+
):
45+
if isinstance(message, AssistantMessage):
46+
for block in message.content:
47+
if isinstance(block, TextBlock):
48+
print(f" Response: {block.text}")
49+
found_response = True
50+
51+
if not found_response:
52+
raise Exception("No response received for options example")
53+
print("✅ Options example test passed")
54+
55+
56+
async def test_with_tools_example():
57+
"""Test example using tools."""
58+
print("\nTesting with tools example...")
59+
60+
options = ClaudeCodeOptions(
61+
allowed_tools=["Read", "Write"],
62+
system_prompt="You are a helpful file assistant.",
63+
)
64+
65+
found_response = False
66+
found_cost = False
67+
async for message in query(
68+
prompt="Create a file called hello.txt with 'Hello, World!' in it",
69+
options=options,
70+
):
71+
if isinstance(message, AssistantMessage):
72+
for block in message.content:
73+
if isinstance(block, TextBlock):
74+
print(f" Response: {block.text[:100]}...")
75+
found_response = True
76+
elif isinstance(message, ResultMessage) and message.total_cost_usd > 0:
77+
print(f" Cost: ${message.total_cost_usd:.4f}")
78+
found_cost = True
79+
80+
if not found_response:
81+
raise Exception("No response received for tools example")
82+
if not found_cost:
83+
print(" Note: Cost information not available (might be expected)")
84+
print("✅ Tools example test passed")
85+
86+
87+
async def main():
88+
"""Run all quickstart tests."""
89+
print("=" * 50)
90+
print("Running Quickstart E2E Tests")
91+
print("=" * 50)
92+
93+
try:
94+
await test_basic_example()
95+
await test_with_options_example()
96+
await test_with_tools_example()
97+
98+
print("\n" + "=" * 50)
99+
print("✅ All quickstart tests passed!")
100+
print("=" * 50)
101+
except Exception as e:
102+
print(f"\n❌ Test failed: {e}")
103+
raise
104+
105+
106+
if __name__ == "__main__":
107+
anyio.run(main)

hello.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, World!

0 commit comments

Comments
 (0)