ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / extension / chatSessions / copilotcli / node / test / permissionHelpers.spec.ts 605 строк · изменён 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
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' ;
import type { CancellationToken, ChatParticipantToolToken } from 'vscode' ;
import { ILogService } from '../../../../../platform/log/common/logService' ;
import { IWorkspaceService } from '../../../../../platform/workspace/common/workspaceService' ;
import { CancellationTokenSource } from '../../../../../util/vs/base/common/cancellation' ;
import { DisposableStore } from '../../../../../util/vs/base/common/lifecycle' ;
import {
IInstantiationService
LanguageModelTextPart LanguageModelToolResult2
createExtensionUnitTestingServices
ToolName
IToolsService
ExternalEditTracker
IWorkspaceInfo
ICopilotCLIImageSupport
buildMcpConfirmationParams buildShellConfirmationParams handleReadPermission handleWritePermission isFileFromSessionWorkspace PermissionRequest requiresFileEditconfirmation showInteractivePermissionPrompt
disposables
instaService IInstantiationService
services disposables
instaService services
disposables
req kind intention fullCommandText
result req
result tool ToolName CoreTerminalConfirmationTool
result input message
result input command
result input isBackground
req kind fullCommandText
result req
result tool ToolName CoreTerminalConfirmationTool
result input message
result input command
req kind
result req
result tool ToolName CoreTerminalConfirmationTool
result input message
workingDirectory
req kind fullCommandText
result req workingDirectory
result input command
result input message
fullCommandText
req kind fullCommandText fullCommandText
workingDirectory
result req workingDirectory
result input command fullCommandText
result input message fullCommandText
fullCommandText
req kind fullCommandText fullCommandText
result req
result input command fullCommandText
result input message fullCommandText
req kind fullCommandText
workingDirectory
result req workingDirectory
result input command
result input message
workingDirectory
fullCommandText
req kind intention fullCommandText fullCommandText
result req workingDirectory
result input message
result input command
workingDirectory
fullCommandText
req kind fullCommandText fullCommandText
result req workingDirectory
result input command
result input message
workingDirectory
fullCommandText
req kind fullCommandText
result req workingDirectory
result input command
result input message
workingDirectory
fullCommandText
req kind fullCommandText
result req workingDirectory
result input command
result input message
workingDirectory
fullCommandText
req kind fullCommandText
result req workingDirectory
result input command
workingDirectory
fullCommandText
req kind fullCommandText
result req workingDirectory
result input command fullCommandText
req kind intention fullCommandText requestSandboxBypass requestSandboxBypassReason
result req
result input command
result input sandboxBypass
result input sandboxBypassReason
req kind intention fullCommandText
result req
result input sandboxBypass
result input sandboxBypassReason
req kind serverName toolTitle toolName args path
result req Extract PermissionRequest kind
result tool ToolName CoreConfirmationTool
result input title
result input message
result input message
req kind toolName args detail
result req Extract PermissionRequest kind
result input title
result input message
result input message
req kind args
result req Extract PermissionRequest kind
result input title
req kind fullCommandText
instaService req
req kind intention
instaService req
req kind fileName fsPath diff intention
instaService req
req kind fileName fsPath diff intention
workingDirectory
instaService req workingDirectory
req kind fileName fsPath diff intention
workingDirectory
instaService req workingDirectory
workspaceInfo IWorkspaceInfo
folder
repository
worktree
worktreeProperties
workspaceInfo
workspaceInfo IWorkspaceInfo
folder
repository
worktree
worktreeProperties
workspaceInfo
workspaceInfo IWorkspaceInfo
folder
repository
worktree
worktreeProperties autoCommit baseCommit branchName repositoryPath worktreePath version
workspaceInfo
workspaceInfo IWorkspaceInfo
folder
repository
worktree
worktreeProperties autoCommit baseCommit branchName repositoryPath worktreePath version
workspaceInfo
workspaceInfo IWorkspaceInfo
folder
repository
worktree
worktreeProperties
workspaceInfo
workspaceInfo IWorkspaceInfo
folder
repository
worktree
worktreeProperties
workspaceInfo
logService ILogService
token CancellationToken
tokenSource CancellationTokenSource
services disposables
accessor services
logService accessor ILogService
tokenSource
token tokenSource token
tokenSource
folder worktree repository IWorkspaceInfo
folder
repository
worktree
worktreeProperties worktree autoCommit baseCommit branchName repositoryPath repository fsPath worktreePath worktree fsPath version
trusted ICopilotCLIImageSupport
_serviceBrand storeImage vi trusted
folders IWorkspaceService
resource folders f resource fsPath f fsPath IWorkspaceService
response IToolsService
invokeTool vi response
IToolsService
req kind path
result
req
ChatParticipantToolToken logService token
result kind
req kind path
result
req
ChatParticipantToolToken logService token
result kind
req kind path
result
req
ChatParticipantToolToken logService token
result kind
filePath
req kind path filePath
attachments type path filePath
result
req attachments
ChatParticipantToolToken logService token
result kind
toolsService
req kind path intention
result
req
toolsService ChatParticipantToolToken logService token
result kind
toolsService invokeTool
toolsService
req kind path
result
req
toolsService ChatParticipantToolToken logService token
result kind
toolsService
req kind path intention
req
toolsService ChatParticipantToolToken logService token
callArgs toolsService invokeTool ReturnType vi fn mock calls
callArgs ToolName CoreConfirmationTool
callArgs input message
toolsService
req kind path
req
toolsService ChatParticipantToolToken logService token
callArgs toolsService invokeTool ReturnType vi fn mock calls
callArgs input message
logService ILogService
token CancellationToken
tokenSource CancellationTokenSource
editTracker ExternalEditTracker
services disposables
accessor services
logService accessor ILogService
tokenSource
token tokenSource token
editTracker
editTracker trackEdit vi
tokenSource
opts folder worktree repository worktreeProperties IWorkspaceInfo
folder opts folder
repository opts repository
worktree opts worktree
worktreeProperties opts worktreeProperties
folders IWorkspaceService
resource folders f resource fsPath f fsPath IWorkspaceService
response IToolsService
invokeTool vi response
IToolsService
wsFolder
req kind fileName fsPath diff intention
result
req editTracker
folder wsFolder
wsFolder
instaService
ChatParticipantToolToken logService token
result kind
worktree
req kind fileName fsPath diff intention
result
req editTracker
folder
worktree
worktreeProperties autoCommit baseCommit branchName repositoryPath worktreePath version
instaService
ChatParticipantToolToken logService token
result kind
toolsService
req kind fileName fsPath diff intention
result
req editTracker
folder
instaService toolsService
ChatParticipantToolToken logService token
result kind
toolsService invokeTool
toolsService
req kind fileName fsPath diff intention
result
req editTracker
folder
instaService toolsService
ChatParticipantToolToken logService token
result kind
req kind intention
result
req editTracker
folder
instaService
ChatParticipantToolToken logService token
result kind
logService ILogService
token CancellationToken
tokenSource CancellationTokenSource
services disposables
accessor services
logService accessor ILogService
tokenSource
token tokenSource token
tokenSource
response IToolsService
invokeTool vi response
IToolsService
toolsService
req kind url
result
req toolsService
ChatParticipantToolToken logService token
result kind
callArgs toolsService invokeTool ReturnType vi fn mock calls
callArgs ToolName CoreConfirmationTool
callArgs input title
toolsService
req kind url
result
req toolsService
ChatParticipantToolToken logService token
result kind
toolsService
invokeTool vi
IToolsService
req kind url
result
req toolsService
ChatParticipantToolToken logService token
result kind
toolsService
req kind url
req toolsService
ChatParticipantToolToken logService token
callArgs toolsService invokeTool ReturnType vi fn mock calls
callArgs subAgentInvocationId
toolsService
req kind url
result
req toolsService
ChatParticipantToolToken logService token
result kind
URI
}
from
'../../../../../util/vs/base/common/uri'
;
import
{
}
from
'../../../../../util/vs/platform/instantiation/common/instantiation'
;
import
{
,
}
from
'../../../../../vscodeTypes'
;
import
{
}
from
'../../../../test/node/services'
;
import
{
}
from
'../../../../tools/common/toolNames'
;
import
{
}
from
'../../../../tools/common/toolsService'
;
import
{
}
from
'../../../common/externalEditTracker'
;
import
{
}
from
'../../../common/workspaceInfo'
;
import
{
}
from
'../copilotCLIImageSupport'
;
import
{
,
,
,
,
,
,
,
}
from
'../permissionHelpers'
;
describe
(
'CopilotCLI permissionHelpers'
,
(
)
=>
{
const
=
new
DisposableStore
(
)
;
let
:
;
beforeEach
(
(
)
=>
{
const
=
.
add
(
createExtensionUnitTestingServices
(
)
)
;
=
.
seal
(
)
;
}
)
;
afterEach
(
(
)
=>
{
.
clear
(
)
;
}
)
;
describe
(
'buildShellConfirmationParams'
,
(
)
=>
{
it
(
'shell: uses intention over command text and sets terminal confirmation tool'
,
(
)
=>
{
const
=
{
:
'shell'
,
:
'List workspace files'
,
:
'ls -la'
}
as
any
;
const
=
buildShellConfirmationParams
(
,
undefined
)
;
expect
(
.
)
.
toBe
(
.
)
;
expect
(
.
.
)
.
toBe
(
'List workspace files'
)
;
expect
(
.
.
)
.
toBe
(
'ls -la'
)
;
expect
(
.
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'shell: falls back to fullCommandText when no intention'
,
(
)
=>
{
const
=
{
:
'shell'
,
:
'echo "hi"'
}
as
any
;
const
=
buildShellConfirmationParams
(
,
undefined
)
;
expect
(
.
)
.
toBe
(
.
)
;
expect
(
.
.
)
.
toBe
(
'echo "hi"'
)
;
expect
(
.
.
)
.
toBe
(
'echo "hi"'
)
;
}
)
;
it
(
'shell: falls back to codeBlock when neither intention nor command text provided'
,
(
)
=>
{
const
=
{
:
'shell'
}
as
any
;
const
=
buildShellConfirmationParams
(
,
undefined
)
;
expect
(
.
)
.
toBe
(
.
)
;
expect
(
.
.
)
.
toMatch
(
/ ^ \n \n ```/
)
;
}
)
;
it
(
'shell: strips cd prefix from command when matching workingDirectory on bash'
,
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
const
=
{
:
'shell'
,
:
` cd ${ workingDirectory. fsPath} && npm test `
}
as
any
;
const
=
buildShellConfirmationParams
(
,
,
false
)
;
expect
(
.
.
)
.
toBe
(
'npm test'
)
;
expect
(
.
.
)
.
toBe
(
'npm test'
)
;
}
)
;
it
(
'shell: keeps full command when cd prefix does not match workingDirectory on bash'
,
(
)
=>
{
const
=
` cd ${ URI . file ( '/other' ) . fsPath} && npm test `
;
const
=
{
:
'shell'
,
:
}
as
any
;
const
=
URI
.
file
(
'/workspace'
)
;
const
=
buildShellConfirmationParams
(
,
,
false
)
;
expect
(
.
.
)
.
toBe
(
)
;
expect
(
.
.
)
.
toBe
(
)
;
}
)
;
it
(
'shell: keeps full command with cd prefix when no workingDirectory'
,
(
)
=>
{
const
=
'cd /workspace && npm test'
;
const
=
{
:
'shell'
,
:
}
as
any
;
const
=
buildShellConfirmationParams
(
,
undefined
,
false
)
;
expect
(
.
.
)
.
toBe
(
)
;
expect
(
.
.
)
.
toBe
(
)
;
}
)
;
it
(
'shell: plain command without cd prefix is unchanged'
,
(
)
=>
{
const
=
{
:
'shell'
,
:
'npm test'
}
as
any
;
const
=
URI
.
file
(
'/workspace'
)
;
const
=
buildShellConfirmationParams
(
,
,
false
)
;
expect
(
.
.
)
.
toBe
(
'npm test'
)
;
expect
(
.
.
)
.
toBe
(
'npm test'
)
;
}
)
;
it
(
'shell: intention takes priority in message even when cd prefix is stripped'
,
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
const
=
` cd ${ workingDirectory. fsPath} && npm test `
;
const
=
{
:
'shell'
,
:
'Run unit tests'
,
:
}
as
any
;
const
=
buildShellConfirmationParams
(
,
,
false
)
;
expect
(
.
.
)
.
toBe
(
'Run unit tests'
)
;
expect
(
.
.
)
.
toBe
(
'npm test'
)
;
}
)
;
it
(
'shell: strips Set-Location prefix when matching workingDirectory on Windows'
,
(
)
=>
{
const
=
URI
.
file
(
'C:\\workspace'
)
;
const
=
` Set-Location ${ workingDirectory. fsPath} ; npm test `
;
const
=
{
:
'shell'
,
:
}
as
any
;
const
=
buildShellConfirmationParams
(
,
,
true
)
;
expect
(
.
.
)
.
toBe
(
'npm test'
)
;
expect
(
.
.
)
.
toBe
(
'npm test'
)
;
}
)
;
it
(
'shell: strips cd /d prefix when matching workingDirectory on Windows'
,
(
)
=>
{
const
=
URI
.
file
(
'C:\\project'
)
;
const
=
` cd /d ${ workingDirectory. fsPath} && npm start `
;
const
=
{
:
'shell'
,
}
as
any
;
const
=
buildShellConfirmationParams
(
,
,
true
)
;
expect
(
.
.
)
.
toBe
(
'npm start'
)
;
expect
(
.
.
)
.
toBe
(
'npm start'
)
;
}
)
;
it
(
'shell: strips Set-Location -Path prefix when matching workingDirectory on Windows'
,
(
)
=>
{
const
=
URI
.
file
(
'C:\\project'
)
;
const
=
` Set-Location -Path ${ workingDirectory. fsPath} && npm start `
;
const
=
{
:
'shell'
,
}
as
any
;
const
=
buildShellConfirmationParams
(
,
,
true
)
;
expect
(
.
.
)
.
toBe
(
'npm start'
)
;
expect
(
.
.
)
.
toBe
(
'npm start'
)
;
}
)
;
it
(
'shell: bash cd prefix not recognized when isWindows is true'
,
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
const
=
` cd ${ workingDirectory. fsPath} && npm test `
;
const
=
{
:
'shell'
,
}
as
any
;
const
=
buildShellConfirmationParams
(
,
,
true
)
;
expect
(
.
.
)
.
toBe
(
'npm test'
)
;
}
)
;
it
(
'shell: Windows Set-Location not recognized when isWindows is false'
,
(
)
=>
{
const
=
URI
.
file
(
'C:\\workspace'
)
;
const
=
` Set-Location -Path ${ workingDirectory. fsPath} ; npm test `
;
const
=
{
:
'shell'
,
}
as
any
;
const
=
buildShellConfirmationParams
(
,
,
false
)
;
expect
(
.
.
)
.
toBe
(
)
;
}
)
;
it
(
'shell: passes sandboxBypass and reason when the command opts out of the sandbox'
,
(
)
=>
{
const
=
{
:
'shell'
,
:
'Read secret'
,
:
'cat ~/secret'
,
:
true
,
:
'Needs access outside the workspace'
}
as
any
;
const
=
buildShellConfirmationParams
(
,
undefined
)
;
expect
(
.
.
)
.
toBe
(
'cat ~/secret'
)
;
expect
(
.
.
)
.
toBe
(
true
)
;
expect
(
.
.
)
.
toBe
(
'Needs access outside the workspace'
)
;
}
)
;
it
(
'shell: omits sandboxBypass for ordinary commands'
,
(
)
=>
{
const
=
{
:
'shell'
,
:
'List workspace files'
,
:
'ls -la'
}
as
any
;
const
=
buildShellConfirmationParams
(
,
undefined
)
;
expect
(
.
.
)
.
toBeUndefined
(
)
;
expect
(
.
.
)
.
toBeUndefined
(
)
;
}
)
;
}
)
;
describe
(
'buildMcpConfirmationParams'
,
(
)
=>
{
it
(
'mcp: formats with serverName, toolTitle and args JSON'
,
(
)
=>
{
const
=
{
:
'mcp'
,
:
'files'
,
:
'List Files'
,
:
'list'
,
:
{
:
'/tmp'
}
}
as
any
;
const
=
buildMcpConfirmationParams
(
as
<
,
{
:
'mcp'
}
>
)
;
expect
(
.
)
.
toBe
(
.
)
;
expect
(
.
.
)
.
toBe
(
'List Files'
)
;
expect
(
.
.
)
.
toContain
(
'Server: files'
)
;
expect
(
.
.
)
.
toContain
(
'"path": "/tmp"'
)
;
}
)
;
it
(
'mcp: falls back to generated title and full JSON when no serverName'
,
(
)
=>
{
const
=
{
:
'mcp'
,
:
'info'
,
:
{
:
true
}
}
as
any
;
const
=
buildMcpConfirmationParams
(
as
<
,
{
:
'mcp'
}
>
)
;
expect
(
.
.
)
.
toBe
(
'MCP Tool: info'
)
;
expect
(
.
.
)
.
toMatch
(
/ ```json /
)
;
expect
(
.
.
)
.
toContain
(
'"detail": true'
)
;
}
)
;
it
(
'mcp: uses Unknown when neither toolTitle nor toolName provided'
,
(
)
=>
{
const
=
{
:
'mcp'
,
:
{
}
}
as
any
;
const
=
buildMcpConfirmationParams
(
as
<
,
{
:
'mcp'
}
>
)
;
expect
(
.
.
)
.
toBe
(
'MCP Tool: Unknown'
)
;
}
)
;
}
)
;
describe
(
'requiresFileEditconfirmation'
,
(
)
=>
{
it
(
'returns false for non-write requests'
,
async
(
)
=>
{
const
=
{
:
'shell'
,
:
'ls'
}
as
any
;
expect
(
await
requiresFileEditconfirmation
(
,
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'returns false when no fileName is provided'
,
async
(
)
=>
{
const
=
{
:
'write'
,
:
'edit'
}
as
any
;
expect
(
await
requiresFileEditconfirmation
(
,
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'requires confirmation for file outside workspace when no workingDirectory'
,
async
(
)
=>
{
const
=
{
:
'write'
,
:
URI
.
file
(
'/some/path/foo.ts'
)
.
,
:
''
,
:
''
}
as
any
;
expect
(
await
requiresFileEditconfirmation
(
,
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'does not require confirmation when workingDirectory covers the file'
,
async
(
)
=>
{
const
=
{
:
'write'
,
:
URI
.
file
(
'/workspace/src/foo.ts'
)
.
,
:
''
,
:
''
}
as
any
;
const
=
URI
.
file
(
'/workspace'
)
;
expect
(
await
requiresFileEditconfirmation
(
,
,
undefined
,
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'does not require confirmation when workingDirectory is provided'
,
async
(
)
=>
{
const
=
{
:
'write'
,
:
URI
.
file
(
'/workspace/other/foo.ts'
)
.
,
:
''
,
:
''
}
as
any
;
const
=
URI
.
file
(
'/workspace'
)
;
expect
(
await
requiresFileEditconfirmation
(
,
,
undefined
,
)
)
.
toBe
(
false
)
;
}
)
;
}
)
;
describe
(
'isFileFromSessionWorkspace'
,
(
)
=>
{
it
(
'returns true for file inside the working directory (folder)'
,
(
)
=>
{
const
:
=
{
:
URI
.
file
(
'/workspace'
)
,
:
undefined
,
:
undefined
,
:
undefined
,
}
;
expect
(
isFileFromSessionWorkspace
(
URI
.
file
(
'/workspace/src/foo.ts'
)
,
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'returns false for file outside all known directories'
,
(
)
=>
{
const
:
=
{
:
URI
.
file
(
'/workspace'
)
,
:
undefined
,
:
undefined
,
:
undefined
,
}
;
expect
(
isFileFromSessionWorkspace
(
URI
.
file
(
'/other/path/foo.ts'
)
,
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'returns true for file inside the worktree'
,
(
)
=>
{
const
:
=
{
:
URI
.
file
(
'/workspace'
)
,
:
URI
.
file
(
'/repo'
)
,
:
URI
.
file
(
'/worktree'
)
,
:
{
:
true
,
:
'abc'
,
:
'test'
,
:
'/repo'
,
:
'/worktree'
,
:
1
}
,
}
;
expect
(
isFileFromSessionWorkspace
(
URI
.
file
(
'/worktree/src/foo.ts'
)
,
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'returns true for file inside repository when worktree exists'
,
(
)
=>
{
const
:
=
{
:
URI
.
file
(
'/workspace'
)
,
:
URI
.
file
(
'/repo'
)
,
:
URI
.
file
(
'/worktree'
)
,
:
{
:
true
,
:
'abc'
,
:
'test'
,
:
'/repo'
,
:
'/worktree'
,
:
1
}
,
}
;
expect
(
isFileFromSessionWorkspace
(
URI
.
file
(
'/repo/src/foo.ts'
)
,
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'returns false for file inside repository when no worktree exists'
,
(
)
=>
{
const
:
=
{
:
URI
.
file
(
'/workspace'
)
,
:
URI
.
file
(
'/repo'
)
,
:
undefined
,
:
undefined
,
}
;
expect
(
isFileFromSessionWorkspace
(
URI
.
file
(
'/repo/src/foo.ts'
)
,
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'returns false when workspaceInfo has no folder, no repository, no worktree'
,
(
)
=>
{
const
:
=
{
:
undefined
,
:
undefined
,
:
undefined
,
:
undefined
,
}
;
expect
(
isFileFromSessionWorkspace
(
URI
.
file
(
'/any/file.ts'
)
,
)
)
.
toBe
(
false
)
;
}
)
;
}
)
;
describe
(
'handleReadPermission'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
beforeEach
(
(
)
=>
{
const
=
.
add
(
createExtensionUnitTestingServices
(
)
)
;
const
=
.
createTestingAccessor
(
)
;
=
.
get
(
)
;
=
new
CancellationTokenSource
(
)
;
=
.
;
}
)
;
afterEach
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
function
makeWorkspaceInfo
(
?
:
URI
,
?
:
URI
,
?
:
URI
)
:
{
return
{
,
,
,
:
?
{
:
true
,
:
'abc'
,
:
'test'
,
:
?.
??
''
,
:
.
,
:
1
}
:
undefined
,
}
;
}
function
makeImageSupport
(
:
boolean
)
:
{
return
{
:
undefined
,
:
.
fn
(
)
,
isTrustedImage
:
(
)
=>
}
;
}
function
makeWorkspaceService
(
:
URI
[
]
)
:
{
return
{
getWorkspaceFolder
:
(
:
URI
)
=>
.
find
(
=>
.
.
startsWith
(
.
)
)
}
as
unknown
as
;
}
function
makeToolsService
(
:
string
)
:
{
return
{
:
.
fn
(
async
(
)
=>
new
LanguageModelToolResult2
(
[
new
LanguageModelTextPart
(
)
]
)
)
,
}
as
unknown
as
;
}
it
(
'auto-approves trusted images'
,
async
(
)
=>
{
const
=
{
:
'read'
,
:
'/images/cat.png'
}
as
any
;
const
=
await
handleReadPermission
(
'session-1'
,
,
undefined
,
[
]
,
makeImageSupport
(
true
)
,
makeWorkspaceInfo
(
)
,
makeWorkspaceService
(
[
]
)
,
makeToolsService
(
'no'
)
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
}
)
;
it
(
'auto-approves files in session workspace (folder)'
,
async
(
)
=>
{
const
=
{
:
'read'
,
:
'/workspace/src/file.ts'
}
as
any
;
const
=
await
handleReadPermission
(
'session-1'
,
,
undefined
,
[
]
,
makeImageSupport
(
false
)
,
makeWorkspaceInfo
(
URI
.
file
(
'/workspace'
)
)
,
makeWorkspaceService
(
[
]
)
,
makeToolsService
(
'no'
)
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
}
)
;
it
(
'auto-approves files in a VS Code workspace folder'
,
async
(
)
=>
{
const
=
{
:
'read'
,
:
'/vscode-ws/src/file.ts'
}
as
any
;
const
=
await
handleReadPermission
(
'session-1'
,
,
undefined
,
[
]
,
makeImageSupport
(
false
)
,
makeWorkspaceInfo
(
URI
.
file
(
'/other'
)
)
,
makeWorkspaceService
(
[
URI
.
file
(
'/vscode-ws'
)
]
)
,
makeToolsService
(
'no'
)
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
}
)
;
it
(
'auto-approves attached files'
,
async
(
)
=>
{
const
=
'/external/attached.ts'
;
const
=
{
:
'read'
,
:
}
as
any
;
const
=
[
{
:
'file'
,
:
}
]
as
any
;
const
=
await
handleReadPermission
(
'session-1'
,
,
undefined
,
,
makeImageSupport
(
false
)
,
makeWorkspaceInfo
(
)
,
makeWorkspaceService
(
[
]
)
,
makeToolsService
(
'no'
)
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
}
)
;
it
(
'falls back to confirmation tool for out-of-workspace reads and approves on "yes"'
,
async
(
)
=>
{
const
=
makeToolsService
(
'yes'
)
;
const
=
{
:
'read'
,
:
'/external/secret.txt'
,
:
'Read config'
}
as
any
;
const
=
await
handleReadPermission
(
'session-1'
,
,
undefined
,
[
]
,
makeImageSupport
(
false
)
,
makeWorkspaceInfo
(
URI
.
file
(
'/workspace'
)
)
,
makeWorkspaceService
(
[
]
)
,
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
expect
(
.
)
.
toHaveBeenCalled
(
)
;
}
)
;
it
(
'denies when confirmation tool returns non-"yes"'
,
async
(
)
=>
{
const
=
makeToolsService
(
'no'
)
;
const
=
{
:
'read'
,
:
'/external/secret.txt'
}
as
any
;
const
=
await
handleReadPermission
(
'session-1'
,
,
undefined
,
[
]
,
makeImageSupport
(
false
)
,
makeWorkspaceInfo
(
URI
.
file
(
'/workspace'
)
)
,
makeWorkspaceService
(
[
]
)
,
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'denied-interactively-by-user'
)
;
}
)
;
it
(
'uses intention as message when available'
,
async
(
)
=>
{
const
=
makeToolsService
(
'yes'
)
;
const
=
{
:
'read'
,
:
'/external/file.txt'
,
:
'Read 3 config files'
}
as
any
;
await
handleReadPermission
(
'session-1'
,
,
undefined
,
[
]
,
makeImageSupport
(
false
)
,
makeWorkspaceInfo
(
)
,
makeWorkspaceService
(
[
]
)
,
,
undefined
as
unknown
as
,
,
,
)
;
const
=
(
.
as
<
typeof
.
>
)
.
.
[
0
]
;
expect
(
[
0
]
)
.
toBe
(
.
)
;
expect
(
[
1
]
.
.
)
.
toBe
(
'Read 3 config files'
)
;
}
)
;
it
(
'falls back to path when no intention'
,
async
(
)
=>
{
const
=
makeToolsService
(
'yes'
)
;
const
=
{
:
'read'
,
:
'/external/file.txt'
}
as
any
;
await
handleReadPermission
(
'session-1'
,
,
undefined
,
[
]
,
makeImageSupport
(
false
)
,
makeWorkspaceInfo
(
)
,
makeWorkspaceService
(
[
]
)
,
,
undefined
as
unknown
as
,
,
,
)
;
const
=
(
.
as
<
typeof
.
>
)
.
.
[
0
]
;
expect
(
[
1
]
.
.
)
.
toBe
(
'/external/file.txt'
)
;
}
)
;
}
)
;
describe
(
'handleWritePermission'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
let
:
;
beforeEach
(
(
)
=>
{
const
=
.
add
(
createExtensionUnitTestingServices
(
)
)
;
const
=
.
createTestingAccessor
(
)
;
=
.
get
(
)
;
=
new
CancellationTokenSource
(
)
;
=
.
;
=
new
ExternalEditTracker
(
)
;
.
=
.
fn
(
async
(
)
=>
{
}
)
;
}
)
;
afterEach
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
function
makeWorkspaceInfo
(
:
{
?
:
URI
;
?
:
URI
;
?
:
URI
;
?
:
any
}
=
{
}
)
:
{
return
{
:
.
,
:
.
,
:
.
,
:
.
,
}
;
}
function
makeWorkspaceService
(
:
URI
[
]
)
:
{
return
{
getWorkspaceFolder
:
(
:
URI
)
=>
.
find
(
=>
.
.
startsWith
(
.
)
)
}
as
unknown
as
;
}
function
makeToolsService
(
:
string
)
:
{
return
{
:
.
fn
(
async
(
)
=>
new
LanguageModelToolResult2
(
[
new
LanguageModelTextPart
(
)
]
)
)
,
}
as
unknown
as
;
}
it
(
'auto-approves writes in workspace folder for non-protected files'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace'
)
;
const
=
{
:
'write'
,
:
URI
.
file
(
'/workspace/src/foo.ts'
)
.
,
:
''
,
:
''
}
as
any
;
const
=
await
handleWritePermission
(
'session-1'
,
,
undefined
,
undefined
,
undefined
,
,
makeWorkspaceInfo
(
{
:
}
)
,
makeWorkspaceService
(
[
]
)
,
,
makeToolsService
(
'no'
)
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
}
)
;
it
(
'auto-approves writes in working directory when isolation is enabled'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/worktree'
)
;
const
=
{
:
'write'
,
:
URI
.
file
(
'/worktree/src/foo.ts'
)
.
,
:
''
,
:
''
}
as
any
;
const
=
await
handleWritePermission
(
'session-1'
,
,
undefined
,
undefined
,
undefined
,
,
makeWorkspaceInfo
(
{
:
URI
.
file
(
'/workspace'
)
,
,
:
{
:
true
,
:
'abc'
,
:
'test'
,
:
'/repo'
,
:
'/worktree'
,
:
1
}
,
}
)
,
makeWorkspaceService
(
[
]
)
,
,
makeToolsService
(
'no'
)
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
}
)
;
it
(
'falls back to confirmation for writes outside workspace'
,
async
(
)
=>
{
const
=
makeToolsService
(
'yes'
)
;
const
=
{
:
'write'
,
:
URI
.
file
(
'/external/foo.ts'
)
.
,
:
''
,
:
''
}
as
any
;
const
=
await
handleWritePermission
(
'session-1'
,
,
undefined
,
undefined
,
undefined
,
,
makeWorkspaceInfo
(
{
:
URI
.
file
(
'/workspace'
)
}
)
,
makeWorkspaceService
(
[
URI
.
file
(
'/workspace'
)
]
)
,
,
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
expect
(
.
)
.
toHaveBeenCalled
(
)
;
}
)
;
it
(
'denies writes outside workspace when user declines confirmation'
,
async
(
)
=>
{
const
=
makeToolsService
(
'no'
)
;
const
=
{
:
'write'
,
:
URI
.
file
(
'/external/foo.ts'
)
.
,
:
''
,
:
''
}
as
any
;
const
=
await
handleWritePermission
(
'session-1'
,
,
undefined
,
undefined
,
undefined
,
,
makeWorkspaceInfo
(
{
:
URI
.
file
(
'/workspace'
)
}
)
,
makeWorkspaceService
(
[
URI
.
file
(
'/workspace'
)
]
)
,
,
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'denied-interactively-by-user'
)
;
}
)
;
it
(
'auto-approves when no file can be determined (no fileName, no toolCall)'
,
async
(
)
=>
{
const
=
{
:
'write'
,
:
'some write'
}
as
any
;
const
=
await
handleWritePermission
(
'session-1'
,
,
undefined
,
undefined
,
undefined
,
,
makeWorkspaceInfo
(
{
:
URI
.
file
(
'/workspace'
)
}
)
,
makeWorkspaceService
(
[
URI
.
file
(
'/workspace'
)
]
)
,
,
makeToolsService
(
'no'
)
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
}
)
;
}
)
;
describe
(
'showInteractivePermissionPrompt'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
beforeEach
(
(
)
=>
{
const
=
.
add
(
createExtensionUnitTestingServices
(
)
)
;
const
=
.
createTestingAccessor
(
)
;
=
.
get
(
)
;
=
new
CancellationTokenSource
(
)
;
=
.
;
}
)
;
afterEach
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
function
makeToolsService
(
:
string
)
:
{
return
{
:
.
fn
(
async
(
)
=>
new
LanguageModelToolResult2
(
[
new
LanguageModelTextPart
(
)
]
)
)
,
}
as
unknown
as
;
}
it
(
'approves when user confirms with "yes"'
,
async
(
)
=>
{
const
=
makeToolsService
(
'yes'
)
;
const
=
{
:
'url'
,
:
'https://example.com'
}
as
any
;
const
=
await
showInteractivePermissionPrompt
(
,
undefined
,
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
const
=
(
.
as
<
typeof
.
>
)
.
.
[
0
]
;
expect
(
[
0
]
)
.
toBe
(
.
)
;
expect
(
[
1
]
.
.
)
.
toBe
(
'Copilot CLI Permission Request'
)
;
}
)
;
it
(
'denies when user declines'
,
async
(
)
=>
{
const
=
makeToolsService
(
'no'
)
;
const
=
{
:
'url'
,
:
'https://example.com'
}
as
any
;
const
=
await
showInteractivePermissionPrompt
(
,
undefined
,
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'denied-interactively-by-user'
)
;
}
)
;
it
(
'denies when invokeTool throws'
,
async
(
)
=>
{
const
=
{
:
.
fn
(
async
(
)
=>
{
throw
new
Error
(
'tool failure'
)
;
}
)
,
}
as
unknown
as
;
const
=
{
:
'url'
,
:
'https://example.com'
}
as
any
;
const
=
await
showInteractivePermissionPrompt
(
,
undefined
,
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'denied-interactively-by-user'
)
;
}
)
;
it
(
'passes toolParentCallId as subAgentInvocationId'
,
async
(
)
=>
{
const
=
makeToolsService
(
'yes'
)
;
const
=
{
:
'url'
,
:
'https://example.com'
}
as
any
;
await
showInteractivePermissionPrompt
(
,
'parent-123'
,
,
undefined
as
unknown
as
,
,
,
)
;
const
=
(
.
as
<
typeof
.
>
)
.
.
[
0
]
;
expect
(
[
1
]
.
)
.
toBe
(
'parent-123'
)
;
}
)
;
it
(
'approves with case-insensitive "Yes"'
,
async
(
)
=>
{
const
=
makeToolsService
(
'Yes'
)
;
const
=
{
:
'url'
,
:
'https://example.com'
}
as
any
;
const
=
await
showInteractivePermissionPrompt
(
,
undefined
,
,
undefined
as
unknown
as
,
,
,
)
;
expect
(
.
)
.
toBe
(
'approve-once'
)
;
}
)
;
}
)
;
}
)
;