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 / vscode-node / test / copilotCLITerminalLinkProvider.spec.ts 733 строк · изменён 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
import { beforeEach, describe, expect, it, vi } from 'vitest' ;
import type { CancellationToken, Terminal, TerminalLinkContext, Uri } from 'vscode' ;
import { TestLogService } from '../../../../platform/testing/common/testLogService' ;
import { CopilotCLITerminalLinkProvider } from '../copilotCLITerminalLinkProvider' ;
const mockStat = vi. hoisted ( ( ) => vi. fn ( ) )
mockReadDirectory vi vi
mockShowTextDocument vi vi
mockShowQuickPick vi vi
mockWorkspaceFolders vi value uri fsPath scheme
vi
Uri
path
fsPath path
scheme
skipEncoding skipEncoding
base fsPath scheme segments
joined base fsPath segments
fsPath joined
scheme base scheme
skipEncoding skipEncoding
Range
startLine
startCharacter
endLine
endCharacter
window
showTextDocument mockShowTextDocument
showQuickPick mockShowQuickPick
l10n
message args message _ i args i
FileType
Unknown
File
Directory
SymbolicLink
workspace
fs
stat mockStat
readDirectory mockReadDirectory
mockWorkspaceFolders value
vi
processId
name
creationOptions
exitStatus
state isInteractedWith shell
selection
shellIntegration
Terminal
Terminal
line terminal Terminal TerminalLinkContext
line terminal
CancellationToken
isCancellationRequested onCancellationRequested vi CancellationToken
CancellationToken
isCancellationRequested onCancellationRequested vi CancellationToken
provider CopilotCLITerminalLinkProvider
terminal Terminal
sessionDirUri Uri
vi
mockWorkspaceFolders value
mockReadDirectory
mockShowQuickPick
vscode
provider
terminal
sessionDirUri vscode Uri
provider terminal
provider terminal sessionDirUri
mockStat type
links provider
terminal
links
links pathText
links uri fsPath
links provider
terminal
links
links pathText
links provider
terminal
links
links pathText
links provider
terminal
links
links pathText
links uri fsPath
links provider
terminal
links
links pathText
links line
links col
links provider
terminal
links
links pathText
links provider
terminal
links
mockStat uri fsPath
uri fsPath
uri fsPath
type
links provider
terminal
todoLink links link link pathText
todoLink
todoLink uri fsPath
mockStat uri fsPath
uri fsPath
uri fsPath
type
links provider
terminal
links
links uri fsPath
mockStat uri fsPath
uri fsPath
uri fsPath
mockReadDirectory uri fsPath
uri fsPath
uri fsPath
links provider
terminal
links
links uri fsPath
links provider
terminal
links
links pathText
links uri fsPath
links provider
terminal
links
links provider
terminal
links
links pathText
links provider
terminal
links
links pathText
links provider
terminal
links
links pathText
links line
links col
links provider
terminal
links
links line
links col
links provider
terminal
links
links provider
terminal
links
longLine
links provider
longLine terminal
links
paths length _ i
links provider
paths terminal
links length
unknownTerminal
links provider
unknownTerminal
links
links provider
terminal
links
mockStat not
mockReadDirectory not
token
cancellationState cancelled
Object token
cancellationState cancelled
mockStat
mockReadDirectory uri fsPath
uri fsPath
cancellationState cancelled
links provider
terminal
token
links
mockReadDirectory
vscode
mockWorkspaceFolders value uri vscode Uri
mockStat uri fsPath
uri fsPath
type
uri fsPath
type
mockShowQuickPick items uri fsPath label description detail
items
items label
items label
items item item description
items item item description
items item item detail
items item item uri fsPath
links provider
terminal
links
provider links
mockShowQuickPick
mockShowTextDocument
mockShowTextDocument mock calls fsPath
vscode
mockWorkspaceFolders value uri vscode Uri
mockStat uri fsPath
uri fsPath
type
uri fsPath
type
mockShowQuickPick
links provider
terminal
links
provider links
mockShowQuickPick
mockShowTextDocument not
vscode
mockWorkspaceFolders value uri vscode Uri
mockStat uri fsPath
uri fsPath
type
links provider
terminal
links
provider links
mockShowQuickPick not
mockShowTextDocument
mockShowTextDocument mock calls fsPath
vscode
freshTerminal
provider freshTerminal
provider _t vscode Uri
links provider
freshTerminal
links
links uri fsPath
vscode
mockStat
type
mockWorkspaceFolders value uri vscode Uri
links provider
terminal
links
links uri fsPath
vscode
freshTerminal
provider freshTerminal
staleDir
realDir
call
provider _t
call
call
vscode Uri staleDir
vscode Uri staleDir vscode Uri realDir
mockStat uri fsPath
uri fsPath
type
first provider
freshTerminal
first
second provider
freshTerminal
call
second
second uri fsPath
vscode
freshTerminal
provider freshTerminal
oldDir
newDir
provider freshTerminal vscode Uri oldDir
provider _t vscode Uri newDir
mockStat uri fsPath
uri fsPath
type
links provider
freshTerminal
links
links uri fsPath
vscode
freshTerminal
provider freshTerminal
staleDir
activeDir
provider freshTerminal vscode Uri staleDir
provider _t vscode Uri activeDir
mockStat type
links provider
freshTerminal
links
links uri fsPath
vscode
terminalA
terminalB
provider terminalA
provider terminalB
sessionXDir
sessionYDir
provider t
t terminalA
vscode Uri sessionXDir vscode Uri sessionYDir
vscode Uri sessionYDir vscode Uri sessionXDir
mockStat type
linksA provider
terminalA
linksA
linksA uri fsPath
linksB provider
terminalB
linksB
linksB uri fsPath
links provider
terminal
links
links pathText
links provider
terminal
links
links pathText
links provider
terminal
links
links uri fsPath
links uri fsPath
links provider
terminal
links
;
const
=
.
hoisted
(
(
)
=>
.
fn
(
)
)
;
const
=
.
hoisted
(
(
)
=>
.
fn
(
)
)
;
const
=
.
hoisted
(
(
)
=>
.
fn
(
)
)
;
const
=
.
hoisted
(
(
)
=>
(
{
:
undefined
as
{
:
{
:
string
;
:
string
}
}
[
]
|
undefined
}
)
)
;
.
mock
(
'vscode'
,
(
)
=>
(
{
:
{
file
:
(
:
string
)
=>
(
{
:
,
:
'file'
,
toString
:
(
?
:
boolean
)
=>
?
` file:// ${ path} `
:
` file:// ${ encodeURI ( path) } `
,
}
)
,
joinPath
:
(
:
{
:
string
;
:
string
}
,
...
:
string
[
]
)
=>
{
const
=
[
.
,
...
]
.
join
(
'/'
)
;
return
{
:
,
:
.
,
toString
:
(
?
:
boolean
)
=>
?
` file:// ${ joined} `
:
` file:// ${ encodeURI ( joined) } `
,
}
;
}
,
}
,
:
class
Range
{
constructor
(
public
readonly
:
number
,
public
readonly
:
number
,
public
readonly
:
number
,
public
readonly
:
number
,
)
{
}
}
,
:
{
:
,
:
,
}
,
:
{
t
:
(
:
string
,
...
:
string
[
]
)
=>
.
replace
(
/ \{ ( \d + ) \} / g
,
(
,
)
=>
[
Number
(
)
]
)
,
}
,
:
{
:
0
,
:
1
,
:
2
,
:
64
,
}
,
:
{
:
{
:
,
:
,
}
,
get
workspaceFolders
(
)
{
return
.
;
}
,
}
,
}
)
)
;
.
mock
(
'os'
,
(
)
=>
(
{
homedir
:
(
)
=>
'/Users/anthonykim'
,
}
)
)
;
const
SESSION_UUID
=
'ak1234fe-ae47-4c68-8123-f4adef123123'
;
const
SESSION_DIR
=
` /Users/anthonykim/.copilot/session-state/ ${ SESSION_UUID } `
;
class
MockTerminal
{
readonly
=
Promise
.
resolve
(
123
)
;
readonly
=
'test'
;
readonly
=
{
}
;
readonly
=
undefined
;
readonly
=
{
:
false
,
:
undefined
}
;
readonly
=
undefined
;
readonly
=
undefined
;
sendText
(
)
{
}
show
(
)
{
}
hide
(
)
{
}
dispose
(
)
{
}
}
function
makeTerminal
(
)
:
{
return
new
MockTerminal
(
)
as
;
}
function
makeContext
(
:
string
,
:
)
:
{
return
{
,
}
;
}
function
makeToken
(
)
:
{
return
{
:
false
,
:
.
fn
(
)
}
as
;
}
function
makeCancelledToken
(
)
:
{
return
{
:
true
,
:
.
fn
(
)
}
as
;
}
describe
(
'CopilotCLITerminalLinkProvider'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
beforeEach
(
async
(
)
=>
{
.
clearAllMocks
(
)
;
.
=
undefined
;
.
mockResolvedValue
(
[
]
)
;
.
mockResolvedValue
(
undefined
)
;
const
=
await
import
(
'vscode'
)
;
=
new
CopilotCLITerminalLinkProvider
(
new
TestLogService
(
)
)
;
=
makeTerminal
(
)
;
=
.
.
file
(
SESSION_DIR
)
;
.
registerTerminal
(
)
;
.
setSessionDir
(
,
)
;
.
mockResolvedValue
(
{
:
1
}
)
;
}
)
;
describe
(
'relative paths'
,
(
)
=>
{
it
(
'should detect files/sample-summary.md'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
' Relative: files/sample-summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'files/sample-summary.md'
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ SESSION_DIR } /files/sample-summary.md `
)
;
}
)
;
it
(
'should detect bare files/sample-summary.md at start of line'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/sample-summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'files/sample-summary.md'
)
;
}
)
;
it
(
'should detect dot-prefixed ./files/sample-summary.md'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'./files/sample-summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'./files/sample-summary.md'
)
;
}
)
;
it
(
'should detect standalone plan.md in a sentence'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'Created plan.md with next steps'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'plan.md'
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ SESSION_DIR } /plan.md `
)
;
}
)
;
it
(
'should detect standalone plan.md with :line:col suffix'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'See plan.md:12:3 for details'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'plan.md'
)
;
expect
(
[
0
]
.
)
.
toBe
(
12
)
;
expect
(
[
0
]
.
)
.
toBe
(
3
)
;
}
)
;
it
(
'should detect standalone filenames with 1-character extensions'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'Compile main.c next'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'main.c'
)
;
}
)
;
it
(
'should not detect numeric tokens like version 1.2'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'Version 1.2 is installed'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
}
)
;
it
(
'should resolve bare filename to files/<name> when root file does not exist'
,
async
(
)
=>
{
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
` ${ SESSION_DIR } /todo.md `
)
{
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
if
(
.
===
` ${ SESSION_DIR } /files/todo.md `
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'| todo.md | /Users/anthonykim/.copilot/session-state/id/files/todo.md | files/todo.md |'
,
)
,
makeToken
(
)
,
)
;
const
=
.
find
(
=>
.
===
'todo.md'
)
;
expect
(
)
.
toBeDefined
(
)
;
expect
(
?.
?.
)
.
toBe
(
` ${ SESSION_DIR } /files/todo.md `
)
;
}
)
;
it
(
'should resolve slash paths relative to files/ when session-root path does not exist'
,
async
(
)
=>
{
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
` ${ SESSION_DIR } /anotherFolderNamehere/thenyourfilehere.txt `
)
{
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
if
(
.
===
` ${ SESSION_DIR } /files/anotherFolderNamehere/thenyourfilehere.txt `
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'anotherFolderNamehere/thenyourfilehere.txt'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ SESSION_DIR } /files/anotherFolderNamehere/thenyourfilehere.txt `
)
;
}
)
;
it
(
'should resolve bare filename in nested session subdirectories'
,
async
(
)
=>
{
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
` ${ SESSION_DIR } /001-created-session-files-and-path.md `
)
{
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
if
(
.
===
` ${ SESSION_DIR } /files/001-created-session-files-and-path.md `
)
{
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
)
;
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
SESSION_DIR
)
{
return
Promise
.
resolve
(
[
[
'checkpoints'
,
2
]
,
]
)
;
}
if
(
.
===
` ${ SESSION_DIR } /checkpoints `
)
{
return
Promise
.
resolve
(
[
[
'001-created-session-files-and-path.md'
,
1
]
,
]
)
;
}
return
Promise
.
resolve
(
[
]
)
;
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'001-created-session-files-and-path.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ SESSION_DIR } /checkpoints/001-created-session-files-and-path.md `
)
;
}
)
;
}
)
;
describe
(
'tilde paths'
,
(
)
=>
{
it
(
'should expand ~/.copilot/session-state/.../files/sample-summary.md'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
` Absolute: ~/.copilot/session-state/ ${ SESSION_UUID } /files/sample-summary.md `
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toContain
(
'~/.copilot/session-state'
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` /Users/anthonykim/.copilot/session-state/ ${ SESSION_UUID } /files/sample-summary.md `
)
;
}
)
;
}
)
;
describe
(
'absolute paths'
,
(
)
=>
{
it
(
'should skip /Users/anthonykim/.copilot/.../files/sample-summary.md'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
` /Users/anthonykim/.copilot/session-state/ ${ SESSION_UUID } /files/sample-summary.md `
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
}
)
;
}
)
;
describe
(
'trailing punctuation'
,
(
)
=>
{
it
(
'should strip trailing period from files/sample-summary.md.'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'file at files/sample-summary.md.'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'files/sample-summary.md'
)
;
}
)
;
it
(
'should strip multiple trailing dots'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/sample-summary.md...'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'files/sample-summary.md'
)
;
}
)
;
}
)
;
describe
(
'line and column suffixes'
,
(
)
=>
{
it
(
'should parse :line:col suffix'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'src/foo/bar.ts:10:5'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'src/foo/bar.ts'
)
;
expect
(
[
0
]
.
)
.
toBe
(
10
)
;
expect
(
[
0
]
.
)
.
toBe
(
5
)
;
}
)
;
it
(
'should parse (line, col) suffix'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'src/foo/bar.ts(42, 7)'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
42
)
;
expect
(
[
0
]
.
)
.
toBe
(
7
)
;
}
)
;
}
)
;
describe
(
'URLs'
,
(
)
=>
{
it
(
'should skip https:// URLs'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'Visit https://example.com/path for info'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
}
)
;
}
)
;
describe
(
'guards'
,
(
)
=>
{
it
(
'should return empty for blank lines'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
' '
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
}
)
;
it
(
'should return empty for lines over 2000 chars'
,
async
(
)
=>
{
const
=
'files/summary.md '
+
'x'
.
repeat
(
2000
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
}
)
;
it
(
'should cap links at 10 per line'
,
async
(
)
=>
{
const
=
Array
.
from
(
{
:
15
}
,
(
,
)
=>
` dir/file ${ i} .ts `
)
.
join
(
' '
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
,
)
,
makeToken
(
)
,
)
;
expect
(
.
)
.
toBeLessThanOrEqual
(
10
)
;
}
)
;
it
(
'should skip unregistered terminals with no session dirs'
,
async
(
)
=>
{
const
=
makeTerminal
(
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
}
)
;
it
(
'should stop processing when cancellation is requested before path resolution'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/sample-summary.md'
,
)
,
makeCancelledToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
expect
(
)
.
.
toHaveBeenCalled
(
)
;
expect
(
)
.
.
toHaveBeenCalled
(
)
;
}
)
;
}
)
;
describe
(
'cancellation'
,
(
)
=>
{
it
(
'should stop nested lookup when token is cancelled during traversal'
,
async
(
)
=>
{
const
=
makeToken
(
)
;
const
=
{
:
false
}
;
.
defineProperty
(
,
'isCancellationRequested'
,
{
get
:
(
)
=>
.
,
}
)
;
.
mockRejectedValue
(
new
Error
(
'not found'
)
)
;
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
SESSION_DIR
)
{
.
=
true
;
return
Promise
.
resolve
(
[
[
'checkpoints'
,
2
]
,
]
)
;
}
return
Promise
.
resolve
(
[
]
)
;
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'001-created-session-files-and-path.md'
,
)
,
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
expect
(
)
.
toHaveBeenCalledTimes
(
1
)
;
}
)
;
}
)
;
describe
(
'handleTerminalLink'
,
(
)
=>
{
it
(
'should prompt when multiple targets exist and open selected target'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
.
=
[
{
:
.
.
file
(
'/workspace/project'
)
}
]
;
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
` ${ SESSION_DIR } /plan.md `
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
if
(
.
===
'/workspace/project/plan.md'
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
)
;
.
mockImplementation
(
async
(
:
Array
<
{
:
{
:
string
}
;
:
string
;
?
:
string
;
?
:
string
}
>
)
=>
{
expect
(
)
.
toHaveLength
(
2
)
;
expect
(
[
0
]
.
)
.
toBe
(
'plan.md'
)
;
expect
(
[
1
]
.
)
.
toBe
(
'plan.md'
)
;
expect
(
.
some
(
=>
.
===
'session-state/ak1234fe-ae47-4c68-8123-f4adef123123'
)
)
.
toBe
(
true
)
;
expect
(
.
some
(
=>
.
===
'workspace'
)
)
.
toBe
(
true
)
;
expect
(
.
every
(
=>
.
===
undefined
)
)
.
toBe
(
true
)
;
return
.
find
(
=>
.
.
===
'/workspace/project/plan.md'
)
;
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'plan.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
await
.
handleTerminalLink
(
[
0
]
)
;
expect
(
)
.
toHaveBeenCalled
(
)
;
expect
(
)
.
toHaveBeenCalled
(
)
;
expect
(
.
.
[
0
]
[
0
]
.
)
.
toBe
(
'/workspace/project/plan.md'
)
;
}
)
;
it
(
'should not open when quick pick is cancelled'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
.
=
[
{
:
.
.
file
(
'/workspace/project'
)
}
]
;
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
` ${ SESSION_DIR } /plan.md `
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
if
(
.
===
'/workspace/project/plan.md'
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
)
;
.
mockResolvedValue
(
undefined
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'plan.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
await
.
handleTerminalLink
(
[
0
]
)
;
expect
(
)
.
toHaveBeenCalled
(
)
;
expect
(
)
.
.
toHaveBeenCalled
(
)
;
}
)
;
it
(
'should open directly without prompting when only one target exists'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
.
=
[
{
:
.
.
file
(
'/workspace/project'
)
}
]
;
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
` ${ SESSION_DIR } /plan.md `
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'plan.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
await
.
handleTerminalLink
(
[
0
]
)
;
expect
(
)
.
.
toHaveBeenCalled
(
)
;
expect
(
)
.
toHaveBeenCalledTimes
(
1
)
;
expect
(
.
.
[
0
]
[
0
]
.
)
.
toBe
(
` ${ SESSION_DIR } /plan.md `
)
;
}
)
;
}
)
;
describe
(
'session dir resolution'
,
(
)
=>
{
it
(
'should resolve via session dir resolver when no cached dir'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
const
=
makeTerminal
(
)
;
.
registerTerminal
(
)
;
.
setSessionDirResolver
(
async
=>
[
.
.
file
(
SESSION_DIR
)
]
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/demo.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ SESSION_DIR } /files/demo.md `
)
;
}
)
;
it
(
'should fall back to workspace folders when file not in session dir'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
.
mockRejectedValueOnce
(
new
Error
(
'not found'
)
)
.
mockResolvedValueOnce
(
{
:
1
}
)
;
.
=
[
{
:
.
.
file
(
'/workspace/project'
)
}
]
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'src/index.ts'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
'/workspace/project/src/index.ts'
)
;
}
)
;
it
(
'should not cache stale resolver result when session tracker learns the real session later'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
const
=
makeTerminal
(
)
;
.
registerTerminal
(
)
;
const
=
'/Users/anthonykim/.copilot/session-state/31830812-0221-4389-b6bf-b1d33fe556e2'
;
const
=
'/Users/anthonykim/.copilot/session-state/278b1a81-eb86-4a81-bff0-ba68035c1b48'
;
let
=
0
;
.
setSessionDirResolver
(
async
=>
{
++
;
return
===
1
?
[
.
.
file
(
)
]
:
[
.
.
file
(
)
,
.
.
file
(
)
]
;
}
)
;
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
` ${ realDir} /files/file-01.md `
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/file-01.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/file-01.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toBe
(
2
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ realDir} /files/file-01.md `
)
;
}
)
;
it
(
'should still consult resolver even when an explicit session dir is cached'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
const
=
makeTerminal
(
)
;
.
registerTerminal
(
)
;
const
=
'/Users/anthonykim/.copilot/session-state/old'
;
const
=
'/Users/anthonykim/.copilot/session-state/new'
;
.
setSessionDir
(
,
.
.
file
(
)
)
;
.
setSessionDirResolver
(
async
=>
[
.
.
file
(
)
]
)
;
.
mockImplementation
(
(
:
{
:
string
}
)
=>
{
if
(
.
===
` ${ newDir} /files/demo.md `
)
{
return
Promise
.
resolve
(
{
:
1
}
)
;
}
return
Promise
.
reject
(
new
Error
(
'not found'
)
)
;
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/demo.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ newDir} /files/demo.md `
)
;
}
)
;
it
(
'should prefer active resolver dir over stale cached dir when file exists in both'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
const
=
makeTerminal
(
)
;
.
registerTerminal
(
)
;
const
=
'/Users/anthonykim/.copilot/session-state/ended-session'
;
const
=
'/Users/anthonykim/.copilot/session-state/active-session'
;
.
setSessionDir
(
,
.
.
file
(
)
)
;
.
setSessionDirResolver
(
async
=>
[
.
.
file
(
)
]
)
;
.
mockResolvedValue
(
{
:
1
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ activeDir} /files/summary.md `
)
;
}
)
;
it
(
'should prefer terminal-matched resolver dirs over unrelated sessions'
,
async
(
)
=>
{
const
=
await
import
(
'vscode'
)
;
const
=
makeTerminal
(
)
;
const
=
makeTerminal
(
)
;
.
registerTerminal
(
)
;
.
registerTerminal
(
)
;
const
=
'/Users/anthonykim/.copilot/session-state/session-x'
;
const
=
'/Users/anthonykim/.copilot/session-state/session-y'
;
.
setSessionDirResolver
(
async
=>
{
if
(
===
)
{
return
[
.
.
file
(
)
,
.
.
file
(
)
]
;
}
return
[
.
.
file
(
)
,
.
.
file
(
)
]
;
}
)
;
.
mockResolvedValue
(
{
:
1
}
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ sessionXDir} /files/summary.md `
)
;
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files/summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toBe
(
` ${ sessionYDir} /files/summary.md `
)
;
}
)
;
}
)
;
describe
(
'extensionless files'
,
(
)
=>
{
it
(
'should detect dir/Makefile'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'dir/Makefile'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'dir/Makefile'
)
;
}
)
;
}
)
;
describe
(
'Windows paths'
,
(
)
=>
{
it
(
'should detect backslash relative paths'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'files\\sample-summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
'files\\sample-summary.md'
)
;
}
)
;
it
(
'should expand tilde with backslash (~\\.copilot\\...)'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'Create ~\\.copilot\\session-state\\5d9e\\files\\sample-summary.md (+4)'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
?.
)
.
toContain
(
'/Users/anthonykim'
)
;
expect
(
[
0
]
.
?.
)
.
toContain
(
'.copilot'
)
;
}
)
;
it
(
'should skip Windows absolute paths (C:\\...)'
,
async
(
)
=>
{
const
=
await
.
provideTerminalLinks
(
makeContext
(
'Absolute: C:\\Users\\antho\\.copilot\\files\\sample-summary.md'
,
)
,
makeToken
(
)
,
)
;
expect
(
)
.
toHaveLength
(
0
)
;
}
)
;
}
)
;
}
)
;