|
| 1 | +import { LLMock } from "@copilotkit/aimock" |
| 2 | + |
| 3 | +type SearchFilesFixture = { |
| 4 | + userMessagePattern: string |
| 5 | + toolName: string |
| 6 | + arguments: string |
| 7 | + toolCallId: string |
| 8 | + result: string |
| 9 | + id: string |
| 10 | +} |
| 11 | + |
| 12 | +export function addSearchFilesResultFixtures(mock: InstanceType<typeof LLMock>) { |
| 13 | + const fixtures: SearchFilesFixture[] = [ |
| 14 | + { |
| 15 | + userMessagePattern: "SEARCH_FILES_FUNCTIONS_SMOKE", |
| 16 | + toolName: "search_files", |
| 17 | + arguments: '{"path":"search-files-tool-fixture","regex":"function\\\\s+\\\\w+"}', |
| 18 | + toolCallId: "call_search_files_functions_001", |
| 19 | + result: "The function search found declarations including `calculateTotal`, `validateUser`, and `formatCurrency`.", |
| 20 | + id: "call_search_files_functions_002", |
| 21 | + }, |
| 22 | + { |
| 23 | + userMessagePattern: "SEARCH_FILES_TODO_SMOKE", |
| 24 | + toolName: "search_files", |
| 25 | + arguments: '{"path":"search-files-tool-fixture","regex":"TODO.*"}', |
| 26 | + toolCallId: "call_search_files_todo_001", |
| 27 | + result: "The TODO search found matching TODO entries in the fixture files, including the validation and user-fetching notes.", |
| 28 | + id: "call_search_files_todo_002", |
| 29 | + }, |
| 30 | + { |
| 31 | + userMessagePattern: "SEARCH_FILES_TYPESCRIPT_SMOKE", |
| 32 | + toolName: "search_files", |
| 33 | + arguments: '{"path":"search-files-tool-fixture","regex":"interface\\\\s+\\\\w+","file_pattern":"*.ts"}', |
| 34 | + toolCallId: "call_search_files_typescript_001", |
| 35 | + result: "The TypeScript-only search found the `User` and `Product` interface definitions.", |
| 36 | + id: "call_search_files_typescript_002", |
| 37 | + }, |
| 38 | + { |
| 39 | + userMessagePattern: "SEARCH_FILES_JSON_SMOKE", |
| 40 | + toolName: "search_files", |
| 41 | + arguments: '{"path":"search-files-tool-fixture","regex":"\\"\\\\w+\\":\\\\s*","file_pattern":"*.json"}', |
| 42 | + toolCallId: "call_search_files_json_001", |
| 43 | + result: "The JSON search found configuration keys such as `name`, `version`, and `dependencies` in `search-config.json`.", |
| 44 | + id: "call_search_files_json_002", |
| 45 | + }, |
| 46 | + { |
| 47 | + userMessagePattern: "SEARCH_FILES_NESTED_SMOKE", |
| 48 | + toolName: "search_files", |
| 49 | + arguments: '{"path":"search-files-tool-fixture","regex":"function\\\\s+(format|debounce)"}', |
| 50 | + toolCallId: "call_search_files_nested_001", |
| 51 | + result: "The nested-directory search found the utility functions `formatCurrency` and `debounce`.", |
| 52 | + id: "call_search_files_nested_002", |
| 53 | + }, |
| 54 | + { |
| 55 | + userMessagePattern: "SEARCH_FILES_COMPLEX_REGEX_SMOKE", |
| 56 | + toolName: "search_files", |
| 57 | + arguments: '{"path":"search-files-tool-fixture","regex":"(import|export).*","file_pattern":"*.{js,ts}"}', |
| 58 | + toolCallId: "call_search_files_complex_regex_001", |
| 59 | + result: "The import/export search found the `export` statement in the JavaScript fixture module.", |
| 60 | + id: "call_search_files_complex_regex_002", |
| 61 | + }, |
| 62 | + { |
| 63 | + userMessagePattern: "SEARCH_FILES_NO_MATCH_SMOKE", |
| 64 | + toolName: "search_files", |
| 65 | + arguments: '{"path":"search-files-tool-fixture","regex":"nonExistentPattern12345"}', |
| 66 | + toolCallId: "call_search_files_no_match_001", |
| 67 | + result: "No matches were found for `nonExistentPattern12345` in the search fixture directory.", |
| 68 | + id: "call_search_files_no_match_002", |
| 69 | + }, |
| 70 | + { |
| 71 | + userMessagePattern: "SEARCH_FILES_CLASS_METHOD_SMOKE", |
| 72 | + toolName: "search_files", |
| 73 | + arguments: |
| 74 | + '{"path":"search-files-tool-fixture","regex":"(class\\\\s+\\\\w+|async\\\\s+\\\\w+)","file_pattern":"*.ts"}', |
| 75 | + toolCallId: "call_search_files_class_method_001", |
| 76 | + result: "The class-and-method search found `UserService` and its async `getUser` method in the TypeScript fixture.", |
| 77 | + id: "call_search_files_class_method_002", |
| 78 | + }, |
| 79 | + ] |
| 80 | + |
| 81 | + for (const fixture of fixtures) { |
| 82 | + mock.addFixture({ |
| 83 | + match: { |
| 84 | + userMessage: new RegExp(fixture.userMessagePattern), |
| 85 | + }, |
| 86 | + response: { |
| 87 | + toolCalls: [ |
| 88 | + { |
| 89 | + name: fixture.toolName, |
| 90 | + arguments: fixture.arguments, |
| 91 | + id: fixture.toolCallId, |
| 92 | + }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + }) |
| 96 | + |
| 97 | + mock.addFixture({ |
| 98 | + match: { |
| 99 | + toolCallId: fixture.toolCallId, |
| 100 | + }, |
| 101 | + response: { |
| 102 | + toolCalls: [ |
| 103 | + { |
| 104 | + name: "attempt_completion", |
| 105 | + arguments: JSON.stringify({ result: fixture.result }), |
| 106 | + id: fixture.id, |
| 107 | + }, |
| 108 | + ], |
| 109 | + }, |
| 110 | + }) |
| 111 | + } |
| 112 | +} |
0 commit comments