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 / node / sshRemoteAgentHostHelpers.test.ts 696 строк · изменён 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
import assert from 'assert' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js' ;
import { TelemetryConfiguration } from '../../../telemetry/common/telemetry.js' ;
import { AGENT_HOST_ENDPOINT_REGISTRY_SCHEMA_VERSION , type IAgentHostEndpointMetadata } from '../../common/agentHostEndpointRegistry.js' ;
import {
buildAgentEndpointsCommand,
buildAgentHostBaseCommand,
buildAgentHostSpawnCommand,
buildAgentRelayCommand,
buildCLIDownloadUrl,
buildCleanupOldCLIsCommand,
buildFindFallbackCLICommand,
filterLiveAgentHostEndpoints,
findNewAgentHostEndpoint,
getRemoteCLIArchiveName,
getRemoteCLIBin,
getRemoteCLIDataDir,
getRemoteCLIInstallRoot,
isValidFallbackCLIPath
parseAgentEndpointsOutput
redactToken
resolveRemotePlatform
runAgentEndpoints
shellEscape
validateAgentHostTelemetryLevel
validateCommit
validateShellToken
waitForNewStandaloneEndpoint
overrides Partial IAgentHostEndpointMetadata Pick IAgentHostEndpointMetadata IAgentHostEndpointMetadata
schemaVersion
protocolVersion
connectionToken
endpoint type host port
quality
tunnelName
overrides
assert
assert
assert
assert
assert
assert
assert
assert
assert
c
assert c c
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
cmd TelemetryConfiguration
assert cmd
cmd TelemetryConfiguration
assert cmd
assert
commit
assert
commit
assert
commit
assert
commit
assert
assert
assert
upper
assert
upper
assert commit
assert
assert
assert
assert
assert os arch
assert os arch
assert os arch
assert os arch
assert os arch
assert os arch
assert os arch
assert
assert os arch
assert os arch
assert os arch
assert
assert
assert
commit
assert
assert
assert
assert
commit
assert
commit
assert
upper
assert
upper
cmd
assert cmd
assert cmd
assert cmd
assert cmd
assert cmd
cmd
assert cmd
assert cmd
assert
assert
cmd
assert cmd
assert cmd
assert cmd
cmd
assert cmd
assert cmd
assert
assert
sdf
q
hex
assert sdf q
assert sdf q
assert
notHex
assert sdf q
assert sdf q
assert sdf q
assert sdf q
assert sdf q
assert sdf q
assert sdf q
assert
assert
assert
assert
assert
assert
assert
TelemetryConfiguration
assert
TelemetryConfiguration
assert
TelemetryConfiguration
assert TelemetryConfiguration
assert TelemetryConfiguration
assert TelemetryConfiguration
cmd TelemetryConfiguration
assert cmd
assert
assert
assert
assert
assert endpoints
assert userDataPath
endpoint type pid instanceId
result userDataPath endpoints endpoint
assert result
assert result userDataPath
assert result endpoints endpoint
good type pid instanceId
result userDataPath endpoints good garbage
assert result
assert result endpoints good
endpoint type pid instanceId
exec
stdout userDataPath endpoints endpoint
stderr
code
result exec
assert result userDataPath
assert result endpoints endpoint
commands
exec command
commands command
stdout userDataPath endpoints stderr code
exec
assert commands c c
exec stdout stderr code
assert
exec
exec stdout stderr code
assert
exec
output
exec stdout output stderr code
result exec
assert result
userDataPath
endpoints
alive type pid instanceId
dead type pid instanceId
exec command
command
stdout stderr code
command
stdout stderr code
result exec alive dead
assert result alive
first type pid instanceId
second type pid instanceId
probes
exec command
command
probes
stdout stderr code
result exec first second
assert probes
assert result length
exec
assert exec
before type pid instanceId
spawned type pid instanceId
after before spawned
assert before after spawned
before IAgentHostEndpointMetadata
newEditor type pid instanceId
assert before newEditor
entries type pid instanceId
assert entries entries
before type pid instanceId
spawned type pid instanceId
poll
exec
poll
endpoints poll before before spawned
stdout userDataPath endpoints stderr code
result exec before intervalMs
assert result spawned
assert poll
before type pid instanceId
exec stdout userDataPath endpoints before stderr code
assert
exec before attempts intervalMs
,
,
,
,
,
,
,
,
,
,
type
ISshExec
,
}
from
'../../node/sshRemoteAgentHostHelpers.js'
;
suite
(
'SSH Remote Agent Host Helpers'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
function
makeEndpoint
(
:
<
>
&
<
,
'type'
|
'pid'
|
'instanceId'
>
)
:
{
return
{
:
AGENT_HOST_ENDPOINT_REGISTRY_SCHEMA_VERSION
,
:
'1.0.0'
,
:
'tok'
,
:
{
:
'tcp'
,
:
'127.0.0.1'
,
:
8080
}
,
:
undefined
,
:
undefined
,
...
,
}
;
}
suite
(
'validateShellToken'
,
(
)
=>
{
test
(
'accepts alphanumeric strings'
,
(
)
=>
{
.
strictEqual
(
validateShellToken
(
'insider'
,
'quality'
)
,
'insider'
)
;
.
strictEqual
(
validateShellToken
(
'stable'
,
'quality'
)
,
'stable'
)
;
.
strictEqual
(
validateShellToken
(
'exploration'
,
'quality'
)
,
'exploration'
)
;
}
)
;
test
(
'accepts dots, dashes, and underscores'
,
(
)
=>
{
.
strictEqual
(
validateShellToken
(
'my-build_1.0'
,
'quality'
)
,
'my-build_1.0'
)
;
}
)
;
test
(
'rejects strings with spaces'
,
(
)
=>
{
.
throws
(
(
)
=>
validateShellToken
(
'foo bar'
,
'quality'
)
,
/ Unsafe quality /
)
;
}
)
;
test
(
'rejects strings with shell metacharacters'
,
(
)
=>
{
.
throws
(
(
)
=>
validateShellToken
(
'foo;rm -rf /'
,
'quality'
)
,
/ Unsafe quality /
)
;
.
throws
(
(
)
=>
validateShellToken
(
'$(whoami)'
,
'quality'
)
,
/ Unsafe quality /
)
;
.
throws
(
(
)
=>
validateShellToken
(
'foo\'bar'
,
'quality'
)
,
/ Unsafe quality /
)
;
}
)
;
test
(
'rejects empty string'
,
(
)
=>
{
.
throws
(
(
)
=>
validateShellToken
(
''
,
'quality'
)
,
/ Unsafe quality /
)
;
}
)
;
}
)
;
suite
(
'validateCommit'
,
(
)
=>
{
test
(
'accepts a 40-char lowercase hex SHA'
,
(
)
=>
{
const
=
'abcdef0123456789abcdef0123456789abcdef01'
;
.
strictEqual
(
validateCommit
(
)
,
)
;
}
)
;
test
(
'normalizes uppercase hex to lowercase'
,
(
)
=>
{
.
strictEqual
(
validateCommit
(
'ABCDEF0123456789ABCDEF0123456789ABCDEF01'
)
,
'abcdef0123456789abcdef0123456789abcdef01'
,
)
;
}
)
;
test
(
'rejects non-hex characters'
,
(
)
=>
{
.
throws
(
(
)
=>
validateCommit
(
'g'
.
repeat
(
40
)
)
,
/ Unsafe commit /
)
;
.
throws
(
(
)
=>
validateCommit
(
'abcdef0123456789abcdef0123456789abcdef0z'
)
,
/ Unsafe commit /
)
;
}
)
;
test
(
'rejects wrong-length values'
,
(
)
=>
{
.
throws
(
(
)
=>
validateCommit
(
'abc'
)
,
/ Unsafe commit /
)
;
.
throws
(
(
)
=>
validateCommit
(
'a'
.
repeat
(
41
)
)
,
/ Unsafe commit /
)
;
.
throws
(
(
)
=>
validateCommit
(
''
)
,
/ Unsafe commit /
)
;
}
)
;
test
(
'rejects shell metacharacters'
,
(
)
=>
{
.
throws
(
(
)
=>
validateCommit
(
'foo;rm'
)
,
/ Unsafe commit /
)
;
.
throws
(
(
)
=>
validateCommit
(
'a'
.
repeat
(
39
)
+
'$'
)
,
/ Unsafe commit /
)
;
}
)
;
}
)
;
suite
(
'getRemoteCLIArchiveName'
,
(
)
=>
{
test
(
'returns code for stable'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIArchiveName
(
'stable'
)
,
'code'
)
;
}
)
;
test
(
'returns code-insiders for insider'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIArchiveName
(
'insider'
)
,
'code-insiders'
)
;
}
)
;
test
(
'returns code-exploration for exploration'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIArchiveName
(
'exploration'
)
,
'code-exploration'
)
;
}
)
;
test
(
'falls back to code-insiders for unknown qualities'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIArchiveName
(
'weirdbuild'
)
,
'code-insiders'
)
;
}
)
;
test
(
'rejects unsafe quality strings'
,
(
)
=>
{
.
throws
(
(
)
=>
getRemoteCLIArchiveName
(
'foo bar'
)
,
/ Unsafe quality /
)
;
}
)
;
}
)
;
suite
(
'getRemoteCLIInstallRoot'
,
(
)
=>
{
test
(
'returns user-home anchored path under the server data folder'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIInstallRoot
(
'.vscode-server-insiders'
)
,
'~/.vscode-server-insiders'
)
;
}
)
;
test
(
'rejects unsafe server data folder names'
,
(
)
=>
{
.
throws
(
(
)
=>
getRemoteCLIInstallRoot
(
'foo bar'
)
,
/ Unsafe server data folder name /
)
;
.
throws
(
(
)
=>
getRemoteCLIInstallRoot
(
'foo/bar'
)
,
/ Unsafe server data folder name /
)
;
.
throws
(
(
)
=>
getRemoteCLIInstallRoot
(
'$(whoami)'
)
,
/ Unsafe server data folder name /
)
;
}
)
;
}
)
;
suite
(
'getRemoteCLIDataDir'
,
(
)
=>
{
test
(
'returns the `cli` subdir under the install root'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIDataDir
(
'.vscode-server'
)
,
'~/.vscode-server/cli'
)
;
.
strictEqual
(
getRemoteCLIDataDir
(
'.vscode-server-insiders'
)
,
'~/.vscode-server-insiders/cli'
)
;
}
)
;
test
(
'rejects unsafe server data folder names'
,
(
)
=>
{
.
throws
(
(
)
=>
getRemoteCLIDataDir
(
'foo;rm'
)
,
/ Unsafe server data folder name /
)
;
}
)
;
}
)
;
suite
(
'buildAgentHostBaseCommand'
,
(
)
=>
{
test
(
'includes --cli-data-dir and the default telemetry level before the agent host subcommand'
,
(
)
=>
{
const
=
buildAgentHostBaseCommand
(
'~/.vscode-server/code-insiders-abc'
,
'~/.vscode-server/cli'
,
.
ON
)
;
.
strictEqual
(
,
'~/.vscode-server/code-insiders-abc --cli-data-dir ~/.vscode-server/cli --telemetry-level all agent host --port 0'
)
;
}
)
;
test
(
'includes telemetry disablement before the agent host subcommand'
,
(
)
=>
{
const
=
buildAgentHostBaseCommand
(
'~/.vscode-server/code-insiders-abc'
,
'~/.vscode-server/cli'
,
.
OFF
)
;
.
strictEqual
(
,
'~/.vscode-server/code-insiders-abc --cli-data-dir ~/.vscode-server/cli --telemetry-level off agent host --port 0'
)
;
}
)
;
test
(
'rejects unsafe telemetry levels'
,
(
)
=>
{
.
throws
(
(
)
=>
validateAgentHostTelemetryLevel
(
'off; touch /tmp/unsafe'
)
,
/ Unsafe telemetry level /
)
;
}
)
;
}
)
;
suite
(
'getRemoteCLIBin'
,
(
)
=>
{
const
=
'abcdef0123456789abcdef0123456789abcdef01'
;
test
(
'returns commit-keyed path under shared install root for stable'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIBin
(
'.vscode-server'
,
'stable'
,
)
,
` ~/.vscode-server/code- ${ commit} `
,
)
;
}
)
;
test
(
'returns commit-keyed path for insider'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIBin
(
'.vscode-server-insiders'
,
'insider'
,
)
,
` ~/.vscode-server-insiders/code-insiders- ${ commit} `
,
)
;
}
)
;
test
(
'returns commit-keyed path for exploration'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIBin
(
'.vscode-server-exploration'
,
'exploration'
,
)
,
` ~/.vscode-server-exploration/code-exploration- ${ commit} `
,
)
;
}
)
;
test
(
'returns non-keyed path when commit is undefined (dev build)'
,
(
)
=>
{
.
strictEqual
(
getRemoteCLIBin
(
'.vscode-server-oss'
,
'insider'
)
,
'~/.vscode-server-oss/code-insiders'
,
)
;
.
strictEqual
(
getRemoteCLIBin
(
'.vscode-server'
,
'stable'
)
,
'~/.vscode-server/code'
,
)
;
}
)
;
test
(
'rejects unsafe commit values'
,
(
)
=>
{
.
throws
(
(
)
=>
getRemoteCLIBin
(
'.vscode-server'
,
'stable'
,
'foo;rm'
)
,
/ Unsafe commit /
)
;
}
)
;
test
(
'normalizes uppercase hex commits to lowercase'
,
(
)
=>
{
const
=
'ABCDEF0123456789ABCDEF0123456789ABCDEF01'
;
.
strictEqual
(
getRemoteCLIBin
(
'.vscode-server'
,
'stable'
,
)
,
'~/.vscode-server/code-abcdef0123456789abcdef0123456789abcdef01'
,
)
;
}
)
;
test
(
'rejects unsafe server data folder names'
,
(
)
=>
{
.
throws
(
(
)
=>
getRemoteCLIBin
(
'foo bar'
,
'stable'
,
)
,
/ Unsafe server data folder name /
)
;
}
)
;
}
)
;
suite
(
'shellEscape'
,
(
)
=>
{
test
(
'wraps simple string in single quotes'
,
(
)
=>
{
.
strictEqual
(
shellEscape
(
'hello'
)
,
'\'hello\''
)
;
}
)
;
test
(
'escapes embedded single quotes'
,
(
)
=>
{
.
strictEqual
(
shellEscape
(
'it\'s'
)
,
'\'it\'\\\'\'s\''
)
;
}
)
;
test
(
'handles empty string'
,
(
)
=>
{
.
strictEqual
(
shellEscape
(
''
)
,
'\'\''
)
;
}
)
;
test
(
'passes through special chars safely wrapped'
,
(
)
=>
{
.
strictEqual
(
shellEscape
(
'$(rm -rf /)'
)
,
'\'$(rm -rf /)\''
)
;
}
)
;
}
)
;
suite
(
'resolveRemotePlatform'
,
(
)
=>
{
test
(
'detects Linux x64'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Linux'
,
'x86_64'
)
,
{
:
'linux'
,
:
'x64'
}
)
;
}
)
;
test
(
'detects Linux amd64'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Linux'
,
'amd64'
)
,
{
:
'linux'
,
:
'x64'
}
)
;
}
)
;
test
(
'detects Linux arm64 (aarch64)'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Linux'
,
'aarch64'
)
,
{
:
'linux'
,
:
'arm64'
}
)
;
}
)
;
test
(
'detects Linux arm64'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Linux'
,
'arm64'
)
,
{
:
'linux'
,
:
'arm64'
}
)
;
}
)
;
test
(
'detects Linux armhf'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Linux'
,
'armv7l'
)
,
{
:
'linux'
,
:
'armhf'
}
)
;
}
)
;
test
(
'detects musl Linux x64 as Alpine'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Linux'
,
'x86_64'
,
'musl'
)
,
{
:
'alpine'
,
:
'x64'
}
)
;
}
)
;
test
(
'detects musl Linux arm64 as Alpine'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Linux'
,
'aarch64'
,
'musl\n'
)
,
{
:
'alpine'
,
:
'arm64'
}
)
;
}
)
;
test
(
'rejects musl Linux armhf because no Alpine CLI artifact exists'
,
(
)
=>
{
.
strictEqual
(
resolveRemotePlatform
(
'Linux'
,
'armv7l'
,
'musl'
)
,
undefined
)
;
}
)
;
test
(
'detects Darwin x64'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Darwin'
,
'x86_64'
)
,
{
:
'darwin'
,
:
'x64'
}
)
;
}
)
;
test
(
'detects Darwin arm64'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
'Darwin'
,
'arm64'
)
,
{
:
'darwin'
,
:
'arm64'
}
)
;
}
)
;
test
(
'handles whitespace in uname output'
,
(
)
=>
{
.
deepStrictEqual
(
resolveRemotePlatform
(
' Linux\n'
,
' x86_64\n'
)
,
{
:
'linux'
,
:
'x64'
}
)
;
}
)
;
test
(
'returns undefined for Windows'
,
(
)
=>
{
.
strictEqual
(
resolveRemotePlatform
(
'MINGW64_NT-10.0-19041'
,
'x86_64'
)
,
undefined
)
;
}
)
;
test
(
'returns undefined for unknown OS'
,
(
)
=>
{
.
strictEqual
(
resolveRemotePlatform
(
'FreeBSD'
,
'amd64'
)
,
undefined
)
;
}
)
;
test
(
'returns undefined for unknown arch'
,
(
)
=>
{
.
strictEqual
(
resolveRemotePlatform
(
'Linux'
,
'ppc64le'
)
,
undefined
)
;
}
)
;
}
)
;
suite
(
'buildCLIDownloadUrl'
,
(
)
=>
{
const
=
'abcdef0123456789abcdef0123456789abcdef01'
;
test
(
'uses `latest` URL when commit is omitted'
,
(
)
=>
{
.
strictEqual
(
buildCLIDownloadUrl
(
'linux'
,
'x64'
,
'insider'
)
,
'https://update.code.visualstudio.com/latest/cli-linux-x64/insider'
)
;
}
)
;
test
(
'works for darwin arm64 stable (no commit)'
,
(
)
=>
{
.
strictEqual
(
buildCLIDownloadUrl
(
'darwin'
,
'arm64'
,
'stable'
)
,
'https://update.code.visualstudio.com/latest/cli-darwin-arm64/stable'
)
;
}
)
;
test
(
'uses the Alpine artifact for musl Linux'
,
(
)
=>
{
.
strictEqual
(
buildCLIDownloadUrl
(
'alpine'
,
'x64'
,
'insider'
)
,
'https://update.code.visualstudio.com/latest/cli-alpine-x64/insider'
)
;
}
)
;
test
(
'pins to commit when provided'
,
(
)
=>
{
.
strictEqual
(
buildCLIDownloadUrl
(
'linux'
,
'x64'
,
'insider'
,
)
,
` https://update.code.visualstudio.com/commit: ${ commit} /cli-linux-x64/insider `
,
)
;
}
)
;
test
(
'pins to commit for darwin arm64 stable'
,
(
)
=>
{
.
strictEqual
(
buildCLIDownloadUrl
(
'darwin'
,
'arm64'
,
'stable'
,
)
,
` https://update.code.visualstudio.com/commit: ${ commit} /cli-darwin-arm64/stable `
,
)
;
}
)
;
test
(
'rejects unsafe commit values'
,
(
)
=>
{
.
throws
(
(
)
=>
buildCLIDownloadUrl
(
'linux'
,
'x64'
,
'insider'
,
'foo;rm'
)
,
/ Unsafe commit /
)
;
}
)
;
test
(
'normalizes uppercase hex commits to lowercase'
,
(
)
=>
{
const
=
'ABCDEF0123456789ABCDEF0123456789ABCDEF01'
;
.
strictEqual
(
buildCLIDownloadUrl
(
'linux'
,
'x64'
,
'insider'
,
)
,
` https://update.code.visualstudio.com/commit:abcdef0123456789abcdef0123456789abcdef01/cli-linux-x64/insider `
,
)
;
}
)
;
}
)
;
suite
(
'buildCleanupOldCLIsCommand'
,
(
)
=>
{
test
(
'produces a snippet that keeps the 5 most recent commit-keyed CLIs for insider'
,
(
)
=>
{
const
=
buildCleanupOldCLIsCommand
(
'.vscode-server-insiders'
,
'insider'
)
;
.
ok
(
.
includes
(
'~/.vscode-server-insiders/code-insiders-'
)
,
` cmd missing install path: ${ cmd} `
)
;
.
ok
(
/ ( \[ 0-9a-f\] ) {40} /
.
test
(
)
,
'cmd should match exactly 40 hex chars'
)
;
.
ok
(
/ ls -1t /
.
test
(
)
,
` cmd should sort by mtime: ${ cmd} `
)
;
.
ok
(
/ awk\s + 'NR>5' /
.
test
(
)
,
` cmd should keep 5: ${ cmd} `
)
;
.
ok
(
/ xargs\s + -I\{ \} \s + rm\s + -f\s + -- /
.
test
(
)
,
` cmd should rm safely: ${ cmd} `
)
;
}
)
;
test
(
'uses `code-` archive name for stable'
,
(
)
=>
{
const
=
buildCleanupOldCLIsCommand
(
'.vscode-server'
,
'stable'
)
;
.
ok
(
.
includes
(
'~/.vscode-server/code-[0-9a-f]'
)
,
` cmd should target stable archive: ${ cmd} `
)
;
.
ok
(
!
.
includes
(
'code-insiders-'
)
,
'stable cmd should not mention insiders archive'
)
;
}
)
;
test
(
'rejects unsafe inputs'
,
(
)
=>
{
.
throws
(
(
)
=>
buildCleanupOldCLIsCommand
(
'foo bar'
,
'stable'
)
,
/ Unsafe server data folder name /
)
;
.
throws
(
(
)
=>
buildCleanupOldCLIsCommand
(
'.vscode-server'
,
'foo bar'
)
,
/ Unsafe quality /
)
;
}
)
;
}
)
;
suite
(
'buildFindFallbackCLICommand'
,
(
)
=>
{
test
(
'lists commit-keyed candidates then legacy paths for insider'
,
(
)
=>
{
const
=
buildFindFallbackCLICommand
(
'.vscode-server-insiders'
,
'insider'
)
;
.
ok
(
.
includes
(
'~/.vscode-server-insiders/code-insiders-'
)
,
` cmd missing new path: ${ cmd} `
)
;
.
ok
(
/ ls -1t /
.
test
(
)
,
'should sort commit-keyed candidates by mtime'
)
;
.
ok
(
.
includes
(
'~/.vscode-cli-insider/code-insiders'
)
,
` cmd missing legacy path: ${ cmd} `
)
;
}
)
;
test
(
'uses no-suffix legacy dir for stable'
,
(
)
=>
{
const
=
buildFindFallbackCLICommand
(
'.vscode-server'
,
'stable'
)
;
.
ok
(
.
includes
(
'~/.vscode-cli/code'
)
,
` cmd missing stable legacy path: ${ cmd} `
)
;
.
ok
(
!
.
includes
(
'.vscode-cli-stable'
)
,
'stable should not get the -<quality> suffix'
)
;
}
)
;
test
(
'rejects unsafe inputs'
,
(
)
=>
{
.
throws
(
(
)
=>
buildFindFallbackCLICommand
(
'foo bar'
,
'stable'
)
,
/ Unsafe server data folder name /
)
;
.
throws
(
(
)
=>
buildFindFallbackCLICommand
(
'.vscode-server'
,
'foo bar'
)
,
/ Unsafe quality /
)
;
}
)
;
}
)
;
suite
(
'isValidFallbackCLIPath'
,
(
)
=>
{
const
=
'.vscode-server-insiders'
;
const
=
'insider'
;
const
=
'0123456789abcdef0123456789abcdef01234567'
;
test
(
'accepts commit-keyed path under the shared install root'
,
(
)
=>
{
.
strictEqual
(
isValidFallbackCLIPath
(
` ~/ ${ sdf} /code-insiders- ${ hex} `
,
,
)
,
true
)
;
}
)
;
test
(
'accepts legacy ~/.vscode-cli-<quality>/<archive> path for insider'
,
(
)
=>
{
.
strictEqual
(
isValidFallbackCLIPath
(
'~/.vscode-cli-insider/code-insiders'
,
,
)
,
true
)
;
}
)
;
test
(
'accepts legacy ~/.vscode-cli/code path for stable'
,
(
)
=>
{
.
strictEqual
(
isValidFallbackCLIPath
(
'~/.vscode-cli/code'
,
'.vscode-server'
,
'stable'
)
,
true
)
;
}
)
;
test
(
'rejects commit suffix with non-hex characters'
,
(
)
=>
{
const
=
'g'
.
repeat
(
40
)
;
.
strictEqual
(
isValidFallbackCLIPath
(
` ~/ ${ sdf} /code-insiders- ${ notHex} `
,
,
)
,
false
)
;
}
)
;
test
(
'rejects commit suffix with wrong length'
,
(
)
=>
{
.
strictEqual
(
isValidFallbackCLIPath
(
` ~/ ${ sdf} /code-insiders- ${ hex. slice ( 0 , 39 ) } `
,
,
)
,
false
)
;
.
strictEqual
(
isValidFallbackCLIPath
(
` ~/ ${ sdf} /code-insiders- ${ hex} a `
,
,
)
,
false
)
;
}
)
;
test
(
'rejects paths under an unexpected root'
,
(
)
=>
{
.
strictEqual
(
isValidFallbackCLIPath
(
` ~/.something-else/code-insiders- ${ hex} `
,
,
)
,
false
)
;
}
)
;
test
(
'rejects empty input'
,
(
)
=>
{
.
strictEqual
(
isValidFallbackCLIPath
(
''
,
,
)
,
false
)
;
}
)
;
test
(
'rejects shell metacharacters'
,
(
)
=>
{
.
strictEqual
(
isValidFallbackCLIPath
(
` ~/ ${ sdf} /code-insiders- ${ hex} ; rm -rf / `
,
,
)
,
false
)
;
.
strictEqual
(
isValidFallbackCLIPath
(
` ~/ ${ sdf} /code-insiders- ${ hex} && evil `
,
,
)
,
false
)
;
}
)
;
}
)
;
suite
(
'redactToken'
,
(
)
=>
{
test
(
'redacts token in WebSocket URL'
,
(
)
=>
{
.
strictEqual
(
redactToken
(
'ws://127.0.0.1:12345?tkn=secret123'
)
,
'ws://127.0.0.1:12345?tkn=***'
)
;
}
)
;
test
(
'redacts token with following whitespace'
,
(
)
=>
{
.
strictEqual
(
redactToken
(
'ws://127.0.0.1:12345?tkn=abc123 done'
)
,
'ws://127.0.0.1:12345?tkn=*** done'
)
;
}
)
;
test
(
'preserves text without tokens'
,
(
)
=>
{
.
strictEqual
(
redactToken
(
'no token here'
)
,
'no token here'
)
;
}
)
;
test
(
'redacts multiple tokens'
,
(
)
=>
{
.
strictEqual
(
redactToken
(
'?tkn=one and ?tkn=two'
)
,
'?tkn=*** and ?tkn=***'
)
;
}
)
;
}
)
;
suite
(
'buildAgentEndpointsCommand'
,
(
)
=>
{
test
(
'omits --user-data-dir when not yet known'
,
(
)
=>
{
.
strictEqual
(
buildAgentEndpointsCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
)
,
'~/.vscode-server/code --cli-data-dir ~/.vscode-server/cli agent endpoints'
,
)
;
}
)
;
test
(
'includes --user-data-dir once resolved'
,
(
)
=>
{
.
strictEqual
(
buildAgentEndpointsCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/home/user/.vscode-remote'
)
,
'~/.vscode-server/code --cli-data-dir ~/.vscode-server/cli agent endpoints --user-data-dir \'/home/user/.vscode-remote\''
,
)
;
}
)
;
}
)
;
suite
(
'buildAgentHostSpawnCommand'
,
(
)
=>
{
test
(
'includes --new-instance, --user-data-dir and default --idle-timeout'
,
(
)
=>
{
.
strictEqual
(
buildAgentHostSpawnCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/home/user/.vscode-remote'
,
.
ON
)
,
'~/.vscode-server/code --cli-data-dir ~/.vscode-server/cli --telemetry-level all agent host --port 0 --new-instance --user-data-dir \'/home/user/.vscode-remote\' --idle-timeout 300'
,
)
;
}
)
;
test
(
'honors a custom idle timeout'
,
(
)
=>
{
.
strictEqual
(
buildAgentHostSpawnCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/home/user/.vscode-remote'
,
.
ON
,
60
)
,
'~/.vscode-server/code --cli-data-dir ~/.vscode-server/cli --telemetry-level all agent host --port 0 --new-instance --user-data-dir \'/home/user/.vscode-remote\' --idle-timeout 60'
,
)
;
}
)
;
test
(
'propagates telemetry disablement to a new dedicated agent host'
,
(
)
=>
{
.
strictEqual
(
buildAgentHostSpawnCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/home/user/.vscode-remote'
,
.
OFF
)
,
'~/.vscode-server/code --cli-data-dir ~/.vscode-server/cli --telemetry-level off agent host --port 0 --new-instance --user-data-dir \'/home/user/.vscode-remote\' --idle-timeout 300'
,
)
;
}
)
;
test
(
'rejects unsafe idle timeout values'
,
(
)
=>
{
.
throws
(
(
)
=>
buildAgentHostSpawnCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/x'
,
.
ON
,
0
)
,
/ Unsafe idle timeout /
)
;
.
throws
(
(
)
=>
buildAgentHostSpawnCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/x'
,
.
ON
,
-
1
)
,
/ Unsafe idle timeout /
)
;
.
throws
(
(
)
=>
buildAgentHostSpawnCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/x'
,
.
ON
,
1.5
)
,
/ Unsafe idle timeout /
)
;
}
)
;
test
(
'always includes --new-instance so an existing standalone is never silently reused'
,
(
)
=>
{
const
=
buildAgentHostSpawnCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/x'
,
.
ON
)
;
.
ok
(
.
includes
(
' --new-instance '
)
,
'spawn command must request a genuinely new instance, not reuse an existing standalone'
)
;
}
)
;
}
)
;
suite
(
'buildAgentRelayCommand'
,
(
)
=>
{
test
(
'builds a relay command scoped to the exact instanceId'
,
(
)
=>
{
.
strictEqual
(
buildAgentRelayCommand
(
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'abc-123'
,
'/home/user/.vscode-remote'
)
,
'~/.vscode-server/code --cli-data-dir ~/.vscode-server/cli agent relay \'abc-123\' --user-data-dir \'/home/user/.vscode-remote\''
,
)
;
}
)
;
}
)
;
suite
(
'parseAgentEndpointsOutput'
,
(
)
=>
{
test
(
'returns undefined for empty output'
,
(
)
=>
{
.
strictEqual
(
parseAgentEndpointsOutput
(
''
)
,
undefined
)
;
.
strictEqual
(
parseAgentEndpointsOutput
(
' \n'
)
,
undefined
)
;
}
)
;
test
(
'returns undefined for invalid JSON'
,
(
)
=>
{
.
strictEqual
(
parseAgentEndpointsOutput
(
'not json'
)
,
undefined
)
;
}
)
;
test
(
'returns undefined when the envelope is missing userDataPath/endpoints'
,
(
)
=>
{
.
strictEqual
(
parseAgentEndpointsOutput
(
JSON
.
stringify
(
{
:
[
]
}
)
)
,
undefined
)
;
.
strictEqual
(
parseAgentEndpointsOutput
(
JSON
.
stringify
(
{
:
'/x'
}
)
)
,
undefined
)
;
}
)
;
test
(
'parses a well-formed envelope and validates each endpoint'
,
(
)
=>
{
const
=
makeEndpoint
(
{
:
'standalone'
,
:
111
,
:
'i1'
}
)
;
const
=
parseAgentEndpointsOutput
(
JSON
.
stringify
(
{
:
'/home/user/.vscode-remote'
,
:
[
]
}
)
)
;
.
ok
(
)
;
.
strictEqual
(
.
,
'/home/user/.vscode-remote'
)
;
.
deepStrictEqual
(
.
,
[
]
)
;
}
)
;
test
(
'drops malformed individual endpoint entries without failing the whole parse'
,
(
)
=>
{
const
=
makeEndpoint
(
{
:
'editor'
,
:
222
,
:
'i2'
}
)
;
const
=
parseAgentEndpointsOutput
(
JSON
.
stringify
(
{
:
'/x'
,
:
[
,
{
:
true
}
]
}
)
)
;
.
ok
(
)
;
.
deepStrictEqual
(
.
,
[
]
)
;
}
)
;
}
)
;
suite
(
'runAgentEndpoints'
,
(
)
=>
{
test
(
'parses stdout on success'
,
async
(
)
=>
{
const
=
makeEndpoint
(
{
:
'standalone'
,
:
333
,
:
'i3'
}
)
;
const
:
ISshExec
=
async
(
)
=>
(
{
:
JSON
.
stringify
(
{
:
'/home/user/.vscode-remote'
,
:
[
]
}
)
,
:
''
,
:
0
,
}
)
;
const
=
await
runAgentEndpoints
(
,
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
)
;
.
strictEqual
(
.
,
'/home/user/.vscode-remote'
)
;
.
deepStrictEqual
(
.
,
[
]
)
;
}
)
;
test
(
'passes the resolved --user-data-dir through to the command'
,
async
(
)
=>
{
const
:
string
[
]
=
[
]
;
const
:
ISshExec
=
async
=>
{
.
push
(
)
;
return
{
:
JSON
.
stringify
(
{
:
'/x'
,
:
[
]
}
)
,
:
''
,
:
0
}
;
}
;
await
runAgentEndpoints
(
,
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/home/user/.vscode-remote'
)
;
.
ok
(
.
some
(
=>
.
includes
(
'--user-data-dir \'/home/user/.vscode-remote\''
)
)
)
;
}
)
;
test
(
'throws (loudly) when the command exits non-zero'
,
async
(
)
=>
{
const
:
ISshExec
=
async
(
)
=>
(
{
:
''
,
:
'command not found'
,
:
127
}
)
;
await
.
rejects
(
(
)
=>
runAgentEndpoints
(
,
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
)
,
/ exit code 127. * command not found / s
,
)
;
}
)
;
test
(
'throws when output cannot be parsed'
,
async
(
)
=>
{
const
:
ISshExec
=
async
(
)
=>
(
{
:
'not json'
,
:
''
,
:
0
}
)
;
await
.
rejects
(
(
)
=>
runAgentEndpoints
(
,
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
)
,
/ unparsable output \( 8 characters\) $ /
,
)
;
}
)
;
test
(
'parses JSON after legacy CLI log output'
,
async
(
)
=>
{
const
=
` [2026-08-06 15:31:19] info Pruning stale local endpoint registry entry\n ${ JSON . stringify ( { userDataPath: '/tmp/user-data' , endpoints: [ ] } ) } `
;
const
:
ISshExec
=
async
(
)
=>
(
{
:
,
:
''
,
:
0
}
)
;
const
=
await
runAgentEndpoints
(
,
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
)
;
.
deepStrictEqual
(
,
{
:
'/tmp/user-data'
,
:
[
]
,
}
)
;
}
)
;
}
)
;
suite
(
'filterLiveAgentHostEndpoints'
,
(
)
=>
{
test
(
'keeps only entries whose PID responds to kill -0'
,
async
(
)
=>
{
const
=
makeEndpoint
(
{
:
'standalone'
,
:
100
,
:
'alive'
}
)
;
const
=
makeEndpoint
(
{
:
'standalone'
,
:
200
,
:
'dead'
}
)
;
const
:
ISshExec
=
async
=>
{
if
(
.
includes
(
'kill -0 100'
)
)
{
return
{
:
''
,
:
''
,
:
0
}
;
}
if
(
.
includes
(
'kill -0 200'
)
)
{
return
{
:
''
,
:
''
,
:
1
}
;
}
throw
new
Error
(
` unexpected command: ${ command} `
)
;
}
;
const
=
await
filterLiveAgentHostEndpoints
(
,
[
,
]
)
;
.
deepStrictEqual
(
,
[
]
)
;
}
)
;
test
(
'probes each distinct PID at most once'
,
async
(
)
=>
{
const
=
makeEndpoint
(
{
:
'editor'
,
:
100
,
:
'e1'
}
)
;
const
=
makeEndpoint
(
{
:
'standalone'
,
:
100
,
:
'e2'
}
)
;
let
=
0
;
const
:
ISshExec
=
async
=>
{
if
(
.
includes
(
'kill -0 100'
)
)
{
++
;
return
{
:
''
,
:
''
,
:
0
}
;
}
throw
new
Error
(
` unexpected command: ${ command} `
)
;
}
;
const
=
await
filterLiveAgentHostEndpoints
(
,
[
,
]
)
;
.
strictEqual
(
,
1
)
;
.
strictEqual
(
.
,
2
)
;
}
)
;
test
(
'returns an empty array for an empty input'
,
async
(
)
=>
{
const
:
ISshExec
=
async
(
)
=>
{
throw
new
Error
(
'should not be called'
)
;
}
;
.
deepStrictEqual
(
await
filterLiveAgentHostEndpoints
(
,
[
]
)
,
[
]
)
;
}
)
;
}
)
;
suite
(
'findNewAgentHostEndpoint'
,
(
)
=>
{
test
(
'returns the standalone entry present only in "after"'
,
(
)
=>
{
const
=
[
makeEndpoint
(
{
:
'standalone'
,
:
1
,
:
'old'
}
)
]
;
const
=
makeEndpoint
(
{
:
'standalone'
,
:
2
,
:
'new'
}
)
;
const
=
[
...
,
]
;
.
deepStrictEqual
(
findNewAgentHostEndpoint
(
,
)
,
)
;
}
)
;
test
(
'ignores new editor-owned entries (only standalone spawns are matched)'
,
(
)
=>
{
const
:
[
]
=
[
]
;
const
=
makeEndpoint
(
{
:
'editor'
,
:
5
,
:
'e'
}
)
;
.
strictEqual
(
findNewAgentHostEndpoint
(
,
[
]
)
,
undefined
)
;
}
)
;
test
(
'returns undefined when nothing changed'
,
(
)
=>
{
const
=
[
makeEndpoint
(
{
:
'standalone'
,
:
1
,
:
'same'
}
)
]
;
.
strictEqual
(
findNewAgentHostEndpoint
(
,
)
,
undefined
)
;
}
)
;
}
)
;
suite
(
'waitForNewStandaloneEndpoint'
,
(
)
=>
{
test
(
'resolves as soon as the new endpoint appears'
,
async
(
)
=>
{
const
=
[
makeEndpoint
(
{
:
'standalone'
,
:
1
,
:
'old'
}
)
]
;
const
=
makeEndpoint
(
{
:
'standalone'
,
:
2
,
:
'new'
}
)
;
let
=
0
;
const
:
ISshExec
=
async
(
)
=>
{
++
;
const
=
<
2
?
:
[
...
,
]
;
return
{
:
JSON
.
stringify
(
{
:
'/x'
,
}
)
,
:
''
,
:
0
}
;
}
;
const
=
await
waitForNewStandaloneEndpoint
(
,
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/x'
,
,
{
:
1
}
)
;
.
deepStrictEqual
(
,
)
;
.
ok
(
>=
2
)
;
}
)
;
test
(
'throws once the attempt budget is exhausted'
,
async
(
)
=>
{
const
=
[
makeEndpoint
(
{
:
'standalone'
,
:
1
,
:
'old'
}
)
]
;
const
:
ISshExec
=
async
(
)
=>
(
{
:
JSON
.
stringify
(
{
:
'/x'
,
:
}
)
,
:
''
,
:
0
}
)
;
await
.
rejects
(
(
)
=>
waitForNewStandaloneEndpoint
(
,
'~/.vscode-server/code'
,
'~/.vscode-server/cli'
,
'/x'
,
,
{
:
2
,
:
1
}
)
,
/ Timed out waiting /
,
)
;
}
)
;
}
)
;
}
)
;