Skip to content

Commit 59b0d38

Browse files
committed
add(test): context management, sub-agent, chat, and provider-specific smoke tests
1 parent 6191e2a commit 59b0d38

8 files changed

Lines changed: 609 additions & 9 deletions

Tests/AgentRunKitTests/Smoke/AnthropicSmokeTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ private let apiKey = ProcessInfo.processInfo.environment["ANTHROPIC_API_KEY"] ??
66
private let hasAPIKey = !apiKey.isEmpty
77
private let model = ProcessInfo.processInfo.environment["SMOKE_ANTHROPIC_MODEL"] ?? "claude-sonnet-4-6"
88

9+
private let cachingSystemPrompt = String(
10+
repeating: "You are a helpful Swift programming assistant. Follow best practices. ",
11+
count: 150
12+
)
13+
914
@Suite(.enabled(if: hasAPIKey, "Requires ANTHROPIC_API_KEY environment variable"))
1015
struct AnthropicSmokeTests {
1116
let client = AnthropicClient(apiKey: apiKey, model: model, maxTokens: 1024)
@@ -46,6 +51,45 @@ struct AnthropicSmokeTests {
4651
try await assertSmokeStreamingTokenUsage(client: client)
4752
}
4853

54+
@Test func chatStreamWithTools() async throws {
55+
try await assertSmokeChatStreamWithTools(client: client)
56+
}
57+
58+
@Test func cachingEnabled() async throws {
59+
let cachingClient = AnthropicClient(
60+
apiKey: apiKey,
61+
model: model,
62+
maxTokens: 1024,
63+
cachingEnabled: true
64+
)
65+
66+
let messages: [ChatMessage] = [
67+
.system(cachingSystemPrompt),
68+
.user("What is Swift?"),
69+
]
70+
71+
let response1 = try await cachingClient.generate(messages: messages, tools: [smokeWeatherTool])
72+
let usage1 = response1.tokenUsage
73+
#expect(usage1 != nil)
74+
#expect((usage1?.cacheWrite ?? 0) > 0)
75+
76+
let response2 = try await cachingClient.generate(messages: messages, tools: [smokeWeatherTool])
77+
let usage2 = response2.tokenUsage
78+
#expect(usage2 != nil)
79+
#expect((usage2?.cacheRead ?? 0) > 0)
80+
}
81+
82+
@Test func nonInterleavedReasoning() async throws {
83+
let nonInterleavedClient = AnthropicClient(
84+
apiKey: apiKey,
85+
model: model,
86+
maxTokens: 16384,
87+
reasoningConfig: .budget(4096),
88+
interleavedThinking: false
89+
)
90+
try await assertSmokeReasoningGenerate(client: nonInterleavedClient)
91+
}
92+
4993
@Test func reasoningStream() async throws {
5094
let thinkingClient = AnthropicClient(
5195
apiKey: apiKey,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@testable import AgentRunKit
2+
import Foundation
3+
import Testing
4+
5+
private let apiKey = ProcessInfo.processInfo.environment["OPENROUTER_API_KEY"] ?? ""
6+
private let hasAPIKey = !apiKey.isEmpty
7+
private let model = ProcessInfo.processInfo.environment["SMOKE_OPENROUTER_MODEL"] ?? "google/gemini-3-flash-preview"
8+
9+
@Suite(.enabled(if: hasAPIKey, "Requires OPENROUTER_API_KEY environment variable"))
10+
struct ContextManagementSmokeTests {
11+
let client = OpenAIClient(
12+
apiKey: apiKey,
13+
model: model,
14+
maxTokens: 1024,
15+
baseURL: OpenAIClient.openRouterBaseURL
16+
)
17+
18+
let budgetClient = OpenAIClient(
19+
apiKey: apiKey,
20+
model: model,
21+
maxTokens: 1024,
22+
contextWindowSize: 500,
23+
baseURL: OpenAIClient.openRouterBaseURL
24+
)
25+
26+
@Test func observationPruning() async throws {
27+
try await assertSmokeObservationPruning(client: budgetClient)
28+
}
29+
30+
@Test func llmSummarization() async throws {
31+
try await assertSmokeLLMSummarization(client: budgetClient)
32+
}
33+
34+
@Test func toolResultTruncation() async throws {
35+
try await assertSmokeToolResultTruncation(client: client)
36+
}
37+
38+
@Test func maxMessages() async throws {
39+
try await assertSmokeMaxMessages(client: client)
40+
}
41+
42+
@Test func budgetEvents() async throws {
43+
try await assertSmokeBudgetEvents(client: budgetClient)
44+
}
45+
46+
@Test func iterationCompleted() async throws {
47+
try await assertSmokeIterationCompleted(client: client)
48+
}
49+
}

Tests/AgentRunKitTests/Smoke/GeminiSmokeTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ struct GeminiSmokeTests {
5050
try await assertSmokeStreamingTokenUsage(client: client)
5151
}
5252

53+
@Test func chatStreamWithTools() async throws {
54+
try await assertSmokeChatStreamWithTools(client: client)
55+
}
56+
57+
@Test func nestedStructuredOutput() async throws {
58+
try await assertSmokeNestedStructuredOutput(client: client)
59+
}
60+
5361
@Test func reasoningStream() async throws {
5462
let thinkingClient = GeminiClient(
5563
apiKey: apiKey,

Tests/AgentRunKitTests/Smoke/OpenAISmokeTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,12 @@ struct OpenAISmokeTests {
5454
@Test func streamingTokenUsage() async throws {
5555
try await assertSmokeStreamingTokenUsage(client: client)
5656
}
57+
58+
@Test func chatStreamWithTools() async throws {
59+
try await assertSmokeChatStreamWithTools(client: client)
60+
}
61+
62+
@Test func nestedStructuredOutput() async throws {
63+
try await assertSmokeNestedStructuredOutput(client: client)
64+
}
5765
}

Tests/AgentRunKitTests/Smoke/OpenRouterSmokeTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,12 @@ struct OpenRouterSmokeTests {
5454
@Test func streamingTokenUsage() async throws {
5555
try await assertSmokeStreamingTokenUsage(client: client)
5656
}
57+
58+
@Test func chatStreamWithTools() async throws {
59+
try await assertSmokeChatStreamWithTools(client: client)
60+
}
61+
62+
@Test func nestedStructuredOutput() async throws {
63+
try await assertSmokeNestedStructuredOutput(client: client)
64+
}
5765
}

Tests/AgentRunKitTests/Smoke/ResponsesAPISmokeTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ struct ResponsesAPISmokeTests {
5858
try await assertSmokeStreamingTokenUsage(client: makeClient())
5959
}
6060

61+
@Test func chatStreamWithTools() async throws {
62+
try await assertSmokeChatStreamWithTools(client: makeClient())
63+
}
64+
65+
@Test func nestedStructuredOutput() async throws {
66+
try await assertSmokeNestedStructuredOutput(client: makeClient())
67+
}
68+
6169
@Test func conversationPersistence() async throws {
6270
let persistentClient = ResponsesAPIClient(
6371
apiKey: apiKey,

0 commit comments

Comments
 (0)