ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / extension / tools / node / test / editFileToolUtils.spec.ts 1156 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
import * as fs from 'fs' ;
import { homedir, tmpdir } from 'os' ;
import * as path from 'path' ;
import { afterEach, beforeEach, describe, expect, test } from 'vitest' ;
import { DefaultsOnlyConfigurationService } from '../../../../platform/configuration/common/defaultsOnlyConfigurationService' ;
import { InMemoryConfigurationService } from '../../../../platform/configuration/test/common/inMemoryConfigurationService' ;
import { IAlternativeNotebookContentService } from '../../../../platform/notebook/common/alternativeContent'
MockAlternativeNotebookContentService
INotebookService
MockCustomInstructionsService
TestWorkspaceService
WorkspaceEdit WorkspaceEditShim
createTextDocumentData IExtHostDocumentData setDocText
isMacintosh isWindows
WorkspaceEdit
applyEdits applyTextEdits
applyEdit assertPathIsSafe ConfirmationCheckResult ContentFormatError makeUriConfirmationChecker MultipleMatchesError NoChangeError NoMatchError setSimilarityMatchThresholdForTests
workspaceEdit WorkspaceEdit
workspaceService TestWorkspaceService
notebookService uri
alternatveContentService IAlternativeNotebookContentService
doc IExtHostDocumentData
oldString newString uri doc document uri
r uri oldString newString workspaceService notebookService INotebookService alternatveContentService
workspaceEdit uri r edits
r
value
doc value
doc
workspaceEdit
workspaceService doc document
notebookService
alternatveContentService
result
result updatedFile
result
result updatedFile
result
result updatedFile
rejects MultipleMatchesError
result
result updatedFile
result
result updatedFile
result
result updatedFile
rejects NoMatchError
result
result updatedFile
rejects ContentFormatError
result
result updatedFile
result
result updatedFile
rejects NoChangeError
result
result updatedFile
result
result updatedFile
rejects NoMatchError
result
result updatedFile
result
result updatedFile
longText
longText
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
error
error NoMatchError
error kindForTelemetry
error file
error
error MultipleMatchesError
error kindForTelemetry
error file
error
error NoChangeError
error kindForTelemetry
error file
error
error ContentFormatError
error kindForTelemetry
error file
result
result updatedFile
result
result updatedFile
result
result updatedFile
rejects MultipleMatchesError
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result
result
result patch
result updatedFile
input fs __dirname
output fs __dirname
toolCall fs __dirname
crlfDoc input
workspaceService textDocuments crlfDoc document
result toolCall oldString toolCall newString crlfDoc document uri
result updatedFile output
input workspaceEdit
output
result
result updatedFile
result updatedFile
result
result updatedFile
rejects MultipleMatchesError
result
result updatedFile
result updatedFile
result
result edits length
result updatedFile
result
result updatedFile
result updatedFile
result updatedFile
result
result updatedFile
result
result updatedFile
rejects NoMatchError
result
result updatedFile
result updatedFile
largeText
largeText
result
result updatedFile
result
result updatedFile
result updatedFile
result updatedFile
result
result updatedFile
result updatedFile
prev
prev
prev
result
result updatedFile
result
result updatedFile
rejects NoMatchError
result
result updatedFile
result
result updatedFile
result
result updatedFile
result
result edits length
result edits newText
result
result updatedFile
result
result edits length
edit result edits
edit newText
edit range start line
result
result updatedFile
not
not
configService InMemoryConfigurationService
workspaceService TestWorkspaceService
customInstructionsService MockCustomInstructionsService
configService
workspaceService
customInstructionsService
workspaceFolder
workspaceService workspaceFolder
checker configService workspaceService workspaceService customInstructionsService
fileInWorkspace
result fileInWorkspace
result ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
checker configService workspaceService workspaceService customInstructionsService
fileOutsideWorkspace
result fileOutsideWorkspace
result ConfirmationCheckResult OutsideWorkspace
workspaceService
checker configService workspaceService workspaceService customInstructionsService
untitledFile
result untitledFile
result ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
externalInstruction
customInstructionsService externalInstruction
checker configService workspaceService workspaceService customInstructionsService
result externalInstruction
result ConfirmationCheckResult OutsideWorkspace
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
testFile
result testFile
result ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
prodFile
result prodFile
result ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
envFile
result envFile
result ConfirmationCheckResult Sensitive
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
files
results files file file
results files ConfirmationCheckResult Sensitive
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
secretFile
result secretFile
result ConfirmationCheckResult Sensitive
workspaceFolder
workspaceService workspaceFolder
checker configService workspaceService workspaceService customInstructionsService
invalidFile
invalidFile rejects
workspace1
workspace2
workspaceService workspace1 workspace2
checker configService workspaceService workspaceService customInstructionsService
fileInWorkspace1
fileInWorkspace2
fileInWorkspace1 ConfirmationCheckResult NoConfirmation
fileInWorkspace2 ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
file1
result1 file1
result1 ConfirmationCheckResult NoConfirmation
file2
result2 file2
result2 ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
testFile
result testFile
result ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
checker configService workspaceService workspaceService customInstructionsService
file
result file
result ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
file
result file
result ConfirmationCheckResult NoConfirmation
isMacintosh
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
normalFile
normalFile ConfirmationCheckResult SystemFile
libraryWorkspace
workspaceService libraryWorkspace
configService
checker configService workspaceService workspaceService customInstructionsService
normalFile
configFile
normalFile ConfirmationCheckResult NoConfirmation
configFile ConfirmationCheckResult Sensitive
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
testConfigFile
result testConfigFile
result ConfirmationCheckResult NoConfirmation
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
srcFile
distFile
srcFile ConfirmationCheckResult NoConfirmation
distFile ConfirmationCheckResult Sensitive
workspace1
workspace2
workspaceService workspace1 workspace2
configService
checker configService workspaceService workspaceService customInstructionsService
secretsInWorkspace1
secretsInWorkspace2
secretsInWorkspace1 ConfirmationCheckResult Sensitive
secretsInWorkspace2 ConfirmationCheckResult Sensitive
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
hookFile
hookFile ConfirmationCheckResult Sensitive
configService
checker configService workspaceService workspaceService customInstructionsService
folderUri
folderUri ConfirmationCheckResult Sensitive
configService
checker configService workspaceService workspaceService customInstructionsService
txtFile
txtFile ConfirmationCheckResult NoConfirmation
configService
checker configService workspaceService workspaceService customInstructionsService
hookFile
otherFile
hookFile ConfirmationCheckResult Sensitive
otherFile ConfirmationCheckResult NoConfirmation
configService
checker configService workspaceService workspaceService customInstructionsService
fileInWorkspace
fileInWorkspace ConfirmationCheckResult NoConfirmation
configService
checker configService workspaceService workspaceService customInstructionsService
hookFile
hookFile ConfirmationCheckResult Sensitive
configService
checker configService workspaceService workspaceService customInstructionsService
pngFile
pngFile ConfirmationCheckResult Sensitive
jsonFile
jsonFile ConfirmationCheckResult NoConfirmation
configService
checker configService workspaceService workspaceService customInstructionsService
hookFile
hookFile ConfirmationCheckResult Sensitive
workspaceFolder
workspaceService workspaceFolder
configService
checker configService workspaceService workspaceService customInstructionsService
prodEnv
testEnv
apiKey
prodEnv ConfirmationCheckResult Sensitive
testEnv ConfirmationCheckResult NoConfirmation
apiKey ConfirmationCheckResult Sensitive
describe isWindows
tmpRoot
workspaceDir
outsideDir
tmpRoot fs path
workspaceDir fs fs path tmpRoot
outsideDir fs fs path tmpRoot
fs tmpRoot recursive force
fs outsideDir path workspaceDir
workspaceService workspaceDir
checker configService workspaceService workspaceService customInstructionsService
target path workspaceDir
target ConfirmationCheckResult OutsideWorkspace
fs outsideDir path workspaceDir
workspaceService workspaceDir
checker configService workspaceService workspaceService customInstructionsService
target path workspaceDir
target ConfirmationCheckResult OutsideWorkspace
configService InMemoryConfigurationService
workspaceService TestWorkspaceService
customInstructionsService MockCustomInstructionsService
configService
workspaceService
customInstructionsService
checker configService workspaceService workspaceService customInstructionsService
files
file files
file ConfirmationCheckResult Sensitive
checker configService workspaceService workspaceService customInstructionsService
ConfirmationCheckResult NoConfirmation
ConfirmationCheckResult NoConfirmation
;
import
{
}
from
'../../../../platform/notebook/common/mockAlternativeContentService'
;
import
{
}
from
'../../../../platform/notebook/common/notebookService'
;
import
{
}
from
'../../../../platform/test/common/testCustomInstructionsService'
;
import
{
}
from
'../../../../platform/test/node/testWorkspaceService'
;
import
{
as
}
from
'../../../../util/common/test/shims/editing'
;
import
{
,
,
}
from
'../../../../util/common/test/shims/textDocument'
;
import
{
,
}
from
'../../../../util/vs/base/common/platform'
;
import
{
URI
}
from
'../../../../util/vs/base/common/uri'
;
import
{
}
from
'../../../../vscodeTypes'
;
import
{
as
}
from
'../../../prompt/node/intents'
;
import
{
,
,
,
,
,
,
,
,
}
from
'../editFileToolUtils'
;
describe
(
'replace_string_in_file - applyEdit'
,
(
)
=>
{
let
:
;
let
:
;
let
:
{
hasSupportedNotebooks
:
(
:
URI
)
=>
boolean
}
;
let
:
;
let
:
;
async
function
doApplyEdit
(
:
string
,
:
string
,
=
.
.
)
{
const
=
await
applyEdit
(
,
,
,
,
as
,
,
undefined
)
;
.
set
(
,
.
)
;
return
;
}
function
setText
(
:
string
)
{
setDocText
(
,
)
;
}
beforeEach
(
(
)
=>
{
=
createTextDocumentData
(
URI
.
file
(
'/my/file.ts'
)
,
''
,
'ts'
)
;
=
new
WorkspaceEditShim
(
)
as
any
;
=
new
TestWorkspaceService
(
[
]
,
[
.
]
)
;
=
{
hasSupportedNotebooks
:
(
)
=>
false
}
;
=
new
MockAlternativeNotebookContentService
(
)
;
}
)
;
test
(
'simple verbatim'
,
async
(
)
=>
{
setText
(
'this is an oldString!'
)
;
const
=
await
doApplyEdit
(
'oldString'
,
'newString'
)
;
expect
(
.
)
.
toBe
(
'this is an newString!'
)
;
}
)
;
test
(
'exact match - single occurrence'
,
async
(
)
=>
{
setText
(
'function hello() {\n\tconsole.log("world");\n}'
)
;
const
=
await
doApplyEdit
(
'console.log("world");'
,
'console.log("hello world");'
)
;
expect
(
.
)
.
toBe
(
'function hello() {\n\tconsole.log("hello world");\n}'
)
;
}
)
;
test
(
'exact match - with newlines'
,
async
(
)
=>
{
setText
(
'line1\nline2\nline3'
)
;
const
=
await
doApplyEdit
(
'line1\nline2'
,
'newline1\nnewline2'
)
;
expect
(
.
)
.
toBe
(
'newline1\nnewline2\nline3'
)
;
}
)
;
test
(
'multiple exact matches - should throw error'
,
async
(
)
=>
{
setText
(
'test\ntest\nother'
)
;
await
expect
(
doApplyEdit
(
'test'
,
'replacement'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'whitespace flexible matching - different indentation'
,
async
(
)
=>
{
setText
(
'function test() {\n console.log("hello");\n}'
)
;
const
=
await
doApplyEdit
(
' console.log("hello");'
,
'\tconsole.log("hi");'
)
;
expect
(
.
)
.
toBe
(
'function test() {\n\tconsole.log("hi");\n}'
)
;
}
)
;
test
(
'whitespace flexible matching - trailing spaces'
,
async
(
)
=>
{
setText
(
'line1 \nline2\nline3'
)
;
const
=
await
doApplyEdit
(
'line1\nline2'
,
'newline1\nnewline2'
)
;
expect
(
.
)
.
toBe
(
'newline1\nnewline2\nline3'
)
;
}
)
;
test
(
'fuzzy matching - with trailing whitespace variations'
,
async
(
)
=>
{
setText
(
'if (condition) {\n\treturn true; \n}'
)
;
const
=
await
doApplyEdit
(
'if (condition) {\n\treturn true;\n}'
,
'if (condition) {\n\treturn false;\n}'
)
;
expect
(
.
)
.
toBe
(
'if (condition) {\n\treturn false;\n}'
)
;
}
)
;
test
(
'no match found - should throw error'
,
async
(
)
=>
{
setText
(
'some text here'
)
;
await
expect
(
doApplyEdit
(
'nonexistent'
,
'replacement'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'empty old string - create new file'
,
async
(
)
=>
{
setText
(
''
)
;
const
=
await
doApplyEdit
(
''
,
'new content'
)
;
expect
(
.
)
.
toBe
(
'new content'
)
;
}
)
;
test
(
'empty old string on existing file - should throw error'
,
async
(
)
=>
{
setText
(
'existing content'
)
;
await
expect
(
doApplyEdit
(
''
,
'new content'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'delete text - empty new string'
,
async
(
)
=>
{
setText
(
'before\nto delete\nafter'
)
;
const
=
await
doApplyEdit
(
'to delete\n'
,
''
)
;
expect
(
.
)
.
toBe
(
'before\nafter'
)
;
}
)
;
test
(
'delete text - exact match without newline'
,
async
(
)
=>
{
setText
(
'before to delete after'
)
;
const
=
await
doApplyEdit
(
'to delete '
,
''
)
;
expect
(
.
)
.
toBe
(
'before after'
)
;
}
)
;
test
(
'no change - identical strings should throw error'
,
async
(
)
=>
{
setText
(
'unchanged text'
)
;
await
expect
(
doApplyEdit
(
'unchanged text'
,
'unchanged text'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'replace entire content'
,
async
(
)
=>
{
setText
(
'old content\nwith multiple lines'
)
;
const
=
await
doApplyEdit
(
'old content\nwith multiple lines'
,
'completely new content'
)
;
expect
(
.
)
.
toBe
(
'completely new content'
)
;
}
)
;
test
(
'replace with multiline content'
,
async
(
)
=>
{
setText
(
'single line'
)
;
const
=
await
doApplyEdit
(
'single line'
,
'line1\nline2\nline3'
)
;
expect
(
.
)
.
toBe
(
'line1\nline2\nline3'
)
;
}
)
;
test
(
'case sensitive matching'
,
async
(
)
=>
{
setText
(
'Hello World'
)
;
await
expect
(
doApplyEdit
(
'hello world'
,
'Hi World'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'special regex characters in search string'
,
async
(
)
=>
{
setText
(
'price is $10.99 (discount)'
)
;
const
=
await
doApplyEdit
(
'$10.99 (discount)'
,
'$9.99 (sale)'
)
;
expect
(
.
)
.
toBe
(
'price is $9.99 (sale)'
)
;
}
)
;
test
(
'unicode characters'
,
async
(
)
=>
{
setText
(
'Hello 世界! 🌍'
)
;
const
=
await
doApplyEdit
(
'世界! 🌍'
,
'世界! 🌎'
)
;
expect
(
.
)
.
toBe
(
'Hello 世界! 🌎'
)
;
}
)
;
test
(
'very long strings'
,
async
(
)
=>
{
const
=
'a'
.
repeat
(
1000
)
+
'middle'
+
'b'
.
repeat
(
1000
)
;
setText
(
)
;
const
=
await
doApplyEdit
(
'middle'
,
'CENTER'
)
;
expect
(
.
)
.
toBe
(
'a'
.
repeat
(
1000
)
+
'CENTER'
+
'b'
.
repeat
(
1000
)
)
;
}
)
;
test
(
'newline variations - CRLF to LF'
,
async
(
)
=>
{
setText
(
'line1\r\nline2\r\nline3'
)
;
const
=
await
doApplyEdit
(
'line1\nline2'
,
'newline1\nnewline2'
)
;
expect
(
.
)
.
toBe
(
'newline1\nnewline2\nline3'
)
;
}
)
;
test
(
'trailing newline handling'
,
async
(
)
=>
{
setText
(
'content\nwith\nnewlines\n'
)
;
const
=
await
doApplyEdit
(
'content\nwith\n'
,
'new\ncontent\n'
)
;
expect
(
.
)
.
toBe
(
'new\ncontent\nnewlines\n'
)
;
}
)
;
test
(
'similarity matching - high similarity content'
,
async
(
)
=>
{
setText
(
'function calculateTotal(items) {\n\tlet sum = 0;\n\tfor (let i = 0; i < items.length; i++) {\n\t\tsum += items[i].price;\n\t}\n\treturn sum;\n}'
)
;
const
=
await
doApplyEdit
(
'function calculateTotal(items) {\n\tlet sum = 0;\n\tfor (let i = 0; i < items.length; i++) {\n\t\tsum += items[i].price;\n\t}\n\treturn sum;\n}'
,
'function calculateTotal(items) {\n\treturn items.reduce((sum, item) => sum + item.price, 0);\n}'
)
;
expect
(
.
)
.
toBe
(
'function calculateTotal(items) {\n\treturn items.reduce((sum, item) => sum + item.price, 0);\n}'
)
;
}
)
;
test
(
'whitespace only differences'
,
async
(
)
=>
{
setText
(
'function test() {\n return true;\n}'
)
;
const
=
await
doApplyEdit
(
' return true;'
,
'\treturn false;'
)
;
expect
(
.
)
.
toBe
(
'function test() {\n\treturn false;\n}'
)
;
}
)
;
test
(
'mixed whitespace and content changes'
,
async
(
)
=>
{
setText
(
'if (condition) {\n console.log("test"); \n}'
)
;
const
=
await
doApplyEdit
(
' console.log("test"); '
,
'\tconsole.log("updated");'
)
;
expect
(
.
)
.
toBe
(
'if (condition) {\n\tconsole.log("updated");\n}'
)
;
}
)
;
test
(
'empty lines handling'
,
async
(
)
=>
{
setText
(
'line1\n\n\nline4'
)
;
const
=
await
doApplyEdit
(
'line1\n\n\nline4'
,
'line1\n\nline3\nline4'
)
;
expect
(
.
)
.
toBe
(
'line1\n\nline3\nline4'
)
;
}
)
;
test
(
'partial line replacement'
,
async
(
)
=>
{
setText
(
'const name = "old value";'
)
;
const
=
await
doApplyEdit
(
'"old value"'
,
'"new value"'
)
;
expect
(
.
)
.
toBe
(
'const name = "new value";'
)
;
}
)
;
test
(
'multiple line partial replacement'
,
async
(
)
=>
{
setText
(
'function test() {\n\tconsole.log("debug");\n\treturn value;\n}'
)
;
const
=
await
doApplyEdit
(
'console.log("debug");\n\treturn value;'
,
'return newValue;'
)
;
expect
(
.
)
.
toBe
(
'function test() {\n\treturn newValue;\n}'
)
;
}
)
;
test
(
'error properties - NoMatchError'
,
async
(
)
=>
{
setText
(
'some text'
)
;
try
{
await
doApplyEdit
(
'missing'
,
'replacement'
)
;
}
catch
(
)
{
expect
(
)
.
toBeInstanceOf
(
)
;
expect
(
.
)
.
toBe
(
'noMatchFound'
)
;
expect
(
.
)
.
toBe
(
'file:///my/file.ts'
)
;
}
}
)
;
test
(
'error properties - MultipleMatchesError'
,
async
(
)
=>
{
setText
(
'same\nsame\nother'
)
;
try
{
await
doApplyEdit
(
'same'
,
'different'
)
;
}
catch
(
)
{
expect
(
)
.
toBeInstanceOf
(
)
;
expect
(
.
)
.
toBe
(
'multipleMatchesFound'
)
;
expect
(
.
)
.
toBe
(
'file:///my/file.ts'
)
;
}
}
)
;
test
(
'error properties - NoChangeError'
,
async
(
)
=>
{
setText
(
'test content'
)
;
try
{
await
doApplyEdit
(
'test content'
,
'test content'
)
;
}
catch
(
)
{
expect
(
)
.
toBeInstanceOf
(
)
;
expect
(
.
)
.
toBe
(
'noChange'
)
;
expect
(
.
)
.
toBe
(
'file:///my/file.ts'
)
;
}
}
)
;
test
(
'error properties - ContentFormatError'
,
async
(
)
=>
{
setText
(
'existing content'
)
;
try
{
await
doApplyEdit
(
''
,
'new content'
)
;
}
catch
(
)
{
expect
(
)
.
toBeInstanceOf
(
)
;
expect
(
.
)
.
toBe
(
'contentFormatError'
)
;
expect
(
.
)
.
toBe
(
'file:///my/file.ts'
)
;
}
}
)
;
test
(
'very small strings'
,
async
(
)
=>
{
setText
(
'a'
)
;
const
=
await
doApplyEdit
(
'a'
,
'b'
)
;
expect
(
.
)
.
toBe
(
'b'
)
;
}
)
;
test
(
'empty file with empty replacement'
,
async
(
)
=>
{
setText
(
''
)
;
const
=
await
doApplyEdit
(
''
,
''
)
;
expect
(
.
)
.
toBe
(
''
)
;
}
)
;
test
(
'single character replacement'
,
async
(
)
=>
{
setText
(
'hello unique'
)
;
const
=
await
doApplyEdit
(
'unique'
,
'special'
)
;
expect
(
.
)
.
toBe
(
'hello special'
)
;
}
)
;
test
(
'multiple single character matches - should throw error'
,
async
(
)
=>
{
setText
(
'hello world'
)
;
await
expect
(
doApplyEdit
(
'l'
,
'L'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'replacement with same length'
,
async
(
)
=>
{
setText
(
'old text here'
)
;
const
=
await
doApplyEdit
(
'old'
,
'new'
)
;
expect
(
.
)
.
toBe
(
'new text here'
)
;
}
)
;
test
(
'replacement with longer text'
,
async
(
)
=>
{
setText
(
'short'
)
;
const
=
await
doApplyEdit
(
'short'
,
'much longer text'
)
;
expect
(
.
)
.
toBe
(
'much longer text'
)
;
}
)
;
test
(
'replacement with shorter text'
,
async
(
)
=>
{
setText
(
'very long text here'
)
;
const
=
await
doApplyEdit
(
'very long text'
,
'short'
)
;
expect
(
.
)
.
toBe
(
'short here'
)
;
}
)
;
test
(
'beginning of file replacement'
,
async
(
)
=>
{
setText
(
'start of file\nrest of content'
)
;
const
=
await
doApplyEdit
(
'start of file'
,
'beginning'
)
;
expect
(
.
)
.
toBe
(
'beginning\nrest of content'
)
;
}
)
;
test
(
'end of file replacement'
,
async
(
)
=>
{
setText
(
'content here\nend of file'
)
;
const
=
await
doApplyEdit
(
'end of file'
,
'conclusion'
)
;
expect
(
.
)
.
toBe
(
'content here\nconclusion'
)
;
}
)
;
test
(
'middle of line replacement'
,
async
(
)
=>
{
setText
(
'prefix MIDDLE suffix'
)
;
const
=
await
doApplyEdit
(
'MIDDLE'
,
'center'
)
;
expect
(
.
)
.
toBe
(
'prefix center suffix'
)
;
}
)
;
test
(
'multiple spaces preservation'
,
async
(
)
=>
{
setText
(
'word1 word2'
)
;
const
=
await
doApplyEdit
(
'word1 word2'
,
'word1 word2'
)
;
expect
(
.
)
.
toBe
(
'word1 word2'
)
;
}
)
;
test
(
'tab character replacement'
,
async
(
)
=>
{
setText
(
'before\tafter'
)
;
const
=
await
doApplyEdit
(
'\t'
,
' '
)
;
expect
(
.
)
.
toBe
(
'before after'
)
;
}
)
;
test
(
'mixed tabs and spaces'
,
async
(
)
=>
{
setText
(
'function() {\n\t mixed indentation\n}'
)
;
const
=
await
doApplyEdit
(
'\t mixed indentation'
,
' proper indentation'
)
;
expect
(
.
)
.
toBe
(
'function() {\n proper indentation\n}'
)
;
}
)
;
test
(
'writes an empty file with LF'
,
async
(
)
=>
{
setText
(
''
)
;
const
=
await
doApplyEdit
(
'\n'
,
'hello world!'
)
;
expect
(
.
)
.
toBe
(
'hello world!'
)
;
}
)
;
test
(
'return value structure'
,
async
(
)
=>
{
setText
(
'old content'
)
;
const
=
await
doApplyEdit
(
'old'
,
'new'
)
;
expect
(
)
.
toHaveProperty
(
'patch'
)
;
expect
(
)
.
toHaveProperty
(
'updatedFile'
)
;
expect
(
Array
.
isArray
(
.
)
)
.
toBe
(
true
)
;
expect
(
typeof
.
)
.
toBe
(
'string'
)
;
}
)
;
test
(
'fixes bad newlines in issue #9753'
,
async
(
)
=>
{
const
=
JSON
.
parse
(
.
readFileSync
(
+
'/editFileToolUtilsFixtures/crlf-input.json'
,
'utf8'
)
)
;
const
=
JSON
.
parse
(
.
readFileSync
(
+
'/editFileToolUtilsFixtures/crlf-output.json'
,
'utf8'
)
)
.
join
(
'\r\n'
)
;
const
=
JSON
.
parse
(
.
readFileSync
(
+
'/editFileToolUtilsFixtures/crlf-tool-call.json'
,
'utf8'
)
)
;
const
=
createTextDocumentData
(
URI
.
file
(
'/my/file2.ts'
)
,
.
join
(
'\r\n'
)
,
'ts'
,
'\r\n'
)
;
.
.
push
(
.
)
;
const
=
await
doApplyEdit
(
.
,
.
,
.
.
)
;
expect
(
.
)
.
toBe
(
)
;
expect
(
applyTextEdits
(
.
join
(
'\r\n'
)
,
.
entries
(
)
[
0
]
[
1
]
)
)
.
toBe
(
)
;
}
)
;
describe
(
'whitespace-flexible matching'
,
(
)
=>
{
test
(
'matches when file has empty line after content'
,
async
(
)
=>
{
setText
(
'function test() {\n \tconsole.log("hello");\n\treturn true;\n\n}'
)
;
const
=
await
doApplyEdit
(
'console.log("hello");\nreturn true;\n'
,
'console.log("updated");\nreturn false;\n'
)
;
expect
(
.
)
.
toContain
(
'console.log("updated");'
)
;
expect
(
.
)
.
toContain
(
'return false;'
)
;
}
)
;
test
(
'matches when indentation varies and empty line follows'
,
async
(
)
=>
{
setText
(
'if (x) {\n\t\t if (y) {\n \t\tcode();\n\t \t}\n\n}'
)
;
const
=
await
doApplyEdit
(
'if (y) {\ncode();\n}\n'
,
'if (y) {\nupdated();\n}\n'
)
;
expect
(
.
)
.
toContain
(
'updated();'
)
;
}
)
;
test
(
'throws error on multiple matches with empty lines'
,
async
(
)
=>
{
setText
(
'function a() {\n \treturn 1;\n\n}\nfunction b() {\n\t return 1;\n\n}'
)
;
await
expect
(
doApplyEdit
(
'return 1;\n'
,
'return 2;\n'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'matches block with trailing empty line preserving structure'
,
async
(
)
=>
{
setText
(
'class Test {\n\t method() {\n \t\tconst x = 1;\n\t const y = 2;\n\n \t}\n}'
)
;
const
=
await
doApplyEdit
(
'const x = 1;\nconst y = 2;\n'
,
'const z = 3;\n'
)
;
expect
(
.
)
.
toContain
(
'const z = 3;'
)
;
expect
(
.
)
.
toContain
(
'class Test'
)
;
}
)
;
test
(
'whitespace-flexible match minimizes edits with empty line'
,
async
(
)
=>
{
setText
(
'function test() {\n \tconst a = 1;\n\t const b = 2;\n\n}'
)
;
const
=
await
doApplyEdit
(
'const a = 1;\nconst b = 2;\n'
,
'const a = 1;\nconst b = 3;\n'
)
;
expect
(
.
.
)
.
toBe
(
1
)
;
expect
(
.
)
.
toContain
(
'const b = 3;'
)
;
}
)
;
test
(
'empty line in haystack required for whitespace-flexible match'
,
async
(
)
=>
{
setText
(
'line1\n \tline2\n\n\t line3'
)
;
const
=
await
doApplyEdit
(
'line1\nline2\n'
,
'new1\nnew2\n'
)
;
expect
(
.
)
.
toContain
(
'new1'
)
;
expect
(
.
)
.
toContain
(
'new2'
)
;
expect
(
.
)
.
toContain
(
'line3'
)
;
}
)
;
}
)
;
describe
(
'similarity matching'
,
(
)
=>
{
test
(
'matches highly similar content with minor differences'
,
async
(
)
=>
{
setText
(
'function calculate(items) {\n\tlet total = 0;\n\tfor (let i = 0; i < items.length; i++) {\n\t\ttotal += items[i].price;\n\t}\n\treturn total;\n}'
)
;
const
=
await
doApplyEdit
(
'function calculate(items) {\n\tlet total = 0;\n\tfor (let i = 0; i < items.length; i++) {\n\t\ttotal += items[i].pric;\n\t}\n\treturn total;\n}'
,
'function calculate(items) {\n\treturn items.reduce((acc, item) => acc + item.price, 0);\n}'
)
;
expect
(
.
)
.
toBe
(
'function calculate(items) {\n\treturn items.reduce((acc, item) => acc + item.price, 0);\n}'
)
;
}
)
;
test
(
'similarity match with small typos in search string'
,
async
(
)
=>
{
setText
(
'const message = "Hello, World!";\nconsole.log(message);'
)
;
const
=
await
doApplyEdit
(
'const mesage = "Hello, World!";\nconsole.log(message);'
,
'const greeting = "Hi there!";\nconsole.log(greeting);'
)
;
expect
(
.
)
.
toContain
(
'greeting'
)
;
}
)
;
test
(
'similarity match does not trigger for low similarity'
,
async
(
)
=>
{
setText
(
'function test() {\n\treturn true;\n}'
)
;
await
expect
(
doApplyEdit
(
'completely different text here with no similarity at all to the original'
,
'replacement'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'similarity match prefers best match among candidates'
,
async
(
)
=>
{
setText
(
'function a() {\n\tconst x = 1;\n\tconst y = 2;\n}\nfunction b() {\n\tconst x = 1;\n\tconst z = 3;\n}'
)
;
const
=
await
doApplyEdit
(
'function a() {\nconst x = 1;\nconst y = 2;\n}'
,
'function a() {\nconst result = 3;\n}'
)
;
expect
(
.
)
.
toContain
(
'const result = 3'
)
;
expect
(
.
)
.
toContain
(
'function b()'
)
;
}
)
;
test
(
'similarity match skips very large strings'
,
async
(
)
=>
{
const
=
'line\n'
.
repeat
(
50
)
+
'target line\n'
+
'line\n'
.
repeat
(
50
)
;
setText
(
)
;
const
=
await
doApplyEdit
(
'target line'
,
'replaced line'
)
;
expect
(
.
)
.
toContain
(
'replaced line'
)
;
}
)
;
test
(
'similarity match minimizes edits - preserves identical lines'
,
async
(
)
=>
{
setText
(
'function test() {\n\tconst a = 1;\n\tconst b = 2;\n\tconst c = 3;\n}'
)
;
const
=
await
doApplyEdit
(
'function test() {\n\tconst a = 1;\n\tconst x = 2;\n\tconst c = 3;\n}'
,
'function test() {\n\tconst a = 1;\n\tconst y = 4;\n\tconst c = 3;\n}'
)
;
expect
(
.
)
.
toContain
(
'const a = 1'
)
;
expect
(
.
)
.
toContain
(
'const y = 4'
)
;
expect
(
.
)
.
toContain
(
'const c = 3'
)
;
}
)
;
test
(
'similarity match with small content blocks'
,
async
(
)
=>
{
setText
(
'const x = 1;\nconst y = 2;\nconst z = 3;'
)
;
const
=
await
doApplyEdit
(
'const x = 1;\nconst w = 2;'
,
'const a = 10;\nconst b = 20;'
)
;
expect
(
.
)
.
toContain
(
'const a = 10'
)
;
expect
(
.
)
.
toContain
(
'const b = 20'
)
;
}
)
;
describe
(
'similarity match - edge cases for slice calculations'
,
(
)
=>
{
let
:
number
;
beforeEach
(
(
)
=>
{
=
setSimilarityMatchThresholdForTests
(
0.6
)
;
}
)
;
afterEach
(
(
)
=>
{
setSimilarityMatchThresholdForTests
(
)
;
}
)
;
test
(
'similarity match preserves lines after replacement when there are identical trailing lines'
,
async
(
)
=>
{
setText
(
'function test() {\n\tconst a = 1;\n\tconst b = 2;\n\tconst c = 3;\n\tconst d = 4;\n}'
)
;
const
=
await
doApplyEdit
(
'function test() {\n\tconst a = 1;\n\tconst x = 2;\n\tconst y = 3;\n\tconst d = 4;\n}'
,
'function test() {\n\tconst a = 1;\n\tconst newB = 20;\n\tconst newC = 30;\n\tconst d = 4;\n}'
)
;
expect
(
.
)
.
toBe
(
'function test() {\n\tconst a = 1;\n\tconst newB = 20;\n\tconst newC = 30;\n\tconst d = 4;\n}'
)
;
}
)
;
test
(
'similarity match with multiple identical trailing lines'
,
async
(
)
=>
{
setText
(
'EXACT_START\nchange_me_1\nchange_me_2\nEXACT_END1\nEXACT_END2'
)
;
const
=
await
doApplyEdit
(
'EXACT_START\nmodify_1\nmodify_2\nEXACT_END1\nEXACT_END2'
,
'EXACT_START\nNEW_1\nNEW_2\nEXACT_END1\nEXACT_END2'
)
;
expect
(
.
)
.
toBe
(
'EXACT_START\nNEW_1\nNEW_2\nEXACT_END1\nEXACT_END2'
)
;
}
)
;
test
(
'similarity match boundary: no identical lines'
,
async
(
)
=>
{
setText
(
'aaa\nbbb\nccc'
)
;
await
expect
(
doApplyEdit
(
'xxx\nyyy\nzzz'
,
'new1\nnew2\nnew3'
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'similarity match edge case: all identical lines except middle'
,
async
(
)
=>
{
setText
(
'Alpha\nBravo\nCharlie\nDelta\nEcho'
)
;
const
=
await
doApplyEdit
(
'Alpha\nBravo\nXray\nDelta\nEcho'
,
'Alpha\nBravo\nNEW\nDelta\nEcho'
)
;
expect
(
.
)
.
toBe
(
'Alpha\nBravo\nNEW\nDelta\nEcho'
)
;
}
)
;
test
(
'similarity match edge case: only last line differs'
,
async
(
)
=>
{
setText
(
'start_line\nmiddle_one\nmiddle_two\nold_ending'
)
;
const
=
await
doApplyEdit
(
'start_line\nmiddle_one\nmiddle_two\nwrong_ending'
,
'start_line\nmiddle_one\nmiddle_two\nnew_ending'
)
;
expect
(
.
)
.
toBe
(
'start_line\nmiddle_one\nmiddle_two\nnew_ending'
)
;
}
)
;
test
(
'similarity match edge case: only first line differs'
,
async
(
)
=>
{
setText
(
'old_beginning\nmiddle_one\nmiddle_two\nending_line'
)
;
const
=
await
doApplyEdit
(
'wrong_beginning\nmiddle_one\nmiddle_two\nending_line'
,
'new_beginning\nmiddle_one\nmiddle_two\nending_line'
)
;
expect
(
.
)
.
toBe
(
'new_beginning\nmiddle_one\nmiddle_two\nending_line'
)
;
}
)
;
}
)
;
}
)
;
describe
(
'edit minimization'
,
(
)
=>
{
test
(
'exact match minimizes edits - preserves identical prefix/suffix'
,
async
(
)
=>
{
setText
(
'prefix unchanged middle changed suffix unchanged'
)
;
const
=
await
doApplyEdit
(
'prefix unchanged middle changed suffix unchanged'
,
'prefix unchanged middle updated suffix unchanged'
)
;
expect
(
.
.
)
.
toBe
(
1
)
;
expect
(
.
[
0
]
.
)
.
toBe
(
'updat'
)
;
}
)
;
test
(
'fuzzy match only replaces different content'
,
async
(
)
=>
{
setText
(
'line1\nline2\nline3\n'
)
;
const
=
await
doApplyEdit
(
'line1\nline2\nline3'
,
'line1\nmodified\nline3'
)
;
expect
(
.
)
.
toBe
(
'line1\nmodified\nline3\n'
)
;
}
)
;
test
(
'edits array contains correct positions'
,
async
(
)
=>
{
setText
(
'start\ntarget line to change\nend'
)
;
const
=
await
doApplyEdit
(
'target line to change'
,
'modified line'
)
;
expect
(
.
.
)
.
toBe
(
1
)
;
const
=
.
[
0
]
;
expect
(
.
)
.
toBe
(
'modified lin'
)
;
expect
(
.
.
.
)
.
toBe
(
1
)
;
}
)
;
test
(
'exact match with partial change minimizes edited text'
,
async
(
)
=>
{
setText
(
'const a = 1;\nconst b = 2;\nconst c = 3;'
)
;
const
=
await
doApplyEdit
(
'const a = 1;\nconst b = 2;\nconst c = 3;'
,
'const a = 10;\nconst b = 2;\nconst c = 30;'
)
;
expect
(
.
)
.
toBe
(
'const a = 10;\nconst b = 2;\nconst c = 30;'
)
;
}
)
;
}
)
;
}
)
;
describe
(
'assertPathIsSafe (Windows scenarios)'
,
(
)
=>
{
test
(
'accepts normal path'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\project\\file.txt'
,
true
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'rejects null byte'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\proje\0ct\\file.txt'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'rejects ADS suffix'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\project\\file.txt:$I30:$INDEX_ALLOCATION'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'rejects additional colon in component'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\file:name.txt'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'rejects invalid characters'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\proj>ect\\file.txt'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'rejects device path prefix \\?\\'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'\\\\?\\C:\\Users\\me\\file.txt'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'rejects reserved device name component'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\CON\\file.txt'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'rejects trailing dot in component'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\folder.\\file.txt'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'rejects trailing space in component'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\folder \\file.txt'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'rejects 8.3 short filename pattern'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\VSCODE~1\\settings.json'
,
true
)
)
.
toThrow
(
)
;
}
)
;
test
(
'allows tilde without digit'
,
(
)
=>
{
expect
(
(
)
=>
assertPathIsSafe
(
'C:\\Users\\me\\my~folder\\file.txt'
,
true
)
)
.
.
toThrow
(
)
;
}
)
;
}
)
;
describe
(
'makeUriConfirmationChecker'
,
async
(
)
=>
{
let
:
;
let
:
;
let
:
;
beforeEach
(
(
)
=>
{
=
new
InMemoryConfigurationService
(
new
DefaultsOnlyConfigurationService
(
)
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
=
new
MockCustomInstructionsService
(
)
;
}
)
;
test
(
'allows files within workspace folder'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/src/file.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'rejects files outside workspace'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/other/file.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'allows untitled files'
,
async
(
)
=>
{
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
parse
(
'untitled:Untitled-1'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'allows external instructions files'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
const
=
URI
.
file
(
'/external/instruction.md'
)
;
.
setExternalFiles
(
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'respects autoApprove patterns - allows matching files'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/*.test.ts'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/src/app.test.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'respects autoApprove patterns - allows non-matching files by default'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/*.test.ts'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/src/app.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'respects autoApprove patterns - blocks explicitly denied files'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/*.env'
:
false
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/.env'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'always checks sensitive configuration files'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/.mcp.json'
:
true
,
'**/.npmrc'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
[
URI
.
file
(
'/workspace/.mcp.json'
)
,
URI
.
file
(
'/workspace/.npmrc'
)
,
URI
.
file
(
'/workspace/packages/nested/.npmrc'
)
,
URI
.
file
(
'/workspace/.vscode/settings.json'
)
,
]
;
const
=
await
Promise
.
all
(
.
map
(
=>
checker
(
)
)
)
;
expect
(
)
.
toEqual
(
.
map
(
(
)
=>
.
)
)
;
}
)
;
test
(
'pattern precedence - later patterns override earlier ones'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/*.ts'
:
true
,
'**/secret.ts'
:
false
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/src/secret.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'handles invalid paths with security checks'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/file\0.ts'
)
;
await
expect
(
checker
(
)
)
.
.
toThrow
(
)
;
}
)
;
test
(
'multiple workspace folders - allows files in any folder'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace1'
)
;
const
=
URI
.
file
(
'/workspace2'
)
;
=
new
TestWorkspaceService
(
[
,
]
,
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace1/file.ts'
)
;
const
=
URI
.
file
(
'/workspace2/file.ts'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'caches patterns per workspace folder'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/*.test.ts'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/test1.test.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
const
=
URI
.
file
(
'/workspace/test2.test.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'case sensitivity handling'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/Test.ts'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/Test.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'empty autoApprove config - blocks all non-workspace files'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/src/file.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'workspace folder excluded by pattern - still allows workspace edits'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'/workspace/**'
:
false
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/file.ts'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
if
(
)
{
test
(
'pattern matching macOS Library path'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
` ${ homedir ( ) } /Library/MyApp/src/app.ts `
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'pattern matching workspace folder on macOS Library path'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ homedir ( ) } /Library/MyApp `
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/*.config'
:
false
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
` ${ homedir ( ) } /Library/MyApp/src/app.ts `
)
;
const
=
URI
.
file
(
` ${ homedir ( ) } /Library/MyApp/settings.config `
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
}
test
(
'nested pattern matching'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/config/**'
:
false
,
'**/config/test/**'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/config/test/settings.json'
)
;
const
=
await
checker
(
)
;
expect
(
)
.
toBe
(
.
)
;
}
)
;
test
(
'handles relative workspace patterns correctly'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'src/**/*.ts'
:
true
,
'dist/**'
:
false
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/src/app.ts'
)
;
const
=
URI
.
file
(
'/workspace/dist/app.js'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'pattern matching is workspace-relative'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace1'
)
;
const
=
URI
.
file
(
'/workspace2'
)
;
=
new
TestWorkspaceService
(
[
,
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'secrets/**'
:
false
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace1/secrets/api-key.txt'
)
;
const
=
URI
.
file
(
'/workspace2/secrets/token.txt'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
describe
(
'hookFilesLocations'
,
(
)
=>
{
beforeEach
(
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
}
)
;
test
(
'folder pattern marks JSON files inside as sensitive'
,
async
(
)
=>
{
await
.
setNonExtensionConfig
(
'chat.hookFilesLocations'
,
{
'.github/hooks'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/.github/hooks/pre-commit.json'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'folder pattern marks the folder itself as sensitive'
,
async
(
)
=>
{
await
.
setNonExtensionConfig
(
'chat.hookFilesLocations'
,
{
'.github/hooks'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/.github/hooks'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'folder pattern does not match non-JSON files'
,
async
(
)
=>
{
await
.
setNonExtensionConfig
(
'chat.hookFilesLocations'
,
{
'.github/hooks'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/.github/hooks/readme.txt'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'direct JSON file path marks only that file as sensitive'
,
async
(
)
=>
{
await
.
setNonExtensionConfig
(
'chat.hookFilesLocations'
,
{
'.github/hooks/hook.json'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/.github/hooks/hook.json'
)
;
const
=
URI
.
file
(
'/workspace/.github/hooks/other.json'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'skips home directory patterns'
,
async
(
)
=>
{
await
.
setNonExtensionConfig
(
'chat.hookFilesLocations'
,
{
'~/hooks'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/hooks/hook.json'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'folder pattern with trailing slash matches JSON files'
,
async
(
)
=>
{
await
.
setNonExtensionConfig
(
'chat.hookFilesLocations'
,
{
'.copilot/hooks/'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/.copilot/hooks/hook.json'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'does not treat file extensions like .png as folders'
,
async
(
)
=>
{
await
.
setNonExtensionConfig
(
'chat.hookFilesLocations'
,
{
'assets/icon.png'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/assets/icon.png'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
const
=
URI
.
file
(
'/workspace/assets/icon.png/something.json'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'pattern starting with **/ is preserved as-is'
,
async
(
)
=>
{
await
.
setNonExtensionConfig
(
'chat.hookFilesLocations'
,
{
'**/hooks'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/deeply/nested/hooks/hook.json'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
}
)
;
test
(
'complex glob patterns'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
=
new
TestWorkspaceService
(
[
]
,
[
]
)
;
await
.
setNonExtensionConfig
(
'chat.tools.edits.autoApprove'
,
{
'**/*.{env,secret,key}'
:
false
,
'**/test/**/*.env'
:
true
,
}
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
'/workspace/.env'
)
;
const
=
URI
.
file
(
'/workspace/test/integration.env'
)
;
const
=
URI
.
file
(
'/workspace/config/api.key'
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
.
skipIf
(
)
(
'symlink escape protection'
,
(
)
=>
{
let
:
string
;
let
:
string
;
let
:
string
;
beforeEach
(
(
)
=>
{
=
.
mkdtempSync
(
.
join
(
tmpdir
(
)
,
'editutils-symlink-'
)
)
;
=
.
realpathSync
(
.
mkdtempSync
(
.
join
(
,
'workspace-'
)
)
)
;
=
.
realpathSync
(
.
mkdtempSync
(
.
join
(
,
'outside-'
)
)
)
;
}
)
;
afterEach
(
(
)
=>
{
.
rmSync
(
,
{
:
true
,
:
true
}
)
;
}
)
;
test
(
'non-existent file under symlinked parent resolves through the symlink'
,
async
(
)
=>
{
.
symlinkSync
(
,
.
join
(
,
'assets'
)
,
'dir'
)
;
=
new
TestWorkspaceService
(
[
URI
.
file
(
)
]
,
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
.
join
(
,
'assets'
,
'pwned.desktop'
)
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
test
(
'non-existent file under symlinked ancestor with non-existent intermediate dirs is still detected'
,
async
(
)
=>
{
.
symlinkSync
(
,
.
join
(
,
'assets'
)
,
'dir'
)
;
=
new
TestWorkspaceService
(
[
URI
.
file
(
)
]
,
[
]
)
;
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
URI
.
file
(
.
join
(
,
'assets'
,
'newdir'
,
'pwned.desktop'
)
)
;
expect
(
await
checker
(
)
)
.
toBe
(
.
)
;
}
)
;
}
)
;
}
)
;
describe
(
'agent definition files require confirmation'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
beforeEach
(
(
)
=>
{
=
new
InMemoryConfigurationService
(
new
DefaultsOnlyConfigurationService
(
)
)
;
=
new
TestWorkspaceService
(
[
URI
.
file
(
'/workspace'
)
]
,
[
]
)
;
=
new
MockCustomInstructionsService
(
)
;
}
)
;
test
(
'requires confirmation for files in agent folders'
,
async
(
)
=>
{
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
const
=
[
'/workspace/.github/agents/dev-helper.md'
,
'/workspace/.github/agents/dev-helper.agent.md'
,
'/workspace/.claude/agents/reviewer.md'
,
'/workspace/.github/agents/nested/deep.md'
,
]
;
for
(
const
of
)
{
expect
(
await
checker
(
URI
.
file
(
)
)
)
.
toBe
(
.
)
;
}
}
)
;
test
(
'does not require confirmation for similarly-named files outside agent folders'
,
async
(
)
=>
{
const
=
makeUriConfirmationChecker
(
,
.
getWorkspaceFolder
.
bind
(
)
,
)
;
expect
(
await
checker
(
URI
.
file
(
'/workspace/src/agents/agent.md'
)
)
)
.
toBe
(
.
)
;
expect
(
await
checker
(
URI
.
file
(
'/workspace/.github/workflows/ci.md'
)
)
)
.
toBe
(
.
)
;
}
)
;
}
)
;