Skip to content

Commit ce539f9

Browse files
committed
Fix unit tests
1 parent 7fedca9 commit ce539f9

7 files changed

Lines changed: 37 additions & 40 deletions

File tree

Copilot for Xcode.xcodeproj/xcshareddata/xcschemes/ExtensionService.xcscheme

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
reference = "container:TestPlan.xctestplan"
4747
default = "YES">
4848
</TestPlanReference>
49+
<TestPlanReference
50+
reference = "container:Pro/ProTestPlan.xctestplan">
51+
</TestPlanReference>
4952
</TestPlans>
5053
</TestAction>
5154
<LaunchAction

Core/Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ let package = Package(
363363
.product(name: "OpenAIService", package: "Tool"),
364364
.product(name: "Preferences", package: "Tool"),
365365
.product(name: "FocusedCodeFinder", package: "Tool"),
366+
.product(name: "AppMonitoring", package: "Tool"),
366367
],
367368
path: "Sources/ChatContextCollectors/ActiveDocumentChatContextCollector"
368369
),

Pro

Submodule Pro updated from 62eba15 to 812ed60

TestPlan.xctestplan

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@
9999
"name" : "SharedUIComponentsTests"
100100
}
101101
},
102-
{
103-
"target" : {
104-
"containerPath" : "container:Pro",
105-
"identifier" : "LicenseManagementTests",
106-
"name" : "LicenseManagementTests"
107-
}
108-
},
109102
{
110103
"target" : {
111104
"containerPath" : "container:Core",
@@ -120,13 +113,6 @@
120113
"name" : "ASTParserTests"
121114
}
122115
},
123-
{
124-
"target" : {
125-
"containerPath" : "container:Pro",
126-
"identifier" : "ChatTabPersistentTests",
127-
"name" : "ChatTabPersistentTests"
128-
}
129-
},
130116
{
131117
"target" : {
132118
"containerPath" : "container:Core",

Tool/Sources/LangChain/Agent.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,17 @@ public struct AgentFinish<Output: AgentOutputParsable> {
7474
}
7575
}
7676

77+
extension AgentFinish.ReturnValue: Equatable where Output: Equatable {}
78+
79+
extension AgentFinish: Equatable where Output: Equatable {}
80+
7781
public enum AgentNextStep<Output: AgentOutputParsable> {
7882
case actions([AgentAction])
7983
case finish(AgentFinish<Output>)
8084
}
8185

86+
extension AgentNextStep: Equatable where Output: Equatable {}
87+
8288
public struct AgentScratchPad<Content: Equatable>: Equatable {
8389
public var content: Content
8490

Tool/Tests/LangChainTests/ChatAgentTests.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,42 @@ private struct FakeChatModel: ChatModel {
1212
}
1313

1414
final class ChatAgentParseOutputTests: XCTestCase {
15-
func test_parsing_well_formatted_final_answer() throws {
15+
func test_parsing_well_formatted_final_answer() async throws {
1616
let finalAnswer = """
1717
Final Answer: The answer is 42.
1818
Because 42 is the answer to everything.
1919
"""
2020

2121
let agent = ChatAgent(chatModel: FakeChatModel(), tools: [], preferredLanguage: "")
22-
let result = agent.parseOutput(finalAnswer)
22+
let result = await agent.parseOutput(.init(role: .assistant, content: finalAnswer))
2323
XCTAssertEqual(result, .finish(.init(
24-
returnValue: """
24+
returnValue: .structured("""
2525
The answer is 42.
2626
Because 42 is the answer to everything.
27-
""",
27+
"""),
2828
log: finalAnswer
2929
)))
3030
}
3131

32-
func test_parsing_final_answer_with_random_prefix() throws {
32+
func test_parsing_final_answer_with_random_prefix() async throws {
3333
let finalAnswer = """
3434
Now I have the final answer.
3535
Final Answer: The answer is 42.
3636
Because 42 is the answer to everything.
3737
"""
3838

3939
let agent = ChatAgent(chatModel: FakeChatModel(), tools: [], preferredLanguage: "")
40-
let result = agent.parseOutput(finalAnswer)
40+
let result = await agent.parseOutput(.init(role: .assistant, content: finalAnswer))
4141
XCTAssertEqual(result, .finish(.init(
42-
returnValue: """
42+
returnValue: .structured("""
4343
The answer is 42.
4444
Because 42 is the answer to everything.
45-
""",
45+
"""),
4646
log: finalAnswer
4747
)))
4848
}
4949

50-
func test_parsing_action() throws {
50+
func test_parsing_action() async throws {
5151
let reply = """
5252
Question: How to setup langchain python?
5353
Thought: I am not familiar with langchain python, I should use the Search tool to find more information on how to set it up.
@@ -61,7 +61,7 @@ final class ChatAgentParseOutputTests: XCTestCase {
6161
"""
6262

6363
let agent = ChatAgent(chatModel: FakeChatModel(), tools: [], preferredLanguage: "")
64-
let result = agent.parseOutput(reply)
64+
let result = await agent.parseOutput(.init(role: .assistant, content: reply))
6565
XCTAssertEqual(result, .actions([
6666
.init(
6767
toolName: "Search",
@@ -71,7 +71,7 @@ final class ChatAgentParseOutputTests: XCTestCase {
7171
]))
7272
}
7373

74-
func test_parsing_broken_action_and_return_everything_ahead_of_it() {
74+
func test_parsing_broken_action_and_return_everything_ahead_of_it() async {
7575
let reply = """
7676
Question: How to setup langchain python?
7777
Thought: I am not familiar with langchain python, I should use the Search tool to find more information on how to set it up.
@@ -82,26 +82,26 @@ final class ChatAgentParseOutputTests: XCTestCase {
8282
"""
8383

8484
let agent = ChatAgent(chatModel: FakeChatModel(), tools: [], preferredLanguage: "")
85-
let result = agent.parseOutput(reply)
85+
let result = await agent.parseOutput(.init(role: .assistant, content: reply))
8686
XCTAssertEqual(result, .finish(.init(
87-
returnValue: """
87+
returnValue: .structured("""
8888
Question: How to setup langchain python?
8989
Thought: I am not familiar with langchain python, I should use the Search tool to find more information on how to set it up.
90-
""",
90+
"""),
9191
log: reply
9292
)))
9393
}
9494

95-
func test_parsing_simple_reply_that_does_not_follow_the_format() {
95+
func test_parsing_simple_reply_that_does_not_follow_the_format() async {
9696
let reply = """
9797
The answer is 42.
9898
Because 42 is the answer to everything.
9999
"""
100100

101101
let agent = ChatAgent(chatModel: FakeChatModel(), tools: [], preferredLanguage: "")
102-
let result = agent.parseOutput(reply)
102+
let result = await agent.parseOutput(.init(role: .assistant, content: reply))
103103
XCTAssertEqual(result, .finish(.init(
104-
returnValue: reply,
104+
returnValue: .structured(reply),
105105
log: reply
106106
)))
107107
}

Tool/Tests/OpenAIServiceTests/ChatGPTStreamTests.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ final class ChatGPTStreamTests: XCTestCase {
139139
.init(name: $0.name, description: $0.description, parameters: $0.argumentSchema)
140140
}, "Function schema is not submitted")
141141
}
142-
142+
143143
func test_handling_multiple_function_call() async throws {
144144
let memory = ConversationChatGPTMemory(systemPrompt: "system", systemMessageId: "s")
145145
let configuration = UserPreferenceChatGPTConfiguration().overriding()
@@ -339,29 +339,30 @@ extension ChatGPTStreamTests {
339339
}
340340

341341
var name: String { "function" }
342-
342+
343343
var description: String { "description" }
344344

345345
var argumentSchema: JSONSchemaValue {
346346
[
347-
.type: ["null"]
347+
.type: ["null"],
348348
]
349349
}
350-
351-
var reportProgress: (String) async -> Void = { print($0) }
352350

353-
func prepare() async {
351+
func prepare(reportProgress: @escaping ReportProgress) async {
354352
print("Function will be called")
355353
}
356354

357-
func call(arguments: Parameters) async throws -> String {
355+
func call(
356+
arguments: Parameters,
357+
reportProgress: @escaping ReportProgress
358+
) async throws -> String {
358359
"Function is called."
359360
}
360361
}
361362

362363
struct FunctionProvider: ChatGPTFunctionProvider {
363364
var functionCallStrategy: OpenAIService.FunctionCallStrategy? { nil }
364-
365+
365366
var functions: [any ChatGPTFunction] { [EmptyFunction()] }
366367
}
367368
}

0 commit comments

Comments
 (0)