ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / platform / sandbox / test / common / terminalSandboxEngine.test.ts 928 строк · изменён 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
import { deepStrictEqual, ok, strictEqual } from 'assert' ;
import { VSBuffer } from '../../../../base/common/buffer.js' ;
import { Emitter } from '../../../../base/common/event.js' ;
import { OperatingSystem } from '../../../../base/common/platform.js' ;
import { arch } from '../../../../base/common/process.js' ;
import { URI } from '../../../../base/common/uri.js' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js' ;
import IFileService
TestInstantiationService
ILogService NullLogService
AgentNetworkDomainSettingId
ISandboxDependencyStatus IWindowsMxcConfig IWindowsMxcFilesystemPolicy IWindowsMxcPolicyContainment IWindowsMxcSandboxPolicy
AgentSandboxEnabledValue AgentSandboxSettingId
ITerminalSandboxEngineHost ITerminalSandboxRuntimeInfo TerminalSandboxEngine
IWindowsMxcTerminalSandboxRuntime WindowsMxcTerminalSandboxRuntime
TerminalSandboxPrerequisiteCheck TerminalSandboxPreCheckRemediation
store
instantiationService TestInstantiationService
sandboxSettings Map
sandboxSettingsEmitter Emitter
fileService MockFileService
createdFiles Map
createFileCount
createdFolders
key value
sandboxSettings key value
sandboxSettingsEmitter
_realpaths
path realpath
_realpaths path realpath
uri
realpath _realpaths uri path
realpath uri path realpath
uri content VSBuffer
createFileCount
contentString content
createdFiles uri path contentString
createdFiles uri fsPath contentString
uri path
createdFiles uri path contentString
uri
createdFolders uri path
_uri
commandLine policy IWindowsMxcSandboxPolicy workingDirectory containerName containment IWindowsMxcPolicyContainment IWindowsMxcConfig
clearPolicy policy filesystem clearPolicyOnExit
network
defaultPolicy policy network allowOutbound
policy network allowLocalNetwork allowLocalNetwork policy network allowLocalNetwork
policy network enforcementMode
version policy version
containerId containerName
containment
lifecycle
destroyOnExit
preservePolicy clearPolicy
process
commandLine
cwd workingDirectory
timeout policy timeoutMs
processContainer
leastPrivilege
capabilities policy network allowOutbound
ui
isolation
desktopSystemControl
systemSettings
ime
filesystem
readwritePaths policy filesystem readwritePaths
readonlyPaths policy filesystem readonlyPaths
deniedPaths policy filesystem deniedPaths
network
ui
disable policy ui allowWindows
clipboard policy ui clipboard
injection policy ui allowInputInjection
overrides Partial ITerminalSandboxEngineHost ITerminalSandboxEngineHost rootsEmitter Emitter
rootsEmitter
defaultRuntime ITerminalSandboxRuntimeInfo
appRoot
execPath
runAsNode
host ITerminalSandboxEngineHost
OperatingSystem Linux
defaultRuntime
onDidChangeRoots rootsEmitter event
checkSandboxDependencies ISandboxDependencyStatus bubblewrapInstalled bubblewrapUsable socatInstalled
getWindowsMxcFilesystemPolicy IWindowsMxcFilesystemPolicy
getWindowsMxcEnvironment
buildWindowsMxcSandboxPayload commandLine policy workingDirectory containerName containment IWindowsMxcConfig commandLine policy workingDirectory containerName containment
getSandboxSetting settingId sandboxSettings settingId sandboxSettings settingId
onDidChangeSandboxSettings sandboxSettingsEmitter event
overrides
Object host rootsEmitter
overrides Partial ITerminalSandboxEngineHost ITerminalSandboxEngineHost rootsEmitter Emitter
OperatingSystem Windows
appRoot arch
scheme path
scheme path
scheme path
scheme path
readonlyPaths readwritePaths
overrides
path
path
AgentSandboxSettingId AgentSandboxWindowsEnabled AgentSandboxEnabledValue On
AgentSandboxSettingId AgentSandboxAllowNetwork
createdFiles
createFileCount
createdFolders
instantiationService store
sandboxSettings
sandboxSettingsEmitter store
fileService
sandboxSettings AgentSandboxSettingId AgentSandboxEnabled AgentSandboxEnabledValue On
sandboxSettings AgentSandboxSettingId AgentSandboxRetryWithAllowNetworkRequests
instantiationService IFileService fileService
instantiationService ILogService
instantiationService IWindowsMxcTerminalSandboxRuntime instantiationService WindowsMxcTerminalSandboxRuntime
host
appRoot execPath runAsNode
engine store instantiationService TerminalSandboxEngine host
engine
wrapped engine
wrapped isSandboxWrapped
wrapped command
host
appRoot execPath runAsNode
engine store instantiationService TerminalSandboxEngine host
engine
wrapped engine
wrapped isSandboxWrapped
wrapped command
host
engine store instantiationService TerminalSandboxEngine host
engine
wrapped engine
wrapped command
host OperatingSystem Macintosh
engine store instantiationService TerminalSandboxEngine host
configPath engine
configPath
config createdFiles configPath
config allowPty
engine store instantiationService TerminalSandboxEngine
configPath engine
configPath
config createdFiles configPath
Object prototype config
engine store instantiationService TerminalSandboxEngine
configPath engine
configPath
config createdFiles configPath
allowRead config filesystem allowRead
allowWrite config filesystem allowWrite
allowRead
allowWrite
AgentSandboxSettingId AgentSandboxAdvancedRuntime allowPty
host OperatingSystem Macintosh
engine store instantiationService TerminalSandboxEngine host
configPath engine
configPath
config createdFiles configPath
config allowPty
AgentSandboxSettingId AgentSandboxAllowNetwork
AgentSandboxSettingId AgentSandboxAdvancedRuntime
network
allowAllUnixSockets
enabled
engine store instantiationService TerminalSandboxEngine
configPath engine
configPath
config createdFiles configPath
config network
allowedDomains
deniedDomains
enabled
allowAllUnixSockets
AgentSandboxSettingId AgentSandboxRetryWithAllowNetworkRequests
engine store instantiationService TerminalSandboxEngine
wrapped engine
configPath engine
configPath
unrestrictedConfig createdFiles configPath
wrapped isSandboxWrapped
wrapped requiresAllowNetworkConfirmation
unrestrictedConfig network allowedDomains deniedDomains enabled
engine
restrictedConfig createdFiles configPath
restrictedConfig network allowedDomains deniedDomains
AgentSandboxSettingId AgentSandboxRetryWithAllowNetworkRequests
engine store instantiationService TerminalSandboxEngine
wrapped engine
configPath engine
configPath
config createdFiles configPath
wrapped isSandboxWrapped
wrapped requiresAllowNetworkConfirmation
config network allowedDomains deniedDomains
AgentSandboxSettingId AgentSandboxAllowUnsandboxedCommands
engine store instantiationService TerminalSandboxEngine
engine
wrapped engine
wrapped isSandboxWrapped
wrapped command
wrapped command
AgentSandboxSettingId AgentSandboxRetryWithAllowNetworkRequests
AgentNetworkDomainSettingId DeniedNetworkDomains
engine store instantiationService TerminalSandboxEngine
wrapped engine
configPath engine
configPath
config createdFiles configPath
wrapped isSandboxWrapped
wrapped requiresAllowNetworkConfirmation
wrapped blockedDomains
wrapped deniedDomains
config network allowedDomains deniedDomains enabled
writeRoots
host
writeRoots
engine store instantiationService TerminalSandboxEngine host
engine
engine
initialWriteCount createFileCount
writeRoots
host rootsEmitter
engine
createFileCount initialWriteCount
configPath engine
configPath
config createdFiles configPath
config filesystem allowWrite
config filesystem allowWrite
os OperatingSystem Linux OperatingSystem Macintosh
engine store instantiationService TerminalSandboxEngine
os
configPath engine
configPath
tempDirPath engine path
tempDirPath
config createdFiles configPath
denyRead config filesystem denyRead configPath
configAllowWrite config filesystem allowWrite configPath
tempDirAllowWrite config filesystem allowWrite tempDirPath
denyRead
configAllowWrite
tempDirAllowWrite
AgentSandboxSettingId AgentSandboxLinuxFileSystem
allowRead
allowWrite
denyRead
denyWrite
fileService
fileService
fileService
fileService
fileService
fileService
host
engine store instantiationService TerminalSandboxEngine host
engine keyword args
configPath engine
configPath
config createdFiles configPath
config filesystem allowWrite
config filesystem allowWrite
config filesystem allowWrite
config filesystem allowWrite
config filesystem allowRead
config filesystem allowRead
config filesystem allowRead
config filesystem allowRead
config filesystem allowWrite
config filesystem allowWrite
config filesystem denyRead
config filesystem denyRead
config filesystem denyWrite
config filesystem denyWrite
AgentSandboxSettingId AgentSandboxLinuxFileSystem
allowRead
allowWrite
denyRead
denyWrite
host
engine store instantiationService TerminalSandboxEngine host
configPath engine
configPath
config createdFiles configPath
config filesystem allowWrite
config filesystem allowWrite
config filesystem allowRead
config filesystem denyRead
config filesystem denyWrite
AgentSandboxSettingId AgentSandboxLinuxFileSystem
allowWrite
denyWrite
engine store instantiationService TerminalSandboxEngine
result engine
result
allowed
denied
AgentSandboxSettingId AgentSandboxLinuxFileSystem
allowRead
allowWrite
engine store instantiationService TerminalSandboxEngine
result engine
result
allowed
denied
AgentSandboxSettingId AgentSandboxLinuxFileSystem
allowWrite
fileService
engine store instantiationService TerminalSandboxEngine
engine
allowed
denied
host
engine store instantiationService TerminalSandboxEngine host
AgentSandboxSettingId AgentSandboxEnabled AgentSandboxEnabledValue Off
engine
engine
host
engine store instantiationService TerminalSandboxEngine host
engine isDefaultApprovalPermissionEnabled
engine isDefaultApprovalPermissionEnabled
engine isDefaultApprovalPermissionEnabled
engine isDefaultApprovalPermissionEnabled
engine isDefaultApprovalPermissionEnabled
enabled
sandboxConfigPath
failedCheck
createFileCount
host
engine store instantiationService TerminalSandboxEngine host
engine
engine
engine
AgentSandboxSettingId AgentSandboxEnabled AgentSandboxEnabledValue Off
host
engine store instantiationService TerminalSandboxEngine host
engine
engine
AgentSandboxSettingId AgentSandboxEnabled AgentSandboxEnabledValue Off
AgentSandboxSettingId AgentSandboxWindowsEnabled AgentSandboxEnabledValue On
host
engine store instantiationService TerminalSandboxEngine host
engine
engine
host
engine store instantiationService TerminalSandboxEngine host
wrapped engine scheme path
configPath engine
configPath
config createdFiles configPath
wrapped isSandboxWrapped
wrapped command
wrapped command
config version
config containment
config process commandLine
config process cwd
config ui disable
config process env
config process env
config process env
config process env
config process env
config process env
config process env
config process env
config process env
config network defaultPolicy enforcementMode
config filesystem readwritePaths path path
config filesystem readwritePaths path path
config filesystem readwritePaths path path
config filesystem readonlyPaths path path
config filesystem readonlyPaths path path
config filesystem readonlyPaths path path
config filesystem readonlyPaths path path
config filesystem deniedPaths path path
AgentSandboxSettingId AgentSandboxWindowsFileSystem
allowWrite
allowRead
denyRead
host
engine store instantiationService TerminalSandboxEngine host
engine
configPath engine
configPath
serializedConfig createdFiles configPath
config serializedConfig
serializedConfig
serializedConfig
serializedConfig
config filesystem readwritePaths path path
config filesystem readonlyPaths path path
config filesystem readwritePaths path path
config filesystem deniedPaths path path
config filesystem deniedPaths path path
AgentSandboxSettingId AgentSandboxWindowsFileSystem
allowWrite
allowRead
denyRead
host
readwritePaths
readonlyPaths
engine store instantiationService TerminalSandboxEngine host
engine
configPath engine
configPath
config createdFiles configPath
paths expectedPath paths path path expectedPath
readwrite config filesystem readwritePaths
config filesystem readonlyPaths
denied config filesystem deniedPaths
readwrite
denied
engine store instantiationService TerminalSandboxEngine
engine
resolveFileSystemPaths engine paths engine
AgentSandboxSettingId AgentSandboxWindowsSchemaVersion
engine store instantiationService TerminalSandboxEngine
engine
configPath engine
configPath
config createdFiles configPath
config version
AgentSandboxSettingId AgentSandboxWindowsFileSystem
allowWrite
allowRead
denyRead
fileService
fileService
fileService
fileService
fileService
host
scheme path
engine store instantiationService TerminalSandboxEngine host
engine
configPath engine
configPath
config createdFiles configPath
config filesystem readwritePaths path path
config filesystem readwritePaths path path
config filesystem readwritePaths path path
config filesystem readwritePaths path path
config filesystem readonlyPaths path path
config filesystem readonlyPaths path path
config filesystem readonlyPaths path path
config filesystem readonlyPaths path path
config filesystem deniedPaths path path
config filesystem deniedPaths path path
host
appRoot arch
engine store instantiationService TerminalSandboxEngine host
wrapped engine
configPath engine
configPath
config createdFiles configPath
wrapped command
config process cwd
host
engine store instantiationService TerminalSandboxEngine host
engine
configPath engine
configPath
firstCommandLine createdFiles configPath process commandLine
firstCommandLine
engine
configPath engine
configPath
secondCommandLine createdFiles configPath process commandLine
secondCommandLine
AgentSandboxSettingId AgentSandboxWindowsEnabled AgentSandboxEnabledValue On
AgentSandboxSettingId AgentSandboxAllowNetwork
host
engine store instantiationService TerminalSandboxEngine host
engine
configPath engine
configPath
config createdFiles configPath
config network defaultPolicy enforcementMode
AgentNetworkDomainSettingId AllowedNetworkDomains
AgentNetworkDomainSettingId DeniedNetworkDomains
host
engine store instantiationService TerminalSandboxEngine host
engine
configPath engine
configPath
config createdFiles configPath
config network defaultPolicy enforcementMode
linuxEngine store instantiationService TerminalSandboxEngine
linuxEngine
isLinuxAbsolutePath linuxEngine path linuxEngine
windowsEngine store instantiationService TerminalSandboxEngine OperatingSystem Windows
windowsEngine
isWindowsAbsolutePath windowsEngine path windowsEngine
status ISandboxDependencyStatus bubblewrapInstalled bubblewrapUsable socatInstalled dependencyInstallCommand
host
status
engine store instantiationService TerminalSandboxEngine host
result engine
result enabled
result failedCheck
result missingDependencies
result canInstallMissingDependencies
status bubblewrapInstalled bubblewrapUsable socatInstalled
result2 engine
result2 failedCheck
callCount
status ISandboxDependencyStatus bubblewrapInstalled bubblewrapUsable socatInstalled
host
callCount
status
engine store instantiationService TerminalSandboxEngine host
first engine
second engine
first failedCheck TerminalSandboxPrerequisiteCheck Dependencies
second failedCheck TerminalSandboxPrerequisiteCheck Dependencies
callCount
status bubblewrapInstalled bubblewrapUsable socatInstalled
cached engine
cached failedCheck TerminalSandboxPrerequisiteCheck Dependencies
callCount
refreshed engine
refreshed failedCheck
callCount
host
bubblewrapInstalled
bubblewrapUsable
bubblewrapError
socatInstalled
apparmorRestrictsUnprivilegedUserNamespaces
engine store instantiationService TerminalSandboxEngine host
result engine
result failedCheck TerminalSandboxPrerequisiteCheck Bubblewrap
result remediations TerminalSandboxPreCheckRemediation DisableUnprivilagedusernamespaceRestriction
result detail
result missingDependencies
AgentSandboxSettingId AgentSandboxAdvancedRuntime allowPty
host
bubblewrapInstalled
bubblewrapUsable
socatInstalled
apparmorRestrictsUnprivilegedUserNamespaces
engine store instantiationService TerminalSandboxEngine host
result engine
configPath engine
config createdFiles configPath
result failedCheck
config enableWeakerNestedSandbox
config allowPty
host
bubblewrapInstalled
bubblewrapUsable
socatInstalled
apparmorRestrictsUnprivilegedUserNamespaces
engine store instantiationService TerminalSandboxEngine host
beforeRemediation engine
afterRemediation engine
config createdFiles afterRemediation sandboxConfigPath
beforeRemediation failedCheck TerminalSandboxPrerequisiteCheck Bubblewrap
afterRemediation failedCheck
config enableWeakerNestedSandbox
{
}
from
'../../../files/common/files.js'
;
import
{
}
from
'../../../instantiation/test/common/instantiationServiceMock.js'
;
import
{
,
}
from
'../../../log/common/log.js'
;
import
{
}
from
'../../../networkFilter/common/settings.js'
;
import
type
{
,
,
,
,
}
from
'../../common/sandboxHelperService.js'
;
import
{
,
}
from
'../../common/settings.js'
;
import
{
,
,
}
from
'../../common/terminalSandboxEngine.js'
;
import
{
,
}
from
'../../common/terminalSandboxMxcRuntime.js'
;
import
{
,
}
from
'../../common/terminalSandboxService.js'
;
suite
(
'TerminalSandboxEngine'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
let
:
;
let
:
<
string
,
unknown
>
;
let
:
<
void
>
;
let
:
;
let
:
<
string
,
string
>
;
let
:
number
;
let
:
string
[
]
;
function
setSandboxSetting
(
:
string
,
:
unknown
)
:
void
{
.
set
(
,
)
;
.
fire
(
)
;
}
class
MockFileService
{
private
readonly
=
new
Map< string , string >
(
)
;
setRealpath
(
:
string
,
:
string
)
:
void
{
this
.
.
set
(
,
)
;
}
async
realpath
(
:
URI
)
:
Promise
<
URI
|
undefined
>
{
const
=
this
.
.
get
(
.
)
;
return
?
.
with
(
{
:
}
)
:
undefined
;
}
async
createFile
(
:
URI
,
:
)
:
Promise
<
any
>
{
++
;
const
=
.
toString
(
)
;
.
set
(
.
,
)
;
.
set
(
.
,
)
;
if
(
/ ^ \/ [ a- z A- Z ] :/
.
test
(
.
)
)
{
.
set
(
.
.
slice
(
1
)
.
replace
(
/ \/ / g
,
'\\'
)
,
)
;
}
return
{
}
;
}
async
createFolder
(
:
URI
)
:
Promise
<
any
>
{
.
push
(
.
)
;
return
{
}
;
}
async
del
(
:
URI
)
:
Promise
<
void
>
{
}
}
function
buildMockWindowsMxcSandboxPayload
(
:
string
,
:
,
?
:
string
,
:
string
=
'vscode-terminal-sandbox'
,
:
=
'process'
)
:
{
const
=
.
?.
??
true
;
const
=
{
:
.
?.
?
'allow'
:
'block'
as
'allow'
|
'block'
,
...
(
.
?.
!==
undefined
?
{
:
.
.
}
:
{
}
)
,
...
(
.
?
{
:
'capabilities'
as
const
}
:
{
}
)
,
}
;
return
{
:
.
,
:
,
,
:
{
:
true
,
:
!
,
}
,
:
{
,
:
,
:
.
??
0
,
}
,
:
{
:
false
,
:
.
?.
?
[
'internetClient'
]
:
[
]
,
:
{
:
'container'
,
:
false
,
:
'none'
,
:
false
,
}
,
}
,
:
{
:
[
...
(
.
?.
??
[
]
)
]
,
:
[
...
(
.
?.
??
[
]
)
]
,
:
[
...
(
.
?.
??
[
]
)
]
,
}
,
,
:
{
:
!
(
.
?.
??
false
)
,
:
.
?.
??
'none'
,
:
.
?.
??
false
,
}
,
}
;
}
function
createHost
(
:
<
>
=
{
}
)
:
&
{
:
<
void
>
}
{
const
=
new
Emitter< void >
(
)
;
const
:
=
{
:
'/app'
,
:
'/app/node'
,
:
false
,
}
;
const
:
=
{
getOS
:
(
)
=>
Promise
.
resolve
(
.
)
,
getRuntimeInfo
:
(
)
=>
Promise
.
resolve
(
)
,
getUserHome
:
(
)
=>
Promise
.
resolve
(
URI
.
file
(
'/home/user'
)
)
,
getSandboxTempDir
:
(
)
=>
Promise
.
resolve
(
URI
.
file
(
'/home/user/.test-data/tmp'
)
)
,
getWorkspaceStorageReadRoot
:
(
)
=>
Promise
.
resolve
(
undefined
)
,
getReadRoots
:
(
)
=>
[
]
,
getWriteRoots
:
(
)
=>
[
URI
.
file
(
'/workspace'
)
]
,
:
.
,
:
(
)
:
Promise
<
|
undefined
>
=>
Promise
.
resolve
(
{
:
true
,
:
true
,
:
true
}
)
,
:
(
)
:
Promise
<
|
undefined
>
=>
Promise
.
resolve
(
undefined
)
,
:
(
)
:
Promise
<
string
[
]
|
undefined
>
=>
Promise
.
resolve
(
undefined
)
,
:
(
,
,
,
,
)
:
Promise
<
|
undefined
>
=>
Promise
.
resolve
(
buildMockWindowsMxcSandboxPayload
(
,
,
,
,
)
)
,
:
<
T
>
(
:
string
)
:
T
|
undefined
=>
.
has
(
)
?
.
get
(
)
as
T
:
undefined
,
:
.
,
...
,
}
;
return
.
assign
(
,
{
}
)
;
}
function
createWindowsHost
(
:
<
>
=
{
}
)
:
&
{
:
<
void
>
}
{
return
createHost
(
{
getOS
:
(
)
=>
Promise
.
resolve
(
.
)
,
getRuntimeInfo
:
(
)
=>
Promise
.
resolve
(
{
:
'C:\\app'
,
:
'x64'
}
)
,
getUserHome
:
(
)
=>
Promise
.
resolve
(
URI
.
from
(
{
:
'file'
,
:
'/c:/Users/user'
}
)
)
,
getSandboxTempDir
:
(
)
=>
Promise
.
resolve
(
URI
.
from
(
{
:
'file'
,
:
'/c:/Users/user/.test-data/tmp'
}
)
)
,
getWorkspaceStorageReadRoot
:
(
)
=>
Promise
.
resolve
(
URI
.
from
(
{
:
'file'
,
:
'/c:/Users/user/workspaceStorage/workspace-id'
}
)
)
,
getWriteRoots
:
(
)
=>
[
URI
.
from
(
{
:
'file'
,
:
'/c:/workspace'
}
)
]
,
getWindowsMxcFilesystemPolicy
:
(
)
=>
Promise
.
resolve
(
{
:
[
'C:\\tools\\node'
,
'C:\\tools\\python'
,
'C:\\Users\\user\\AppData\\Local\\Programs\\Git'
]
,
:
[
'C:\\Users\\user\\AppData\\Local\\Temp'
]
}
)
,
getWindowsMxcEnvironment
:
(
)
=>
Promise
.
resolve
(
[
'SystemRoot=C:\\Windows'
,
'PATH=C:\\tools\\node;C:\\Windows\\System32'
,
'ComSpec=C:\\Windows\\System32\\cmd.exe'
,
'PATHEXT=.COM;.EXE;.BAT;.CMD;.PS1'
,
'PSModulePath=C:\\Users\\user\\Documents\\PowerShell\\Modules;C:\\Program Files\\PowerShell\\Modules'
,
'USERPROFILE=C:\\Users\\user'
,
'APPDATA=C:\\Users\\user\\AppData\\Roaming'
,
'LOCALAPPDATA=C:\\Users\\user\\AppData\\Local'
,
'PSHOME=C:\\Program Files\\PowerShell\\7'
]
)
,
...
,
}
)
;
}
function
normalizeWindowsPathForAssert
(
:
string
)
:
string
{
return
.
replace
(
/ \\ / g
,
'/'
)
.
toLowerCase
(
)
;
}
function
enableWindowsSandbox
(
)
:
void
{
setSandboxSetting
(
.
,
.
)
;
setSandboxSetting
(
.
,
true
)
;
}
setup
(
(
)
=>
{
=
new
Map
(
)
;
=
0
;
=
[
]
;
=
.
add
(
new
TestInstantiationService
(
)
)
;
=
new
Map
(
)
;
=
.
add
(
new
Emitter< void >
(
)
)
;
=
new
MockFileService
(
)
;
.
set
(
.
,
.
)
;
.
set
(
.
,
true
)
;
.
stub
(
,
)
;
.
stub
(
,
new
NullLogService
(
)
)
;
.
stub
(
,
.
createInstance
(
)
)
;
}
)
;
test
(
'runAsNode=true prefixes the wrapped command with ELECTRON_RUN_AS_NODE=1'
,
async
(
)
=>
{
const
=
createHost
(
{
getRuntimeInfo
:
(
)
=>
Promise
.
resolve
(
{
:
'/app'
,
:
'/app/electron'
,
:
true
}
)
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
getSandboxConfigPath
(
)
;
const
=
await
.
wrapCommand
(
'echo hi'
)
;
strictEqual
(
.
,
true
)
;
ok
(
.
.
startsWith
(
'ELECTRON_RUN_AS_NODE=1 '
)
,
` Expected ELECTRON_RUN_AS_NODE=1 prefix. Actual: ${ wrapped. command} `
)
;
}
)
;
test
(
'runAsNode=false omits the ELECTRON_RUN_AS_NODE=1 prefix'
,
async
(
)
=>
{
const
=
createHost
(
{
getRuntimeInfo
:
(
)
=>
Promise
.
resolve
(
{
:
'/app'
,
:
'/app/node'
,
:
false
}
)
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
getSandboxConfigPath
(
)
;
const
=
await
.
wrapCommand
(
'echo hi'
)
;
strictEqual
(
.
,
true
)
;
ok
(
!
.
.
startsWith
(
'ELECTRON_RUN_AS_NODE='
)
,
` Did not expect ELECTRON_RUN_AS_NODE prefix. Actual: ${ wrapped. command} `
)
;
}
)
;
test
(
'wrapCommand adds ripgrep-universal platform-arch bin directory to PATH'
,
async
(
)
=>
{
const
=
createHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
getSandboxConfigPath
(
)
;
const
=
await
.
wrapCommand
(
'echo hi'
)
;
ok
(
.
.
includes
(
` /app/node_modules/@vscode/ripgrep-universal/bin/linux- ${ arch} `
)
,
` Expected ripgrep-universal platform-arch path in command. Actual: ${ wrapped. command} `
)
;
}
)
;
test
(
'sandbox config enables PTY access by default on macOS'
,
async
(
)
=>
{
const
=
createHost
(
{
getOS
:
(
)
=>
Promise
.
resolve
(
.
)
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
,
true
)
;
}
)
;
test
(
'sandbox config does not enable PTY access by default on Linux'
,
async
(
)
=>
{
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
.
hasOwnProperty
.
call
(
,
'allowPty'
)
,
false
)
;
}
)
;
test
(
'sandbox config includes host read roots without granting write access'
,
async
(
)
=>
{
const
=
.
add
(
.
createInstance
(
,
createHost
(
{
getReadRoots
:
(
)
=>
[
URI
.
file
(
'/home/user/copilot-terminal-output'
)
]
,
}
)
)
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
deepStrictEqual
(
{
:
.
.
.
includes
(
'/home/user/copilot-terminal-output'
)
,
:
.
.
.
includes
(
'/home/user/copilot-terminal-output'
)
,
}
,
{
:
true
,
:
false
,
}
)
;
}
)
;
test
(
'sandbox config respects explicitly disabled PTY access on macOS'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
{
:
false
}
)
;
const
=
createHost
(
{
getOS
:
(
)
=>
Promise
.
resolve
(
.
)
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
,
false
)
;
}
)
;
test
(
'sandbox config preserves advanced runtime network settings when allowNetwork is enabled'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
true
)
;
setSandboxSetting
(
.
,
{
:
{
:
true
,
:
true
,
}
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
deepStrictEqual
(
.
,
{
:
[
]
,
:
[
]
,
:
false
,
:
true
,
}
)
;
}
)
;
test
(
'requestAllowNetwork keeps the command sandboxed and refreshes its network config'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
true
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
const
=
await
.
wrapCommand
(
'curl https://example.com'
,
false
,
'bash'
,
undefined
,
undefined
,
true
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
,
true
)
;
strictEqual
(
.
,
true
)
;
deepStrictEqual
(
.
,
{
:
[
]
,
:
[
]
,
:
false
}
)
;
await
.
wrapCommand
(
'echo restricted again'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
deepStrictEqual
(
.
,
{
:
[
]
,
:
[
]
}
)
;
}
)
;
test
(
'requestAllowNetwork does not relax network access when per-command requests are disabled'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
false
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
const
=
await
.
wrapCommand
(
'curl https://example.com'
,
false
,
'bash'
,
undefined
,
undefined
,
true
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
,
true
)
;
strictEqual
(
.
,
undefined
)
;
deepStrictEqual
(
.
,
{
:
[
]
,
:
[
]
}
)
;
}
)
;
test
(
'unsandboxed retry preserves the original working directory on Linux'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
true
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
await
.
getSandboxConfigPath
(
)
;
const
=
await
.
wrapCommand
(
'pwd'
,
true
,
'bash'
,
URI
.
file
(
'/workspace/with spaces'
)
)
;
strictEqual
(
.
,
false
)
;
ok
(
.
.
includes
(
` /workspace/with spaces `
)
,
` Expected the unsandboxed command to include cwd. Actual: ${ wrapped. command} `
)
;
ok
(
.
.
includes
(
` && pwd `
)
,
` Expected the unsandboxed command to change to cwd before execution. Actual: ${ wrapped. command} `
)
;
}
)
;
test
(
'blocked domains request sandboxed network access before execution when enabled'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
true
)
;
setSandboxSetting
(
.
,
[
'example.com'
]
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
const
=
await
.
wrapCommand
(
'curl https://example.com'
,
false
,
'bash'
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
,
true
)
;
strictEqual
(
.
,
true
)
;
deepStrictEqual
(
.
,
[
'example.com'
]
)
;
deepStrictEqual
(
.
,
[
'example.com'
]
)
;
deepStrictEqual
(
.
,
{
:
[
]
,
:
[
]
,
:
false
}
)
;
}
)
;
test
(
'onDidChangeRoots triggers a sandbox config rewrite on the next wrap'
,
async
(
)
=>
{
let
:
URI
[
]
=
[
URI
.
file
(
'/workspace-a'
)
]
;
const
=
createHost
(
{
getWriteRoots
:
(
)
=>
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
getSandboxConfigPath
(
)
;
await
.
wrapCommand
(
'echo a'
)
;
const
=
;
=
[
URI
.
file
(
'/workspace-b'
)
]
;
.
.
fire
(
)
;
await
.
wrapCommand
(
'echo b'
)
;
ok
(
>
,
` Expected sandbox config to be rewritten after onDidChangeRoots (initial= ${ initialWriteCount} , after= ${ createFileCount} ) `
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
!
)
!
)
;
ok
(
.
.
.
includes
(
'/workspace-b'
)
,
'Refreshed config should include the new write root'
)
;
ok
(
!
.
.
.
includes
(
'/workspace-a'
)
,
'Refreshed config should drop the old write root'
)
;
}
)
;
test
(
'always denies reads of the sandbox config file on Linux and macOS'
,
async
(
)
=>
{
for
(
const
of
[
.
,
.
]
)
{
const
=
.
add
(
.
createInstance
(
,
createHost
(
{
getOS
:
(
)
=>
Promise
.
resolve
(
)
,
}
)
)
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
.
getTempDir
(
)
?.
;
ok
(
,
'Temp dir path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
deepStrictEqual
(
{
:
.
.
.
includes
(
)
,
:
.
.
.
includes
(
)
,
:
.
.
.
includes
(
)
,
}
,
{
:
true
,
:
false
,
:
true
,
}
)
;
}
}
)
;
test
(
'preserves filesystem symlink paths and resolves their targets on Linux when writing the config'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
{
:
[
'~/read-link'
]
,
:
[
'/write-link'
]
,
:
[
'~/deny-read-link'
]
,
:
[
'/deny-write-link'
]
,
}
)
;
.
setRealpath
(
'/workspace-link'
,
'/real/workspace'
)
;
.
setRealpath
(
'/write-link'
,
'/real/write'
)
;
.
setRealpath
(
'/home/user/read-link'
,
'/real/read'
)
;
.
setRealpath
(
'/home/user/deny-read-link'
,
'/real/deny-read'
)
;
.
setRealpath
(
'/deny-write-link'
,
'/real/deny-write'
)
;
.
setRealpath
(
'/home/user/.gnupg'
,
'/real/gnupg'
)
;
const
=
createHost
(
{
getWriteRoots
:
(
)
=>
[
URI
.
file
(
'/workspace-link'
)
]
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
wrapCommand
(
'git commit -S'
,
false
,
undefined
,
undefined
,
[
{
:
'git'
,
:
[
'commit'
,
'-S'
]
}
]
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
ok
(
.
.
.
includes
(
'/workspace-link'
)
,
'Workspace write root symlink should be preserved'
)
;
ok
(
.
.
.
includes
(
'/real/workspace'
)
,
'Workspace write root symlink target should be included'
)
;
ok
(
.
.
.
includes
(
'/write-link'
)
,
'Configured allowWrite symlink should be preserved'
)
;
ok
(
.
.
.
includes
(
'/real/write'
)
,
'Configured allowWrite symlink target should be included'
)
;
ok
(
.
.
.
includes
(
'/home/user/read-link'
)
,
'Configured allowRead should expand ~ and preserve the symlink'
)
;
ok
(
.
.
.
includes
(
'/real/read'
)
,
'Configured allowRead symlink target should be included'
)
;
ok
(
.
.
.
includes
(
'/home/user/.gnupg'
)
,
'Command runtime allowRead symlink should be preserved'
)
;
ok
(
.
.
.
includes
(
'/real/gnupg'
)
,
'Command runtime allowRead symlink target should be included'
)
;
ok
(
.
.
.
includes
(
'/home/user/.gnupg'
)
,
'Command runtime allowWrite symlink should be preserved'
)
;
ok
(
.
.
.
includes
(
'/real/gnupg'
)
,
'Command runtime allowWrite symlink target should be included'
)
;
ok
(
.
.
.
includes
(
'/home/user/deny-read-link'
)
,
'Configured denyRead should expand ~ and preserve the symlink'
)
;
ok
(
.
.
.
includes
(
'/real/deny-read'
)
,
'Configured denyRead symlink target should be included'
)
;
ok
(
.
.
.
includes
(
'/deny-write-link'
)
,
'Configured denyWrite symlink should be preserved'
)
;
ok
(
.
.
.
includes
(
'/real/deny-write'
)
,
'Configured denyWrite symlink target should be included'
)
;
}
)
;
test
(
'keeps filesystem paths without symlinks when writing the config'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
{
:
[
'~/read-plain'
]
,
:
[
'/write-plain'
]
,
:
[
'~/deny-read-plain'
]
,
:
[
'/deny-write-plain'
]
,
}
)
;
const
=
createHost
(
{
getWriteRoots
:
(
)
=>
[
URI
.
file
(
'/workspace-plain'
)
]
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
ok
(
.
.
.
includes
(
'/workspace-plain'
)
,
'Workspace write root without symlink should be preserved'
)
;
ok
(
.
.
.
includes
(
'/write-plain'
)
,
'Configured allowWrite without symlink should be preserved'
)
;
ok
(
.
.
.
includes
(
'/home/user/read-plain'
)
,
'Configured allowRead without symlink should expand ~ and be preserved'
)
;
ok
(
.
.
.
includes
(
'/home/user/deny-read-plain'
)
,
'Configured denyRead without symlink should expand ~ and be preserved'
)
;
ok
(
.
.
.
includes
(
'/deny-write-plain'
)
,
'Configured denyWrite without symlink should be preserved'
)
;
}
)
;
test
(
'checkFileAccess validates write paths against allowWrite and denyWrite on Linux'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
{
:
[
'/configured/write'
,
'/glob/**/*.ts'
]
,
:
[
'/workspace/blocked'
]
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
const
=
await
.
checkFileAccess
(
'write'
,
[
'/workspace/file.txt'
,
'/configured/write/file.txt'
,
'/glob/nested/file.ts'
,
'/outside/file.txt'
,
'/workspace/blocked/file.txt'
,
]
)
;
deepStrictEqual
(
,
{
:
false
,
:
[
'/outside/file.txt'
,
'/workspace/blocked/file.txt'
]
,
}
)
;
}
)
;
test
(
'checkFileAccess validates read paths against denyRead and allowRead on Linux'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
{
:
[
'~/.allowed-read'
]
,
:
[
'~/.allowed-write'
]
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
const
=
await
.
checkFileAccess
(
'read'
,
[
'/home/user/private.txt'
,
'/home/user/.allowed-read/config.json'
,
'/home/user/.allowed-write/file.txt'
,
'/etc/hosts'
,
]
)
;
deepStrictEqual
(
,
{
:
false
,
:
[
'/home/user/private.txt'
]
,
}
)
;
}
)
;
test
(
'checkFileAccess preserves symlink source and target permissions on Linux'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
{
:
[
'/write-link'
]
,
}
)
;
.
setRealpath
(
'/write-link'
,
'/real/write'
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
deepStrictEqual
(
await
.
checkFileAccess
(
'write'
,
[
'/write-link/file.txt'
,
'/real/write/file.txt'
]
)
,
{
:
true
,
:
[
]
,
}
)
;
}
)
;
test
(
'cleanupTempDir is a no-op when no temp dir was ever created'
,
async
(
)
=>
{
const
=
createHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
setSandboxSetting
(
.
,
.
)
;
strictEqual
(
.
getTempDir
(
)
,
undefined
)
;
await
.
cleanupTempDir
(
)
;
}
)
;
test
(
'precheck inputs can disable sandboxing when default approval permission is disabled'
,
async
(
)
=>
{
const
=
createHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
strictEqual
(
await
.
isEnabled
(
{
:
true
}
)
,
true
)
;
strictEqual
(
await
.
isEnabled
(
{
:
false
}
)
,
false
)
;
strictEqual
(
await
.
isSandboxAllowNetworkEnabled
(
{
:
false
}
)
,
false
)
;
strictEqual
(
await
.
getSandboxConfigPath
(
false
,
{
:
false
}
)
,
undefined
)
;
deepStrictEqual
(
await
.
checkForSandboxingPrereqs
(
false
,
{
:
false
}
)
,
{
:
false
,
:
undefined
,
:
undefined
,
}
)
;
strictEqual
(
,
0
,
'Disabled sandbox precheck should not create sandbox config files'
)
;
}
)
;
test
(
'isEnabled returns false on Windows when Windows sandbox setting is disabled by default'
,
async
(
)
=>
{
const
=
createWindowsHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
strictEqual
(
await
.
isEnabled
(
)
,
false
)
;
strictEqual
(
await
.
isSandboxAllowNetworkEnabled
(
)
,
false
)
;
strictEqual
(
await
.
getSandboxConfigPath
(
)
,
undefined
)
;
}
)
;
test
(
'isEnabled returns true on Windows when Windows sandbox setting is enabled even if global sandboxing is off'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
.
)
;
enableWindowsSandbox
(
)
;
const
=
createWindowsHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
strictEqual
(
await
.
isEnabled
(
)
,
true
)
;
strictEqual
(
await
.
isSandboxAllowNetworkEnabled
(
)
,
true
)
;
}
)
;
test
(
'enabledWindows on value does not enable allowNetwork on Windows'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
.
)
;
setSandboxSetting
(
.
,
.
)
;
const
=
createWindowsHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
strictEqual
(
await
.
isEnabled
(
)
,
true
)
;
strictEqual
(
await
.
isSandboxAllowNetworkEnabled
(
)
,
false
)
;
}
)
;
test
(
'wrapCommand uses MXC executable and writes MXC config on Windows'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
const
=
createWindowsHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
wrapCommand
(
'echo hello'
,
false
,
'C:\\Program Files\\PowerShell\\7\\pwsh.exe'
,
URI
.
from
(
{
:
'file'
,
:
'/c:/workspace'
}
)
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
,
true
)
;
ok
(
.
.
startsWith
(
` & 'C:\\app\\node_modules\\@microsoft\\mxc-sdk\\bin\\x64\\wxc-exec.exe' `
)
,
` Expected MXC executable. Actual: ${ wrapped. command} `
)
;
ok
(
.
.
includes
(
` ' ${ configPath} ' `
)
,
` Expected wrapped command to pass the MXC config path. Actual: ${ wrapped. command} `
)
;
strictEqual
(
.
,
'0.6.0-alpha'
)
;
strictEqual
(
.
,
'process'
)
;
strictEqual
(
.
.
,
'"C:\\Program Files\\PowerShell\\7\\pwsh.exe" -NoProfile -Command "echo hello"'
)
;
strictEqual
(
normalizeWindowsPathForAssert
(
.
.
)
,
'c:/workspace'
)
;
strictEqual
(
.
.
,
false
)
;
ok
(
.
.
.
includes
(
'SystemRoot=C:\\Windows'
)
,
'SystemRoot should be injected into the MXC process env'
)
;
ok
(
.
.
.
includes
(
'PATH=C:\\tools\\node;C:\\Windows\\System32'
)
,
'PATH should be injected into the MXC process env'
)
;
ok
(
.
.
.
includes
(
'ComSpec=C:\\Windows\\System32\\cmd.exe'
)
,
'ComSpec should be injected into the MXC process env'
)
;
ok
(
.
.
.
includes
(
'PATHEXT=.COM;.EXE;.BAT;.CMD;.PS1'
)
,
'PATHEXT should be injected into the MXC process env'
)
;
ok
(
.
.
.
includes
(
'PSModulePath=C:\\Users\\user\\Documents\\PowerShell\\Modules;C:\\Program Files\\PowerShell\\Modules'
)
,
'PSModulePath should be injected into the MXC process env'
)
;
ok
(
.
.
.
includes
(
'USERPROFILE=C:\\Users\\user'
)
,
'USERPROFILE should be injected into the MXC process env'
)
;
ok
(
.
.
.
includes
(
'APPDATA=C:\\Users\\user\\AppData\\Roaming'
)
,
'APPDATA should be injected into the MXC process env'
)
;
ok
(
.
.
.
includes
(
'LOCALAPPDATA=C:\\Users\\user\\AppData\\Local'
)
,
'LOCALAPPDATA should be injected into the MXC process env'
)
;
ok
(
.
.
.
includes
(
'PSHOME=C:\\Program Files\\PowerShell\\7'
)
,
'PSHOME should be injected into the MXC process env'
)
;
deepStrictEqual
(
.
,
{
:
'allow'
,
:
'capabilities'
}
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/workspace'
)
,
'Workspace should be writable'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
.
endsWith
(
'/.test-data/tmp'
)
)
,
'Sandbox temp dir should be writable'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/users/user/appdata/local/temp'
)
,
'MXC temporary files policy should add host temp path to writable paths'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
.
endsWith
(
'/.test-data/tmp'
)
)
,
'Sandbox temp dir should be readable through readonly paths'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/tools/node'
)
,
'MXC available tools policy should add tool paths to readonly paths'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/program files/powershell/7'
)
,
'Resolved PowerShell executable directory should be readable'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/users/user/appdata/local/programs/git'
)
,
'MXC user profile policy should add user profile paths to readonly paths'
)
;
ok
(
!
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/users/user'
)
,
'User home should not be denied by default on Windows'
)
;
}
)
;
test
(
'wrapCommand applies Windows filesystem setting to MXC config'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
setSandboxSetting
(
.
,
{
:
[
'C:/configured/write'
]
,
:
[
'C:/configured/read'
]
,
:
[
'C:/configured/secret'
]
,
}
)
;
const
=
createWindowsHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
wrapCommand
(
'echo hello'
,
false
,
'pwsh'
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
.
get
(
)
!
;
const
=
JSON
.
parse
(
)
;
ok
(
.
includes
(
'C:\\\\configured\\\\write'
)
,
'Configured Windows allowWrite path should be escaped in the serialized MXC config'
)
;
ok
(
.
includes
(
'C:\\\\configured\\\\read'
)
,
'Configured Windows allowRead path should be escaped in the serialized MXC config'
)
;
ok
(
.
includes
(
'C:\\\\configured\\\\secret'
)
,
'Configured Windows denyRead path should be escaped in the serialized MXC config'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/configured/write'
)
,
'Configured Windows allowWrite path should be writable'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/configured/read'
)
,
'Configured Windows allowRead path should be readonly'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/users/user/appdata/local/temp'
)
,
'Host temp path from Windows policy should be writable'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/configured/secret'
)
,
'Configured Windows denyRead path should be denied'
)
;
ok
(
!
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/users/user'
)
,
'User home should not be denied by default on Windows'
)
;
}
)
;
test
(
'deduplicates Windows filesystem paths regardless of case or separator'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
setSandboxSetting
(
.
,
{
:
[
'C:/configured/write'
]
,
:
[
'C:\\configured\\read'
]
,
:
[
'C:/configured/secret'
,
'c:\\configured\\secret'
]
,
}
)
;
const
=
createWindowsHost
(
{
getWindowsMxcFilesystemPolicy
:
(
)
=>
Promise
.
resolve
(
{
:
[
'c:\\configured\\write'
]
,
:
[
'c:/configured/read'
]
,
}
)
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
wrapCommand
(
'echo hello'
,
false
,
'pwsh'
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
const
matchingPaths
=
(
:
string
[
]
,
:
string
)
=>
.
filter
(
=>
normalizeWindowsPathForAssert
(
)
===
)
;
deepStrictEqual
(
{
:
matchingPaths
(
.
.
,
'c:/configured/write'
)
,
readonly
:
matchingPaths
(
.
.
,
'c:/configured/read'
)
,
:
matchingPaths
(
.
.
,
'c:/configured/secret'
)
,
}
,
{
:
[
'C:\\configured\\write'
]
,
readonly
:
[
'C:\\configured\\read'
]
,
:
[
'C:\\configured\\secret'
]
,
}
)
;
}
)
;
test
(
'deduplicates resolved Windows paths regardless of case or separator'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
const
=
.
add
(
.
createInstance
(
,
createWindowsHost
(
)
)
)
;
await
.
getOS
(
)
;
const
=
(
as
unknown
as
{
_resolveFileSystemPaths
(
:
string
[
]
)
:
Promise
<
string
[
]
>
}
)
.
_resolveFileSystemPaths
.
bind
(
)
;
deepStrictEqual
(
await
resolveFileSystemPaths
(
[
'C:/configured/path'
,
'c:\\configured\\path'
,
'C:\\configured\\other-path'
,
]
)
,
[
'C:/configured/path'
,
'C:\\configured\\other-path'
,
]
)
;
}
)
;
test
(
'wrapCommand applies configured Windows MXC schema version'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
setSandboxSetting
(
.
,
'0.5.0-alpha'
)
;
const
=
.
add
(
.
createInstance
(
,
createWindowsHost
(
)
)
)
;
await
.
wrapCommand
(
'echo hello'
,
false
,
'pwsh'
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
,
'0.5.0-alpha'
)
;
}
)
;
test
(
'preserves Windows filesystem symlink paths and resolves their targets when writing MXC config'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
setSandboxSetting
(
.
,
{
:
[
'C:\\configured\\write-link'
]
,
:
[
'C:\\configured\\read-link'
]
,
:
[
'C:\\configured\\secret-link'
]
,
}
)
;
.
setRealpath
(
'/c:/workspace-link'
,
'/c:/real/workspace'
)
;
.
setRealpath
(
'/c:/configured/write-link'
,
'/c:/real/configured-write'
)
;
.
setRealpath
(
'/c:/configured/read-link'
,
'/c:/real/configured-read'
)
;
.
setRealpath
(
'/c:/configured/secret-link'
,
'/c:/real/configured-secret'
)
;
.
setRealpath
(
'/c:/tools/node'
,
'/c:/real/tools-node'
)
;
const
=
createWindowsHost
(
{
getWriteRoots
:
(
)
=>
[
URI
.
from
(
{
:
'file'
,
:
'/c:/workspace-link'
}
)
]
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
wrapCommand
(
'echo hello'
,
false
,
'pwsh'
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/workspace-link'
)
,
'Workspace write root symlink should be preserved on Windows'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/real/workspace'
)
,
'Workspace write root symlink target should be included on Windows'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/configured/write-link'
)
,
'Configured Windows allowWrite symlink should be preserved'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/real/configured-write'
)
,
'Configured Windows allowWrite symlink target should be included'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/configured/read-link'
)
,
'Configured Windows allowRead symlink should be preserved'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/real/configured-read'
)
,
'Configured Windows allowRead symlink target should be included'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/tools/node'
)
,
'Windows policy readonly symlink should be preserved'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/real/tools-node'
)
,
'Windows policy readonly symlink target should be included'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/configured/secret-link'
)
,
'Configured Windows denyRead symlink should be preserved'
)
;
ok
(
.
.
.
some
(
(
:
string
)
=>
normalizeWindowsPathForAssert
(
)
===
'c:/real/configured-secret'
)
,
'Configured Windows denyRead symlink target should be included'
)
;
}
)
;
test
(
'wrapCommand uses arm64 MXC executable on Windows arm64'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
const
=
createWindowsHost
(
{
getRuntimeInfo
:
(
)
=>
Promise
.
resolve
(
{
:
'C:\\app'
,
:
'arm64'
}
)
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
wrapCommand
(
'echo hello'
,
false
,
'pwsh'
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
strictEqual
(
.
,
` & 'C:\\app\\node_modules\\@microsoft\\mxc-sdk\\bin\\arm64\\wxc-exec.exe' ' ${ configPath} ' `
)
;
strictEqual
(
normalizeWindowsPathForAssert
(
.
.
)
,
'c:/workspace'
)
;
}
)
;
test
(
'wrapCommand rewrites MXC config when Windows command changes'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
const
=
createWindowsHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
wrapCommand
(
'echo first'
,
false
,
'C:\\Program Files\\PowerShell\\7\\pwsh.exe'
)
;
let
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
.
.
;
strictEqual
(
,
'"C:\\Program Files\\PowerShell\\7\\pwsh.exe" -NoProfile -Command "echo first"'
)
;
await
.
wrapCommand
(
'echo second'
,
false
,
'C:\\Program Files\\PowerShell\\7\\pwsh.exe'
)
;
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
.
.
;
strictEqual
(
,
'"C:\\Program Files\\PowerShell\\7\\pwsh.exe" -NoProfile -Command "echo second"'
)
;
}
)
;
test
(
'allowNetwork maps to MXC allow network config on Windows'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
.
)
;
setSandboxSetting
(
.
,
true
)
;
const
=
createWindowsHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
wrapCommand
(
'curl https://example.com'
,
false
,
'pwsh'
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
deepStrictEqual
(
.
,
{
:
'allow'
,
:
'capabilities'
}
)
;
}
)
;
test
(
'Windows MXC config ignores unsupported network host lists'
,
async
(
)
=>
{
enableWindowsSandbox
(
)
;
setSandboxSetting
(
.
,
[
'example.com'
]
)
;
setSandboxSetting
(
.
,
[
'blocked.example.com'
]
)
;
const
=
createWindowsHost
(
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
await
.
wrapCommand
(
'curl https://example.com'
,
false
,
'pwsh'
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
ok
(
,
'Config path should be defined'
)
;
const
=
JSON
.
parse
(
.
get
(
)
!
)
;
deepStrictEqual
(
.
,
{
:
'allow'
,
:
'capabilities'
}
)
;
}
)
;
test
(
'uses OS-specific filesystem absolute path detection'
,
async
(
)
=>
{
const
=
.
add
(
.
createInstance
(
,
createHost
(
)
)
)
;
await
.
getOS
(
)
;
const
=
(
as
unknown
as
{
_isAbsoluteFileSystemPath
(
:
string
)
:
boolean
}
)
.
_isAbsoluteFileSystemPath
.
bind
(
)
;
strictEqual
(
isLinuxAbsolutePath
(
'/home/user'
)
,
true
)
;
strictEqual
(
isLinuxAbsolutePath
(
'relative/path'
)
,
false
)
;
strictEqual
(
isLinuxAbsolutePath
(
'C:\\Users\\user'
)
,
false
)
;
const
=
.
add
(
.
createInstance
(
,
createHost
(
{
getOS
:
(
)
=>
Promise
.
resolve
(
.
)
}
)
)
)
;
await
.
getOS
(
)
;
const
=
(
as
unknown
as
{
_isAbsoluteFileSystemPath
(
:
string
)
:
boolean
}
)
.
_isAbsoluteFileSystemPath
.
bind
(
)
;
strictEqual
(
isWindowsAbsolutePath
(
'/Users/user'
)
,
true
)
;
strictEqual
(
isWindowsAbsolutePath
(
'C:\\Users\\user'
)
,
true
)
;
strictEqual
(
isWindowsAbsolutePath
(
'C:/Users/user'
)
,
true
)
;
strictEqual
(
isWindowsAbsolutePath
(
'\\\\server\\share'
)
,
true
)
;
strictEqual
(
isWindowsAbsolutePath
(
'relative\\path'
)
,
false
)
;
}
)
;
test
(
'checkForSandboxingPrereqs reports missing dependencies'
,
async
(
)
=>
{
let
:
=
{
:
false
,
:
false
,
:
true
,
:
'sudo pacman -S --needed --noconfirm'
}
;
const
=
createHost
(
{
checkSandboxDependencies
:
(
)
=>
Promise
.
resolve
(
)
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
checkForSandboxingPrereqs
(
)
;
strictEqual
(
.
,
true
)
;
strictEqual
(
.
,
'dependencies'
)
;
strictEqual
(
.
?.
[
0
]
,
'bubblewrap'
)
;
strictEqual
(
.
,
true
)
;
=
{
:
true
,
:
true
,
:
true
}
;
const
=
await
.
checkForSandboxingPrereqs
(
true
)
;
strictEqual
(
.
,
undefined
)
;
}
)
;
test
(
'checkForSandboxingPrereqs caches missing dependencies until force refresh'
,
async
(
)
=>
{
let
=
0
;
let
:
=
{
:
false
,
:
false
,
:
true
}
;
const
=
createHost
(
{
checkSandboxDependencies
:
(
)
=>
{
++
;
return
Promise
.
resolve
(
)
;
}
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
checkForSandboxingPrereqs
(
)
;
const
=
await
.
checkForSandboxingPrereqs
(
)
;
strictEqual
(
.
,
.
)
;
strictEqual
(
.
,
.
)
;
strictEqual
(
,
1
,
'Missing dependencies should be checked once and cached'
)
;
=
{
:
true
,
:
true
,
:
true
}
;
const
=
await
.
checkForSandboxingPrereqs
(
)
;
strictEqual
(
.
,
.
,
'Non-forced checks should keep using the cached missing status'
)
;
strictEqual
(
,
1
)
;
const
=
await
.
checkForSandboxingPrereqs
(
true
)
;
strictEqual
(
.
,
undefined
)
;
strictEqual
(
,
2
,
'Force refresh should re-check dependencies after install or repair'
)
;
}
)
;
test
(
'checkForSandboxingPrereqs reports remediation when bubblewrap is unusable'
,
async
(
)
=>
{
const
=
createHost
(
{
checkSandboxDependencies
:
(
)
=>
Promise
.
resolve
(
{
:
true
,
:
false
,
:
'Creating new namespace failed'
,
:
true
,
:
true
,
}
)
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
checkForSandboxingPrereqs
(
)
;
strictEqual
(
.
,
.
)
;
deepStrictEqual
(
.
,
[
.
]
)
;
strictEqual
(
.
,
'Creating new namespace failed'
)
;
strictEqual
(
.
,
undefined
)
;
}
)
;
test
(
'checkForSandboxingPrereqs enables weaker nested sandbox when AppArmor is not restricting user namespaces'
,
async
(
)
=>
{
setSandboxSetting
(
.
,
{
:
false
}
)
;
const
=
createHost
(
{
checkSandboxDependencies
:
(
)
=>
Promise
.
resolve
(
{
:
true
,
:
false
,
:
true
,
:
false
,
}
)
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
checkForSandboxingPrereqs
(
)
;
const
=
await
.
getSandboxConfigPath
(
)
;
const
=
JSON
.
parse
(
.
get
(
!
)
!
)
;
strictEqual
(
.
,
undefined
)
;
strictEqual
(
.
,
true
)
;
strictEqual
(
.
,
false
)
;
}
)
;
test
(
'checkForSandboxingPrereqs enables weaker nested sandbox after AppArmor remediation does not fix bubblewrap'
,
async
(
)
=>
{
const
=
createHost
(
{
checkSandboxDependencies
:
(
)
=>
Promise
.
resolve
(
{
:
true
,
:
false
,
:
true
,
:
true
,
}
)
,
}
)
;
const
=
.
add
(
.
createInstance
(
,
)
)
;
const
=
await
.
checkForSandboxingPrereqs
(
)
;
const
=
await
.
checkForSandboxingPrereqs
(
true
)
;
const
=
JSON
.
parse
(
.
get
(
.
!
)
!
)
;
strictEqual
(
.
,
.
)
;
strictEqual
(
.
,
undefined
)
;
strictEqual
(
.
,
true
)
;
}
)
;
}
)
;