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 / toolUtils.spec.ts 816 строк · изменён 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
import * as fs from 'fs' ;
import { tmpdir } from 'os' ;
import * as path from 'path' ;
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, suite, test } from 'vitest' ;
import { ConfigKey, IConfigurationService } from '../../../../platform/configuration/common/configurationService' ;
import { InMemoryConfigurationService } from '../../../../platform/configuration/test/common/inMemoryConfigurationService' ;
import ICustomInstructionsService
IFileSystemService
MockFileSystemService
IIgnoreService NullIgnoreService
MockCustomInstructionsService
ITestingServicesAccessor
TestWorkspaceService
IWorkspaceService NullWorkspaceService
WorkingDirectory
CancellationToken
ResourceSet
posix
isWindows
SyncDescriptor
IInstantiationService
ChatVariablesCollection CustomizationsIndexId
IBuildPromptContext
createExtensionUnitTestingServices
encodeUrlHostname
assertFileNotContentExcluded inputGlobToPattern isDirExternalAndNeedsConfirmation isExternalSymlinkedFile isFileExternalAndNeedsConfirmation
_ignoredUris
uris
_ignoredUris
uri uris
_ignoredUris uri
override file _token CancellationToken
_ignoredUris file
accessor ITestingServicesAccessor
instantiationService IInstantiationService
configService InMemoryConfigurationService
ignoreService TestIgnoreService
services
services IWorkspaceService
TestWorkspaceService
ignoreService
services IIgnoreService ignoreService
accessor services
instantiationService accessor IInstantiationService
configService accessor IConfigurationService InMemoryConfigurationService
accessor
configService ConfigKey AdditionalReadAccessPaths
ignoreService
uri readOnly
instantiationService acc acc uri readOnly readOnly
uri readOnly
instantiationService acc acc uri readOnly readOnly
uri
ignoreService uri
instantiationService accessor accessor uri
rejects
uri
realPath
ignoreService realPath
instantiationService accessor accessor uri realPath
rejects
needsConfirmation realPath
rejects
rejects
needsConfirmation realPath
configService ConfigKey AdditionalReadAccessPaths
needsConfirmation realPath
configService ConfigKey AdditionalReadAccessPaths
needsConfirmation realPath
configService ConfigKey AdditionalReadAccessPaths
rejects
configService ConfigKey AdditionalReadAccessPaths
rejects
configService ConfigKey AdditionalReadAccessPaths
configService ConfigKey AdditionalReadAccessPaths
configService ConfigKey AdditionalReadAccessPaths
workingDir
uri
instantiationService acc acc uri readOnly workingDirectory workingDir
uri
instantiationService acc acc uri readOnly workingDirectory workingDir
needsConfirmation realPath
rejects
accessor ITestingServicesAccessor
instantiationService IInstantiationService
mockCustomInstructionsService MockCustomInstructionsService
skillFolderUri
requestId IBuildPromptContext
requestId
query
history
chatVariables
id CustomizationsIndexId
name
value
services
services IWorkspaceService
TestWorkspaceService
mockCustomInstructionsService
skillFolders
skillFolders skillFolderUri
mockCustomInstructionsService
instructions
skills
skillFolders
agents
services ICustomInstructionsService mockCustomInstructionsService
accessor services
instantiationService accessor IInstantiationService
accessor
uri buildPromptContext IBuildPromptContext
instantiationService acc acc uri buildPromptContext
skillFolderUri
subDir
subDir
deepDir
deepDir
siblingDir
siblingDir
parentDir
parentDir
skillFolderUri
accessor ITestingServicesAccessor
instantiationService IInstantiationService
mockFs MockFileSystemService
services
services IWorkspaceService
TestWorkspaceService
mockFs
services IFileSystemService mockFs
accessor services
instantiationService accessor IInstantiationService
accessor
uri
instantiationService acc acc uri
mockFs
needsConfirmation realPath
rejects
mockFs
needsConfirmation realPath
needsConfirmation realPath
describe isWindows
temporaryDirectory
workspaceDirectory
externalDirectory
temporaryDirectory fs path
workspaceDirectory fs fs path temporaryDirectory
externalDirectory fs fs path temporaryDirectory
fs temporaryDirectory recursive force
uri
workspaceUri workspaceDirectory
uri fsPath workspaceDirectory uri fsPath workspaceUri
uri workspaceDirectories workspaceDirectory
services
services IWorkspaceService
TestWorkspaceService
workspaceDirectories file
accessor services
result accessor IInstantiationService acc acc uri
result realPath result realPath fsPath
accessor
externalFile path externalDirectory
symlinkedFile path workspaceDirectory
fs externalFile
fs externalFile symlinkedFile
symlinkedFile getFolder resolves
externalFile path externalDirectory
symlinkedFile path workspaceDirectory
fs externalFile
fs externalFile symlinkedFile
symlinkedFile resolves
needsConfirmation
realPath externalFile
secondWorkspaceDirectory fs fs path temporaryDirectory
targetFile path secondWorkspaceDirectory
symlinkedFile path workspaceDirectory
fs targetFile
fs targetFile symlinkedFile
symlinkedFile workspaceDirectory secondWorkspaceDirectory resolves
needsConfirmation
realPath targetFile
targetFile path workspaceDirectory
symlinkedFile path workspaceDirectory
fs targetFile
fs targetFile symlinkedFile
symlinkedFile resolves
needsConfirmation
realPath targetFile
externalFile path externalDirectory
symlinkedDirectory path workspaceDirectory
fs externalFile
fs externalDirectory symlinkedDirectory
path symlinkedDirectory getFolder resolves
symlinkedDirectory path workspaceDirectory
fs externalDirectory symlinkedDirectory
path symlinkedDirectory getFolder resolves
targetFile path workspaceDirectory
symlinkedFile path workspaceDirectory
fs targetFile
fs targetFile symlinkedFile
symlinkedFile getFolder resolves
file path workspaceDirectory
fs file
file getFolder resolves
path workspaceDirectory getFolder resolves
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result encoded
result isDifferent
result
result isDifferent
result encoded
result
result isDifferent
result encoded
override workspaceFolderUri
posix workspaceFolderUri path
folder1
folder2
workspaceService folder1 folder2
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
result folderRelativePattern
result workspaceService
result patterns
result patterns pattern
result folderName
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
result folderRelativePattern
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
result folderRelativePattern
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
result folderRelativePattern
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
result workspaceService
result patterns
result patterns baseUri folder2 pattern
result folderName
result workspaceService
result patterns
result patterns
result folderName
result workspaceService
result patterns
result patterns
result folderName
singleRoot folder1
result singleRoot
result patterns
result patterns
result folderName
result workspaceService
result patterns
result patterns
result folderName
result workspaceService
result patterns
result patterns
result folderName
workingDirUri
folder1
workspaceService folder1
result workingDirUri workspaceService
result patterns
result patterns baseUri workingDirUri pattern
result workingDirUri workspaceService
result patterns
result patterns baseUri workingDirUri pattern
result workingDirUri workspaceService
result patterns
result patterns baseUri workingDirUri pattern
result folderRelativePattern
result workingDirUri workspaceService
result patterns
result patterns baseUri workingDirUri pattern
result folderRelativePattern
result workingDirUri workspaceService
result patterns
result folderName
multiRoot folder1
result workingDirUri multiRoot
result patterns
result patterns baseUri workingDirUri pattern
result folderName
result workingDirUri workspaceService
result patterns
result patterns baseUri workingDirUri pattern
result workspaceService
result patterns
result patterns baseUri folder1 pattern
result folderName
{
}
from
'../../../../platform/customInstructions/common/customInstructionsService'
;
import
{
}
from
'../../../../platform/filesystem/common/fileSystemService'
;
import
{
}
from
'../../../../platform/filesystem/node/test/mockFileSystemService'
;
import
{
,
}
from
'../../../../platform/ignore/common/ignoreService'
;
import
{
}
from
'../../../../platform/test/common/testCustomInstructionsService'
;
import
{
}
from
'../../../../platform/test/node/services'
;
import
{
}
from
'../../../../platform/test/node/testWorkspaceService'
;
import
{
,
}
from
'../../../../platform/workspace/common/workspaceService'
;
import
{
}
from
'../../../../platform/workspace/common/workingDirectory'
;
import
{
}
from
'../../../../util/vs/base/common/cancellation'
;
import
{
}
from
'../../../../util/vs/base/common/map'
;
import
{
}
from
'../../../../util/vs/base/common/path'
;
import
{
}
from
'../../../../util/vs/base/common/platform'
;
import
{
URI
}
from
'../../../../util/vs/base/common/uri'
;
import
{
}
from
'../../../../util/vs/platform/instantiation/common/descriptors'
;
import
{
}
from
'../../../../util/vs/platform/instantiation/common/instantiation'
;
import
{
,
}
from
'../../../prompt/common/chatVariablesCollection'
;
import
{
}
from
'../../../prompt/common/intents'
;
import
{
}
from
'../../../test/node/services'
;
import
{
}
from
'../../common/toolUtils'
;
import
{
,
,
,
,
}
from
'../toolUtils'
;
class
TestIgnoreService
extends
NullIgnoreService
{
private
readonly
=
new
Set< string >
(
)
;
setIgnoredUris
(
:
URI
[
]
)
:
void
{
this
.
.
clear
(
)
;
for
(
const
of
)
{
this
.
.
add
(
.
toString
(
)
)
;
}
}
async
isCopilotIgnored
(
:
URI
,
?
:
)
:
Promise
<
boolean
>
{
return
this
.
.
has
(
.
toString
(
)
)
;
}
}
suite
(
'toolUtils - additionalReadAccessPaths'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
let
:
;
beforeAll
(
(
)
=>
{
const
=
createExtensionUnitTestingServices
(
)
;
.
define
(
,
new
SyncDescriptor
(
,
[
[
URI
.
file
(
'/workspace'
)
]
,
[
]
]
)
)
;
=
new
TestIgnoreService
(
)
;
.
define
(
,
)
;
=
.
createTestingAccessor
(
)
;
=
.
get
(
)
;
=
.
get
(
)
as
;
}
)
;
afterAll
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
beforeEach
(
async
(
)
=>
{
await
.
setConfig
(
.
,
[
]
)
;
.
setIgnoredUris
(
[
]
)
;
}
)
;
function
invokeIsFileExternalAndNeedsConfirmation
(
:
URI
,
?
:
boolean
)
{
return
.
invokeFunction
(
=>
isFileExternalAndNeedsConfirmation
(
,
,
undefined
,
?
{
}
:
undefined
)
)
;
}
function
invokeIsDirExternalAndNeedsConfirmation
(
:
URI
,
?
:
boolean
)
{
return
.
invokeFunction
(
=>
isDirExternalAndNeedsConfirmation
(
,
,
undefined
,
?
{
}
:
undefined
)
)
;
}
describe
(
'assertFileNotContentExcluded'
,
(
)
=>
{
test
(
'rejects an excluded URI'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace/secret.ts'
)
;
.
setIgnoredUris
(
[
]
)
;
await
expect
(
.
invokeFunction
(
=>
assertFileNotContentExcluded
(
,
)
)
)
.
.
toThrow
(
/ configured to be ignored by Copilot /
)
;
}
)
;
test
(
'rejects an excluded resolved target'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace/link.ts'
)
;
const
=
URI
.
file
(
'/workspace/secret.ts'
)
;
.
setIgnoredUris
(
[
]
)
;
await
expect
(
.
invokeFunction
(
=>
assertFileNotContentExcluded
(
,
,
)
)
)
.
.
toThrow
(
/ configured to be ignored by Copilot /
)
;
}
)
;
}
)
;
describe
(
'isFileExternalAndNeedsConfirmation'
,
(
)
=>
{
test
(
'workspace file does not need confirmation'
,
async
(
)
=>
{
expect
(
await
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/workspace/file.ts'
)
)
)
.
toEqual
(
{
:
false
,
:
undefined
}
)
;
}
)
;
test
(
'external file that does not exist throws'
,
async
(
)
=>
{
await
expect
(
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/file.ts'
)
)
)
.
.
toThrow
(
/ does not exist /
)
;
}
)
;
test
(
'non-existent file throws'
,
async
(
)
=>
{
await
expect
(
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/nonexistent/file.ts'
)
)
)
.
.
toThrow
(
/ does not exist /
)
;
}
)
;
test
(
'non-existent workspace file does not need confirmation'
,
async
(
)
=>
{
expect
(
await
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/workspace/nonexistent.ts'
)
)
)
.
toEqual
(
{
:
false
,
:
undefined
}
)
;
}
)
;
test
(
'external file under additional paths with readOnly does not need confirmation'
,
async
(
)
=>
{
await
.
setConfig
(
.
,
[
'/external'
]
)
;
expect
(
await
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/file.ts'
)
,
true
)
)
.
toEqual
(
{
:
false
,
:
undefined
}
)
;
}
)
;
test
(
'nested file under additional paths with readOnly does not need confirmation'
,
async
(
)
=>
{
await
.
setConfig
(
.
,
[
'/external'
]
)
;
expect
(
await
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/deep/nested/file.ts'
)
,
true
)
)
.
toEqual
(
{
:
false
,
:
undefined
}
)
;
}
)
;
test
(
'external file under additional paths without readOnly throws when file does not exist'
,
async
(
)
=>
{
await
.
setConfig
(
.
,
[
'/external'
]
)
;
await
expect
(
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/file.ts'
)
,
false
)
)
.
.
toThrow
(
/ does not exist /
)
;
}
)
;
test
(
'file outside additional paths throws when file does not exist'
,
async
(
)
=>
{
await
.
setConfig
(
.
,
[
'/allowed'
]
)
;
await
expect
(
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/disallowed/file.ts'
)
,
true
)
)
.
.
toThrow
(
/ does not exist /
)
;
}
)
;
}
)
;
describe
(
'isDirExternalAndNeedsConfirmation'
,
(
)
=>
{
test
(
'workspace dir does not need confirmation'
,
(
)
=>
{
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
URI
.
file
(
'/workspace/subdir'
)
)
)
.
toBe
(
false
)
;
}
)
;
test
(
'external dir needs confirmation by default'
,
(
)
=>
{
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/dir'
)
)
)
.
toBe
(
true
)
;
}
)
;
test
(
'external dir under additional paths with readOnly does not need confirmation'
,
async
(
)
=>
{
await
.
setConfig
(
.
,
[
'/external'
]
)
;
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/dir'
)
,
true
)
)
.
toBe
(
false
)
;
}
)
;
test
(
'subdirectory under additional paths does not need confirmation'
,
async
(
)
=>
{
await
.
setConfig
(
.
,
[
'/external'
]
)
;
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/a/b/c'
)
,
true
)
)
.
toBe
(
false
)
;
}
)
;
test
(
'external dir under additional paths still needs confirmation without readOnly'
,
async
(
)
=>
{
await
.
setConfig
(
.
,
[
'/external'
]
)
;
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/dir'
)
,
false
)
)
.
toBe
(
true
)
;
}
)
;
}
)
;
describe
(
'workingDirectory support'
,
(
)
=>
{
const
=
URI
.
file
(
'/my-project'
)
;
function
invokeIsFileExternalWithWd
(
:
URI
)
{
return
.
invokeFunction
(
=>
isFileExternalAndNeedsConfirmation
(
,
,
undefined
,
{
:
true
,
:
}
)
)
;
}
function
invokeIsDirExternalWithWd
(
:
URI
)
{
return
.
invokeFunction
(
=>
isDirExternalAndNeedsConfirmation
(
,
,
undefined
,
{
:
true
,
:
}
)
)
;
}
test
(
'isFileExternalAndNeedsConfirmation: file within workingDirectory is not external'
,
async
(
)
=>
{
expect
(
await
invokeIsFileExternalWithWd
(
URI
.
file
(
'/my-project/src/file.ts'
)
)
)
.
toEqual
(
{
:
false
,
:
undefined
}
)
;
}
)
;
test
(
'isFileExternalAndNeedsConfirmation: workspace file is external when workingDirectory is set'
,
async
(
)
=>
{
await
expect
(
invokeIsFileExternalWithWd
(
URI
.
file
(
'/workspace/file.ts'
)
)
)
.
.
toThrow
(
/ does not exist /
)
;
}
)
;
test
(
'isDirExternalAndNeedsConfirmation: dir within workingDirectory is not external'
,
(
)
=>
{
expect
(
invokeIsDirExternalWithWd
(
URI
.
file
(
'/my-project/src'
)
)
)
.
toBe
(
false
)
;
}
)
;
test
(
'isDirExternalAndNeedsConfirmation: workspace dir is external when workingDirectory is set'
,
(
)
=>
{
expect
(
invokeIsDirExternalWithWd
(
URI
.
file
(
'/workspace/subdir'
)
)
)
.
toBe
(
true
)
;
}
)
;
test
(
'isDirExternalAndNeedsConfirmation: dir outside workingDirectory is external'
,
(
)
=>
{
expect
(
invokeIsDirExternalWithWd
(
URI
.
file
(
'/other-project/dir'
)
)
)
.
toBe
(
true
)
;
}
)
;
}
)
;
}
)
;
suite
(
'toolUtils - isDirExternalAndNeedsConfirmation with skill folders'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
const
=
URI
.
file
(
'/home/user/.agents/skills/my-skill'
)
;
function
makeBuildPromptContext
(
:
string
)
:
{
return
{
,
:
'test'
,
:
[
]
,
:
new
ChatVariablesCollection
(
[
{
:
,
:
'customizations-index'
,
:
'<index/>'
,
}
]
)
,
}
;
}
beforeAll
(
(
)
=>
{
const
=
createExtensionUnitTestingServices
(
)
;
.
define
(
,
new
SyncDescriptor
(
,
[
[
URI
.
file
(
'/workspace'
)
]
,
[
]
]
)
)
;
=
new
MockCustomInstructionsService
(
)
;
const
=
new
ResourceSet
(
)
;
.
add
(
)
;
.
parseInstructionIndexFile
=
(
)
=>
(
{
:
new
ResourceSet
(
)
,
:
new
ResourceSet
(
)
,
,
:
new
Set< string >
(
)
,
}
)
;
.
define
(
,
)
;
=
.
createTestingAccessor
(
)
;
=
.
get
(
)
;
}
)
;
afterAll
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
function
invokeIsDirExternalAndNeedsConfirmation
(
:
URI
,
?
:
)
{
return
.
invokeFunction
(
=>
isDirExternalAndNeedsConfirmation
(
,
,
)
)
;
}
test
(
'exact skill folder does not need confirmation'
,
(
)
=>
{
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
,
makeBuildPromptContext
(
'req-1'
)
)
)
.
toBe
(
false
)
;
}
)
;
test
(
'subdirectory under skill folder does not need confirmation'
,
(
)
=>
{
const
=
URI
.
file
(
'/home/user/.agents/skills/my-skill/references'
)
;
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
,
makeBuildPromptContext
(
'req-2'
)
)
)
.
toBe
(
false
)
;
}
)
;
test
(
'deeply nested subdirectory under skill folder does not need confirmation'
,
(
)
=>
{
const
=
URI
.
file
(
'/home/user/.agents/skills/my-skill/a/b/c'
)
;
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
,
makeBuildPromptContext
(
'req-3'
)
)
)
.
toBe
(
false
)
;
}
)
;
test
(
'sibling of skill folder still needs confirmation'
,
(
)
=>
{
const
=
URI
.
file
(
'/home/user/.agents/skills/other-skill'
)
;
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
,
makeBuildPromptContext
(
'req-4'
)
)
)
.
toBe
(
true
)
;
}
)
;
test
(
'parent of skill folder still needs confirmation'
,
(
)
=>
{
const
=
URI
.
file
(
'/home/user/.agents/skills'
)
;
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
,
makeBuildPromptContext
(
'req-5'
)
)
)
.
toBe
(
true
)
;
}
)
;
test
(
'without buildPromptContext, external dir needs confirmation'
,
(
)
=>
{
expect
(
invokeIsDirExternalAndNeedsConfirmation
(
)
)
.
toBe
(
true
)
;
}
)
;
}
)
;
suite
(
'toolUtils - external file existence'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
beforeAll
(
(
)
=>
{
const
=
createExtensionUnitTestingServices
(
)
;
.
define
(
,
new
SyncDescriptor
(
,
[
[
URI
.
file
(
'/workspace'
)
]
,
[
]
]
)
)
;
=
new
MockFileSystemService
(
)
;
.
define
(
,
)
;
=
.
createTestingAccessor
(
)
;
=
.
get
(
)
;
}
)
;
afterAll
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
function
invokeIsFileExternalAndNeedsConfirmation
(
:
URI
)
{
return
.
invokeFunction
(
=>
isFileExternalAndNeedsConfirmation
(
,
)
)
;
}
test
(
'external file that exists needs confirmation'
,
async
(
)
=>
{
.
mockFile
(
URI
.
file
(
'/external/existing-file.ts'
)
,
'content'
)
;
expect
(
await
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/existing-file.ts'
)
)
)
.
toEqual
(
{
:
true
,
:
undefined
}
)
;
}
)
;
test
(
'external file that does not exist throws'
,
async
(
)
=>
{
await
expect
(
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/external/nonexistent.ts'
)
)
)
.
.
toThrow
(
/ does not exist /
)
;
}
)
;
test
(
'workspace file does not need confirmation even if it exists'
,
async
(
)
=>
{
.
mockFile
(
URI
.
file
(
'/workspace/file.ts'
)
,
'content'
)
;
expect
(
await
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/workspace/file.ts'
)
)
)
.
toEqual
(
{
:
false
,
:
undefined
}
)
;
}
)
;
test
(
'workspace file does not need confirmation even if it does not exist'
,
async
(
)
=>
{
expect
(
await
invokeIsFileExternalAndNeedsConfirmation
(
URI
.
file
(
'/workspace/nonexistent.ts'
)
)
)
.
toEqual
(
{
:
false
,
:
undefined
}
)
;
}
)
;
}
)
;
.
skipIf
(
)
(
'isExternalSymlinkedFile'
,
(
)
=>
{
let
:
string
;
let
:
string
;
let
:
string
;
beforeEach
(
(
)
=>
{
=
.
mkdtempSync
(
.
join
(
tmpdir
(
)
,
'toolutils-symlink-'
)
)
;
=
.
realpathSync
(
.
mkdtempSync
(
.
join
(
,
'workspace-'
)
)
)
;
=
.
realpathSync
(
.
mkdtempSync
(
.
join
(
,
'external-'
)
)
)
;
}
)
;
afterEach
(
(
)
=>
{
.
rmSync
(
,
{
:
true
,
:
true
}
)
;
}
)
;
function
getFolder
(
:
URI
)
:
URI
|
undefined
{
const
=
URI
.
file
(
)
;
return
.
===
||
.
.
startsWith
(
` ${ workspaceDirectory} ${ path. sep} `
)
?
:
undefined
;
}
async
function
invokeIsFileExternal
(
:
URI
,
=
[
]
)
{
const
=
createExtensionUnitTestingServices
(
)
;
.
define
(
,
new
SyncDescriptor
(
,
[
.
map
(
URI
.
)
,
[
]
]
)
)
;
const
=
.
createTestingAccessor
(
)
;
try
{
const
=
await
.
get
(
)
.
invokeFunction
(
=>
isFileExternalAndNeedsConfirmation
(
,
)
)
;
return
{
...
,
:
.
?.
}
;
}
finally
{
.
dispose
(
)
;
}
}
test
(
'returns true when the file symlink points outside the workspace'
,
async
(
)
=>
{
const
=
.
join
(
,
'external.txt'
)
;
const
=
.
join
(
,
'linked.txt'
)
;
.
writeFileSync
(
,
'content'
)
;
.
symlinkSync
(
,
)
;
await
expect
(
isExternalSymlinkedFile
(
URI
.
file
(
)
,
)
)
.
.
toBe
(
true
)
;
}
)
;
test
(
'returns the real path when a workspace symlink points outside the workspace'
,
async
(
)
=>
{
const
=
.
join
(
,
'external.txt'
)
;
const
=
.
join
(
,
'linked.txt'
)
;
.
writeFileSync
(
,
'content'
)
;
.
symlinkSync
(
,
)
;
await
expect
(
invokeIsFileExternal
(
URI
.
file
(
)
)
)
.
.
toEqual
(
{
:
true
,
:
,
}
)
;
}
)
;
test
(
'does not require confirmation when a workspace symlink points into another workspace folder'
,
async
(
)
=>
{
const
=
.
realpathSync
(
.
mkdtempSync
(
.
join
(
,
'workspace-'
)
)
)
;
const
=
.
join
(
,
'target.txt'
)
;
const
=
.
join
(
,
'linked.txt'
)
;
.
writeFileSync
(
,
'content'
)
;
.
symlinkSync
(
,
)
;
await
expect
(
invokeIsFileExternal
(
URI
.
file
(
)
,
[
,
]
)
)
.
.
toEqual
(
{
:
false
,
:
,
}
)
;
}
)
;
test
(
'returns the real path without confirmation when a symlink target is inside the workspace'
,
async
(
)
=>
{
const
=
.
join
(
,
'target.txt'
)
;
const
=
.
join
(
,
'linked.txt'
)
;
.
writeFileSync
(
,
'content'
)
;
.
symlinkSync
(
,
)
;
await
expect
(
invokeIsFileExternal
(
URI
.
file
(
)
)
)
.
.
toEqual
(
{
:
false
,
:
,
}
)
;
}
)
;
test
(
'returns true when a parent directory symlink points outside the workspace'
,
async
(
)
=>
{
const
=
.
join
(
,
'external.txt'
)
;
const
=
.
join
(
,
'linked'
)
;
.
writeFileSync
(
,
'content'
)
;
.
symlinkSync
(
,
,
'dir'
)
;
await
expect
(
isExternalSymlinkedFile
(
URI
.
file
(
.
join
(
,
'external.txt'
)
)
,
)
)
.
.
toBe
(
true
)
;
}
)
;
test
(
'returns true for a nonexistent file under a parent directory symlink that points outside the workspace'
,
async
(
)
=>
{
const
=
.
join
(
,
'linked'
)
;
.
symlinkSync
(
,
,
'dir'
)
;
await
expect
(
isExternalSymlinkedFile
(
URI
.
file
(
.
join
(
,
'missing.txt'
)
)
,
)
)
.
.
toBe
(
true
)
;
}
)
;
test
(
'returns false when the symlink target is inside the workspace'
,
async
(
)
=>
{
const
=
.
join
(
,
'target.txt'
)
;
const
=
.
join
(
,
'linked.txt'
)
;
.
writeFileSync
(
,
'content'
)
;
.
symlinkSync
(
,
)
;
await
expect
(
isExternalSymlinkedFile
(
URI
.
file
(
)
,
)
)
.
.
toBe
(
false
)
;
}
)
;
test
(
'returns false when the file is not a symlink'
,
async
(
)
=>
{
const
=
.
join
(
,
'file.txt'
)
;
.
writeFileSync
(
,
'content'
)
;
await
expect
(
isExternalSymlinkedFile
(
URI
.
file
(
)
,
)
)
.
.
toBe
(
false
)
;
}
)
;
test
(
'returns false when the file does not exist'
,
async
(
)
=>
{
await
expect
(
isExternalSymlinkedFile
(
URI
.
file
(
.
join
(
,
'missing.txt'
)
)
,
)
)
.
.
toBe
(
false
)
;
}
)
;
}
)
;
describe
(
'encodeUrlHostname'
,
(
)
=>
{
describe
(
'ASCII URLs'
,
(
)
=>
{
it
(
'handles standard ASCII domain'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://example.com'
)
;
expect
(
.
)
.
toBe
(
'https://example.com'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'handles ASCII domain with path'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://example.com/path/to/page'
)
;
expect
(
.
)
.
toBe
(
'https://example.com/path/to/page'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'handles ASCII domain with query string'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://example.com/page?foo=bar&baz=qux'
)
;
expect
(
.
)
.
toBe
(
'https://example.com/page?foo=bar&baz=qux'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'handles ASCII domain with fragment'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://example.com/page#section'
)
;
expect
(
.
)
.
toBe
(
'https://example.com/page#section'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'handles http scheme'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'http://example.com'
)
;
expect
(
.
)
.
toBe
(
'http://example.com'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
}
)
;
describe
(
'internationalized domain names (IDN)'
,
(
)
=>
{
it
(
'encodes Cyrillic domain'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://пример.рф'
)
;
expect
(
.
)
.
toBe
(
'https://xn--e1afmkfd.xn--p1ai'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'encodes Chinese domain'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://例え.jp'
)
;
expect
(
.
)
.
toBe
(
'https://xn--r8jz45g.jp'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'encodes German domain with umlaut'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://müller.de'
)
;
expect
(
.
)
.
toBe
(
'https://xn--mller-kva.de'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'encodes Arabic domain'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://مثال.السعودية'
)
;
expect
(
.
)
.
toBe
(
'https://xn--mgbh0fb.xn--mgberp4a5d4ar'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'preserves path when encoding IDN'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://пример.рф/path/to/page'
)
;
expect
(
.
)
.
toBe
(
'https://xn--e1afmkfd.xn--p1ai/path/to/page'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'preserves query string when encoding IDN'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://пример.рф?foo=bar'
)
;
expect
(
.
)
.
toBe
(
'https://xn--e1afmkfd.xn--p1ai?foo=bar'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
}
)
;
describe
(
'URLs with port'
,
(
)
=>
{
it
(
'handles ASCII domain with port'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://example.com:8080'
)
;
expect
(
.
)
.
toBe
(
'https://example.com:8080'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'encodes IDN with port'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://пример.рф:8080'
)
;
expect
(
.
)
.
toBe
(
'https://xn--e1afmkfd.xn--p1ai:8080'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'handles port with path'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://пример.рф:8080/path'
)
;
expect
(
.
)
.
toBe
(
'https://xn--e1afmkfd.xn--p1ai:8080/path'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
}
)
;
describe
(
'URLs with userinfo'
,
(
)
=>
{
it
(
'handles userinfo with ASCII domain'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://user:pass@example.com'
)
;
expect
(
.
)
.
toBe
(
'https://user:pass@example.com'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'encodes IDN with userinfo'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://user:pass@пример.рф'
)
;
expect
(
.
)
.
toBe
(
'https://user:pass@xn--e1afmkfd.xn--p1ai'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'handles userinfo with port'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://user:pass@пример.рф:8080'
)
;
expect
(
.
)
.
toBe
(
'https://user:pass@xn--e1afmkfd.xn--p1ai:8080'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'handles username without password'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://user@пример.рф'
)
;
expect
(
.
)
.
toBe
(
'https://user@xn--e1afmkfd.xn--p1ai'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
}
)
;
describe
(
'subdomain handling'
,
(
)
=>
{
it
(
'encodes subdomain with non-ASCII characters'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://поддомен.пример.рф'
)
;
expect
(
.
)
.
toBe
(
'https://xn--d1aad1agbce.xn--e1afmkfd.xn--p1ai'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'handles mixed ASCII and non-ASCII subdomains'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://www.пример.рф'
)
;
expect
(
.
)
.
toBe
(
'https://www.xn--e1afmkfd.xn--p1ai'
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
}
)
;
describe
(
'edge cases'
,
(
)
=>
{
it
(
'handles localhost'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'http://localhost:3000'
)
;
expect
(
.
)
.
toBe
(
'http://localhost:3000'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'handles IP address'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'http://192.168.1.1:8080'
)
;
expect
(
.
)
.
toBe
(
'http://192.168.1.1:8080'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'handles IPv6 address'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'http://[::1]:8080'
)
;
expect
(
.
)
.
toBe
(
'http://[::1]:8080'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'handles empty authority gracefully'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'file:///path/to/file'
)
;
expect
(
.
)
.
toBe
(
'file:///path/to/file'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'handles invalid URL gracefully'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'not a url'
)
;
expect
(
.
)
.
toBe
(
'not a url'
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
}
)
;
describe
(
'homograph attack prevention'
,
(
)
=>
{
it
(
'encodes Cyrillic "a" that looks like Latin "a"'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://exаmple.com'
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toContain
(
'xn--'
)
;
}
)
;
it
(
'encodes Greek omicron that looks like Latin "o"'
,
(
)
=>
{
const
=
encodeUrlHostname
(
'https://gοοgle.com'
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toContain
(
'xn--'
)
;
}
)
;
}
)
;
}
)
;
class
MultiRootWorkspaceService
extends
NullWorkspaceService
{
getWorkspaceFolderName
(
:
URI
)
:
string
{
return
.
basename
(
.
)
;
}
}
describe
(
'inputGlobToPattern - multi-root workspace'
,
(
)
=>
{
const
=
URI
.
file
(
'/workspace/vscode'
)
;
const
=
URI
.
file
(
'/workspace/vscode-copilot-chat'
)
;
const
=
new
MultiRootWorkspaceService
(
[
,
]
)
;
test
(
'absolute path to workspace folder root resolves to empty relative pattern'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/workspace/vscode'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
''
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
expect
(
.
)
.
toBe
(
''
)
;
}
)
;
test
(
'absolute path to workspace folder root with trailing slash'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/workspace/vscode/'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
''
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
}
)
;
test
(
'absolute path with subdirectory'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/workspace/vscode/src'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'src'
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
expect
(
.
)
.
toBe
(
'src'
)
;
}
)
;
test
(
'absolute path with glob pattern'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/workspace/vscode/src/**/*.ts'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'src/**/*.ts'
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
expect
(
.
)
.
toBe
(
'src/**/*.ts'
)
;
}
)
;
test
(
'bare folder name resolves to ** pattern'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'vscode'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'**'
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
}
)
;
test
(
'folder name with glob suffix'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'vscode/**'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'**'
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
}
)
;
test
(
'folder name with subdirectory pattern'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'vscode/src/**/*.ts'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'src/**/*.ts'
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
expect
(
.
)
.
toBe
(
'src/**/*.ts'
)
;
}
)
;
test
(
'**/folderName resolves to folder'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'**/vscode'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'**'
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
}
)
;
test
(
'**/folderName/rest resolves to folder with pattern'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'**/vscode/src/**/*.ts'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'src/**/*.ts'
}
)
;
expect
(
.
)
.
toBe
(
'vscode'
)
;
}
)
;
test
(
'second folder name resolves correctly'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'vscode-copilot-chat/src/**'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'src/**'
}
)
;
expect
(
.
)
.
toBe
(
'vscode-copilot-chat'
)
;
}
)
;
test
(
'does not rewrite when folder name is unknown'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'**/unknown-folder/src/**'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toBe
(
'**/unknown-folder/src/**'
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
test
(
'does not rewrite wildcard-only patterns'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'**/*.ts'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toBe
(
'**/*.ts'
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
test
(
'does not rewrite folder names in single-root workspace'
,
(
)
=>
{
const
=
new
MultiRootWorkspaceService
(
[
]
)
;
const
=
inputGlobToPattern
(
'**/vscode/src/**'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toBe
(
'**/vscode/src/**'
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
test
(
'absolute path outside workspace is not rewritten'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/other/path'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toBe
(
'/other/path'
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
test
(
'plain glob pattern passes through'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'src/**/*.ts'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toBe
(
'src/**/*.ts'
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
}
)
;
describe
(
'inputGlobToPattern - workingDirectory'
,
(
)
=>
{
const
=
URI
.
file
(
'/projects/ski-planner'
)
;
const
=
URI
.
file
(
'/workspace/other-project'
)
;
const
=
new
MultiRootWorkspaceService
(
[
]
)
;
test
(
'unscoped glob pattern is scoped to workingDirectory'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'**/*.ts'
,
new
WorkingDirectory
(
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'**/*.ts'
}
)
;
}
)
;
test
(
'unscoped relative pattern is scoped to workingDirectory'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'src/**'
,
new
WorkingDirectory
(
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'src/**'
}
)
;
}
)
;
test
(
'absolute path within workingDirectory is resolved relative to it'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/projects/ski-planner/src/index.ts'
,
new
WorkingDirectory
(
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'src/index.ts'
}
)
;
expect
(
.
)
.
toBe
(
'src/index.ts'
)
;
}
)
;
test
(
'absolute path outside workingDirectory is not rewritten to relative'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/other/path/file.ts'
,
new
WorkingDirectory
(
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'/other/path/file.ts'
}
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
test
(
'absolute path in workspace folder is NOT resolved against workspace when workingDirectory is set'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/workspace/other-project/src'
,
new
WorkingDirectory
(
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
test
(
'folder-name rewriting is suppressed when workingDirectory is set'
,
(
)
=>
{
const
=
new
MultiRootWorkspaceService
(
[
,
URI
.
file
(
'/workspace/vscode'
)
]
)
;
const
=
inputGlobToPattern
(
'vscode/src/**'
,
new
WorkingDirectory
(
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'vscode/src/**'
}
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
test
(
'bare wildcard is scoped to workingDirectory'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'*'
,
new
WorkingDirectory
(
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'*'
}
)
;
}
)
;
test
(
'without workingDirectory, falls back to workspace folders for absolute paths'
,
(
)
=>
{
const
=
inputGlobToPattern
(
'/workspace/other-project/src'
,
new
WorkingDirectory
(
undefined
,
)
,
undefined
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
.
[
0
]
)
.
toMatchObject
(
{
:
,
:
'src'
}
)
;
expect
(
.
)
.
toBe
(
'other-project'
)
;
}
)
;
}
)
;