ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / platform / agentHost / test / common / agentHostFileSystemProvider.test.ts 1073 строк · изменён 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
import assert from 'assert' ;
import { timeout } from '../../../../base/common/async.js' ;
import { VSBuffer } from '../../../../base/common/buffer.js' ;
import { Emitter, Event } from '../../../../base/common/event.js' ;
import { URI } from '../../../../base/common/uri.js' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js' ;
import { FileChangeType, FilePermission, FileSystemProviderErrorCode, FileType, IFileChange, toFileSystemProviderErrorCode } from
AgentHostFileSystemProvider agentHostRemotePath agentHostUri
remoteAgentHostSessionTypeId
agentHostAuthority createAgentHostResourceUriMapper fromAgentHostUri identityAgentHostResourceUriMapper isAgentHostContentRefUri toAgentHostContentUri toAgentHostUri
ContentEncoding ResourceType
AhpErrorCodes
ProtocolError
uri
assert uri scheme
assert uri authority
assert uri path
uri
assert uri
original
uri original
assert uri original
assert
assert
assert
assert
assert
assert
authority
assert authority
assert
assert
assert
assert
assert
authority
wrapped authority
assert
authority
normalizedAuthority
similarAddressAuthority
wrappedScheme wrapped scheme
wrappedAuthority wrapped authority
authority
normalizedAuthority
similarAddressAuthority
wrappedScheme
wrappedAuthority
cases
results cases agentHostAuthority
unique results
assert unique size cases length
addresses
address addresses
authority address
uri scheme authority path
assert uri authority authority
addresses
address addresses
authority address
scheme authority
uri scheme path
assert uri scheme scheme
original
wrapped original
assert wrapped scheme
assert wrapped authority
unwrapped wrapped
assert unwrapped scheme
assert unwrapped path original path
original scheme authority path
wrapped original
unwrapped wrapped
assert unwrapped scheme
assert unwrapped authority
assert unwrapped path
original
scheme
path
query sessionUri sha
fragment
wrapped original
unwrapped wrapped
assert
wrappedPath wrapped path
wrappedFragment wrapped fragment
unwrapped unwrapped
wrappedPath original path
wrappedFragment original fragment
unwrapped original
original
result original
assert result original
original
asContent original
asFile original
assert
contentMarked asContent
fileMarked asFile
plainUriMarked original
roundTripped asContent
contentMarked
fileMarked
plainUriMarked
roundTripped original
original
assert original original
original
remote
mapped remote original
assert
mapped mapped
unmapped remote mapped
localFrom identityAgentHostResourceUriMapper original
localTo identityAgentHostResourceUriMapper original
mapped original
unmapped original
localFrom original
localTo original
authority
uri authority
assert uri scheme
assert uri authority authority
assert uri path
uri scheme authority path
result uri
assert result scheme
assert result path
authority
originalPath
encodedUri authority originalPath
assert formatting label
assert encodedUri path originalPath
originalUri scheme authority path
encodedUri originalUri
assert encodedUri path
originalUri
scheme
path
query sessionUri sha
encodedUri originalUri
assert encodedUri path
disposables
listCalls
name
uri ResourceListResult
listCalls uri
entries name type
ResourceReadResult data encoding ContentEncoding Utf8
params ResourceResolveParams ResourceResolveResult
uri params uri params uri params uri
uri uri type ResourceType File
provider disposables
first
second
firstRegistration disposables provider first
disposables provider second
firstRegistration
entries provider
assert entries firstCalls first listCalls secondCalls second listCalls uri uri
entries FileType File
firstCalls
secondCalls
provider disposables
first
second
disposables provider first
secondRegistration provider second
secondRegistration
entries provider
assert entries firstCalls first listCalls uri uri secondCalls second listCalls
entries FileType File
firstCalls
secondCalls
provider disposables
first
second
firstRegistration provider first
firstRegistration
pending provider
disposables provider second
entries pending
assert entries firstCalls first listCalls secondCalls second listCalls uri uri
entries FileType File
firstCalls
secondCalls
provider disposables
first
firstRegistration provider first
firstRegistration
pending provider
caught
pending
err
caught err
assert caught
assert caught Error FileSystemProviderErrorCode Unavailable
provider disposables
caught
provider
err
caught err
assert caught
assert caught Error FileSystemProviderErrorCode Unavailable
disposables
readCalls
readEncodings ContentEncoding
listCalls
resolveCalls ResourceResolveParams
readResult ResourceReadResult data encoding ContentEncoding Utf8 contentType
uri encoding ContentEncoding ResourceReadResult
readCalls uri
readEncodings encoding
readResult
uri ResourceListResult
listCalls uri
entries
params ResourceResolveParams ResourceResolveResult
resolveCalls params
uri params uri params uri params uri
uri uri type ResourceType File
provider disposables
connection
disposables provider connection
provider connection
provider connection
inner scheme authority path
wrapped inner
stat provider wrapped
assert stat type FileType File
assert connection listCalls
provider connection
inner scheme authority path
wrapped inner
stat provider wrapped
assert stat type FileType File
assert connection listCalls
provider disposables
connection
disposables provider connection
wrapped
provider wrapped
assert connection resolveCalls length
assert connection listCalls length
provider disposables
connection
disposables provider connection
inner
wrapped inner
stat provider wrapped
assert
type stat type
stat permissions FilePermission Readonly
resolved connection resolveCalls length
listed connection listCalls length
type FileType File
resolved
listed
provider disposables
connection
disposables provider connection
inner
wrapped inner
path provider wrapped
assert path resolved connection resolveCalls length
path wrapped path
resolved
provider disposables
connection
disposables provider connection
wrapped
stat provider wrapped
assert wrappedPath wrapped path type stat type
wrappedPath
type FileType File
provider disposables
connection
disposables provider connection
inner
bytes provider inner
assert
content VSBuffer bytes
resources connection readCalls u u
content
resources inner
provider connection
inner scheme authority path
wrapped inner
bytes provider wrapped
assert VSBuffer bytes
assert
resources connection readCalls u u
encodings connection readEncodings
resources inner
encodings ContentEncoding Base64
provider connection
disposables provider connection
connection readResult data encoding ContentEncoding Base64 contentType
bytes provider
assert bytes
provider
inner scheme authority path
wrapped inner
stat provider wrapped
assert stat type FileType File
bytes provider wrapped
assert VSBuffer bytes
disposables
readError
writeError
listError
deleteError
moveError
copyError
resolveError
mkdirError
requestError
requestCalls ResourceRequestParams
hasResourceRequest
ResourceReadResult
readError readError
data encoding ContentEncoding Utf8
ResourceListResult
listError listError
entries
writeError writeError
copyError copyError
deleteError deleteError
moveError moveError
params ResourceResolveParams ResourceResolveResult
resolveError resolveError
uri params uri params uri params uri
uri uri type ResourceType File
mkdirError mkdirError
resourceRequest params ResourceRequestParams ResourceRequestResult
requestCalls params
requestError requestError
opts withResourceRequest
provider disposables
connection
opts withResourceRequest
connection hasResourceRequest
connection resourceRequest
disposables provider connection
provider connection
uri ProtocolError
AhpErrorCodes PermissionDenied request uri read
provider connection
wrapped
connection readError wrapped
provider wrapped
assert
err
assert
err err
FileSystemProviderErrorCode NoPermissions
provider connection
wrapped
connection readError
provider wrapped
assert
err
assert
err err
FileSystemProviderErrorCode FileNotFound
provider connection
wrapped
denied wrapped
connection writeError denied
connection deleteError denied
connection moveError denied
connection listError denied
codes FileSystemProviderErrorCode
err
codes err err
provider wrapped create overwrite unlock atomic
provider wrapped recursive useTrash atomic
provider wrapped overwrite
provider wrapped
assert codes
FileSystemProviderErrorCode NoPermissions
FileSystemProviderErrorCode NoPermissions
FileSystemProviderErrorCode NoPermissions
FileSystemProviderErrorCode NoPermissions
provider connection
wrapped
provider wrapped read write
assert connection requestCalls
channel uri read write
provider withResourceRequest
wrapped
provider wrapped read
assert
err
assert
err err
FileSystemProviderErrorCode Unavailable
provider connection
wrapped
connection requestError wrapped
provider wrapped read
assert
err
assert
err err
FileSystemProviderErrorCode NoPermissions
disposables
resolveCalls ResourceResolveParams
mkdirCalls ResourceMkdirParams
copyCalls ResourceCopyParams
watchCalls CreateResourceWatchParams
nextWatchHandle onDidChange Event IFileChange
watchError
nextResolveResult ResourceResolveResult uri type ResourceType File size mtime etag
ResourceReadResult data encoding ContentEncoding Utf8
ResourceListResult entries
params ResourceCopyParams
copyCalls params
params ResourceResolveParams ResourceResolveResult
resolveCalls params
nextResolveResult uri params uri params uri params uri
params ResourceMkdirParams
mkdirCalls params
params CreateResourceWatchParams onDidChange Event IFileChange
watchCalls params
watchError
watchError
nextWatchHandle
nextWatchHandle
provider disposables
connection
disposables provider connection
provider connection
provider connection
connection nextResolveResult uri type ResourceType Directory size mtime
wrapped
stat provider wrapped
assert stat type FileType Directory
assert stat mtime Date
assert connection resolveCalls length
provider connection
connection nextResolveResult uri type ResourceType File size mtime
wrapped
stat provider wrapped
assert stat permissions
provider connection
connection resourceResolve params ResourceResolveParams ResourceResolveResult
connection resolveCalls params
uri type ResourceType File
wrapped
real provider wrapped
assert real path
assert connection resolveCalls length
provider connection
wrapped
provider wrapped
assert connection mkdirCalls length
assert connection mkdirCalls uri wrapped
provider connection
from
to
provider from to overwrite
assert connection copyCalls length
assert connection copyCalls source from
assert connection copyCalls destination to
assert connection copyCalls failIfExists
provider connection
onDidChange
handleDisposed
connection nextWatchHandle
onDidChange onDidChange event
handleDisposed onDidChange
wrapped
received IFileChange
sub provider c received c
watchDisposable provider wrapped recursive excludes
resolve resolve
assert connection watchCalls length
assert connection watchCalls recursive
assert connection watchCalls excludes items
incomingChange IFileChange resource type FileChangeType
expectedChange IFileChange resource type FileChangeType
onDidChange incomingChange
assert received expectedChange
watchDisposable
assert handleDisposed
sub
provider connection
onDidChange
connection nextWatchHandle
onDidChange onDidChange event
onDidChange
wrapped
watchDisposable provider wrapped
recursive
excludes
includes base pattern
resolve resolve
assert connection watchCalls includes items
watchDisposable
provider connection
connection watchError
wrapped
errors
sub provider message errors message
watchDisposable provider wrapped recursive excludes
assert errors
watchDisposable
sub
provider connection
onDidChange
handleDisposed
handleCreated
connection nextWatchHandle
onDidChange onDidChange event
handleDisposed onDidChange
originalWatchResource connection connection
connection params
handleCreated
params
wrapped
watchDisposable provider wrapped recursive excludes
assert handleCreated
watchDisposable
assert handleDisposed
provider disposables
first
firstChanges
firstHandleDisposed
first nextWatchHandle
onDidChange firstChanges event
firstHandleDisposed firstChanges
firstReg provider first
wrapped
received IFileChange
disposables provider c received c
disposables provider wrapped recursive excludes
firstChanges resource type FileChangeType
firstReg
second
secondChanges
secondHandleDisposed
second nextWatchHandle
onDidChange secondChanges event
secondHandleDisposed secondChanges
disposables provider second
secondChanges resource type FileChangeType
assert
firstWatchCalls first watchCalls length
secondWatchCalls second watchCalls length
firstHandleDisposed
secondHandleDisposed
received received batch batch c c resource c type
firstWatchCalls
secondWatchCalls
firstHandleDisposed
secondHandleDisposed
received
FileChangeType
FileChangeType
provider disposables
wrapped
received IFileChange
disposables provider c received c
disposables provider wrapped recursive excludes
r r
connection
changes
connection nextWatchHandle
onDidChange changes event
changes
disposables provider connection
changes resource type FileChangeType
assert connection watchCalls length
assert received length
assert received resource
'../../../files/common/files.js'
;
import
{
,
,
,
type
IRemoteFilesystemConnection
}
from
'../../common/agentHostFileSystemProvider.js'
;
import
{
}
from
'../../common/agentHostSessionType.js'
;
import
{
AGENT_HOST_LABEL_FORMATTER
,
AGENT_HOST_SCHEME
,
,
,
,
,
,
,
}
from
'../../common/agentHostUri.js'
;
import
{
,
,
type
CreateResourceWatchParams
,
type
ResourceCopyParams
,
type
ResourceListResult
,
type
ResourceMkdirParams
,
type
ResourceReadResult
,
type
ResourceRequestParams
,
type
ResourceRequestResult
,
type
ResourceResolveParams
,
type
ResourceResolveResult
}
from
'../../common/state/protocol/commands.js'
;
import
{
}
from
'../../common/state/protocol/errors.js'
;
import
{
}
from
'../../common/state/sessionProtocol.js'
;
import
{
ROOT_STATE_URI
}
from
'../../common/state/sessionState.js'
;
suite
(
'AgentHostFileSystemProvider - URI helpers'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'agentHostUri builds correct URI'
,
(
)
=>
{
const
=
agentHostUri
(
'localhost'
,
'/home/user/project'
)
;
.
strictEqual
(
.
,
AGENT_HOST_SCHEME
)
;
.
strictEqual
(
.
,
'localhost'
)
;
.
ok
(
.
.
includes
(
'/home/user/project'
)
)
;
}
)
;
test
(
'agentHostRemotePath extracts the original path'
,
(
)
=>
{
const
=
agentHostUri
(
'host'
,
'/some/path'
)
;
.
strictEqual
(
agentHostRemotePath
(
)
,
'/some/path'
)
;
}
)
;
test
(
'agentHostRemotePath round-trips with agentHostUri'
,
(
)
=>
{
const
=
'/home/user/project'
;
const
=
agentHostUri
(
'host'
,
)
;
.
strictEqual
(
agentHostRemotePath
(
)
,
)
;
}
)
;
}
)
;
suite
(
'AgentHostAuthority - encoding'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'lowercase alphanumeric address is returned as-is'
,
(
)
=>
{
.
strictEqual
(
agentHostAuthority
(
'localhost'
)
,
'localhost'
)
;
}
)
;
test
(
'normal host:port address uses human-readable encoding'
,
(
)
=>
{
.
strictEqual
(
agentHostAuthority
(
'localhost:8081'
)
,
'localhost__8081'
)
;
.
strictEqual
(
agentHostAuthority
(
'192.168.1.1:8080'
)
,
'192.168.1.1__8080'
)
;
.
strictEqual
(
agentHostAuthority
(
'my-host:9090'
)
,
'my-host__9090'
)
;
.
strictEqual
(
agentHostAuthority
(
'host.name:80'
)
,
'host.name__80'
)
;
}
)
;
test
(
'address with uppercase or underscore falls through to hex'
,
(
)
=>
{
.
strictEqual
(
agentHostAuthority
(
'LOCALHOST'
)
,
'hex-4c4f43414c484f5354'
)
;
const
=
agentHostAuthority
(
'host_name:8080'
)
;
.
ok
(
.
startsWith
(
'hex-'
)
,
` expected hex for underscore address, got: ${ authority} `
)
;
}
)
;
test
(
'address with exotic characters is hex-encoded'
,
(
)
=>
{
.
ok
(
agentHostAuthority
(
'user@host:8080'
)
.
startsWith
(
'hex-'
)
)
;
.
ok
(
agentHostAuthority
(
'host with spaces'
)
.
startsWith
(
'hex-'
)
)
;
.
ok
(
agentHostAuthority
(
'http://myhost:3000'
)
.
startsWith
(
'hex-'
)
)
;
}
)
;
test
(
'ws:// prefix is normalized so authority matches bare address'
,
(
)
=>
{
.
strictEqual
(
agentHostAuthority
(
'ws://127.0.0.1:8080'
)
,
agentHostAuthority
(
'127.0.0.1:8080'
)
)
;
.
strictEqual
(
agentHostAuthority
(
'ws://localhost:9090'
)
,
agentHostAuthority
(
'localhost:9090'
)
)
;
}
)
;
test
(
'remote local address does not collide with the ambient authority'
,
(
)
=>
{
const
=
agentHostAuthority
(
'local'
)
;
const
=
toAgentHostUri
(
URI
.
file
(
'/remote/file.txt'
)
,
)
;
.
deepStrictEqual
(
{
,
:
agentHostAuthority
(
'ws://local'
)
,
:
agentHostAuthority
(
'remote_local'
)
,
:
.
,
:
.
,
}
,
{
:
'remote_local'
,
:
'remote_local'
,
:
'hex-72656d6f74655f6c6f63616c'
,
:
AGENT_HOST_SCHEME
,
:
'remote_local'
,
}
)
;
}
)
;
test
(
'different addresses produce different authorities'
,
(
)
=>
{
const
=
[
'localhost:8080'
,
'localhost:8081'
,
'192.168.1.1:8080'
,
'host-name:80'
,
'host.name:80'
,
'host_name:80'
,
'user@host:8080'
,
'_'
,
'hex-5f'
,
'HEX-5f'
]
;
const
=
.
map
(
)
;
const
=
new
Set
(
)
;
.
strictEqual
(
.
,
.
,
'all authorities must be unique'
)
;
}
)
;
test
(
'authority is valid in a URI authority position'
,
(
)
=>
{
const
=
[
'localhost'
,
'LOCALHOST'
,
'localhost:8081'
,
'user@host:8080'
,
'host with spaces'
,
'wss://example.com/Path'
,
'192.168.1.1:9090'
]
;
for
(
const
of
)
{
const
=
agentHostAuthority
(
)
;
const
=
URI
.
from
(
{
:
AGENT_HOST_SCHEME
,
,
:
'/test'
}
)
;
.
strictEqual
(
URI
.
parse
(
.
toString
(
)
)
.
,
,
` authority for ' ${ address} ' must round-trip through URI serialization `
)
;
}
}
)
;
test
(
'authority is valid in a URI scheme position'
,
(
)
=>
{
const
=
[
'localhost'
,
'LOCALHOST'
,
'localhost:8081'
,
'user@host:8080'
,
'host with spaces'
,
'wss://example.com/Path'
]
;
for
(
const
of
)
{
const
=
agentHostAuthority
(
)
;
const
=
remoteAgentHostSessionTypeId
(
,
'copilot'
)
;
const
=
URI
.
from
(
{
,
:
'/test'
}
)
;
.
strictEqual
(
URI
.
parse
(
.
toString
(
)
)
.
,
,
` scheme for ' ${ address} ' must round-trip through URI serialization `
)
;
}
}
)
;
}
)
;
suite
(
'toAgentHostUri / fromAgentHostUri'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'round-trips a file URI'
,
(
)
=>
{
const
=
URI
.
file
(
'/home/user/project/file.ts'
)
;
const
=
toAgentHostUri
(
,
'my-server'
)
;
.
strictEqual
(
.
,
AGENT_HOST_SCHEME
)
;
.
strictEqual
(
.
,
'my-server'
)
;
const
=
fromAgentHostUri
(
)
;
.
strictEqual
(
.
,
'file'
)
;
.
strictEqual
(
.
,
.
)
;
}
)
;
test
(
'round-trips a URI with authority'
,
(
)
=>
{
const
=
URI
.
from
(
{
:
'agenthost-content'
,
:
'session1'
,
:
'/snap/before'
}
)
;
const
=
toAgentHostUri
(
,
'remote-host'
)
;
const
=
fromAgentHostUri
(
)
;
.
strictEqual
(
.
,
'agenthost-content'
)
;
.
strictEqual
(
.
,
'session1'
)
;
.
strictEqual
(
.
,
'/snap/before'
)
;
}
)
;
test
(
'round-trips query and fragment for synthetic content URIs'
,
(
)
=>
{
const
=
URI
.
from
(
{
:
'git-blob'
,
:
'/src/app.ts'
,
:
JSON
.
stringify
(
{
:
'copilot:/abc'
,
:
'cafe1234'
}
)
,
:
'L1'
,
}
)
;
const
=
toAgentHostUri
(
,
'remote-host'
)
;
const
=
fromAgentHostUri
(
)
;
.
deepStrictEqual
(
{
:
.
,
:
.
,
:
.
toString
(
)
,
}
,
{
:
.
,
:
.
,
:
.
toString
(
)
,
}
)
;
}
)
;
test
(
'local authority returns original URI unchanged'
,
(
)
=>
{
const
=
URI
.
file
(
'/workspace/test.ts'
)
;
const
=
toAgentHostUri
(
,
'local'
)
;
.
strictEqual
(
.
toString
(
)
,
.
toString
(
)
)
;
}
)
;
test
(
'a content ref is marked as one and still round-trips'
,
(
)
=>
{
const
=
URI
.
parse
(
'ahp-session:/ab456a26/changeset/turncontent/2011679d'
)
;
const
=
toAgentHostContentUri
(
,
'remote-host'
)
;
const
=
toAgentHostUri
(
,
'remote-host'
)
;
.
deepStrictEqual
(
{
:
isAgentHostContentRefUri
(
)
,
:
isAgentHostContentRefUri
(
)
,
:
isAgentHostContentRefUri
(
)
,
:
fromAgentHostUri
(
)
.
toString
(
)
,
}
,
{
:
true
,
:
false
,
:
false
,
:
.
toString
(
)
,
}
)
;
}
)
;
test
(
'a content ref that is a plain file on the local connection stays unwrapped'
,
(
)
=>
{
const
=
URI
.
file
(
'/workspace/test.ts'
)
;
.
strictEqual
(
toAgentHostContentUri
(
,
'local'
)
.
toString
(
)
,
.
toString
(
)
)
;
}
)
;
test
(
'resource URI mappers translate remote resources and preserve local resources'
,
(
)
=>
{
const
=
URI
.
file
(
'/remote/file.txt'
)
;
const
=
createAgentHostResourceUriMapper
(
'remote-host'
)
;
const
=
.
fromAgentHost
(
)
;
.
deepStrictEqual
(
{
:
.
toString
(
)
,
:
.
toAgentHost
(
)
.
toString
(
)
,
:
.
fromAgentHost
(
)
.
toString
(
)
,
:
.
toAgentHost
(
)
.
toString
(
)
,
}
,
{
:
toAgentHostUri
(
,
'remote-host'
)
.
toString
(
)
,
:
.
toString
(
)
,
:
.
toString
(
)
,
:
.
toString
(
)
,
}
)
;
}
)
;
test
(
'agentHostUri for root path produces valid encoded URI'
,
(
)
=>
{
const
=
agentHostAuthority
(
'localhost:8089'
)
;
const
=
agentHostUri
(
,
'/'
)
;
.
strictEqual
(
.
,
AGENT_HOST_SCHEME
)
;
.
strictEqual
(
.
,
)
;
.
strictEqual
(
fromAgentHostUri
(
)
.
,
'/'
)
;
}
)
;
test
(
'fromAgentHostUri falls back to a file URI when metadata is missing'
,
(
)
=>
{
const
=
URI
.
from
(
{
:
AGENT_HOST_SCHEME
,
:
'host'
,
:
'/file'
}
)
;
const
=
fromAgentHostUri
(
)
;
.
strictEqual
(
.
,
'file'
)
;
.
strictEqual
(
.
,
'/file'
)
;
}
)
;
}
)
;
suite
(
'AGENT_HOST_LABEL_FORMATTER'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'label is the original path verbatim for file URIs'
,
(
)
=>
{
const
=
agentHostAuthority
(
'localhost:8089'
)
;
const
=
'/Users/roblou/code/vscode'
;
const
=
agentHostUri
(
,
)
;
.
strictEqual
(
AGENT_HOST_LABEL_FORMATTER
.
.
,
'${path}'
)
;
.
strictEqual
(
.
,
)
;
}
)
;
test
(
'label is the original path verbatim for URIs with authority'
,
(
)
=>
{
const
=
URI
.
from
(
{
:
'agenthost-content'
,
:
'myhost'
,
:
'/snap/before'
}
)
;
const
=
toAgentHostUri
(
,
'remote-host'
)
;
.
strictEqual
(
.
,
'/snap/before'
)
;
}
)
;
test
(
'label is the original path verbatim for git-blob URIs'
,
(
)
=>
{
const
=
URI
.
from
(
{
:
'git-blob'
,
:
'/src/app.ts'
,
:
JSON
.
stringify
(
{
:
'copilot:/abc'
,
:
'cafe1234'
}
)
,
}
)
;
const
=
toAgentHostUri
(
,
'remote-host'
)
;
.
strictEqual
(
.
,
'/src/app.ts'
)
;
}
)
;
}
)
;
suite
(
'AgentHostFileSystemProvider - authority registrations'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
class
NamedConnection
implements
IRemoteFilesystemConnection
{
readonly
:
URI
[
]
=
[
]
;
constructor
(
private
readonly
:
string
)
{
}
async
resourceList
(
:
URI
)
:
Promise
<
>
{
this
.
.
push
(
)
;
return
{
:
[
{
:
` ${ this . name} .txt `
,
:
'file'
}
]
}
;
}
async
resourceRead
(
)
:
Promise
<
>
{
return
{
:
''
,
:
.
}
;
}
async
resourceWrite
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceCopy
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceDelete
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceMove
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceResolve
(
:
)
:
Promise
<
>
{
const
=
typeof
.
===
'string'
?
URI
.
parse
(
.
)
:
URI
.
revive
(
.
)
!
;
return
{
:
.
toString
(
)
,
:
.
}
;
}
async
resourceMkdir
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
}
test
(
'disposing a stale registration does not remove a newer registration for the same authority'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
NamedConnection
(
'first'
)
;
const
=
new
NamedConnection
(
'second'
)
;
const
=
.
add
(
.
registerAuthority
(
'client'
,
)
)
;
.
add
(
.
registerAuthority
(
'client'
,
)
)
;
.
dispose
(
)
;
const
=
await
.
readdir
(
agentHostUri
(
'client'
,
'/workspace'
)
)
;
.
deepStrictEqual
(
{
,
:
.
,
:
.
.
map
(
=>
.
toString
(
)
)
}
,
{
:
[
[
'second.txt'
,
.
]
]
,
:
[
]
,
:
[
URI
.
file
(
'/workspace'
)
.
toString
(
)
]
,
}
)
;
}
)
;
test
(
'disposing the newest registration falls back to the previous one without entering grace'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
NamedConnection
(
'first'
)
;
const
=
new
NamedConnection
(
'second'
)
;
.
add
(
.
registerAuthority
(
'client'
,
)
)
;
const
=
.
registerAuthority
(
'client'
,
)
;
.
dispose
(
)
;
const
=
await
.
readdir
(
agentHostUri
(
'client'
,
'/workspace'
)
)
;
.
deepStrictEqual
(
{
,
:
.
.
map
(
=>
.
toString
(
)
)
,
:
.
}
,
{
:
[
[
'first.txt'
,
.
]
]
,
:
[
URI
.
file
(
'/workspace'
)
.
toString
(
)
]
,
:
[
]
,
}
)
;
}
)
;
test
(
'operation issued during reconnect window waits for the replacement registration'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
50
)
)
;
const
=
new
NamedConnection
(
'first'
)
;
const
=
new
NamedConnection
(
'second'
)
;
const
=
.
registerAuthority
(
'client'
,
)
;
.
dispose
(
)
;
const
=
.
readdir
(
agentHostUri
(
'client'
,
'/workspace'
)
)
;
.
add
(
.
registerAuthority
(
'client'
,
)
)
;
const
=
await
;
.
deepStrictEqual
(
{
,
:
.
,
:
.
.
map
(
=>
.
toString
(
)
)
}
,
{
:
[
[
'second.txt'
,
.
]
]
,
:
[
]
,
:
[
URI
.
file
(
'/workspace'
)
.
toString
(
)
]
,
}
)
;
}
)
;
test
(
'operation issued in the grace window rejects with Unavailable when no reconnect arrives'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
20
)
)
;
const
=
new
NamedConnection
(
'first'
)
;
const
=
.
registerAuthority
(
'client'
,
)
;
.
dispose
(
)
;
const
=
.
readdir
(
agentHostUri
(
'client'
,
'/workspace'
)
)
;
let
:
unknown
;
try
{
await
;
}
catch
(
)
{
=
;
}
.
ok
(
instanceof
Error
,
'expected an error'
)
;
.
strictEqual
(
toFileSystemProviderErrorCode
(
as
)
,
.
)
;
}
)
;
test
(
'operation rejects immediately when no authority was ever registered'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
50
)
)
;
let
:
unknown
;
try
{
await
.
readdir
(
agentHostUri
(
'never'
,
'/workspace'
)
)
;
}
catch
(
)
{
=
;
}
.
ok
(
instanceof
Error
,
'expected an error'
)
;
.
strictEqual
(
toFileSystemProviderErrorCode
(
as
)
,
.
)
;
}
)
;
}
)
;
suite
(
'AgentHostFileSystemProvider - synthetic content schemes'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
class
StubConnection
implements
IRemoteFilesystemConnection
{
readonly
:
URI
[
]
=
[
]
;
readonly
:
(
|
undefined
)
[
]
=
[
]
;
readonly
:
URI
[
]
=
[
]
;
readonly
:
[
]
=
[
]
;
:
=
{
:
'stub-content'
,
:
.
,
:
'text/plain'
}
;
async
resourceRead
(
:
URI
,
?
:
)
:
Promise
<
>
{
this
.
.
push
(
)
;
this
.
.
push
(
)
;
return
this
.
;
}
async
resourceList
(
:
URI
)
:
Promise
<
>
{
this
.
.
push
(
)
;
return
{
:
[
]
}
;
}
async
resourceWrite
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceCopy
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceDelete
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceMove
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceResolve
(
:
)
:
Promise
<
>
{
this
.
.
push
(
)
;
const
=
typeof
.
===
'string'
?
URI
.
parse
(
.
)
:
URI
.
revive
(
.
)
!
;
return
{
:
.
toString
(
)
,
:
.
}
;
}
async
resourceMkdir
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
}
function
setup
(
)
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
StubConnection
(
)
;
.
add
(
.
registerAuthority
(
'local'
,
)
)
;
return
{
,
}
;
}
test
(
'stat returns File for git-blob: URIs without listing the parent'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
URI
.
from
(
{
:
'git-blob'
,
:
'sess1'
,
:
'/sha/encoded/file.ts'
}
)
;
const
=
toAgentHostUri
(
,
'local'
)
;
const
=
await
.
stat
(
)
;
.
strictEqual
(
.
,
.
)
;
.
deepStrictEqual
(
.
,
[
]
,
'stat must not list a synthetic parent directory'
)
;
}
)
;
test
(
'stat returns File for session-db: URIs (parity with git-blob)'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
URI
.
from
(
{
:
'session-db'
,
:
'sess1'
,
:
'/snap/some-blob'
}
)
;
const
=
toAgentHostUri
(
,
'local'
)
;
const
=
await
.
stat
(
)
;
.
strictEqual
(
.
,
.
)
;
.
deepStrictEqual
(
.
,
[
]
)
;
}
)
;
test
(
'stat uses resourceResolve for ordinary file: URIs'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
StubConnection
(
)
;
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
const
=
agentHostUri
(
'remote'
,
'/some/file.ts'
)
;
await
.
stat
(
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
.
,
0
)
;
}
)
;
test
(
'stat treats a marked content ref as a read-only file whatever its scheme'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
StubConnection
(
)
;
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
const
=
URI
.
parse
(
'ahp-session:/ab456a26/changeset/turncontent/2011679d'
)
;
const
=
toAgentHostContentUri
(
,
'remote'
)
;
const
=
await
.
stat
(
)
;
.
deepStrictEqual
(
{
:
.
,
readonly
:
.
===
.
,
:
.
.
,
:
.
.
,
}
,
{
:
.
,
readonly
:
true
,
:
0
,
:
0
,
}
)
;
}
)
;
test
(
'realpath returns a marked content ref unchanged without resolving it'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
StubConnection
(
)
;
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
const
=
URI
.
parse
(
'ahp-session:/ab456a26/changeset/turncontent/2011679d'
)
;
const
=
toAgentHostContentUri
(
,
'remote'
)
;
const
=
await
.
realpath
(
)
;
.
deepStrictEqual
(
{
,
:
.
.
}
,
{
:
.
,
:
0
,
}
)
;
}
)
;
test
(
'stat reports a pathless content ref as a file, not the provider root'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
StubConnection
(
)
;
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
const
=
toAgentHostContentUri
(
URI
.
parse
(
'agenthost-content://session'
)
,
'remote'
)
;
const
=
await
.
stat
(
)
;
.
deepStrictEqual
(
{
:
.
,
:
.
}
,
{
:
'/'
,
:
.
,
}
)
;
}
)
;
test
(
'readFile still asks the host for the content ref it declined to stat'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
StubConnection
(
)
;
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
const
=
URI
.
parse
(
'ahp-session:/ab456a26/changeset/turncontent/2011679d'
)
;
const
=
await
.
readFile
(
toAgentHostContentUri
(
,
'remote'
)
)
;
.
deepStrictEqual
(
{
:
.
wrap
(
)
.
toString
(
)
,
:
.
.
map
(
=>
.
toString
(
)
)
,
}
,
{
:
'stub-content'
,
:
[
.
toString
(
)
]
,
}
)
;
}
)
;
test
(
'readFile passes the decoded synthetic URI through to the connection'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
URI
.
from
(
{
:
'git-blob'
,
:
'sess1'
,
:
'/sha/encoded/file.ts'
}
)
;
const
=
toAgentHostUri
(
,
'local'
)
;
const
=
await
.
readFile
(
)
;
.
strictEqual
(
.
wrap
(
)
.
toString
(
)
,
'stub-content'
)
;
.
deepStrictEqual
(
{
:
.
.
map
(
=>
.
toString
(
)
)
,
:
.
,
}
,
{
:
[
.
toString
(
)
]
,
:
[
.
]
,
}
)
;
}
)
;
test
(
'readFile decodes binary Base64 content'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
.
=
{
:
'UEsAAf8='
,
:
.
,
:
'application/zip'
}
;
const
=
await
.
readFile
(
agentHostUri
(
'remote'
,
'/tmp/logs.zip'
)
)
;
.
deepStrictEqual
(
[
...
]
,
[
80
,
75
,
0
,
1
,
255
]
)
;
}
)
;
test
(
'full stat-then-read round-trip mirrors the diff editor flow'
,
async
(
)
=>
{
const
{
}
=
setup
(
)
;
const
=
URI
.
from
(
{
:
'git-blob'
,
:
'sess1'
,
:
'/sha/encoded/file.ts'
}
)
;
const
=
toAgentHostUri
(
,
'local'
)
;
const
=
await
.
stat
(
)
;
.
strictEqual
(
.
,
.
)
;
const
=
await
.
readFile
(
)
;
.
strictEqual
(
.
wrap
(
)
.
toString
(
)
,
'stub-content'
)
;
}
)
;
}
)
;
suite
(
'AgentHostFileSystemProvider - permission errors and requestResourceAccess'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
class
ConfigurableConnection
implements
IRemoteFilesystemConnection
{
:
unknown
|
undefined
;
:
unknown
|
undefined
;
:
unknown
|
undefined
;
:
unknown
|
undefined
;
:
unknown
|
undefined
;
:
unknown
|
undefined
;
:
unknown
|
undefined
;
:
unknown
|
undefined
;
:
unknown
|
undefined
;
readonly
:
[
]
=
[
]
;
=
true
;
async
resourceRead
(
)
:
Promise
<
>
{
if
(
this
.
)
{
throw
this
.
;
}
return
{
:
''
,
:
.
}
;
}
async
resourceList
(
)
:
Promise
<
>
{
if
(
this
.
)
{
throw
this
.
;
}
return
{
:
[
]
}
;
}
async
resourceWrite
(
)
:
Promise
<
{
}
>
{
if
(
this
.
)
{
throw
this
.
;
}
return
{
}
;
}
async
resourceCopy
(
)
:
Promise
<
{
}
>
{
if
(
this
.
)
{
throw
this
.
;
}
return
{
}
;
}
async
resourceDelete
(
)
:
Promise
<
{
}
>
{
if
(
this
.
)
{
throw
this
.
;
}
return
{
}
;
}
async
resourceMove
(
)
:
Promise
<
{
}
>
{
if
(
this
.
)
{
throw
this
.
;
}
return
{
}
;
}
async
resourceResolve
(
:
)
:
Promise
<
>
{
if
(
this
.
)
{
throw
this
.
;
}
const
=
typeof
.
===
'string'
?
URI
.
parse
(
.
)
:
URI
.
revive
(
.
)
!
;
return
{
:
.
toString
(
)
,
:
.
}
;
}
async
resourceMkdir
(
)
:
Promise
<
{
}
>
{
if
(
this
.
)
{
throw
this
.
;
}
return
{
}
;
}
?
=
async
(
:
)
:
Promise
<
>
=>
{
this
.
.
push
(
)
;
if
(
this
.
)
{
throw
this
.
;
}
return
{
}
;
}
;
}
function
setup
(
:
{
?
:
boolean
}
=
{
}
)
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
ConfigurableConnection
(
)
;
if
(
.
===
false
)
{
.
=
false
;
delete
.
;
}
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
return
{
,
}
;
}
function
permissionDenied
(
:
string
)
:
{
return
new
ProtocolError
(
.
,
'denied'
,
{
:
{
,
:
true
}
}
)
;
}
test
(
'readFile maps PermissionDenied to NoPermissions (not FileNotFound)'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
agentHostUri
(
'remote'
,
'/secret'
)
;
.
=
permissionDenied
(
.
toString
(
)
)
;
try
{
await
.
readFile
(
)
;
.
fail
(
'expected readFile to reject'
)
;
}
catch
(
)
{
.
strictEqual
(
toFileSystemProviderErrorCode
(
instanceof
Error
?
:
undefined
)
,
.
,
)
;
}
}
)
;
test
(
'readFile still maps generic errors to FileNotFound'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
agentHostUri
(
'remote'
,
'/missing'
)
;
.
=
new
Error
(
'boom'
)
;
try
{
await
.
readFile
(
)
;
.
fail
(
'expected readFile to reject'
)
;
}
catch
(
)
{
.
strictEqual
(
toFileSystemProviderErrorCode
(
instanceof
Error
?
:
undefined
)
,
.
,
)
;
}
}
)
;
test
(
'writeFile / delete / rename / readdir all surface NoPermissions on PermissionDenied'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
agentHostUri
(
'remote'
,
'/no-write'
)
;
const
=
permissionDenied
(
.
toString
(
)
)
;
.
=
;
.
=
;
.
=
;
.
=
;
const
:
(
|
undefined
)
[
]
=
[
]
;
const
collect
=
async
(
op
:
(
)
=>
Promise
<
unknown
>
)
=>
{
try
{
await
op
(
)
;
}
catch
(
)
{
.
push
(
toFileSystemProviderErrorCode
(
instanceof
Error
?
:
undefined
)
)
;
}
}
;
await
collect
(
(
)
=>
.
writeFile
(
,
new
Uint8Array
(
)
,
{
:
true
,
:
true
,
:
false
,
:
false
}
)
)
;
await
collect
(
(
)
=>
.
delete
(
,
{
:
false
,
:
false
,
:
false
}
)
)
;
await
collect
(
(
)
=>
.
rename
(
,
agentHostUri
(
'remote'
,
'/dst'
)
,
{
:
true
}
)
)
;
await
collect
(
(
)
=>
.
readdir
(
)
)
;
.
deepStrictEqual
(
,
[
.
,
.
,
.
,
.
,
]
)
;
}
)
;
test
(
'requestResourceAccess forwards the decoded URI and access flags'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
agentHostUri
(
'remote'
,
'/etc/foo'
)
;
await
.
requestResourceAccess
(
,
{
:
true
,
:
true
}
)
;
.
deepStrictEqual
(
.
,
[
{
:
ROOT_STATE_URI
,
:
URI
.
file
(
'/etc/foo'
)
.
toString
(
)
,
:
true
,
:
true
}
,
]
)
;
}
)
;
test
(
'requestResourceAccess throws Unavailable when the connection has no resourceRequest'
,
async
(
)
=>
{
const
{
}
=
setup
(
{
:
false
}
)
;
const
=
agentHostUri
(
'remote'
,
'/etc/foo'
)
;
try
{
await
.
requestResourceAccess
(
,
{
:
true
}
)
;
.
fail
(
'expected requestResourceAccess to reject'
)
;
}
catch
(
)
{
.
strictEqual
(
toFileSystemProviderErrorCode
(
instanceof
Error
?
:
undefined
)
,
.
,
)
;
}
}
)
;
test
(
'requestResourceAccess maps PermissionDenied to NoPermissions'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
agentHostUri
(
'remote'
,
'/etc/foo'
)
;
.
=
permissionDenied
(
.
toString
(
)
)
;
try
{
await
.
requestResourceAccess
(
,
{
:
true
}
)
;
.
fail
(
'expected requestResourceAccess to reject'
)
;
}
catch
(
)
{
.
strictEqual
(
toFileSystemProviderErrorCode
(
instanceof
Error
?
:
undefined
)
,
.
,
)
;
}
}
)
;
}
)
;
suite
(
'AgentHostFileSystemProvider - resolve / mkdir / copy / watch'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
class
FullConnection
implements
IRemoteFilesystemConnection
{
readonly
:
[
]
=
[
]
;
readonly
:
[
]
=
[
]
;
readonly
:
[
]
=
[
]
;
readonly
:
[
]
=
[
]
;
:
{
:
<
readonly
[
]
>
;
dispose
(
)
:
void
}
|
undefined
;
:
unknown
|
undefined
;
:
=
{
:
''
,
:
.
,
:
42
,
:
'2026-01-15T12:34:56.789Z'
,
:
'etag-1'
}
;
async
resourceRead
(
)
:
Promise
<
>
{
return
{
:
''
,
:
.
}
;
}
async
resourceList
(
)
:
Promise
<
>
{
return
{
:
[
]
}
;
}
async
resourceWrite
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceDelete
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceMove
(
)
:
Promise
<
{
}
>
{
return
{
}
;
}
async
resourceCopy
(
:
)
:
Promise
<
{
}
>
{
this
.
.
push
(
)
;
return
{
}
;
}
async
resourceResolve
(
:
)
:
Promise
<
>
{
this
.
.
push
(
)
;
return
{
...
this
.
,
:
typeof
.
===
'string'
?
.
:
URI
.
revive
(
.
)
.
toString
(
)
}
;
}
async
resourceMkdir
(
:
)
:
Promise
<
{
}
>
{
this
.
.
push
(
)
;
return
{
}
;
}
async
watchResource
(
:
)
:
Promise
<
{
:
<
readonly
[
]
>
;
dispose
(
)
:
void
}
>
{
this
.
.
push
(
)
;
if
(
this
.
)
{
throw
this
.
;
}
if
(
!
this
.
)
{
throw
new
Error
(
'test forgot to set nextWatchHandle'
)
;
}
return
this
.
;
}
}
function
setup
(
)
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
)
)
;
const
=
new
FullConnection
(
)
;
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
return
{
,
}
;
}
test
(
'stat uses resourceResolve when available and maps size/mtime/type'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
.
=
{
:
''
,
:
.
,
:
0
,
:
'2026-01-15T00:00:00.000Z'
}
;
const
=
agentHostUri
(
'remote'
,
'/some/dir'
)
;
const
=
await
.
stat
(
)
;
.
strictEqual
(
.
,
.
)
;
.
strictEqual
(
.
,
.
parse
(
'2026-01-15T00:00:00.000Z'
)
)
;
.
strictEqual
(
.
.
,
1
,
'resourceResolve was called'
)
;
}
)
;
test
(
'stat does not mark resolved files readonly so they remain editable'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
.
=
{
:
''
,
:
.
,
:
10
,
:
'2026-01-15T00:00:00.000Z'
}
;
const
=
agentHostUri
(
'remote'
,
'/some/file.ts'
)
;
const
=
await
.
stat
(
)
;
.
strictEqual
(
.
??
0
,
0
,
'resolved files must not carry the Readonly permission'
)
;
}
)
;
test
(
'realpath re-encodes the connection canonical URI back into provider space'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
.
=
async
(
:
)
:
Promise
<
>
=>
{
.
.
push
(
)
;
return
{
:
'file:///real/target.ts'
,
:
.
}
;
}
;
const
=
agentHostUri
(
'remote'
,
'/link/source.ts'
)
;
const
=
await
.
realpath
(
)
;
.
strictEqual
(
,
agentHostUri
(
'remote'
,
'/real/target.ts'
)
.
)
;
.
strictEqual
(
.
.
,
1
)
;
}
)
;
test
(
'mkdir delegates to resourceMkdir'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
agentHostUri
(
'remote'
,
'/new/dir'
)
;
await
.
mkdir
(
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
[
0
]
.
,
fromAgentHostUri
(
)
.
toString
(
)
)
;
}
)
;
test
(
'copy delegates to resourceCopy with overwrite mapped to !failIfExists'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
agentHostUri
(
'remote'
,
'/a'
)
;
const
=
agentHostUri
(
'remote'
,
'/b'
)
;
await
.
copy
(
,
,
{
:
false
}
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
[
0
]
.
,
fromAgentHostUri
(
)
.
toString
(
)
)
;
.
strictEqual
(
.
[
0
]
.
,
fromAgentHostUri
(
)
.
toString
(
)
)
;
.
strictEqual
(
.
[
0
]
.
,
true
)
;
}
)
;
test
(
'watch starts watchResource, forwards changes to onDidChangeFile, dispose tears down handle'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
new
Emitter< readonly IFileChange[ ] >
(
)
;
let
=
false
;
.
=
{
:
.
,
dispose
:
(
)
=>
{
=
true
;
.
dispose
(
)
;
}
,
}
;
const
=
agentHostUri
(
'remote'
,
'/watched'
)
;
const
:
[
]
[
]
=
[
]
;
const
=
.
onDidChangeFile
(
=>
.
push
(
[
...
]
)
)
;
const
=
.
watch
(
,
{
:
true
,
:
[
'**/node_modules/**'
]
}
)
;
await
new
Promise < void >
(
=>
queueMicrotask
(
)
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
[
0
]
.
,
true
)
;
.
deepStrictEqual
(
.
[
0
]
.
,
{
:
[
'**/node_modules/**'
]
}
)
;
const
:
=
{
:
URI
.
parse
(
'file:///watched/a.txt'
)
,
:
.
UPDATED
}
;
const
:
=
{
:
toAgentHostUri
(
URI
.
parse
(
'file:///watched/a.txt'
)
,
'remote'
)
,
:
.
UPDATED
}
;
.
fire
(
[
]
)
;
.
deepStrictEqual
(
,
[
[
]
]
)
;
.
dispose
(
)
;
.
strictEqual
(
,
true
,
'underlying handle should be disposed when wrapper is disposed'
)
;
.
dispose
(
)
;
}
)
;
test
(
'watch forwards includes patterns to watchResource'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
new
Emitter< readonly IFileChange[ ] >
(
)
;
.
=
{
:
.
,
dispose
:
(
)
=>
.
dispose
(
)
,
}
;
const
=
agentHostUri
(
'remote'
,
'/watched'
)
;
const
=
.
watch
(
,
{
:
false
,
:
[
]
,
:
[
'**/*.ts'
,
{
:
'/watched'
,
:
'**/*.md'
}
]
,
}
)
;
await
new
Promise < void >
(
=>
queueMicrotask
(
)
)
;
.
deepStrictEqual
(
.
[
0
]
.
,
{
:
[
'**/*.ts'
,
'**/*.md'
]
}
)
;
.
dispose
(
)
;
}
)
;
test
(
'watch setup failures are surfaced on onDidWatchError'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
.
=
new
Error
(
'watch setup failed'
)
;
const
=
agentHostUri
(
'remote'
,
'/watched'
)
;
const
:
string
[
]
=
[
]
;
const
=
.
onDidWatchError
(
=>
.
push
(
)
)
;
const
=
.
watch
(
,
{
:
false
,
:
[
]
}
)
;
await
timeout
(
0
)
;
.
deepStrictEqual
(
,
[
'watch setup failed'
]
)
;
.
dispose
(
)
;
.
dispose
(
)
;
}
)
;
test
(
'watch disposed before async setup completes still tears down the handle'
,
async
(
)
=>
{
const
{
,
}
=
setup
(
)
;
const
=
new
Emitter< readonly IFileChange[ ] >
(
)
;
let
=
false
;
let
=
false
;
.
=
{
:
.
,
dispose
:
(
)
=>
{
=
true
;
.
dispose
(
)
;
}
,
}
;
const
=
.
watchResource
.
bind
(
)
;
.
watchResource
=
async
=>
{
=
true
;
await
timeout
(
0
)
;
return
originalWatchResource
(
)
;
}
;
const
=
agentHostUri
(
'remote'
,
'/watched'
)
;
const
=
.
watch
(
,
{
:
false
,
:
[
]
}
)
;
await
timeout
(
0
)
;
.
strictEqual
(
,
true
)
;
.
dispose
(
)
;
await
timeout
(
0
)
;
await
timeout
(
0
)
;
.
strictEqual
(
,
true
)
;
}
)
;
test
(
'watch reattaches to the next connection registered for the authority after disconnect'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
20
)
)
;
const
=
new
FullConnection
(
)
;
const
=
new
Emitter< readonly IFileChange[ ] >
(
)
;
let
=
false
;
.
=
{
:
.
,
dispose
:
(
)
=>
{
=
true
;
.
dispose
(
)
;
}
,
}
;
const
=
.
registerAuthority
(
'remote'
,
)
;
const
=
agentHostUri
(
'remote'
,
'/watched'
)
;
const
:
[
]
[
]
=
[
]
;
.
add
(
.
onDidChangeFile
(
=>
.
push
(
[
...
]
)
)
)
;
.
add
(
.
watch
(
,
{
:
false
,
:
[
]
}
)
)
;
await
timeout
(
0
)
;
await
timeout
(
0
)
;
.
fire
(
[
{
:
URI
.
file
(
'/watched/a.txt'
)
,
:
.
UPDATED
}
]
)
;
.
dispose
(
)
;
const
=
new
FullConnection
(
)
;
const
=
new
Emitter< readonly IFileChange[ ] >
(
)
;
let
=
false
;
.
=
{
:
.
,
dispose
:
(
)
=>
{
=
true
;
.
dispose
(
)
;
}
,
}
;
.
add
(
.
registerAuthority
(
'remote'
,
)
)
;
await
timeout
(
0
)
;
await
timeout
(
0
)
;
.
fire
(
[
{
:
URI
.
file
(
'/watched/b.txt'
)
,
:
.
ADDED
}
]
)
;
.
deepStrictEqual
(
{
:
.
.
,
:
.
.
,
,
,
:
.
map
(
=>
.
map
(
=>
[
.
.
toString
(
)
,
.
]
)
)
,
}
,
{
:
1
,
:
1
,
:
true
,
:
false
,
:
[
[
[
agentHostUri
(
'remote'
,
'/watched/a.txt'
)
.
toString
(
)
,
.
UPDATED
]
]
,
[
[
agentHostUri
(
'remote'
,
'/watched/b.txt'
)
.
toString
(
)
,
.
ADDED
]
]
,
]
,
}
)
;
}
)
;
test
(
'watch attaches to a freshly-registered authority that did not exist when watch() was called'
,
async
(
)
=>
{
const
=
.
add
(
new
AgentHostFileSystemProvider
(
20
)
)
;
const
=
agentHostUri
(
'never-registered'
,
'/path'
)
;
const
:
[
]
[
]
=
[
]
;
.
add
(
.
onDidChangeFile
(
=>
.
push
(
[
...
]
)
)
)
;
.
add
(
.
watch
(
,
{
:
false
,
:
[
]
}
)
)
;
await
new
Promise
(
=>
setTimeout
(
,
40
)
)
;
const
=
new
FullConnection
(
)
;
const
=
new
Emitter< readonly IFileChange[ ] >
(
)
;
.
=
{
:
.
,
dispose
:
(
)
=>
.
dispose
(
)
,
}
;
.
add
(
.
registerAuthority
(
'never-registered'
,
)
)
;
await
timeout
(
0
)
;
await
timeout
(
0
)
;
.
fire
(
[
{
:
URI
.
file
(
'/path/late.txt'
)
,
:
.
ADDED
}
]
)
;
.
strictEqual
(
.
.
,
1
,
'watch attached after late registration'
)
;
.
strictEqual
(
.
,
1
)
;
.
strictEqual
(
[
0
]
[
0
]
.
.
toString
(
)
,
agentHostUri
(
'never-registered'
,
'/path/late.txt'
)
.
toString
(
)
)
;
}
)
;
}
)
;