1
1
import * as ideUtils from "core/util/ideUtils" ;
2
2
import { beforeEach , describe , expect , it , Mock , vi } from "vitest" ;
3
+ import { applyForEditTool } from "../../redux/thunks/handleApplyStateUpdate" ;
3
4
import { ClientToolExtras } from "./callClientTool" ;
4
5
import { multiEditImpl } from "./multiEditImpl" ;
5
6
@@ -11,14 +12,20 @@ vi.mock("core/util/ideUtils", () => ({
11
12
resolveRelativePathInDir : vi . fn ( ) ,
12
13
} ) ) ;
13
14
15
+ vi . mock ( "../../redux/thunks/handleApplyStateUpdate" , ( ) => ( {
16
+ applyForEditTool : vi . fn ( ) ,
17
+ } ) ) ;
18
+
14
19
describe ( "multiEditImpl" , ( ) => {
15
20
let mockExtras : ClientToolExtras ;
16
21
let mockResolveRelativePathInDir : Mock ;
22
+ let mockApplyForEditTool : Mock ;
17
23
18
24
beforeEach ( ( ) => {
19
25
vi . clearAllMocks ( ) ;
20
26
21
27
mockResolveRelativePathInDir = vi . mocked ( ideUtils . resolveRelativePathInDir ) ;
28
+ mockApplyForEditTool = vi . mocked ( applyForEditTool ) ;
22
29
23
30
mockExtras = {
24
31
getState : vi . fn ( ( ) => ( {
@@ -106,16 +113,13 @@ describe("multiEditImpl", () => {
106
113
mockExtras ,
107
114
) ;
108
115
109
- expect ( mockExtras . ideMessenger . request ) . toHaveBeenCalledWith (
110
- "applyToFile" ,
111
- {
112
- streamId : "test-uuid" ,
113
- toolCallId : "id" ,
114
- text : "Hi world" ,
115
- filepath : "/test/file.txt" ,
116
- isSearchAndReplace : true ,
117
- } ,
118
- ) ;
116
+ expect ( mockApplyForEditTool ) . toHaveBeenCalledWith ( {
117
+ streamId : "test-uuid" ,
118
+ toolCallId : "id" ,
119
+ text : "Hi world" ,
120
+ filepath : "/test/file.txt" ,
121
+ isSearchAndReplace : true ,
122
+ } ) ;
119
123
} ) ;
120
124
121
125
it ( "should apply multiple edits sequentially" , async ( ) => {
@@ -135,16 +139,13 @@ describe("multiEditImpl", () => {
135
139
mockExtras ,
136
140
) ;
137
141
138
- expect ( mockExtras . ideMessenger . request ) . toHaveBeenCalledWith (
139
- "applyToFile" ,
140
- {
141
- streamId : "test-uuid" ,
142
- toolCallId : "id" ,
143
- text : "Hi universe\nGoodbye universe" ,
144
- filepath : "/test/file.txt" ,
145
- isSearchAndReplace : true ,
146
- } ,
147
- ) ;
142
+ expect ( mockApplyForEditTool ) . toHaveBeenCalledWith ( {
143
+ streamId : "test-uuid" ,
144
+ toolCallId : "id" ,
145
+ text : "Hi universe\nGoodbye universe" ,
146
+ filepath : "/test/file.txt" ,
147
+ isSearchAndReplace : true ,
148
+ } ) ;
148
149
} ) ;
149
150
150
151
it ( "should handle edits that depend on previous edits" , async ( ) => {
@@ -164,16 +165,13 @@ describe("multiEditImpl", () => {
164
165
mockExtras ,
165
166
) ;
166
167
167
- expect ( mockExtras . ideMessenger . request ) . toHaveBeenCalledWith (
168
- "applyToFile" ,
169
- {
170
- streamId : "test-uuid" ,
171
- toolCallId : "id" ,
172
- text : "let x = 2;" ,
173
- filepath : "/test/file.txt" ,
174
- isSearchAndReplace : true ,
175
- } ,
176
- ) ;
168
+ expect ( mockApplyForEditTool ) . toHaveBeenCalledWith ( {
169
+ streamId : "test-uuid" ,
170
+ toolCallId : "id" ,
171
+ text : "let x = 2;" ,
172
+ filepath : "/test/file.txt" ,
173
+ isSearchAndReplace : true ,
174
+ } ) ;
177
175
} ) ;
178
176
179
177
it ( "should throw if string not found in edit sequence" , async ( ) => {
@@ -227,16 +225,13 @@ describe("multiEditImpl", () => {
227
225
mockExtras ,
228
226
) ;
229
227
230
- expect ( mockExtras . ideMessenger . request ) . toHaveBeenCalledWith (
231
- "applyToFile" ,
232
- {
233
- streamId : "test-uuid" ,
234
- toolCallId : "id" ,
235
- text : "New content\nLine 2" ,
236
- filepath : "new.txt" ,
237
- isSearchAndReplace : true ,
238
- } ,
239
- ) ;
228
+ expect ( mockApplyForEditTool ) . toHaveBeenCalledWith ( {
229
+ streamId : "test-uuid" ,
230
+ toolCallId : "id" ,
231
+ text : "New content\nLine 2" ,
232
+ filepath : "new.txt" ,
233
+ isSearchAndReplace : true ,
234
+ } ) ;
240
235
} ) ;
241
236
242
237
it ( "should create and edit new file" , async ( ) => {
@@ -254,16 +249,13 @@ describe("multiEditImpl", () => {
254
249
mockExtras ,
255
250
) ;
256
251
257
- expect ( mockExtras . ideMessenger . request ) . toHaveBeenCalledWith (
258
- "applyToFile" ,
259
- {
260
- streamId : "test-uuid" ,
261
- toolCallId : "id" ,
262
- text : "Hello universe" ,
263
- filepath : "new.txt" ,
264
- isSearchAndReplace : true ,
265
- } ,
266
- ) ;
252
+ expect ( mockApplyForEditTool ) . toHaveBeenCalledWith ( {
253
+ streamId : "test-uuid" ,
254
+ toolCallId : "id" ,
255
+ text : "Hello universe" ,
256
+ filepath : "new.txt" ,
257
+ isSearchAndReplace : true ,
258
+ } ) ;
267
259
} ) ;
268
260
} ) ;
269
261
@@ -286,16 +278,13 @@ describe("multiEditImpl", () => {
286
278
mockExtras ,
287
279
) ;
288
280
289
- expect ( mockExtras . ideMessenger . request ) . toHaveBeenCalledWith (
290
- "applyToFile" ,
291
- {
292
- streamId : "test-uuid" ,
293
- toolCallId : "id" ,
294
- text : "qux bar qux baz qux" ,
295
- filepath : "/test/file.txt" ,
296
- isSearchAndReplace : true ,
297
- } ,
298
- ) ;
281
+ expect ( mockApplyForEditTool ) . toHaveBeenCalledWith ( {
282
+ streamId : "test-uuid" ,
283
+ toolCallId : "id" ,
284
+ text : "qux bar qux baz qux" ,
285
+ filepath : "/test/file.txt" ,
286
+ isSearchAndReplace : true ,
287
+ } ) ;
299
288
} ) ;
300
289
301
290
it ( "should handle mixed replace_all settings" , async ( ) => {
@@ -315,16 +304,13 @@ describe("multiEditImpl", () => {
315
304
mockExtras ,
316
305
) ;
317
306
318
- expect ( mockExtras . ideMessenger . request ) . toHaveBeenCalledWith (
319
- "applyToFile" ,
320
- {
321
- streamId : "test-uuid" ,
322
- toolCallId : "id" ,
323
- text : "a b a z a" ,
324
- filepath : "/test/file.txt" ,
325
- isSearchAndReplace : true ,
326
- } ,
327
- ) ;
307
+ expect ( mockApplyForEditTool ) . toHaveBeenCalledWith ( {
308
+ streamId : "test-uuid" ,
309
+ toolCallId : "id" ,
310
+ text : "a b a z a" ,
311
+ filepath : "/test/file.txt" ,
312
+ isSearchAndReplace : true ,
313
+ } ) ;
328
314
} ) ;
329
315
} ) ;
330
316
@@ -346,25 +332,6 @@ describe("multiEditImpl", () => {
346
332
) ,
347
333
) . rejects . toThrow ( "Failed to apply multi edit: Read failed" ) ;
348
334
} ) ;
349
-
350
- it ( "should wrap applyToFile errors" , async ( ) => {
351
- mockResolveRelativePathInDir . mockResolvedValue ( "/test/file.txt" ) ;
352
- mockExtras . ideMessenger . ide . readFile = vi . fn ( ) . mockResolvedValue ( "test" ) ;
353
- mockExtras . ideMessenger . request = vi
354
- . fn ( )
355
- . mockRejectedValue ( new Error ( "Write failed" ) ) ;
356
-
357
- await expect (
358
- multiEditImpl (
359
- {
360
- filepath : "file.txt" ,
361
- edits : [ { old_string : "test" , new_string : "new" } ] ,
362
- } ,
363
- "id" ,
364
- mockExtras ,
365
- ) ,
366
- ) . rejects . toThrow ( "Failed to apply multi edit: Write failed" ) ;
367
- } ) ;
368
335
} ) ;
369
336
370
337
describe ( "return value" , ( ) => {
0 commit comments