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 / chatSessionWorkspaceFolderService.spec.ts 726 строк · изменён 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
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' ;
import * as vscode from 'vscode' ;
import { IVSCodeExtensionContext } from '../../../../platform/extContext/common/extensionContext' ;
import { RepoContext } from '../../../../platform/git/common/gitService' ;
import { MockGitService } from '../../../../platform/ignore/node/test/mockGitService' ;
import { ILogService } from '../../../../platform/log/common/logService' ;
import { mock } from '../../../../util/common/test/simpleMock'
constObservable observableValue
IChatSessionMetadataStore RepositoryProperties WorkspaceFolderEntry
ChatSessionWorkspaceFolderService
Memento
data
key defaultValue
value data key
value defaultValue
key value
value
data key
data key value
data
_keys
override globalState
override extensionPath vscode Uri fsPath
override globalStorageUri vscode Uri
override storagePath vscode Uri fsPath
override globalStoragePath vscode Uri fsPath
override logPath vscode Uri fsPath
override logUri vscode Uri
override extensionUri vscode Uri
override trace vi
override info vi
override warn vi
override error vi
override debug vi
_data
_repoData
override storeWorktreeInfo vi
override storeWorkspaceFolderInfo vi _sessionId _entry WorkspaceFolderEntry
_data _sessionId _entry
override storeRepositoryProperties vi _sessionId properties RepositoryProperties
_repoData _sessionId properties
override getWorktreeProperties vi
override getRepositoryProperties vi _sessionId _repoData _sessionId
override getSessionWorkspaceFolder vi _sessionId vscode Uri
entry _data _sessionId
entry folderPath
vscode Uri entry folderPath
override deleteSessionMetadata vi _sessionId
_data _sessionId
_repoData _sessionId
service ChatSessionWorkspaceFolderService
extensionContext MockExtensionContext
gitService MockGitService
logService MockLogService
metadataStore MockMetadataStore
extensionContext
logService
gitService
metadataStore
service gitService logService metadataStore extensionContext
vi
sessionId
folderPath vscode Uri fsPath
service sessionId folderPath
tracked service sessionId
tracked fsPath folderPath
sessionId
folderPath vscode Uri fsPath
beforeTime Date
service sessionId folderPath
afterTime Date
metadataStore storeWorkspaceFolderInfo
sessionId
expect folderPath
entry metadataStore storeWorkspaceFolderInfo mock calls
entry timestamp beforeTime
entry timestamp afterTime
sessionId
folderPath vscode Uri fsPath
service sessionId folderPath
metadataStore storeWorkspaceFolderInfo
sessionId
expect folderPath
sessionIds
folderPaths vscode Uri fsPath vscode Uri fsPath vscode Uri fsPath
sessionIds sessionId idx service sessionId folderPaths idx
i i sessionIds length i
tracked service sessionIds i
tracked fsPath folderPaths i
oldData Record
i i i
oldData
folderPath vscode Uri fsPath
timestamp Date i
extensionContext globalState oldData
service vscode Uri fsPath
data extensionContext globalState
entryCount Object data length
entryCount
result service
result
sessionId
folderPath vscode Uri fsPath
service sessionId folderPath
result service sessionId
result
result fsPath folderPath
sessionId
folderPath vscode Uri fsPath
service sessionId folderPath
result service sessionId
result vscode Uri
result scheme
extensionContext globalState
result service
result
extensionContext globalState
folderPath timestamp Date
result service
result
folderPath vscode Uri fsPath
metadataStore getSessionWorkspaceFolder vscode Uri folderPath
result service
result fsPath folderPath
metadataStore getSessionWorkspaceFolder
sessionId
inMemoryPath vscode Uri fsPath
service sessionId inMemoryPath
metadataStore getSessionWorkspaceFolder vscode Uri
result service sessionId
result fsPath inMemoryPath
sessionId
folderPath vscode Uri fsPath
service sessionId folderPath
service sessionId
service sessionId
service sessionId
sessionId
service sessionId vscode Uri fsPath
service sessionId
metadataStore deleteSessionMetadata sessionId
repo
rootUri
kind
isUsingVirtualFileSystem
headBranchName
headCommitHash
headIncomingChanges
headOutgoingChanges
upstreamBranchName
upstreamRemote
isRebasing
remotes
remoteFetchUrls
worktrees
changes mergeChanges indexChanges workingTree untrackedChanges
headBranchNameObs
headCommitHashObs
upstreamBranchNameObs
upstreamRemoteObs
isRebasingObs
RepoContext
gitService getRepository vi repo
sessionId1
sessionId2
sharedProperties
repositoryPath
branchName
baseBranchName
service sessionId1 sharedProperties
service sessionId2 sharedProperties
service sessionId1
service sessionId1
service sessionId2
gitService getRepository
service resolves
session1
session2
service session1 vscode Uri fsPath
service session2 vscode Uri fsPath
service session1
service session1
service session2
oldData Record
i i i
oldData
folderPath vscode Uri fsPath
timestamp i
extensionContext globalState oldData
now Date
data extensionContext globalState
data
folderPath vscode Uri fsPath
timestamp now
extensionContext globalState data
service vscode Uri fsPath
finalData extensionContext globalState
finalData
headCommitHash ReturnType observableValue
overrides Partial RepoContext RepoContext
headCommitHash
rootUri
kind
headBranchName
headCommitHash
upstreamBranchName
upstreamRemote
isRebasing
remotes
remoteFetchUrls
worktrees
changes mergeChanges indexChanges workingTree untrackedChanges
headBranchNameObs
headCommitHashObs headCommitHash
upstreamBranchNameObs
upstreamRemoteObs
isRebasingObs
overrides
RepoContext
repo
gitService getRepository vi repo
gitService diffIndexWithHEADShortStats vi insertions deletions
sessionId
metadataStore sessionId
repositoryPath
branchName
first service sessionId
second service sessionId
first second
gitService getRepository
repo
gitService getRepository vi repo
gitService diffIndexWithHEADShortStats vi insertions deletions
sessionId
metadataStore sessionId
repositoryPath
branchName
service sessionId
service sessionId
service sessionId
gitService getRepository
repo
gitService getRepository vi repo
gitService diffIndexWithHEADShortStats vi insertions deletions
sessionId
metadataStore sessionId
repositoryPath
branchName
service sessionId
service sessionId
service sessionId
gitService getRepository
repo changes
gitService getRepository vi repo
metadataStore
repositoryPath
branchName
result service
result
gitService getRepository vi
metadataStore
repositoryPath
branchName
result service
result
result1 service
result2 service
result1
result2
metadataStore getRepositoryProperties
repo
gitService getRepository vi repo
result1 service
result1
service
repositoryPath
branchName
result2 service
result2
metadataStore getRepositoryProperties
repo
gitService getRepository vi repo
gitService diffIndexWithHEADShortStats vi insertions deletions
sessionId
metadataStore sessionId
repositoryPath
branchName
service sessionId
service sessionId
service sessionId
service sessionId
service sessionId
gitService getRepository
repo1
repo2
folder1 vscode Uri
folder2 vscode Uri
gitService getRepository vi
uri
uri fsPath folder1 fsPath
repo1
repo2
gitService diffIndexWithHEADShortStats vi insertions deletions
sessionId1
sessionId2
service sessionId1 folder1 fsPath
repositoryPath folder1 fsPath
branchName
service sessionId2 folder2 fsPath
repositoryPath folder2 fsPath
branchName
service sessionId1
service sessionId2
service sessionId1
service sessionId2
service sessionId1
calls gitService getRepository ReturnType vi fn mock calls
sessionId1Calls calls c c fsPath folder1 fsPath length
sessionId2Calls calls c c fsPath folder2 fsPath length
sessionId1Calls
sessionId2Calls
repo
repoPath
gitService getRepository vi
resolve resolve
repo
sessionId1
sessionId2
metadataStore sessionId1
repositoryPath repoPath
branchName
baseBranchName
metadataStore sessionId2
repositoryPath repoPath
branchName
baseBranchName
result1 result2
service sessionId1
service sessionId2
result1
result2
result1 result2
gitService getRepository
repo
repoPath
gitService getRepository vi
resolve resolve
repo
metadataStore
repositoryPath repoPath
branchName
baseBranchName
metadataStore
repositoryPath repoPath
branchName
baseBranchName
service
service
gitService getRepository
folder vscode Uri
repo rootUri
gitService getRepository vi repo
gitService diffIndexWithHEADShortStats vi insertions deletions
sessionId1
sessionId2
service sessionId1 folder fsPath
repositoryPath folder fsPath
branchName
service sessionId2 folder fsPath
repositoryPath folder fsPath
branchName
service sessionId1
service sessionId2
gitService getRepository
clearedIds service folder
clearedIds sessionId1
clearedIds sessionId2
service sessionId1
service sessionId2
gitService getRepository
unknownFolder vscode Uri
result service unknownFolder
result
folder vscode Uri
sessionId
service folder
service sessionId folder fsPath
service folder sessionId
folder vscode Uri
sessionId
service sessionId folder fsPath
service folder sessionId
service sessionId
service folder
;
import
{
,
}
from
'../../../../util/vs/base/common/observableInternal'
;
import
{
URI
}
from
'../../../../util/vs/base/common/uri'
;
import
{
,
,
}
from
'../../common/chatSessionMetadataStore'
;
import
{
}
from
'../chatSessionWorkspaceFolderServiceImpl'
;
class
MockGlobalState
implements
vscode
.
{
private
=
new
Map< string , unknown >
(
)
;
get < T >
(
:
string
,
?
:
T
)
:
T
{
const
=
this
.
.
get
(
)
;
return
(
??
)
as
T
;
}
async
update
(
:
string
,
:
unknown
)
:
Promise
<
void
>
{
if
(
===
undefined
)
{
this
.
.
delete
(
)
;
}
else
{
this
.
.
set
(
,
)
;
}
}
keys
(
)
:
readonly
string
[
]
{
return
Array
.
from
(
this
.
.
keys
(
)
)
;
}
setKeysForSync
(
:
readonly
string
[
]
)
:
void
{
}
}
class
MockExtensionContext
extends
mock< IVSCodeExtensionContext>
(
)
{
public
=
new
MockGlobalState
(
)
;
=
.
.
file
(
'/mock/extension/path'
)
.
;
=
.
.
file
(
'/mock/global/storage'
)
;
=
.
.
file
(
'/mock/storage/path'
)
.
;
=
.
.
file
(
'/mock/global/storage/path'
)
.
;
=
.
.
file
(
'/mock/log/path'
)
.
;
=
.
.
file
(
'/mock/log/uri'
)
;
=
.
.
file
(
'/mock/extension'
)
;
}
class
MockLogService
extends
mock< ILogService>
(
)
{
=
.
fn
(
)
;
=
.
fn
(
)
;
=
.
fn
(
)
;
=
.
fn
(
)
;
=
.
fn
(
)
;
}
class
MockMetadataStore
extends
mock< IChatSessionMetadataStore>
(
)
{
private
readonly
=
new
Map< string , WorkspaceFolderEntry>
(
)
;
private
readonly
=
new
Map< string , RepositoryProperties>
(
)
;
=
.
fn
(
async
(
)
=>
{
}
)
;
=
.
fn
(
async
(
:
string
,
:
)
=>
{
this
.
.
set
(
,
)
;
}
)
;
=
.
fn
(
async
(
:
string
,
:
)
=>
{
this
.
.
set
(
,
)
;
}
)
;
=
.
fn
(
async
(
)
=>
undefined
)
;
=
.
fn
(
async
(
:
string
)
=>
this
.
.
get
(
)
)
;
=
.
fn
(
async
(
:
string
)
:
Promise
<
.
|
undefined
>
=>
{
const
=
this
.
.
get
(
)
;
if
(
?.
)
{
return
.
.
file
(
.
)
;
}
return
undefined
;
}
)
;
=
.
fn
(
async
(
:
string
)
=>
{
this
.
.
delete
(
)
;
this
.
.
delete
(
)
;
}
)
;
}
describe
(
'ChatSessionWorkspaceFolderService'
,
(
)
=>
{
let
:
;
let
:
;
let
:
;
let
:
;
let
:
;
beforeEach
(
(
)
=>
{
=
new
MockExtensionContext
(
)
;
=
new
MockLogService
(
)
;
=
new
MockGitService
(
)
;
=
new
MockMetadataStore
(
)
;
=
new
ChatSessionWorkspaceFolderService
(
,
,
,
)
;
}
)
;
afterEach
(
(
)
=>
{
.
clearAllMocks
(
)
;
}
)
;
describe
(
'trackSessionWorkspaceFolder'
,
(
)
=>
{
it
(
'should track a workspace folder for a session'
,
async
(
)
=>
{
const
=
'session-1'
;
const
=
.
.
file
(
'/path/to/folder'
)
.
;
await
.
trackSessionWorkspaceFolder
(
,
)
;
const
=
await
.
getSessionWorkspaceFolder
(
)
;
expect
(
?.
)
.
toBe
(
)
;
}
)
;
it
(
'should update timestamp when tracking a folder'
,
async
(
)
=>
{
const
=
'session-1'
;
const
=
.
.
file
(
'/path/to/folder'
)
.
;
const
=
.
now
(
)
;
await
.
trackSessionWorkspaceFolder
(
,
)
;
const
=
.
now
(
)
;
expect
(
.
)
.
toHaveBeenCalledWith
(
,
.
objectContaining
(
{
}
)
)
;
const
=
.
.
.
[
0
]
[
1
]
;
expect
(
.
)
.
toBeGreaterThanOrEqual
(
)
;
expect
(
.
)
.
toBeLessThanOrEqual
(
)
;
}
)
;
it
(
'should persist data to metadata store'
,
async
(
)
=>
{
const
=
'session-1'
;
const
=
.
.
file
(
'/path/to/folder'
)
.
;
await
.
trackSessionWorkspaceFolder
(
,
)
;
expect
(
.
)
.
toHaveBeenCalledWith
(
,
.
objectContaining
(
{
}
)
)
;
}
)
;
it
(
'should handle multiple concurrent tracking calls'
,
async
(
)
=>
{
const
=
[
'session-1'
,
'session-2'
,
'session-3'
]
;
const
=
[
.
.
file
(
'/path/1'
)
.
,
.
.
file
(
'/path/2'
)
.
,
.
.
file
(
'/path/3'
)
.
]
;
await
Promise
.
all
(
.
map
(
(
,
)
=>
.
trackSessionWorkspaceFolder
(
,
[
]
)
)
)
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
await
.
getSessionWorkspaceFolder
(
[
]
)
;
expect
(
?.
)
.
toBe
(
[
]
)
;
}
}
)
;
it
(
'should trigger cleanup when exceeding MAX_ENTRIES'
,
async
(
)
=>
{
const
MAX_ENTRIES
=
1500
;
const
:
<
string
,
unknown
>
=
{
}
;
for
(
let
=
0
;
<
MAX_ENTRIES
;
++
)
{
[
` session-old- ${ i} `
]
=
{
:
.
.
file
(
` /old/path/ ${ i} `
)
.
,
:
.
now
(
)
-
10000
+
}
;
}
await
.
.
update
(
'github.copilot.cli.sessionWorkspaceFolders'
,
)
;
await
.
trackSessionWorkspaceFolder
(
'session-new'
,
.
.
file
(
'/new/path'
)
.
)
;
const
=
.
.
get < Record< string , unknown >>
(
'github.copilot.cli.sessionWorkspaceFolders'
,
{
}
)
;
const
=
.
keys
(
)
.
;
expect
(
)
.
toBeLessThan
(
MAX_ENTRIES
+
1
)
;
}
)
;
}
)
;
describe
(
'getSessionWorkspaceFolder'
,
(
)
=>
{
it
(
'should return undefined for non-existent session'
,
async
(
)
=>
{
const
=
await
.
getSessionWorkspaceFolder
(
'non-existent-session'
)
;
expect
(
)
.
toBeUndefined
(
)
;
}
)
;
it
(
'should return correct URI for tracked session'
,
async
(
)
=>
{
const
=
'session-1'
;
const
=
.
.
file
(
'/path/to/folder'
)
.
;
await
.
trackSessionWorkspaceFolder
(
,
)
;
const
=
await
.
getSessionWorkspaceFolder
(
)
;
expect
(
)
.
toBeDefined
(
)
;
expect
(
?.
)
.
toBe
(
)
;
}
)
;
it
(
'should return URI object with correct properties'
,
async
(
)
=>
{
const
=
'session-1'
;
const
=
.
.
file
(
'/path/to/folder'
)
.
;
await
.
trackSessionWorkspaceFolder
(
,
)
;
const
=
await
.
getSessionWorkspaceFolder
(
)
;
expect
(
)
.
toBeInstanceOf
(
.
)
;
expect
(
?.
)
.
toBe
(
'file'
)
;
}
)
;
it
(
'should handle malformed data gracefully'
,
async
(
)
=>
{
await
.
.
update
(
'github.copilot.cli.sessionWorkspaceFolders'
,
{
'session-bad'
:
{
}
}
)
;
const
=
await
.
getSessionWorkspaceFolder
(
'session-bad'
)
;
expect
(
)
.
toBeUndefined
(
)
;
}
)
;
it
(
'should return undefined if folderPath is empty string'
,
async
(
)
=>
{
await
.
.
update
(
'github.copilot.cli.sessionWorkspaceFolders'
,
{
'session-empty'
:
{
:
''
,
:
.
now
(
)
}
}
)
;
const
=
await
.
getSessionWorkspaceFolder
(
'session-empty'
)
;
expect
(
)
.
toBeUndefined
(
)
;
}
)
;
it
(
'should fall back to metadata store when session is not in memory'
,
async
(
)
=>
{
const
=
.
.
file
(
'/metadata-store/folder'
)
.
;
.
.
mockResolvedValueOnce
(
.
.
file
(
)
)
;
const
=
await
.
getSessionWorkspaceFolder
(
'session-from-store'
)
;
expect
(
?.
)
.
toBe
(
)
;
expect
(
.
)
.
toHaveBeenCalledWith
(
'session-from-store'
)
;
}
)
;
it
(
'should prefer in-memory state over metadata store'
,
async
(
)
=>
{
const
=
'session-both'
;
const
=
.
.
file
(
'/in-memory/folder'
)
.
;
await
.
trackSessionWorkspaceFolder
(
,
)
;
.
.
mockResolvedValueOnce
(
.
.
file
(
'/store/different'
)
)
;
const
=
await
.
getSessionWorkspaceFolder
(
)
;
expect
(
?.
)
.
toBe
(
)
;
}
)
;
}
)
;
describe
(
'deleteTrackedWorkspaceFolder'
,
(
)
=>
{
it
(
'should delete tracked folder for session'
,
async
(
)
=>
{
const
=
'session-1'
;
const
=
.
.
file
(
'/path/to/folder'
)
.
;
await
.
trackSessionWorkspaceFolder
(
,
)
;
expect
(
await
.
getSessionWorkspaceFolder
(
)
)
.
toBeDefined
(
)
;
await
.
deleteTrackedWorkspaceFolder
(
)
;
expect
(
await
.
getSessionWorkspaceFolder
(
)
)
.
toBeUndefined
(
)
;
}
)
;
it
(
'should call metadata store when deleting'
,
async
(
)
=>
{
const
=
'session-1'
;
await
.
trackSessionWorkspaceFolder
(
,
.
.
file
(
'/path/to/folder'
)
.
)
;
await
.
deleteTrackedWorkspaceFolder
(
)
;
expect
(
.
)
.
toHaveBeenCalledWith
(
)
;
}
)
;
it
(
'should invalidate workspace changes cache when deleting a tracked folder'
,
async
(
)
=>
{
const
=
{
:
URI
.
file
(
'/repo'
)
,
:
'repository'
as
const
,
:
false
,
:
'main'
,
:
'abc123'
,
:
0
,
:
0
,
:
undefined
,
:
undefined
,
:
false
,
:
[
]
,
:
[
]
,
:
[
]
,
:
{
:
[
]
,
:
[
]
,
:
[
]
,
:
[
]
}
,
:
constObservable
(
'main'
)
,
:
observableValue
(
'test-head-commit'
,
'abc123'
)
,
:
constObservable
(
undefined
)
,
:
constObservable
(
undefined
)
,
:
constObservable
(
false
)
,
isIgnored
:
async
(
)
=>
false
,
}
as
;
.
=
.
fn
(
)
.
mockResolvedValue
(
)
;
const
=
'session-1'
;
const
=
'session-2'
;
const
=
{
:
'/repo'
,
:
'main'
,
:
'origin/main'
,
}
;
await
.
trackSessionWorkspaceFolder
(
,
'/repo'
,
)
;
await
.
trackSessionWorkspaceFolder
(
,
'/repo'
,
)
;
await
.
getWorkspaceChanges
(
)
;
await
.
deleteTrackedWorkspaceFolder
(
)
;
await
.
getWorkspaceChanges
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
2
)
;
}
)
;
it
(
'should handle deletion of non-existent session'
,
async
(
)
=>
{
await
expect
(
.
deleteTrackedWorkspaceFolder
(
'non-existent'
)
)
.
.
toBeUndefined
(
)
;
}
)
;
it
(
'should not affect other sessions when deleting one'
,
async
(
)
=>
{
const
=
'session-1'
;
const
=
'session-2'
;
await
.
trackSessionWorkspaceFolder
(
,
.
.
file
(
'/path/1'
)
.
)
;
await
.
trackSessionWorkspaceFolder
(
,
.
.
file
(
'/path/2'
)
.
)
;
await
.
deleteTrackedWorkspaceFolder
(
)
;
expect
(
await
.
getSessionWorkspaceFolder
(
)
)
.
toBeUndefined
(
)
;
expect
(
await
.
getSessionWorkspaceFolder
(
)
)
.
toBeDefined
(
)
;
}
)
;
}
)
;
describe
(
'cleanupOldEntries'
,
(
)
=>
{
it
(
'should keep newer entries and remove older ones'
,
async
(
)
=>
{
const
MAX_ENTRIES
=
1500
;
const
:
<
string
,
unknown
>
=
{
}
;
for
(
let
=
0
;
<
MAX_ENTRIES
;
++
)
{
[
` session-old- ${ i} `
]
=
{
:
.
.
file
(
` /old/path/ ${ i} `
)
.
,
:
1000
+
}
;
}
await
.
.
update
(
'github.copilot.cli.sessionWorkspaceFolders'
,
)
;
const
=
.
now
(
)
;
const
=
.
.
get < Record< string , unknown >>
(
'github.copilot.cli.sessionWorkspaceFolders'
,
{
}
)
;
(
as
any
)
[
'session-new'
]
=
{
:
.
.
file
(
'/new/path'
)
.
,
:
}
;
await
.
.
update
(
'github.copilot.cli.sessionWorkspaceFolders'
,
)
;
await
.
trackSessionWorkspaceFolder
(
'session-trigger'
,
.
.
file
(
'/trigger/path'
)
.
)
;
const
=
.
.
get < Record< string , unknown >>
(
'github.copilot.cli.sessionWorkspaceFolders'
,
{
}
)
;
expect
(
[
'session-new'
]
)
.
toBeDefined
(
)
;
}
)
;
}
)
;
describe
(
'integration scenarios'
,
(
)
=>
{
describe
(
'getWorkspaceChanges - cache invalidation'
,
(
)
=>
{
let
:
<
typeof
<
string
|
undefined
>>
;
function
makeRepoContext
(
?
:
<
>
)
:
{
=
observableValue
(
'test-head-commit'
,
'abc123'
)
;
return
{
:
URI
.
file
(
'/repo'
)
,
:
'repository'
,
:
'main'
,
:
'abc123'
,
:
undefined
,
:
undefined
,
:
false
,
:
[
]
,
:
[
]
,
:
[
]
,
:
{
:
[
]
,
:
[
]
,
:
[
]
,
:
[
]
}
,
:
constObservable
(
'main'
)
,
:
,
:
constObservable
(
undefined
)
,
:
constObservable
(
undefined
)
,
:
constObservable
(
false
)
,
isIgnored
:
async
(
)
=>
false
,
...
,
}
as
;
}
it
(
'should return cached changes on second call'
,
async
(
)
=>
{
const
=
makeRepoContext
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
{
:
1
,
:
0
}
)
;
const
=
'session-1'
;
await
.
storeRepositoryProperties
(
,
{
:
'/repo'
,
:
'main'
,
}
)
;
const
=
await
.
getWorkspaceChanges
(
)
;
const
=
await
.
getWorkspaceChanges
(
)
;
expect
(
)
.
toBe
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
1
)
;
}
)
;
it
(
'should invalidate cache when clearWorkspaceChanges is called'
,
async
(
)
=>
{
const
=
makeRepoContext
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
{
:
1
,
:
0
}
)
;
const
=
'session-1'
;
await
.
storeRepositoryProperties
(
,
{
:
'/repo'
,
:
'main'
,
}
)
;
await
.
getWorkspaceChanges
(
)
;
.
clearWorkspaceChanges
(
)
;
await
.
getWorkspaceChanges
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
2
)
;
}
)
;
it
(
'should invalidate cache when handleRequestCompleted is called'
,
async
(
)
=>
{
const
=
makeRepoContext
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
{
:
1
,
:
0
}
)
;
const
=
'session-1'
;
await
.
storeRepositoryProperties
(
,
{
:
'/repo'
,
:
'main'
,
}
)
;
await
.
getWorkspaceChanges
(
)
;
await
.
handleRequestCompleted
(
)
;
await
.
getWorkspaceChanges
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
2
)
;
}
)
;
it
(
'should return empty array when repository has no changes'
,
async
(
)
=>
{
const
=
makeRepoContext
(
{
:
undefined
}
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
)
;
await
.
storeRepositoryProperties
(
'session-1'
,
{
:
'/repo'
,
:
'main'
,
}
)
;
const
=
await
.
getWorkspaceChanges
(
'session-1'
)
;
expect
(
)
.
toEqual
(
[
]
)
;
}
)
;
it
(
'should return empty array when no repository is found'
,
async
(
)
=>
{
.
=
.
fn
(
)
.
mockResolvedValue
(
undefined
)
;
await
.
storeRepositoryProperties
(
'session-1'
,
{
:
'/repo'
,
:
'main'
,
}
)
;
const
=
await
.
getWorkspaceChanges
(
'session-1'
)
;
expect
(
)
.
toEqual
(
[
]
)
;
}
)
;
it
(
'should cache empty result when session has no repository properties'
,
async
(
)
=>
{
const
=
await
.
getWorkspaceChanges
(
'no-repo-session'
)
;
const
=
await
.
getWorkspaceChanges
(
'no-repo-session'
)
;
expect
(
)
.
toEqual
(
[
]
)
;
expect
(
)
.
toEqual
(
[
]
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
1
)
;
}
)
;
it
(
'should clear negative cache when repository properties are later provided via trackSessionWorkspaceFolder'
,
async
(
)
=>
{
const
=
makeRepoContext
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
)
;
const
=
await
.
getWorkspaceChanges
(
'late-init-session'
)
;
expect
(
)
.
toEqual
(
[
]
)
;
await
.
trackSessionWorkspaceFolder
(
'late-init-session'
,
'/repo'
,
{
:
'/repo'
,
:
'main'
,
}
)
;
const
=
await
.
getWorkspaceChanges
(
'late-init-session'
)
;
expect
(
)
.
toBeDefined
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
2
)
;
}
)
;
it
(
'should not re-fetch when cache is valid for a folder'
,
async
(
)
=>
{
const
=
makeRepoContext
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
{
:
1
,
:
0
}
)
;
const
=
'session-1'
;
await
.
storeRepositoryProperties
(
,
{
:
'/repo'
,
:
'main'
,
}
)
;
await
.
getWorkspaceChanges
(
)
;
.
clearWorkspaceChanges
(
)
;
await
.
getWorkspaceChanges
(
)
;
.
clearWorkspaceChanges
(
)
;
await
.
getWorkspaceChanges
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
3
)
;
}
)
;
it
(
'should track changes per workspace folder independently'
,
async
(
)
=>
{
const
=
makeRepoContext
(
)
;
const
=
makeRepoContext
(
)
;
const
=
.
.
file
(
'/repo1'
)
;
const
=
.
.
file
(
'/repo2'
)
;
.
=
.
fn
(
)
.
mockImplementation
(
(
:
URI
)
=>
{
if
(
.
===
.
)
{
return
Promise
.
resolve
(
)
;
}
return
Promise
.
resolve
(
)
;
}
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
{
:
0
,
:
0
}
)
;
const
=
'session-1'
;
const
=
'session-2'
;
await
.
trackSessionWorkspaceFolder
(
,
.
,
{
:
.
,
:
'main'
,
}
)
;
await
.
trackSessionWorkspaceFolder
(
,
.
,
{
:
.
,
:
'main'
,
}
)
;
await
.
getWorkspaceChanges
(
)
;
await
.
getWorkspaceChanges
(
)
;
.
clearWorkspaceChanges
(
)
;
await
.
getWorkspaceChanges
(
)
;
await
.
getWorkspaceChanges
(
)
;
const
=
(
.
as
<
typeof
.
>
)
.
.
;
const
=
.
filter
(
(
:
URI
[
]
)
=>
[
0
]
.
===
.
)
.
;
const
=
.
filter
(
(
:
URI
[
]
)
=>
[
0
]
.
===
.
)
.
;
expect
(
)
.
toBe
(
2
)
;
expect
(
)
.
toBe
(
1
)
;
}
)
;
it
(
'should serialize git operations for different sessions sharing the same repo, base branch and branch'
,
async
(
)
=>
{
const
=
makeRepoContext
(
)
;
const
=
'/shared-repo'
;
.
=
.
fn
(
)
.
mockImplementation
(
async
(
)
=>
{
await
new
Promise
(
=>
setTimeout
(
,
10
)
)
;
return
;
}
)
;
const
=
'session-A'
;
const
=
'session-B'
;
await
.
storeRepositoryProperties
(
,
{
:
,
:
'feature'
,
:
'main'
,
}
)
;
await
.
storeRepositoryProperties
(
,
{
:
,
:
'feature'
,
:
'main'
,
}
)
;
const
[
,
]
=
await
Promise
.
all
(
[
.
getWorkspaceChanges
(
)
,
.
getWorkspaceChanges
(
)
,
]
)
;
expect
(
)
.
toBeDefined
(
)
;
expect
(
)
.
toBeDefined
(
)
;
expect
(
)
.
toBe
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
1
)
;
}
)
;
it
(
'should not share cache for sessions with different branch names in the same repo and base branch'
,
async
(
)
=>
{
const
=
makeRepoContext
(
)
;
const
=
'/shared-repo'
;
.
=
.
fn
(
)
.
mockImplementation
(
async
(
)
=>
{
await
new
Promise
(
=>
setTimeout
(
,
10
)
)
;
return
;
}
)
;
await
.
storeRepositoryProperties
(
'session-main'
,
{
:
,
:
'main'
,
:
'origin/main'
,
}
)
;
await
.
storeRepositoryProperties
(
'session-feature'
,
{
:
,
:
'feature'
,
:
'origin/main'
,
}
)
;
await
Promise
.
all
(
[
.
getWorkspaceChanges
(
'session-main'
)
,
.
getWorkspaceChanges
(
'session-feature'
)
,
]
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
2
)
;
}
)
;
it
(
'should invalidate cache for all sessions when clearWorkspaceChanges is called with folder URI'
,
async
(
)
=>
{
const
=
.
.
file
(
'/shared-folder'
)
;
const
=
makeRepoContext
(
{
:
URI
.
file
(
'/shared-folder'
)
}
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
)
;
.
=
.
fn
(
)
.
mockResolvedValue
(
{
:
1
,
:
0
}
)
;
const
=
'session-1'
;
const
=
'session-2'
;
await
.
trackSessionWorkspaceFolder
(
,
.
,
{
:
.
,
:
'main'
,
}
)
;
await
.
trackSessionWorkspaceFolder
(
,
.
,
{
:
.
,
:
'develop'
,
}
)
;
await
.
getWorkspaceChanges
(
)
;
await
.
getWorkspaceChanges
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
2
)
;
const
=
.
clearWorkspaceChanges
(
)
;
expect
(
)
.
toContain
(
)
;
expect
(
)
.
toContain
(
)
;
await
.
getWorkspaceChanges
(
)
;
await
.
getWorkspaceChanges
(
)
;
expect
(
.
)
.
toHaveBeenCalledTimes
(
4
)
;
}
)
;
it
(
'should return empty array when clearWorkspaceChanges is called with untracked folder URI'
,
(
)
=>
{
const
=
.
.
file
(
'/unknown-folder'
)
;
const
=
.
clearWorkspaceChanges
(
)
;
expect
(
)
.
toEqual
(
[
]
)
;
}
)
;
it
(
'should populate folder associations eagerly on trackSessionWorkspaceFolder'
,
async
(
)
=>
{
const
=
.
.
file
(
'/my-folder'
)
;
const
=
'session-eager'
;
expect
(
.
clearWorkspaceChanges
(
)
)
.
toEqual
(
[
]
)
;
await
.
trackSessionWorkspaceFolder
(
,
.
)
;
expect
(
.
clearWorkspaceChanges
(
)
)
.
toEqual
(
[
]
)
;
}
)
;
it
(
'should clean up folder associations on deleteTrackedWorkspaceFolder'
,
async
(
)
=>
{
const
=
.
.
file
(
'/cleanup-folder'
)
;
const
=
'session-cleanup'
;
await
.
trackSessionWorkspaceFolder
(
,
.
)
;
expect
(
.
clearWorkspaceChanges
(
)
)
.
toEqual
(
[
]
)
;
await
.
deleteTrackedWorkspaceFolder
(
)
;
expect
(
.
clearWorkspaceChanges
(
)
)
.
toEqual
(
[
]
)
;
}
)
;
}
)
;
}
)
;
}
)
;