* Helper function to execute the edit_file tool with different parameters
(
params: Partial<ToolUse["params"]> = {},
options: {
fileExists?: boolean
fileContent?: string
isPartial?: boolean
accessAllowed?: boolean
} = {},
)
| 162 | * Helper function to execute the edit_file tool with different parameters |
| 163 | */ |
| 164 | async function executeEditFileTool( |
| 165 | params: Partial<ToolUse["params"]> = {}, |
| 166 | options: { |
| 167 | fileExists?: boolean |
| 168 | fileContent?: string |
| 169 | isPartial?: boolean |
| 170 | accessAllowed?: boolean |
| 171 | } = {}, |
| 172 | ): Promise<ToolResponse | undefined> { |
| 173 | const fileExists = options.fileExists ?? true |
| 174 | const fileContent = options.fileContent ?? testFileContent |
| 175 | const isPartial = options.isPartial ?? false |
| 176 | const accessAllowed = options.accessAllowed ?? true |
| 177 | |
| 178 | mockedFileExistsAtPath.mockResolvedValue(fileExists) |
| 179 | mockedFsReadFile.mockResolvedValue(fileContent) |
| 180 | mockTask.rooIgnoreController.validateAccess.mockReturnValue(accessAllowed) |
| 181 | |
| 182 | const nativeArgs: Record<string, unknown> = { |
| 183 | file_path: testFilePath, |
| 184 | old_string: testOldString, |
| 185 | new_string: testNewString, |
| 186 | } |
| 187 | for (const [key, value] of Object.entries(params)) { |
| 188 | nativeArgs[key] = value |
| 189 | } |
| 190 | // Keep expected_replacements numeric in native args when provided. |
| 191 | if (typeof nativeArgs.expected_replacements === "string") { |
| 192 | nativeArgs.expected_replacements = Number(nativeArgs.expected_replacements) |
| 193 | } |
| 194 | |
| 195 | const toolUse: ToolUse = { |
| 196 | type: "tool_use", |
| 197 | name: "edit_file", |
| 198 | params: { |
| 199 | file_path: testFilePath, |
| 200 | old_string: testOldString, |
| 201 | new_string: testNewString, |
| 202 | ...params, |
| 203 | }, |
| 204 | nativeArgs: nativeArgs as any, |
| 205 | partial: isPartial, |
| 206 | } |
| 207 | |
| 208 | mockPushToolResult = vi.fn((result: ToolResponse) => { |
| 209 | toolResult = result |
| 210 | }) |
| 211 | |
| 212 | await editFileTool.handle(mockTask, toolUse as ToolUse<"edit_file">, { |
| 213 | askApproval: mockAskApproval, |
| 214 | handleError: mockHandleError, |
| 215 | pushToolResult: mockPushToolResult, |
| 216 | }) |
| 217 | |
| 218 | return toolResult |
| 219 | } |
| 220 | |
| 221 | describe("parameter validation", () => { |
no test coverage detected