Skip to content

Commit a7335af

Browse files
committed
Fix unit tests
1 parent 6c03a20 commit a7335af

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

Tool/Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ let package = Package(
215215
name: "BuiltinExtension",
216216
dependencies: [
217217
"SuggestionModel",
218+
"SuggestionProvider",
218219
"ChatBasic",
219220
"Workspace",
220221
"ChatTab",
@@ -369,6 +370,7 @@ let package = Package(
369370
"TokenEncoder",
370371
"Keychain",
371372
"BuiltinExtension",
373+
"ChatBasic",
372374
.product(name: "JSONRPC", package: "JSONRPC"),
373375
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
374376
.product(name: "GoogleGenerativeAI", package: "generative-ai-swift"),
@@ -382,6 +384,7 @@ let package = Package(
382384
name: "OpenAIServiceTests",
383385
dependencies: [
384386
"OpenAIService",
387+
"ChatBasic",
385388
.product(
386389
name: "ComposableArchitecture",
387390
package: "swift-composable-architecture"

Tool/Tests/GitHubCopilotServiceTests/FetchSuggestionsTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ final class FetchSuggestionTests: XCTestCase {
1515
func test_process_suggestions_from_server() async throws {
1616
struct TestServer: GitHubCopilotLSP {
1717
func sendNotification(_: LanguageServerProtocol.ClientNotification) async throws {
18-
throw CancellationError()
18+
return
1919
}
2020

21-
func sendRequest<E>(_: E) async throws -> E.Response where E: GitHubCopilotRequestType {
21+
func sendRequest<E>(_: E, timeout: TimeInterval?) async throws -> E.Response
22+
where E: GitHubCopilotRequestType
23+
{
2224
return GitHubCopilotRequest.InlineCompletion.Response(items: [
2325
.init(
2426
insertText: "Hello World\n",
@@ -70,7 +72,9 @@ final class FetchSuggestionTests: XCTestCase {
7072
// unimplemented
7173
}
7274

73-
func sendRequest<E>(_: E) async throws -> E.Response where E: GitHubCopilotRequestType {
75+
func sendRequest<E>(_: E, timeout: TimeInterval?) async throws -> E.Response
76+
where E: GitHubCopilotRequestType
77+
{
7478
return GitHubCopilotRequest.InlineCompletion.Response(items: [
7579
.init(
7680
insertText: "Hello World\n",

Tool/Tests/OpenAIServiceTests/AutoManagedChatGPTMemoryRetrievedContentTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ChatBasic
12
import Foundation
23
import XCTest
34

@@ -20,7 +21,7 @@ class AutoManagedChatGPTMemoryRetrievedContentTests: XCTestCase {
2021

2122
func test_retrieved_content_when_the_context_window_is_large_enough() async {
2223
let strategy = Strategy()
23-
24+
2425
let memory = AutoManagedChatGPTMemory(
2526
systemPrompt: "",
2627
configuration: UserPreferenceChatGPTConfiguration(),
@@ -57,7 +58,7 @@ class AutoManagedChatGPTMemoryRetrievedContentTests: XCTestCase {
5758
"""
5859

5960
let maxTokenCount = await strategy.countToken(.init(role: .user, content: fullContent))
60-
61+
6162
let result = await memory.generateRetrievedContentMessage(
6263
maxTokenCount: maxTokenCount,
6364
strategy: strategy
@@ -159,7 +160,7 @@ class AutoManagedChatGPTMemoryRetrievedContentTests: XCTestCase {
159160
D
160161
""")
161162
}
162-
163+
163164
func test_retrieved_content_when_the_context_window_can_take_only_one_document() async {
164165
let strategy = Strategy()
165166

@@ -200,7 +201,7 @@ class AutoManagedChatGPTMemoryRetrievedContentTests: XCTestCase {
200201
A
201202
""")
202203
}
203-
204+
204205
func test_retrieved_content_when_the_context_window_empty() async {
205206
let strategy = Strategy()
206207

Tool/Tests/OpenAIServiceTests/ChatGPTStreamTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ChatBasic
12
import Dependencies
23
import XCTest
34
@testable import OpenAIService

Tool/Tests/OpenAIServiceTests/LimitMessagesTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ChatBasic
12
import Foundation
23
import TokenEncoder
34
import XCTest
@@ -103,11 +104,11 @@ class MockEncoder: TokenEncoder {
103104

104105
struct MockStrategy: AutoManagedChatGPTMemoryStrategy {
105106
let encoder = MockEncoder()
106-
func countToken(_ message: OpenAIService.ChatMessage) async -> Int {
107+
func countToken(_ message: ChatBasic.ChatMessage) async -> Int {
107108
await encoder.countToken(message)
108109
}
109110

110-
func countToken<F>(_: F) async -> Int where F: OpenAIService.ChatGPTFunction {
111+
func countToken<F>(_: F) async -> Int where F: ChatBasic.ChatGPTFunction {
111112
0
112113
}
113114

0 commit comments

Comments
 (0)