11import { LLMock } from "@copilotkit/aimock"
2+ import type { ChatCompletionRequest , ChatMessage } from "@copilotkit/aimock"
23
34type SearchFilesFixture = {
45 userMessagePattern : string
56 toolName : string
67 arguments : string
78 toolCallId : string
9+ expected : string [ ]
810 result : string
911 id : string
1012}
1113
14+ function toolResultContains ( req : ChatCompletionRequest , toolCallId : string , expected : string [ ] ) {
15+ const messages = Array . isArray ( req ?. messages ) ? req . messages : [ ]
16+ const toolMessage = messages . find (
17+ ( message : ChatMessage ) => message ?. role === "tool" && message . tool_call_id === toolCallId ,
18+ )
19+
20+ const content = toolMessage ?. content
21+ if ( typeof content !== "string" ) {
22+ return false
23+ }
24+
25+ return expected . every ( ( text ) => content . includes ( text ) )
26+ }
27+
1228export function addSearchFilesResultFixtures ( mock : InstanceType < typeof LLMock > ) {
1329 const fixtures : SearchFilesFixture [ ] = [
1430 {
1531 userMessagePattern : "SEARCH_FILES_FUNCTIONS_SMOKE" ,
1632 toolName : "search_files" ,
1733 arguments : '{"path":"search-files-tool-fixture","regex":"function\\\\s+\\\\w+"}' ,
1834 toolCallId : "call_search_files_functions_001" ,
35+ expected : [
36+ "# search-files-tool-fixture/search-fixture.js" ,
37+ "function calculateTotal(items) {" ,
38+ "function validateUser(user) {" ,
39+ ] ,
1940 result : "The function search found declarations including `calculateTotal`, `validateUser`, and `formatCurrency`." ,
2041 id : "call_search_files_functions_002" ,
2142 } ,
@@ -24,6 +45,11 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
2445 toolName : "search_files" ,
2546 arguments : '{"path":"search-files-tool-fixture","regex":"TODO.*"}' ,
2647 toolCallId : "call_search_files_todo_001" ,
48+ expected : [
49+ "# search-files-tool-fixture/search-fixture.js" ,
50+ "// TODO: Add more validation functions" ,
51+ "// TODO: Implement user fetching" ,
52+ ] ,
2753 result : "The TODO search found matching TODO entries in the fixture files, including the validation and user-fetching notes." ,
2854 id : "call_search_files_todo_002" ,
2955 } ,
@@ -32,6 +58,7 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
3258 toolName : "search_files" ,
3359 arguments : '{"path":"search-files-tool-fixture","regex":"interface\\\\s+\\\\w+","file_pattern":"*.ts"}' ,
3460 toolCallId : "call_search_files_typescript_001" ,
61+ expected : [ "# search-files-tool-fixture/search-fixture.ts" , "interface User {" , "interface Product {" ] ,
3562 result : "The TypeScript-only search found the `User` and `Product` interface definitions." ,
3663 id : "call_search_files_typescript_002" ,
3764 } ,
@@ -40,6 +67,7 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
4067 toolName : "search_files" ,
4168 arguments : '{"path":"search-files-tool-fixture","regex":"\\"\\\\w+\\":\\\\s*","file_pattern":"*.json"}' ,
4269 toolCallId : "call_search_files_json_001" ,
70+ expected : [ "# search-files-tool-fixture/search-config.json" , '"name": "test-app",' , '"dependencies": {' ] ,
4371 result : "The JSON search found configuration keys such as `name`, `version`, and `dependencies` in `search-config.json`." ,
4472 id : "call_search_files_json_002" ,
4573 } ,
@@ -48,6 +76,11 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
4876 toolName : "search_files" ,
4977 arguments : '{"path":"search-files-tool-fixture","regex":"function\\\\s+(format|debounce)"}' ,
5078 toolCallId : "call_search_files_nested_001" ,
79+ expected : [
80+ "# search-files-tool-fixture/nested/nested-search.js" ,
81+ "function formatCurrency(amount) {" ,
82+ "function debounce(func, wait) {" ,
83+ ] ,
5184 result : "The nested-directory search found the utility functions `formatCurrency` and `debounce`." ,
5285 id : "call_search_files_nested_002" ,
5386 } ,
@@ -56,6 +89,11 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
5689 toolName : "search_files" ,
5790 arguments : '{"path":"search-files-tool-fixture","regex":"(import|export).*","file_pattern":"*.{js,ts}"}' ,
5891 toolCallId : "call_search_files_complex_regex_001" ,
92+ expected : [
93+ "# search-files-tool-fixture/search-fixture.js" ,
94+ "export { calculateTotal, validateUser }" ,
95+ "module.exports = { formatCurrency, debounce }" ,
96+ ] ,
5997 result : "The import/export search found the `export` statement in the JavaScript fixture module." ,
6098 id : "call_search_files_complex_regex_002" ,
6199 } ,
@@ -64,6 +102,7 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
64102 toolName : "search_files" ,
65103 arguments : '{"path":"search-files-tool-fixture","regex":"nonExistentPattern12345"}' ,
66104 toolCallId : "call_search_files_no_match_001" ,
105+ expected : [ "Found 0 results." ] ,
67106 result : "No matches were found for `nonExistentPattern12345` in the search fixture directory." ,
68107 id : "call_search_files_no_match_002" ,
69108 } ,
@@ -73,6 +112,11 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
73112 arguments :
74113 '{"path":"search-files-tool-fixture","regex":"(class\\\\s+\\\\w+|async\\\\s+\\\\w+)","file_pattern":"*.ts"}' ,
75114 toolCallId : "call_search_files_class_method_001" ,
115+ expected : [
116+ "# search-files-tool-fixture/search-fixture.ts" ,
117+ "class UserService {" ,
118+ "async getUser(id: number): Promise<User> {" ,
119+ ] ,
76120 result : "The class-and-method search found `UserService` and its async `getUser` method in the TypeScript fixture." ,
77121 id : "call_search_files_class_method_002" ,
78122 } ,
@@ -97,6 +141,7 @@ export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>)
97141 mock . addFixture ( {
98142 match : {
99143 toolCallId : fixture . toolCallId ,
144+ predicate : ( req ) => toolResultContains ( req , fixture . toolCallId , fixture . expected ) ,
100145 } ,
101146 response : {
102147 toolCalls : [
0 commit comments