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 / copilotCliSessionService.spec.ts 1192 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
import type { SessionOptions } from '@github/copilot/sdk' ;
import { mkdir, mkdtemp, rm, writeFile as writeNodeFile } from 'node:fs/promises' ;
import { tmpdir } from 'node:os' ;
import { join } from 'node:path' ;
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' ;
import type { ChatContext, ChatCustomAgent, ChatParticipantToolToken, Uri }
CancellationToken
IAuthenticationService
NullChatDebugFileLoggerService
IConfigurationService
InMemoryConfigurationService
IVSCodeExtensionContext
MockFileSystemService
FileType
MockGitService
ILogService
NullMcpService
NoopOTelService resolveOTelConfig
MockPromptsService
NullRequestLogger
NullExperimentationService
NullTelemetryService
NullWorkspaceService
mock
DisposableStore IReference toDisposable
IInstantiationService
ChatRequestTurn2
NullPromptVariablesService
createExtensionUnitTestingServices
IAgentSessionsWorkspace
IChatSessionWorkspaceFolderService
IChatSessionWorktreeService
MockChatSessionMetadataStore
IWorkspaceInfo
FakeToolsService
ICustomSessionTitleService
IChatDelegationSummaryService
getCopilotCLISessionDir
ICopilotCLISDK
CopilotCLISession ICopilotCLISession
CopilotCLISessionService CopilotCLISessionWorkspaceTracker ICopilotCLISessionItem
CopilotCLIMCPHandler
MissionControlApiClient
IQuestion IQuestionAnswer IUserQuestionHandler
MockCliSdkSession MockCliSdkSessionManager MockSkillLocations NullCopilotCLIAgents NullCopilotCLIModels NullICopilotCLIImageSupport
MockCliSdkSession MockCliSdkSessionManager MockSkillLocations NullCopilotCLIAgents NullICopilotCLIImageSupport
events type
unknownEvent events event event type
unknownEvent
_serviceBrand
isAgentSessionsWorkspace
readDirectoryCallCount
override uri FileType
readDirectoryCallCount
uri
override globalStorageUri Uri
override deleteTrackedWorkspaceFolder vi
override trackSessionWorkspaceFolder vi
override getSessionWorkspaceFolder vi
override handleRequestCompleted vi
override getWorkspaceChanges vi
override clearWorkspaceChanges IChatSessionWorkspaceFolderService vi _sessionIdOrFolderUri Uri
override getWorktreeProperties IChatSessionWorktreeService vi
_serviceBrand
titles
sessionId titles sessionId
sessionId title
titles sessionId title
_sessionId _request prompt command
workingDirectory Uri IWorkspaceInfo
folder workingDirectory
repository
worktree
worktreeProperties
workingDirectory Uri
workspace workingDirectory
uri name ChatCustomAgent
uri
source
name
description
userInvocable
disableModelInvocation
enabled
configurationService IConfigurationService
extensionContext IVSCodeExtensionContext
fileSystem MockFileSystemService
isAgentSessionsWorkspace
disposables
logService ILogService
instantiationService IInstantiationService
service CopilotCLISessionService
manager MockCliSdkSessionManager
metadataStore MockChatSessionMetadataStore
promptsService MockPromptsService
configurationService IConfigurationService
options ICreateSessionServiceOptions CopilotCLISessionService
tempStateHome
originalCopilotHome process env
vi
sdk
getPackage vi internal LocalSessionManager MockCliSdkSessionManager NoopTelemetryService LocalSession MockLocalSession createLocalFeatureFlagServiceCreator AutoModeSessionManager noopTelemetryBinder
getRequestId vi
ICopilotCLISDK
services disposables
accessor services
logService accessor ILogService
workspaceService
cliAgents
authService
getCopilotToken vi token
IAuthenticationService
delegationService
override context ChatContext token CancellationToken
override prompt reference
_serviceBrand
question IQuestion toolInvocationToken ChatParticipantToolToken token CancellationToken IQuestionAnswer
instantiationService
accessor args args
accessor args
ctor workspaceInfo agentName sdkSession
ctor CopilotCLISessionWorkspaceTracker
override
override _sessionId isOldGlobalSession isWorkspaceSession
isOldGlobalSession isWorkspaceSession
ctor MissionControlApiClient
createSession vi
submitEvents vi
getPendingCommands vi
deleteSession vi
disposables workspaceInfo agentName sdkSession logService workspaceService instantiationService accessor IConfigurationService env extensionVersion sessionId _serviceBrand _serviceBrand
IInstantiationService
configurationService accessor IConfigurationService
nullMcpServer disposables
titleService
metadataStore
promptsService disposables
options
serviceConfiguration options configurationService configurationService
logService sdk instantiationService options fileSystem logService authService serviceConfiguration nullMcpServer cliAgents workspaceService titleService serviceConfiguration delegationService metadataStore options isAgentSessionsWorkspace env extensionVersion sessionId promptsService options extensionContext
service disposables
manager service MockCliSdkSessionManager
tempStateHome
tempStateHome recursive force
tempStateHome
originalCopilotHome
process env
process env originalCopilotHome
vi
vi
disposables
agentUri
promptsService agentUri
promptsService agentUri
firstSessionId
metadataStore firstSessionId vscodeRequestId copilotRequestId agentId toolIdEditMap
firstSession firstSessionId
firstSession events
id type data selectedModel
id type data content attachments
manager sessions firstSessionId firstSession
firstHistory service sessionId firstSessionId workspace CancellationToken None
firstRequest firstHistory turn turn
firstRequest
firstRequest modeInstructions2 content
promptsService agentUri
promptsService agentUri
secondSessionId
metadataStore secondSessionId vscodeRequestId copilotRequestId agentId toolIdEditMap
secondSession secondSessionId
secondSession events
id type data selectedModel
id type data content attachments
manager sessions secondSessionId secondSession
secondHistory service sessionId secondSessionId workspace CancellationToken None
secondRequest secondHistory turn turn
secondRequest
content secondRequest modeInstructions2 content
name secondRequest modeInstructions2 name
uri secondRequest modeInstructions2 uri
content
name
uri agentUri
agentUri
promptsService agentUri
promptsService agentUri
sessionId
turns length _ i
vscodeRequestId
copilotRequestId
agentId
toolIdEditMap
metadataStore sessionId turns
session sessionId
session events id type data selectedModel
t turns
session events id t copilotRequestId type data content attachments
manager sessions sessionId session
service sessionId workspace CancellationToken None
promptsService agentUri
getCustomAgentsSpy vi promptsService
service sessionId workspace CancellationToken None
getCustomAgentsSpy
session service model CancellationToken None
existingSession service sessionId session object sessionId CancellationToken None
existingSession session
session service model CancellationToken None
session
resolve resolve
existingSession service sessionId session object sessionId CancellationToken None
existingSession object
existingSession object not session
existingSession object sessionId session object sessionId
createSessionSpy vi manager
service model CancellationToken None
createSessionSpy expect
clientName
createSessionSpy vi manager
service model CancellationToken None
callArgs createSessionSpy mock calls
callArgs systemMessage
mode
sections
identity
action
content
variableContext
vi NullPromptVariablesService prototype variableContext
createSessionSpy vi manager
service model CancellationToken None
systemMessage createSessionSpy mock calls systemMessage
systemMessage mode
systemMessage mode
identity systemMessage sections identity
identity action
identity action
systemMessage content variableContext
identity content
identity content not variableContext
createSessionSpy vi manager
service model reasoningEffort CancellationToken None
createSessionSpy expect
model
createSessionSpy vi manager
service model CancellationToken None
createSessionSpy expect
model
callArgs createSessionSpy mock calls
callArgs reasoningEffort
targetId
manager sessions targetId targetId
getSessionSpy vi manager
service sessionId targetId model reasoningEffort CancellationToken None
getSessionSpy expect
model
targetId
manager sessions targetId targetId
getSessionSpy vi manager
service sessionId targetId model CancellationToken None
getSessionSpy expect
systemMessage
mode
sections
identity
action
content
targetId
manager sessions targetId targetId
getSessionSpy vi manager
service sessionId targetId model CancellationToken None
getSessionSpy
callArgs getSessionSpy mock calls
callArgs reasoningEffort
targetId
sdkSession targetId
manager sessions targetId sdkSession
originalGetSession manager manager
getSessionSpy vi opts SessionOptions sessionId writable
resolve opts writable
manager getSession getSessionSpy manager getSession
promises IReference ICopilotCLISession
i i i
promises service sessionId targetId CancellationToken None
results promises
first results
r results
r first
getSessionSpy
sentinelDisposed
first object CopilotCLISession sentinelDisposed
results r r
sentinelDisposed
first
sentinelDisposed
slowId
fastId
manager sessions slowId slowId
manager sessions fastId fastId
originalGetSession manager manager
manager getSession vi opts SessionOptions sessionId writable
opts sessionId slowId
resolve opts writable
opts writable
manager getSession
slowPromise service sessionId slowId CancellationToken None
fastPromise service sessionId fastId CancellationToken None
firstResolved slowPromise fastPromise
firstResolved
id
manager sessions id id
sessions IReference ICopilotCLISession
i i i
sessions service sessionId id CancellationToken None
base sessions
s sessions
s base
sentinelDisposed
lastSession sessions
lastSession object CopilotCLISession sentinelDisposed
sessions s s
sentinelDisposed
lastSession
sentinelDisposed
session service sessionId CancellationToken None
disposables session
session
sessionId
manager sessions sessionId sessionId
service sessionId
manager sessions sessionId title
service sessionId CancellationToken None
session service sessionId CancellationToken None
service session object sessionId
manager sessions session object sessionId title
service session object sessionId CancellationToken None
session
sessionId
manager sessions sessionId sessionId
service sessionId
manager sessions sessionId summary
service sessionId CancellationToken None
sessionId service
service customSessionTitleService ICustomSessionTitleService customSessionTitleService sessionId
session service sessionId CancellationToken None
manager sessions sessionId summary
service sessionId CancellationToken None
session
sessionId
sdkSession sessionId
sdkSession summary
manager sessions sessionId sdkSession
session service sessionId CancellationToken None
session object _pendingPrompt _pendingPrompt
sessions service CancellationToken None
sessions item item id sessionId label
session
tempStateHome
process env tempStateHome
sessionId
sessionDir sessionId
fileSystem
sdk
getPackage vi internal LocalSessionManager MockCliSdkSessionManager NoopTelemetryService LocalSession MockLocalSession createLocalFeatureFlagServiceCreator AutoModeSessionManager noopTelemetryBinder
ICopilotCLISDK
services
disposables services
accessor services
configurationService accessor IConfigurationService
authService
getCopilotToken vi token
IAuthenticationService
nullMcpServer disposables
titleService
delegationService
override prompt reference
partialService disposables logService sdk instantiationService fileSystem logService authService configurationService nullMcpServer titleService configurationService delegationService env extensionVersion sessionId disposables
sessionDir fsPath recursive
sessionDir fsPath
id type timestamp parentId data sessionId startTime selectedModel version producer copilotVersion context cwd fsPath gitRoot fsPath repository fsPath
id type timestamp parentId data content attachments
id type timestamp parentId data content
partialHistory partialService sessionId
partialHistory
partialHistory
partialService sessionId fsPath fsPath
tempStateHome
process env tempStateHome
sessionId
sessionDir sessionId
fileSystem
sdk
getPackage vi internal LocalSessionManager MockCliSdkSessionManager NoopTelemetryService LocalSession MockLocalSession createLocalFeatureFlagServiceCreator AutoModeSessionManager noopTelemetryBinder
ICopilotCLISDK
services
disposables services
accessor services
configurationService accessor IConfigurationService
authService getCopilotToken vi token IAuthenticationService
nullMcpServer disposables
titleService
delegationService
override prompt reference
partialService disposables logService sdk instantiationService fileSystem logService authService configurationService nullMcpServer titleService configurationService delegationService env extensionVersion sessionId disposables
sessionDir fsPath recursive
eventsFilePath sessionDir fsPath
eventsFilePath
id type timestamp parentId data sessionId startTime selectedModel version producer copilotVersion context cwd fsPath
id type timestamp parentId data content attachments
history1 partialService sessionId
eventsFilePath
history2 partialService sessionId
history2 history1
tempStateHome
process env tempStateHome
result service
result
fileSystem
globalStorageUri
fileSystem
FileType Directory
FileType File
filteredService disposables
extensionContext globalStorageUri
fileSystem
filteredManager filteredService MockCliSdkSessionManager
sessions
id clientName
id clientName
id clientName
id clientName
id clientName sessions
sdkSession id
sdkSession clientName clientName
sdkSession summary id
filteredManager sessions id sdkSession
result filteredService CancellationToken None
targetedAgentHostItem filteredService CancellationToken None
sessionIds result item item id
targetedAgentHostItem
readDirectoryCallCount fileSystem readDirectoryCallCount
statCallCount fileSystem
sessionIds
targetedAgentHostItem
readDirectoryCallCount
statCallCount
configurationService InMemoryConfigurationService
migrateService disposables
migrateManager migrateService MockCliSdkSessionManager
id
sdkSession id
sdkSession clientName
sdkSession summary id
migrateManager sessions id sdkSession
metadataStore
result migrateService CancellationToken None
result item item id
external
external summary
manager sessions external sessionId external
metadataStore external sessionId
local
local summary
manager sessions local sessionId local
listedBeforeLoad service CancellationToken None
loaded service sessionId external sessionId CancellationToken None
disposables loaded
listedBeforeLoad listedBeforeLoad item item id
listedAfterLoad service CancellationToken None item item id
externalItem service external sessionId CancellationToken None
localItem service local sessionId CancellationToken None id
listedBeforeLoad
listedAfterLoad
externalItem
localItem
session service model CancellationToken None
disposables session
s1
s1 messages role content
s1 events type data content timestamp
manager sessions s1 sessionId s1
result service CancellationToken None
result length
item result
item id
tempStateHome
process env tempStateHome
sessionId
sessionDir sessionId
fileSystem
sdk
getPackage vi internal LocalSessionManager MockCliSdkSessionManager NoopTelemetryService LocalSession MockLocalSession createLocalFeatureFlagServiceCreator AutoModeSessionManager noopTelemetryBinder
ICopilotCLISDK
services
disposables services
accessor services
configurationService accessor IConfigurationService
authService
getCopilotToken vi token
IAuthenticationService
nullMcpServer disposables
titleService
delegationService
override prompt reference
partialService disposables logService sdk instantiationService fileSystem logService authService configurationService nullMcpServer titleService configurationService delegationService env extensionVersion sessionId disposables
partialManager partialService MockCliSdkSessionManager
session sessionId
session summary
partialManager sessions sessionId session
partialManager getSession vi
partialManager getSession
sessionDir fsPath recursive
sessionDir fsPath
id type timestamp parentId data sessionId startTime selectedModel version producer copilotVersion context cwd fsPath
id type timestamp parentId data content attachments
sessions partialService CancellationToken None
sessions
sessions id sessionId
sessions label
tempStateHome
process env tempStateHome
sessionId
sessionDir sessionId
fileSystem
sdk
getPackage vi internal LocalSessionManager MockCliSdkSessionManager NoopTelemetryService LocalSession MockLocalSession createLocalFeatureFlagServiceCreator AutoModeSessionManager noopTelemetryBinder
ICopilotCLISDK
services
disposables services
accessor services
configurationService accessor IConfigurationService
authService getCopilotToken vi token IAuthenticationService
nullMcpServer disposables
titleService
delegationService
override prompt reference
partialService disposables logService sdk instantiationService fileSystem logService authService configurationService nullMcpServer titleService configurationService delegationService env extensionVersion sessionId disposables
partialManager partialService MockCliSdkSessionManager
session sessionId
session summary
partialManager sessions sessionId session
partialManager getSession vi
partialManager getSession
sessionDir fsPath recursive
sessionDir fsPath
id type timestamp parentId data sessionId startTime selectedModel version producer copilotVersion context cwd fsPath
sessions partialService CancellationToken None
sessions
sessions id sessionId
sessions label
session service CancellationToken None
id session object sessionId
fired
disposables session
disposables service fired
service id
manager sessions id
fired
service sessionId id CancellationToken None
session service CancellationToken None
id session object sessionId
deletedIds
disposables session
disposables service deletedId deletedIds deletedId
service id
deletedIds
deletedIds id
session service CancellationToken None
id session object sessionId
disposables session
partialHistories service _partialSessionHistories Map
workingDirs service _sessionWorkingDirectories Map Uri
partialHistories id
workingDirs id
partialHistories id
workingDirs id
service id
partialHistories id
workingDirs id
session service CancellationToken None
id session object sessionId
partialHistories service _partialSessionHistories Map
partialHistories id
partialHistories id
reused service sessionId id CancellationToken None
reused session
partialHistories id
session
reused
s
s messages role content
s events type data content timestamp Date
manager sessions s sessionId s
sessions service CancellationToken None
item sessions i i id
item label
item label
s
s summary
s events type data content timestamp Date
manager sessions s sessionId s
getSessionSpy vi manager
sessions service CancellationToken None
item sessions i i id
item label
getSessionSpy not
s
s summary
s events type data content timestamp Date
manager sessions s sessionId s
getSessionSpy vi manager
sessions service CancellationToken None
item sessions i i id
item label
getSessionSpy
s
s events type data content timestamp Date
manager sessions s sessionId s
sessions1 service CancellationToken None
item1 sessions1 i i id
item1 label
getSessionSpy vi manager
sessions2 service CancellationToken None
item2 sessions2 i i id
item2 label
getSessionSpy not
s
s events type data content timestamp Date
manager sessions s sessionId s
sessions1 service CancellationToken None
sessions1 i i id label
s summary
sessions2 service CancellationToken None
sessions2 i i id label
s
s events type data content timestamp Date
manager sessions s sessionId s
service CancellationToken None
labelCache service _sessionLabels Map
labelCache
s
s summary
manager sessions s sessionId s
service CancellationToken None
labelCache service _sessionLabels Map
labelCache
id service
id
service id
service
a service
b service
a not b
service a
service b
id service
service id
service model sessionId id CancellationToken None
service id
sourceId
manager sessions sourceId sourceId
forkSpy vi manager
newId service sessionId sourceId requestId workspace CancellationToken None
forkSpy sourceId
newId
newId not sourceId
sourceId
manager sessions sourceId sourceId
metadataStore
storeMetadataSpy vi metadataStore
sdk
getPackage vi internal LocalSessionManager MockCliSdkSessionManager NoopTelemetryService LocalSession MockLocalSession createLocalFeatureFlagServiceCreator AutoModeSessionManager noopTelemetryBinder
getRequestId vi
ICopilotCLISDK
services disposables
accessor services
configurationService accessor IConfigurationService
authService getCopilotToken vi token IAuthenticationService
nullMcpServer disposables
delegationService
override prompt reference
localService disposables logService sdk instantiationService logService authService configurationService nullMcpServer configurationService delegationService metadataStore env extensionVersion sessionId disposables
localManager localService MockCliSdkSessionManager
localManager sessions sourceId sourceId
newId localService sessionId sourceId requestId workspace CancellationToken None
storeMetadataSpy sourceId newId expect
sourceId
manager sessions sourceId sourceId
created ICopilotCLISessionItem
disposables service item created item
newId service sessionId sourceId requestId workspace CancellationToken None
created
created id newId
created label
sourceId
sdkSession sourceId
sdkSession events type id data content timestamp
manager sessions sourceId sdkSession
sdk
getPackage vi internal LocalSessionManager MockCliSdkSessionManager NoopTelemetryService LocalSession MockLocalSession createLocalFeatureFlagServiceCreator AutoModeSessionManager noopTelemetryBinder
getRequestId vi vscodeRequestId copilotRequestId
ICopilotCLISDK
services disposables
accessor services
configurationService accessor IConfigurationService
authService getCopilotToken vi token IAuthenticationService
nullMcpServer disposables
delegationService
override prompt reference
override
metadataStore
metadataStore sourceId vscodeRequestId copilotRequestId toolIdEditMap
localService disposables logService sdk instantiationService logService authService configurationService nullMcpServer configurationService delegationService metadataStore env extensionVersion sessionId disposables
localManager localService MockCliSdkSessionManager
localManager sessions sourceId sdkSession
forkSpy vi localManager
localService sessionId sourceId requestId workspace CancellationToken None
forkSpy sourceId
it
vi
session service CancellationToken None
vi
session object isDisposed
from
'vscode'
;
import
{
}
from
'vscode-languageserver-protocol'
;
import
{
}
from
'../../../../../platform/authentication/common/authentication'
;
import
{
}
from
'../../../../../platform/chat/common/chatDebugFileLoggerService'
;
import
{
}
from
'../../../../../platform/configuration/common/configurationService'
;
import
{
}
from
'../../../../../platform/configuration/test/common/inMemoryConfigurationService'
;
import
{
}
from
'../../../../../platform/extContext/common/extensionContext'
;
import
{
}
from
'../../../../../platform/filesystem/node/test/mockFileSystemService'
;
import
{
}
from
'../../../../../platform/filesystem/common/fileTypes'
;
import
{
}
from
'../../../../../platform/ignore/node/test/mockGitService'
;
import
{
}
from
'../../../../../platform/log/common/logService'
;
import
{
}
from
'../../../../../platform/mcp/common/mcpService'
;
import
{
,
}
from
'../../../../../platform/otel/common/index'
;
import
{
}
from
'../../../../../platform/promptFiles/test/common/mockPromptsService'
;
import
{
}
from
'../../../../../platform/requestLogger/node/nullRequestLogger'
;
import
{
}
from
'../../../../../platform/telemetry/common/nullExperimentationService'
;
import
{
}
from
'../../../../../platform/telemetry/common/nullTelemetryService'
;
import
{
}
from
'../../../../../platform/workspace/common/workspaceService'
;
import
{
}
from
'../../../../../util/common/test/simpleMock'
;
import
{
,
,
}
from
'../../../../../util/vs/base/common/lifecycle'
;
import
{
URI
}
from
'../../../../../util/vs/base/common/uri'
;
import
{
}
from
'../../../../../util/vs/platform/instantiation/common/instantiation'
;
import
{
}
from
'../../../../../vscodeTypes'
;
import
{
}
from
'../../../../prompt/node/promptVariablesService'
;
import
{
}
from
'../../../../test/node/services'
;
import
{
}
from
'../../../common/agentSessionsWorkspace'
;
import
{
}
from
'../../../common/chatSessionWorkspaceFolderService'
;
import
{
}
from
'../../../common/chatSessionWorktreeService'
;
import
{
}
from
'../../../common/test/mockChatSessionMetadataStore'
;
import
{
}
from
'../../../common/workspaceInfo'
;
import
{
}
from
'../../common/copilotCLITools'
;
import
{
}
from
'../../common/customSessionTitleService'
;
import
{
}
from
'../../common/delegationSummaryService'
;
import
{
}
from
'../cliHelpers'
;
import
{
}
from
'../copilotCli'
;
import
{
,
}
from
'../copilotcliSession'
;
import
{
COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE
,
,
,
}
from
'../copilotcliSessionService'
;
import
{
}
from
'../mcpHandler'
;
import
{
}
from
'../missionControlApiClient'
;
import
{
,
,
}
from
'../userInputHelpers'
;
import
{
,
,
,
,
,
}
from
'./testHelpers'
;
export
{
,
,
,
,
}
from
'./testHelpers'
;
class
MockLocalSession
{
static
async
fromEvents
(
:
readonly
{
:
string
}
[
]
)
:
Promise
<
{
}
>
{
const
=
.
find
(
=>
.
===
'custom.unknown'
)
;
if
(
)
{
throw
new
Error
(
` Unknown event type: ${ unknownEvent. type } . Failed to deserialize session. `
)
;
}
return
{
}
;
}
}
export
class
NullAgentSessionsWorkspace
implements
IAgentSessionsWorkspace
{
:
undefined
;
constructor
(
readonly
=
false
)
{
}
}
class
TrackingFileSystemService
extends
MockFileSystemService
{
=
0
;
async
readDirectory
(
:
URI
)
:
Promise
<
[
string
,
]
[
]
>
{
this
.
++
;
return
super
.
readDirectory
(
)
;
}
}
class
TestExtensionContext
extends
mock< IVSCodeExtensionContext>
(
)
{
constructor
(
public
readonly
:
)
{
super
(
)
;
}
}
class
NullChatSessionWorkspaceFolderService
extends
mock< IChatSessionWorkspaceFolderService>
(
)
{
=
.
fn
(
async
(
)
=>
{
}
)
;
=
.
fn
(
async
(
)
=>
{
}
)
;
=
.
fn
(
async
(
)
=>
undefined
)
;
=
.
fn
(
async
(
)
=>
{
}
)
;
=
.
fn
(
async
(
)
=>
undefined
)
;
:
[
'clearWorkspaceChanges'
]
=
.
fn
(
(
:
string
|
)
=>
[
]
)
;
}
class
NullChatSessionWorktreeService
extends
mock< IChatSessionWorktreeService>
(
)
{
:
[
'getWorktreeProperties'
]
=
.
fn
(
async
(
)
=>
undefined
)
;
}
class
NullCustomSessionTitleService
implements
ICustomSessionTitleService
{
declare
:
undefined
;
private
readonly
=
new
Map< string , string >
(
)
;
async
getCustomSessionTitle
(
:
string
)
:
Promise
<
string
|
undefined
>
{
return
this
.
.
get
(
)
;
}
async
setCustomSessionTitle
(
:
string
,
:
string
)
:
Promise
<
void
>
{
this
.
.
set
(
,
)
;
}
async
generateSessionTitle
(
:
string
,
:
{
?
:
string
;
?
:
string
}
)
:
Promise
<
string
|
undefined
>
{
return
undefined
;
}
}
function
workspaceInfoFor
(
:
|
undefined
)
:
{
return
{
:
,
:
undefined
,
:
undefined
,
:
undefined
,
}
;
}
function
sessionOptionsFor
(
?
:
)
{
return
{
:
workspaceInfoFor
(
)
,
}
;
}
function
createCustomAgent
(
:
URI
,
:
string
)
:
{
return
{
,
:
'local'
,
,
:
''
,
:
true
,
:
false
,
:
true
,
}
;
}
interface
ICreateSessionServiceOptions
{
readonly
?
:
;
readonly
?
:
;
readonly
?
:
;
readonly
?
:
boolean
;
}
const
createLocalFeatureFlagServiceCreator
=
(
)
=>
(
)
=>
(
{
}
)
;
describe
(
'CopilotCLISessionService'
,
(
)
=>
{
const
=
new
DisposableStore
(
)
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
;
let
createSessionService
:
(
?
:
)
=>
;
let
:
string
|
undefined
;
const
=
.
.
COPILOT_HOME
;
beforeEach
(
async
(
)
=>
{
.
useRealTimers
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
{
:
,
:
class
{
}
}
,
:
,
,
:
class
{
}
,
:
{
}
}
)
)
,
:
.
fn
(
(
)
=>
undefined
)
,
}
as
unknown
as
;
const
=
.
add
(
createExtensionUnitTestingServices
(
)
)
;
const
=
.
createTestingAccessor
(
)
;
=
.
get
(
)
;
const
=
new
NullWorkspaceService
(
)
;
const
=
new
NullCopilotCLIAgents
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
'test-token'
}
)
)
,
}
as
unknown
as
;
const
=
new
class
extends
mock< IChatDelegationSummaryService>
(
)
{
async
summarize
(
:
,
:
)
:
Promise
<
string
|
undefined
>
{
return
undefined
;
}
extractPrompt
(
)
:
{
:
string
;
:
never
}
|
undefined
{
return
undefined
;
}
}
(
)
;
class
FakeUserQuestionHandler
implements
IUserQuestionHandler
{
:
undefined
;
async
askUserQuestion
(
:
,
:
,
:
)
:
Promise
<
|
undefined
>
{
return
undefined
;
}
}
=
{
invokeFunction
(
fn
:
(
:
unknown
,
...
:
any
[
]
)
=>
any
,
...
:
any
[
]
)
:
any
{
return
fn
(
,
...
)
;
}
,
createInstance
:
(
:
unknown
,
:
any
,
:
any
,
:
any
)
=>
{
if
(
===
)
{
return
new
class
extends
mock< CopilotCLISessionWorkspaceTracker>
(
)
{
async
initialize
(
)
:
Promise
<
void
>
{
return
;
}
shouldShowSession
(
:
string
)
:
{
?
:
boolean
;
?
:
boolean
}
{
return
{
:
false
,
:
true
}
;
}
}
(
)
;
}
if
(
===
)
{
return
{
:
.
fn
(
)
,
:
.
fn
(
)
,
:
.
fn
(
async
(
)
=>
[
]
)
,
:
.
fn
(
async
(
)
=>
{
}
)
,
}
;
}
return
.
add
(
new
CopilotCLISession
(
,
,
,
[
]
,
undefined
,
,
,
new
MockChatSessionMetadataStore
(
)
,
,
new
NullRequestLogger
(
)
,
new
NullICopilotCLIImageSupport
(
)
,
new
FakeToolsService
(
)
,
new
FakeUserQuestionHandler
(
)
,
.
get
(
)
,
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
new
MockGitService
(
)
,
{
:
undefined
}
as
any
,
{
:
undefined
,
resetTurnCredits
(
)
{
}
,
getCreditsForTurn
(
)
{
return
undefined
;
}
,
setLastCopilotUsage
(
)
{
}
}
as
any
,
new
NullTelemetryService
(
)
)
)
;
}
}
as
unknown
as
;
=
.
get
(
)
;
const
=
.
add
(
new
NullMcpService
(
)
)
;
const
=
new
NullCustomSessionTitleService
(
)
;
=
new
MockChatSessionMetadataStore
(
)
;
=
.
add
(
new
MockPromptsService
(
)
)
;
createSessionService
=
(
=
{
}
)
=>
{
const
=
.
??
;
return
new
CopilotCLISessionService
(
,
,
,
.
??
new
MockFileSystemService
(
)
,
new
CopilotCLIMCPHandler
(
,
,
,
)
,
,
,
,
,
new
MockSkillLocations
(
)
,
,
,
new
NullAgentSessionsWorkspace
(
.
)
,
new
NullChatSessionWorkspaceFolderService
(
)
,
new
NullChatSessionWorktreeService
(
)
,
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
new
NullPromptVariablesService
(
)
,
new
NullChatDebugFileLoggerService
(
)
,
,
new
NullCopilotCLIModels
(
)
,
new
NullExperimentationService
(
)
,
.
)
;
}
;
=
.
add
(
createSessionService
(
)
)
;
=
await
.
getSessionManager
(
)
as
unknown
as
;
}
)
;
afterEach
(
(
)
=>
{
if
(
)
{
void
rm
(
,
{
:
true
,
:
true
}
)
;
=
undefined
;
}
if
(
===
undefined
)
{
delete
.
.
COPILOT_HOME
;
}
else
{
.
.
COPILOT_HOME
=
;
}
.
useRealTimers
(
)
;
.
restoreAllMocks
(
)
;
.
clear
(
)
;
}
)
;
describe
(
'CopilotCLISessionService.getChatHistory'
,
(
)
=>
{
it
(
'refreshes cached custom agent mode instructions when custom agents change'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace/.github/agents/review.agent.md'
)
;
.
setFileContent
(
,
'---\nname: Review\n---\nFirst instructions'
)
;
.
setCustomAgents
(
[
createCustomAgent
(
,
'Review'
)
]
)
;
const
=
'history-agent-first'
;
await
.
updateRequestDetails
(
,
[
{
:
'request-1'
,
:
'sdk-request-1'
,
:
'Review'
,
:
{
}
}
]
)
;
const
=
new
MockCliSdkSession
(
,
new
Date
(
'2024-01-01T00:00:00.000Z'
)
)
;
.
.
push
(
{
:
'start-1'
,
:
'session.start'
,
:
{
:
'gpt-test'
}
}
,
{
:
'sdk-request-1'
,
:
'user.message'
,
:
{
:
'Review the first change'
,
:
[
]
}
}
,
)
;
.
.
set
(
,
)
;
const
=
await
.
getChatHistory
(
{
:
,
:
workspaceInfoFor
(
undefined
)
}
,
.
)
;
const
=
.
find
(
=>
instanceof
ChatRequestTurn2
)
;
if
(
!
(
instanceof
ChatRequestTurn2
)
)
{
throw
new
Error
(
'Expected a request turn'
)
;
}
expect
(
.
?.
)
.
toBe
(
'First instructions'
)
;
.
setFileContent
(
,
'---\nname: Review\n---\nUpdated instructions'
)
;
.
setCustomAgents
(
[
createCustomAgent
(
,
'Review'
)
]
)
;
const
=
'history-agent-second'
;
await
.
updateRequestDetails
(
,
[
{
:
'request-2'
,
:
'sdk-request-2'
,
:
'Review'
,
:
{
}
}
]
)
;
const
=
new
MockCliSdkSession
(
,
new
Date
(
'2024-01-01T00:00:01.000Z'
)
)
;
.
.
push
(
{
:
'start-2'
,
:
'session.start'
,
:
{
:
'gpt-test'
}
}
,
{
:
'sdk-request-2'
,
:
'user.message'
,
:
{
:
'Review the second change'
,
:
[
]
}
}
,
)
;
.
.
set
(
,
)
;
const
=
await
.
getChatHistory
(
{
:
,
:
workspaceInfoFor
(
undefined
)
}
,
.
)
;
const
=
.
find
(
=>
instanceof
ChatRequestTurn2
)
;
if
(
!
(
instanceof
ChatRequestTurn2
)
)
{
throw
new
Error
(
'Expected a request turn'
)
;
}
expect
(
{
:
.
?.
,
:
.
?.
,
:
.
?.
?.
toString
(
)
,
}
)
.
toEqual
(
{
:
'Updated instructions'
,
:
'Review'
,
:
.
toString
(
)
,
}
)
;
}
)
;
it
(
'issues a single getCustomAgents call when multiple turns resolve in parallel after agent change'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/workspace/.github/agents/parallel.agent.md'
)
;
.
setFileContent
(
,
'---\nname: Parallel\n---\nInstructions'
)
;
.
setCustomAgents
(
[
createCustomAgent
(
,
'Parallel'
)
]
)
;
const
=
'history-agent-parallel'
;
const
=
Array
.
from
(
{
:
5
}
,
(
,
)
=>
(
{
:
` request- ${ i} `
,
:
` sdk-request- ${ i} `
,
:
'Parallel'
,
:
{
}
,
}
)
)
;
await
.
updateRequestDetails
(
,
)
;
const
=
new
MockCliSdkSession
(
,
new
Date
(
'2024-01-01T00:00:00.000Z'
)
)
;
.
.
push
(
{
:
'start'
,
:
'session.start'
,
:
{
:
'gpt-test'
}
}
)
;
for
(
const
of
)
{
.
.
push
(
{
:
.
,
:
'user.message'
,
:
{
:
'm'
,
:
[
]
}
}
)
;
}
.
.
set
(
,
)
;
await
.
getChatHistory
(
{
,
:
workspaceInfoFor
(
undefined
)
}
,
.
)
;
.
setCustomAgents
(
[
createCustomAgent
(
,
'Parallel'
)
]
)
;
const
=
.
spyOn
(
,
'getCustomAgents'
)
;
await
.
getChatHistory
(
{
,
:
workspaceInfoFor
(
undefined
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledTimes
(
1
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.createSession'
,
(
)
=>
{
it
(
'get session will return the same session created using createSession'
,
async
(
)
=>
{
const
=
await
.
createSession
(
{
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
const
=
await
.
getSession
(
{
:
.
.
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
)
.
toBe
(
)
;
}
)
;
it
(
'get session will return new once previous session is disposed'
,
async
(
)
=>
{
const
=
await
.
createSession
(
{
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
.
dispose
(
)
;
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
const
=
await
.
getSession
(
{
:
.
.
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
?.
)
.
toBeDefined
(
)
;
expect
(
?.
)
.
.
toBe
(
)
;
expect
(
?.
.
)
.
toBe
(
.
.
)
;
}
)
;
it
(
'passes clientName: vscode to session manager'
,
async
(
)
=>
{
const
=
.
spyOn
(
,
'createSession'
)
;
await
.
createSession
(
{
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledWith
(
.
objectContaining
(
{
:
'vscode'
}
)
)
;
}
)
;
it
(
'passes the VS Code Copilot CLI identity system message to session manager'
,
async
(
)
=>
{
const
=
.
spyOn
(
,
'createSession'
)
;
await
.
createSession
(
{
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
const
=
.
.
[
0
]
[
0
]
;
expect
(
.
)
.
toEqual
(
{
:
'customize'
,
:
{
:
{
:
'replace'
,
:
COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE
,
}
,
}
,
}
)
;
}
)
;
it
(
'preserves prompt variable context separately from the VS Code Copilot CLI identity system message'
,
async
(
)
=>
{
const
=
'Resolved template variables are available here.'
;
.
spyOn
(
.
,
'buildTemplateVariablesContext'
)
.
mockReturnValue
(
)
;
const
=
.
spyOn
(
,
'createSession'
)
;
await
.
createSession
(
{
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
const
=
.
.
[
0
]
[
0
]
.
;
expect
(
?.
)
.
toBe
(
'customize'
)
;
if
(
?.
!==
'customize'
)
{
throw
new
Error
(
'Expected customize-mode system message'
)
;
}
const
=
.
?.
;
expect
(
?.
)
.
toBe
(
'replace'
)
;
if
(
?.
!==
'replace'
)
{
throw
new
Error
(
'Expected replace identity section override'
)
;
}
expect
(
.
)
.
toBe
(
)
;
expect
(
.
)
.
toBe
(
COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE
)
;
expect
(
.
)
.
.
toContain
(
)
;
}
)
;
it
(
'passes reasoningEffort to session manager when provided'
,
async
(
)
=>
{
const
=
.
spyOn
(
,
'createSession'
)
;
await
.
createSession
(
{
:
'gpt-test'
,
:
'high'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledWith
(
.
objectContaining
(
{
:
'gpt-test'
,
}
)
)
;
}
)
;
it
(
'does not set reasoningEffort when not provided'
,
async
(
)
=>
{
const
=
.
spyOn
(
,
'createSession'
)
;
await
.
createSession
(
{
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledWith
(
.
objectContaining
(
{
:
'gpt-test'
,
}
)
)
;
const
=
.
.
[
0
]
[
0
]
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.getSession'
,
(
)
=>
{
it
(
'passes reasoningEffort to session manager when creating a new session'
,
async
(
)
=>
{
const
=
'reasoning-get'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
=
.
spyOn
(
,
'getSession'
)
;
await
.
getSession
(
{
:
,
:
'gpt-test'
,
:
'medium'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledWith
(
.
objectContaining
(
{
:
'gpt-test'
,
}
)
,
true
)
;
}
)
;
it
(
'passes the VS Code Copilot CLI identity system message when getting an existing session'
,
async
(
)
=>
{
const
=
'system-message-get'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
=
.
spyOn
(
,
'getSession'
)
;
await
.
getSession
(
{
:
,
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledWith
(
.
objectContaining
(
{
:
{
:
'customize'
,
:
{
:
{
:
'replace'
,
:
COPILOT_CLI_CHAT_PANEL_SYSTEM_MESSAGE
,
}
,
}
,
}
,
}
)
,
true
)
;
}
)
;
it
(
'does not set reasoningEffort when not provided'
,
async
(
)
=>
{
const
=
'no-reasoning-get'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
=
.
spyOn
(
,
'getSession'
)
;
await
.
getSession
(
{
:
,
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalled
(
)
;
const
=
.
.
[
0
]
[
0
]
;
expect
(
.
)
.
toBeUndefined
(
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.getSession concurrency & locking'
,
(
)
=>
{
it
(
'concurrent getSession calls for same id create only one wrapper'
,
async
(
)
=>
{
const
=
'concurrent'
;
const
=
new
MockCliSdkSession
(
,
new
Date
(
)
)
;
.
.
set
(
,
)
;
const
=
.
getSession
.
bind
(
)
;
const
=
.
fn
(
(
:
&
{
:
string
}
,
:
boolean
)
=>
{
return
new
Promise
(
=>
setTimeout
(
(
)
=>
resolve
(
originalGetSession
(
,
)
)
,
20
)
)
;
}
)
;
.
=
as
unknown
as
typeof
.
;
const
:
Promise
<
<
>
|
undefined
>
[
]
=
[
]
;
for
(
let
=
0
;
<
10
;
++
)
{
.
push
(
.
getSession
(
{
:
,
...
sessionOptionsFor
(
)
}
,
.
)
)
;
}
const
=
await
Promise
.
all
(
)
;
const
=
.
shift
(
)
!
;
for
(
const
of
)
{
expect
(
)
.
toBe
(
)
;
}
expect
(
)
.
toHaveBeenCalledTimes
(
1
)
;
let
=
false
;
(
.
as
)
.
add
(
toDisposable
(
(
)
=>
{
=
true
;
}
)
)
;
.
forEach
(
=>
?.
dispose
(
)
)
;
expect
(
)
.
toBe
(
false
)
;
.
dispose
(
)
;
expect
(
)
.
toBe
(
true
)
;
}
)
;
it
(
'getSession for different ids does not block on mutex for another id'
,
async
(
)
=>
{
const
=
'slow'
;
const
=
'fast'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
=
.
getSession
.
bind
(
)
;
.
=
.
fn
(
(
:
&
{
:
string
}
,
:
boolean
)
=>
{
if
(
.
===
)
{
return
new
Promise
(
=>
setTimeout
(
(
)
=>
resolve
(
originalGetSession
(
,
)
)
,
40
)
)
;
}
return
originalGetSession
(
,
)
;
}
)
as
unknown
as
typeof
.
;
const
=
.
getSession
(
{
:
,
...
sessionOptionsFor
(
)
}
,
.
)
.
then
(
(
)
=>
'slow'
)
;
const
=
.
getSession
(
{
:
,
...
sessionOptionsFor
(
)
}
,
.
)
.
then
(
(
)
=>
'fast'
)
;
const
=
await
Promise
.
race
(
[
,
]
)
;
expect
(
)
.
toBe
(
'fast'
)
;
}
)
;
it
(
'session only fully disposes after all acquired references dispose'
,
async
(
)
=>
{
const
=
'refcount'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
:
<
>
[
]
=
[
]
;
for
(
let
=
0
;
<
5
;
++
)
{
.
push
(
(
await
.
getSession
(
{
:
,
...
sessionOptionsFor
(
)
}
,
.
)
)
!
)
;
}
const
=
[
0
]
;
for
(
const
of
)
{
expect
(
)
.
toBe
(
)
;
}
let
=
false
;
const
=
.
pop
(
)
!
;
(
.
as
)
.
add
(
toDisposable
(
(
)
=>
{
=
true
;
}
)
)
;
.
forEach
(
=>
.
dispose
(
)
)
;
expect
(
)
.
toBe
(
false
)
;
.
dispose
(
)
;
expect
(
)
.
toBe
(
true
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.getSession missing'
,
(
)
=>
{
it
(
'returns undefined when underlying manager has no session'
,
async
(
)
=>
{
const
=
await
.
getSession
(
{
:
'does-not-exist'
,
...
sessionOptionsFor
(
)
}
,
.
)
;
.
add
(
!
)
;
expect
(
)
.
toBeUndefined
(
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.renameSession'
,
(
)
=>
{
it
(
'renames an inactive session through copilot/sdk'
,
async
(
)
=>
{
const
=
'rename-inactive'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
await
.
renameSession
(
,
'Renamed From VS Code'
)
;
expect
(
.
.
get
(
)
?.
)
.
toBe
(
'Renamed From VS Code'
)
;
expect
(
await
.
getSessionTitle
(
,
.
)
)
.
toBe
(
'Renamed From VS Code'
)
;
}
)
;
it
(
'renames an active wrapped session through copilot/sdk'
,
async
(
)
=>
{
const
=
await
.
createSession
(
{
:
'rename-active'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
await
.
renameSession
(
.
.
,
'Wrapped Session Name'
)
;
expect
(
.
.
get
(
.
.
)
?.
)
.
toBe
(
'Wrapped Session Name'
)
;
expect
(
await
.
getSessionTitle
(
.
.
,
.
)
)
.
toBe
(
'Wrapped Session Name'
)
;
.
dispose
(
)
;
}
)
;
it
(
'updates session summaries through copilot/sdk for untitled sessions'
,
async
(
)
=>
{
const
=
'summary-session'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
await
.
updateSessionSummary
(
,
'Generated Summary'
)
;
expect
(
.
.
get
(
)
?.
)
.
toBe
(
'Generated Summary'
)
;
expect
(
await
.
getSessionTitle
(
,
.
)
)
.
toBe
(
'Generated Summary'
)
;
}
)
;
it
(
'syncs staged titles for newly created vscode sessions into copilot/sdk'
,
async
(
)
=>
{
const
=
.
createNewSessionId
(
)
;
await
(
as
unknown
as
{
:
}
)
.
.
setCustomSessionTitle
(
,
'Staged Session Title'
)
;
const
=
await
.
createSession
(
{
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
.
.
get
(
)
?.
)
.
toBe
(
'Staged Session Title'
)
;
expect
(
await
.
getSessionTitle
(
,
.
)
)
.
toBe
(
'Staged Session Title'
)
;
.
dispose
(
)
;
}
)
;
it
(
'keeps an established session list title stable while a new request is pending'
,
async
(
)
=>
{
const
=
'stable-while-pending'
;
const
=
new
MockCliSdkSession
(
,
new
Date
(
)
)
;
.
=
'Original Session Title'
;
.
.
set
(
,
)
;
const
=
await
.
getSession
(
{
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
(
!
.
as
unknown
as
{
:
string
|
undefined
}
)
.
=
'Latest in-flight request'
;
const
=
await
.
getAllSessions
(
.
)
;
expect
(
.
find
(
=>
.
===
)
?.
)
.
toBe
(
'Original Session Title'
)
;
!
.
dispose
(
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.tryGetPartialSesionHistory'
,
(
)
=>
{
it
(
'reconstructs history from persisted files'
,
async
(
)
=>
{
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'copilot-cli-session-service-'
)
)
;
.
.
COPILOT_HOME
=
join
(
,
'.copilot'
)
;
const
=
'partial-session'
;
const
=
URI
.
file
(
getCopilotCLISessionDir
(
)
)
;
const
=
new
MockFileSystemService
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
{
:
,
:
class
{
}
}
,
:
,
,
:
class
{
}
,
:
{
}
}
)
)
}
as
unknown
as
;
const
=
createExtensionUnitTestingServices
(
)
;
.
add
(
)
;
const
=
.
createTestingAccessor
(
)
;
const
=
.
get
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
'test-token'
}
)
)
,
}
as
unknown
as
;
const
=
.
add
(
new
NullMcpService
(
)
)
;
const
=
new
NullCustomSessionTitleService
(
)
;
const
=
new
class
extends
mock< IChatDelegationSummaryService>
(
)
{
extractPrompt
(
)
:
{
:
string
;
:
never
}
|
undefined
{
return
undefined
;
}
}
(
)
;
const
=
.
add
(
new
CopilotCLISessionService
(
,
,
,
,
new
CopilotCLIMCPHandler
(
,
,
,
)
,
new
NullCopilotCLIAgents
(
)
,
new
NullWorkspaceService
(
)
,
,
,
new
MockSkillLocations
(
)
,
,
new
MockChatSessionMetadataStore
(
)
,
new
NullAgentSessionsWorkspace
(
)
,
new
NullChatSessionWorkspaceFolderService
(
)
,
new
NullChatSessionWorktreeService
(
)
,
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
new
NullPromptVariablesService
(
)
,
new
NullChatDebugFileLoggerService
(
)
,
.
add
(
new
MockPromptsService
(
)
)
,
new
NullCopilotCLIModels
(
)
,
new
NullExperimentationService
(
)
)
)
;
await
mkdir
(
.
,
{
:
true
}
)
;
await
writeNodeFile
(
join
(
.
,
'events.jsonl'
)
,
[
JSON
.
stringify
(
{
:
'1'
,
:
'session.start'
,
:
'2024-01-01T00:00:00.000Z'
,
:
null
,
:
{
,
:
'2024-01-01T00:00:00.000Z'
,
:
'gpt-test'
,
:
1
,
:
'test'
,
:
'1.0.0'
,
:
{
:
URI
.
file
(
'/workspace/project'
)
.
,
:
URI
.
file
(
'/workspace/repo'
)
.
,
:
URI
.
file
(
'/workspace/repo'
)
.
}
}
}
)
,
JSON
.
stringify
(
{
:
'2'
,
:
'user.message'
,
:
'2024-01-01T00:00:01.000Z'
,
:
'1'
,
:
{
:
'Repair the session'
,
:
[
]
}
}
)
,
JSON
.
stringify
(
{
:
'3'
,
:
'assistant.message'
,
:
'2024-01-01T00:00:03.000Z'
,
:
'2'
,
:
{
:
'Recovered history'
}
}
)
,
]
.
join
(
'\n'
)
)
;
const
=
await
.
tryGetPartialSessionHistory
(
)
;
expect
(
)
.
toBeDefined
(
)
;
expect
(
)
.
toHaveLength
(
2
)
;
expect
(
.
getSessionWorkingDirectory
(
)
?.
)
.
toBe
(
URI
.
file
(
'/workspace/project'
)
.
)
;
}
)
;
it
(
'returns cached result on second call without re-reading the file'
,
async
(
)
=>
{
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'copilot-cli-session-service-'
)
)
;
.
.
COPILOT_HOME
=
join
(
,
'.copilot'
)
;
const
=
'cache-test-session'
;
const
=
URI
.
file
(
getCopilotCLISessionDir
(
)
)
;
const
=
new
MockFileSystemService
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
{
:
,
:
class
{
}
}
,
:
,
,
:
class
{
}
,
:
{
}
}
)
)
}
as
unknown
as
;
const
=
createExtensionUnitTestingServices
(
)
;
.
add
(
)
;
const
=
.
createTestingAccessor
(
)
;
const
=
.
get
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
'test-token'
}
)
)
}
as
unknown
as
;
const
=
.
add
(
new
NullMcpService
(
)
)
;
const
=
new
NullCustomSessionTitleService
(
)
;
const
=
new
class
extends
mock< IChatDelegationSummaryService>
(
)
{
extractPrompt
(
)
:
{
:
string
;
:
never
}
|
undefined
{
return
undefined
;
}
}
(
)
;
const
=
.
add
(
new
CopilotCLISessionService
(
,
,
,
,
new
CopilotCLIMCPHandler
(
,
,
,
)
,
new
NullCopilotCLIAgents
(
)
,
new
NullWorkspaceService
(
)
,
,
,
new
MockSkillLocations
(
)
,
,
new
MockChatSessionMetadataStore
(
)
,
new
NullAgentSessionsWorkspace
(
)
,
new
NullChatSessionWorkspaceFolderService
(
)
,
new
NullChatSessionWorktreeService
(
)
,
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
new
NullPromptVariablesService
(
)
,
new
NullChatDebugFileLoggerService
(
)
,
.
add
(
new
MockPromptsService
(
)
)
,
new
NullCopilotCLIModels
(
)
,
new
NullExperimentationService
(
)
)
)
;
await
mkdir
(
.
,
{
:
true
}
)
;
const
=
join
(
.
,
'events.jsonl'
)
;
await
writeNodeFile
(
,
[
JSON
.
stringify
(
{
:
'1'
,
:
'session.start'
,
:
'2024-01-01T00:00:00.000Z'
,
:
null
,
:
{
,
:
'2024-01-01T00:00:00.000Z'
,
:
'gpt-test'
,
:
1
,
:
'test'
,
:
'1.0.0'
,
:
{
:
URI
.
file
(
'/workspace/project'
)
.
}
}
}
)
,
JSON
.
stringify
(
{
:
'2'
,
:
'user.message'
,
:
'2024-01-01T00:00:01.000Z'
,
:
'1'
,
:
{
:
'First call fills cache'
,
:
[
]
}
}
)
,
]
.
join
(
'\n'
)
)
;
const
=
await
.
tryGetPartialSessionHistory
(
)
;
await
rm
(
)
;
const
=
await
.
tryGetPartialSessionHistory
(
)
;
expect
(
)
.
toBe
(
)
;
}
)
;
it
(
'returns undefined when the events file does not exist'
,
async
(
)
=>
{
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'copilot-cli-session-service-'
)
)
;
.
.
COPILOT_HOME
=
join
(
,
'.copilot'
)
;
const
=
await
.
tryGetPartialSessionHistory
(
'nonexistent-session-id'
)
;
expect
(
)
.
toBeUndefined
(
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.getAllSessions'
,
(
)
=>
{
it
(
'filters Agent Host sessions without per-session stats'
,
async
(
)
=>
{
const
=
new
TrackingFileSystemService
(
)
;
const
=
URI
.
file
(
'/user-data/User/globalStorage/github.copilot-chat'
)
;
.
mockDirectory
(
URI
.
file
(
'/user-data/agentSessionData'
)
,
[
[
'legacy-owned'
,
.
]
,
[
'not-a-session'
,
.
]
,
]
)
;
const
=
.
add
(
createSessionService
(
{
:
new
TestExtensionContext
(
)
,
,
}
)
)
;
const
=
await
.
getSessionManager
(
)
as
unknown
as
;
const
=
[
{
:
'agent-host'
,
:
'vscode-agent-host'
}
,
{
:
'legacy:owned'
,
:
'vscode'
}
,
{
:
'extension-host'
,
:
'vscode'
}
,
{
:
'standalone'
,
:
'copilot-cli'
}
,
]
;
for
(
const
{
,
}
of
)
{
const
=
new
MockCliSdkSession
(
,
new
Date
(
0
)
)
;
.
=
;
.
=
;
.
.
set
(
,
)
;
}
const
=
await
.
getAllSessions
(
.
)
;
const
=
await
.
getSessionItem
(
'agent-host'
,
.
)
;
expect
(
{
:
.
map
(
=>
.
)
,
,
:
.
,
:
.
getStatCallCount
(
)
,
}
)
.
toEqual
(
{
:
[
'extension-host'
,
'standalone'
]
,
:
undefined
,
:
1
,
:
0
,
}
)
;
}
)
;
it
(
'lists all legacy sessions when migration is enabled (extension owns them until opened)'
,
async
(
)
=>
{
await
(
as
)
.
setNonExtensionConfig
(
'chat.agentSessions.migrateLegacyCopilotCli'
,
true
)
;
const
=
.
add
(
createSessionService
(
)
)
;
const
=
await
.
getSessionManager
(
)
as
unknown
as
;
for
(
const
of
[
'legacy-active'
,
'legacy-archived'
]
)
{
const
=
new
MockCliSdkSession
(
,
new
Date
(
0
)
)
;
.
=
'vscode'
;
.
=
;
.
.
set
(
,
)
;
}
await
.
setSessionArchived
(
'legacy-archived'
,
true
)
;
const
=
await
.
getAllSessions
(
.
)
;
expect
(
.
map
(
=>
.
)
.
sort
(
)
)
.
toEqual
(
[
'legacy-active'
,
'legacy-archived'
]
)
;
}
)
;
it
(
'does not list sessions created outside VS Code, even once loaded into memory'
,
async
(
)
=>
{
const
=
new
MockCliSdkSession
(
'external-cli'
,
new
Date
(
0
)
)
;
.
=
'external-cli'
;
.
.
set
(
.
,
)
;
.
setSessionOriginForTest
(
.
,
'other'
)
;
const
=
new
MockCliSdkSession
(
'vscode-created'
,
new
Date
(
0
)
)
;
.
=
'vscode-created'
;
.
.
set
(
.
,
)
;
const
=
await
.
getAllSessions
(
.
)
;
const
=
await
.
getSession
(
{
:
.
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
.
add
(
!
)
;
expect
(
{
:
.
map
(
=>
.
)
,
:
(
await
.
getAllSessions
(
.
)
)
.
map
(
=>
.
)
,
:
await
.
getSessionItem
(
.
,
.
)
,
:
(
await
.
getSessionItem
(
.
,
.
)
)
?.
,
}
)
.
toEqual
(
{
:
[
'vscode-created'
]
,
:
[
'vscode-created'
]
,
:
undefined
,
:
'vscode-created'
,
}
)
;
}
)
;
it
(
'will not list created sessions'
,
async
(
)
=>
{
const
=
await
.
createSession
(
{
:
'gpt-test'
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
.
add
(
)
;
const
=
new
MockCliSdkSession
(
's1'
,
new
Date
(
0
)
)
;
.
.
push
(
{
:
'user'
,
:
'a'
.
repeat
(
100
)
}
)
;
.
.
push
(
{
:
'user.message'
,
:
{
:
'a'
.
repeat
(
100
)
}
,
:
'2024-01-01T00:00:00.000Z'
}
)
;
.
.
set
(
.
,
)
;
const
=
await
.
getAllSessions
(
.
)
;
expect
(
.
)
.
toBe
(
1
)
;
const
=
[
0
]
;
expect
(
.
)
.
toBe
(
's1'
)
;
}
)
;
it
(
'falls back to partial session data when getSession fails with an unknown event type'
,
async
(
)
=>
{
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'copilot-cli-session-service-'
)
)
;
.
.
COPILOT_HOME
=
join
(
,
'.copilot'
)
;
const
=
'invalid-session'
;
const
=
URI
.
file
(
getCopilotCLISessionDir
(
)
)
;
const
=
new
MockFileSystemService
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
{
:
,
:
class
{
}
}
,
:
,
,
:
class
{
}
,
:
{
}
}
)
)
}
as
unknown
as
;
const
=
createExtensionUnitTestingServices
(
)
;
.
add
(
)
;
const
=
.
createTestingAccessor
(
)
;
const
=
.
get
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
'test-token'
}
)
)
,
}
as
unknown
as
;
const
=
.
add
(
new
NullMcpService
(
)
)
;
const
=
new
NullCustomSessionTitleService
(
)
;
const
=
new
class
extends
mock< IChatDelegationSummaryService>
(
)
{
extractPrompt
(
)
:
{
:
string
;
:
never
}
|
undefined
{
return
undefined
;
}
}
(
)
;
const
=
.
add
(
new
CopilotCLISessionService
(
,
,
,
,
new
CopilotCLIMCPHandler
(
,
,
,
)
,
new
NullCopilotCLIAgents
(
)
,
new
NullWorkspaceService
(
)
,
,
,
new
MockSkillLocations
(
)
,
,
new
MockChatSessionMetadataStore
(
)
,
new
NullAgentSessionsWorkspace
(
)
,
new
NullChatSessionWorkspaceFolderService
(
)
,
new
NullChatSessionWorktreeService
(
)
,
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
new
NullPromptVariablesService
(
)
,
new
NullChatDebugFileLoggerService
(
)
,
.
add
(
new
MockPromptsService
(
)
)
,
new
NullCopilotCLIModels
(
)
,
new
NullExperimentationService
(
)
)
)
;
const
=
await
.
getSessionManager
(
)
as
unknown
as
;
const
=
new
MockCliSdkSession
(
,
new
Date
(
'2024-01-01T00:00:00.000Z'
)
)
;
.
=
'Broken summary <current_dateti...'
;
.
.
set
(
,
)
;
.
=
.
fn
(
async
(
)
=>
{
throw
new
Error
(
'Failed to load session. Unknown event type: custom.unknown.'
)
;
}
)
as
unknown
as
typeof
.
;
await
mkdir
(
.
,
{
:
true
}
)
;
await
writeNodeFile
(
join
(
.
,
'events.jsonl'
)
,
[
JSON
.
stringify
(
{
:
'1'
,
:
'session.start'
,
:
'2024-01-01T00:00:00.000Z'
,
:
null
,
:
{
,
:
'2024-01-01T00:00:00.000Z'
,
:
'gpt-test'
,
:
1
,
:
'test'
,
:
'1.0.0'
,
:
{
:
URI
.
file
(
'/workspace/project'
)
.
}
}
}
)
,
JSON
.
stringify
(
{
:
'2'
,
:
'user.message'
,
:
'2024-01-01T00:00:01.000Z'
,
:
'1'
,
:
{
:
'Use fallback history'
,
:
[
]
}
}
)
,
]
.
join
(
'\n'
)
)
;
const
=
await
.
getAllSessions
(
.
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
)
;
expect
(
[
0
]
.
)
.
toBe
(
'Use fallback history'
)
;
}
)
;
it
(
'does not emit session when summary is truncated and no user turns exist'
,
async
(
)
=>
{
=
await
mkdtemp
(
join
(
tmpdir
(
)
,
'copilot-cli-session-service-'
)
)
;
.
.
COPILOT_HOME
=
join
(
,
'.copilot'
)
;
const
=
'no-user-turns-session'
;
const
=
URI
.
file
(
getCopilotCLISessionDir
(
)
)
;
const
=
new
MockFileSystemService
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
{
:
,
:
class
{
}
}
,
:
,
,
:
class
{
}
,
:
{
}
}
)
)
}
as
unknown
as
;
const
=
createExtensionUnitTestingServices
(
)
;
.
add
(
)
;
const
=
.
createTestingAccessor
(
)
;
const
=
.
get
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
'test-token'
}
)
)
}
as
unknown
as
;
const
=
.
add
(
new
NullMcpService
(
)
)
;
const
=
new
NullCustomSessionTitleService
(
)
;
const
=
new
class
extends
mock< IChatDelegationSummaryService>
(
)
{
extractPrompt
(
)
:
{
:
string
;
:
never
}
|
undefined
{
return
undefined
;
}
}
(
)
;
const
=
.
add
(
new
CopilotCLISessionService
(
,
,
,
,
new
CopilotCLIMCPHandler
(
,
,
,
)
,
new
NullCopilotCLIAgents
(
)
,
new
NullWorkspaceService
(
)
,
,
,
new
MockSkillLocations
(
)
,
,
new
MockChatSessionMetadataStore
(
)
,
new
NullAgentSessionsWorkspace
(
)
,
new
NullChatSessionWorkspaceFolderService
(
)
,
new
NullChatSessionWorktreeService
(
)
,
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
new
NullPromptVariablesService
(
)
,
new
NullChatDebugFileLoggerService
(
)
,
.
add
(
new
MockPromptsService
(
)
)
,
new
NullCopilotCLIModels
(
)
,
new
NullExperimentationService
(
)
)
)
;
const
=
await
.
getSessionManager
(
)
as
unknown
as
;
const
=
new
MockCliSdkSession
(
,
new
Date
(
'2024-01-01T00:00:00.000Z'
)
)
;
.
=
'Summary without user turns <current_dateti...'
;
.
.
set
(
,
)
;
.
=
.
fn
(
async
(
)
=>
{
throw
new
Error
(
'Failed to load session. Unknown event type: custom.unknown.'
)
;
}
)
as
unknown
as
typeof
.
;
await
mkdir
(
.
,
{
:
true
}
)
;
await
writeNodeFile
(
join
(
.
,
'events.jsonl'
)
,
[
JSON
.
stringify
(
{
:
'1'
,
:
'session.start'
,
:
'2024-01-01T00:00:00.000Z'
,
:
null
,
:
{
,
:
'2024-01-01T00:00:00.000Z'
,
:
'gpt-test'
,
:
1
,
:
'test'
,
:
'1.0.0'
,
:
{
:
URI
.
file
(
'/workspace/project'
)
.
}
}
}
)
,
]
.
join
(
'\n'
)
)
;
const
=
await
.
getAllSessions
(
.
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
)
;
expect
(
[
0
]
.
)
.
toBe
(
'Summary without user turns <current_dateti...'
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.deleteSession'
,
(
)
=>
{
it
(
'disposes active wrapper, removes from manager and fires change event'
,
async
(
)
=>
{
const
=
await
.
createSession
(
{
...
sessionOptionsFor
(
)
}
,
.
)
;
const
=
!
.
.
;
let
=
false
;
.
add
(
)
;
.
add
(
.
onDidChangeSessions
(
(
)
=>
{
=
true
;
}
)
)
;
await
.
deleteSession
(
)
;
expect
(
.
.
has
(
)
)
.
toBe
(
false
)
;
expect
(
)
.
toBe
(
true
)
;
expect
(
await
.
getSession
(
{
:
,
...
sessionOptionsFor
(
)
}
,
.
)
)
.
toBeUndefined
(
)
;
}
)
;
it
(
'fires onDidDeleteSession with the session id'
,
async
(
)
=>
{
const
=
await
.
createSession
(
{
...
sessionOptionsFor
(
)
}
,
.
)
;
const
=
!
.
.
;
const
:
string
[
]
=
[
]
;
.
add
(
)
;
.
add
(
.
onDidDeleteSession
(
=>
.
push
(
)
)
)
;
await
.
deleteSession
(
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
)
.
toBe
(
)
;
}
)
;
it
(
'clears partial session history cache and working directory on delete'
,
async
(
)
=>
{
const
=
await
.
createSession
(
{
...
sessionOptionsFor
(
)
}
,
.
)
;
const
=
.
.
;
.
add
(
)
;
const
=
(
as
any
)
.
as
<
string
,
readonly
unknown
[
]
>
;
const
=
(
as
any
)
.
as
<
string
,
|
undefined
>
;
.
set
(
,
[
]
)
;
.
set
(
,
URI
.
file
(
'/some/working/dir'
)
)
;
expect
(
.
has
(
)
)
.
toBe
(
true
)
;
expect
(
.
has
(
)
)
.
toBe
(
true
)
;
await
.
deleteSession
(
)
;
expect
(
.
has
(
)
)
.
toBe
(
false
)
;
expect
(
.
has
(
)
)
.
toBe
(
false
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.getSession cache clearing'
,
(
)
=>
{
it
(
'clears partial session history when reusing an existing active session'
,
async
(
)
=>
{
const
=
await
.
createSession
(
{
...
sessionOptionsFor
(
)
}
,
.
)
;
const
=
.
.
;
const
=
(
as
any
)
.
as
<
string
,
readonly
unknown
[
]
>
;
.
set
(
,
[
]
)
;
expect
(
.
has
(
)
)
.
toBe
(
true
)
;
const
=
await
.
getSession
(
{
:
,
...
sessionOptionsFor
(
)
}
,
.
)
;
expect
(
)
.
toBe
(
)
;
expect
(
.
has
(
)
)
.
toBe
(
false
)
;
.
dispose
(
)
;
?.
dispose
(
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.label generation'
,
(
)
=>
{
it
(
'uses first user message line when present'
,
async
(
)
=>
{
const
=
new
MockCliSdkSession
(
'lab1'
,
new
Date
(
)
)
;
.
.
push
(
{
:
'user'
,
:
'Line1\nLine2'
}
)
;
.
.
push
(
{
:
'user.message'
,
:
{
:
'Line1\nLine2'
}
,
:
.
now
(
)
.
toString
(
)
}
)
;
.
.
set
(
.
,
)
;
const
=
await
.
getAllSessions
(
.
)
;
const
=
.
find
(
=>
.
===
'lab1'
)
;
expect
(
?.
)
.
includes
(
'Line1'
)
;
expect
(
?.
)
.
includes
(
'Line2'
)
;
}
)
;
it
(
'uses clean summary from metadata without loading the full session'
,
async
(
)
=>
{
const
=
new
MockCliSdkSession
(
'summary1'
,
new
Date
(
)
)
;
.
=
'Fix the login bug'
;
.
.
push
(
{
:
'user.message'
,
:
{
:
'Fix the login bug in auth.ts'
}
,
:
.
now
(
)
.
toString
(
)
}
)
;
.
.
set
(
.
,
)
;
const
=
.
spyOn
(
,
'getSession'
)
;
const
=
await
.
getAllSessions
(
.
)
;
const
=
.
find
(
=>
.
===
'summary1'
)
;
expect
(
?.
)
.
toBe
(
'Fix the login bug'
)
;
expect
(
)
.
.
toHaveBeenCalled
(
)
;
}
)
;
it
(
'falls through to session load when summary contains angle bracket'
,
async
(
)
=>
{
const
=
new
MockCliSdkSession
(
'truncated1'
,
new
Date
(
)
)
;
.
=
'Fix the bug... <current_dateti...'
;
.
.
push
(
{
:
'user.message'
,
:
{
:
'Fix the bug in the parser'
}
,
:
.
now
(
)
.
toString
(
)
}
)
;
.
.
set
(
.
,
)
;
const
=
.
spyOn
(
,
'getSession'
)
;
const
=
await
.
getAllSessions
(
.
)
;
const
=
.
find
(
=>
.
===
'truncated1'
)
;
expect
(
?.
)
.
toBe
(
'Fix the bug in the parser'
)
;
expect
(
)
.
toHaveBeenCalled
(
)
;
}
)
;
it
(
'uses cached label on second call without loading session again'
,
async
(
)
=>
{
const
=
new
MockCliSdkSession
(
'cache1'
,
new
Date
(
)
)
;
.
.
push
(
{
:
'user.message'
,
:
{
:
'Refactor the tests'
}
,
:
.
now
(
)
.
toString
(
)
}
)
;
.
.
set
(
.
,
)
;
const
=
await
.
getAllSessions
(
.
)
;
const
=
.
find
(
=>
.
===
'cache1'
)
;
expect
(
?.
)
.
toBe
(
'Refactor the tests'
)
;
const
=
.
spyOn
(
,
'getSession'
)
;
const
=
await
.
getAllSessions
(
.
)
;
const
=
.
find
(
=>
.
===
'cache1'
)
;
expect
(
?.
)
.
toBe
(
'Refactor the tests'
)
;
expect
(
)
.
.
toHaveBeenCalled
(
)
;
}
)
;
it
(
'uses metadata summary over stale internal label cache'
,
async
(
)
=>
{
const
=
new
MockCliSdkSession
(
'priority1'
,
new
Date
(
)
)
;
.
.
push
(
{
:
'user.message'
,
:
{
:
'Original label from events'
}
,
:
.
now
(
)
.
toString
(
)
}
)
;
.
.
set
(
.
,
)
;
const
=
await
.
getAllSessions
(
.
)
;
expect
(
.
find
(
=>
.
===
'priority1'
)
?.
)
.
toBe
(
'Original label from events'
)
;
.
=
'Different summary label'
;
const
=
await
.
getAllSessions
(
.
)
;
expect
(
.
find
(
=>
.
===
'priority1'
)
?.
)
.
toBe
(
'Original label from events'
)
;
}
)
;
it
(
'populates cache after loading session for label'
,
async
(
)
=>
{
const
=
new
MockCliSdkSession
(
'populate1'
,
new
Date
(
)
)
;
.
.
push
(
{
:
'user.message'
,
:
{
:
'Add unit tests for auth'
}
,
:
.
now
(
)
.
toString
(
)
}
)
;
.
.
set
(
.
,
)
;
await
.
getAllSessions
(
.
)
;
const
=
(
as
any
)
.
as
<
string
,
string
>
;
expect
(
.
get
(
'populate1'
)
)
.
toBe
(
'Add unit tests for auth'
)
;
}
)
;
it
(
'does not cache when using clean summary from metadata directly'
,
async
(
)
=>
{
const
=
new
MockCliSdkSession
(
'nocache1'
,
new
Date
(
)
)
;
.
=
'Clean summary without brackets'
;
.
.
set
(
.
,
)
;
await
.
getAllSessions
(
.
)
;
const
=
(
as
any
)
.
as
<
string
,
string
>
;
expect
(
.
has
(
'nocache1'
)
)
.
toBe
(
false
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.createNewSessionId / isNewSessionId'
,
(
)
=>
{
it
(
'createNewSessionId returns a unique id that isNewSessionId recognises'
,
(
)
=>
{
const
=
.
createNewSessionId
(
)
;
expect
(
)
.
toBeTruthy
(
)
;
expect
(
.
isNewSessionId
(
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'isNewSessionId returns false for an unknown id'
,
(
)
=>
{
expect
(
.
isNewSessionId
(
'not-a-new-id'
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'successive calls return distinct ids'
,
(
)
=>
{
const
=
.
createNewSessionId
(
)
;
const
=
.
createNewSessionId
(
)
;
expect
(
)
.
.
toBe
(
)
;
expect
(
.
isNewSessionId
(
)
)
.
toBe
(
true
)
;
expect
(
.
isNewSessionId
(
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'createSession clears the new-session flag'
,
async
(
)
=>
{
const
=
.
createNewSessionId
(
)
;
expect
(
.
isNewSessionId
(
)
)
.
toBe
(
true
)
;
await
.
createSession
(
{
:
'gpt-test'
,
:
,
...
sessionOptionsFor
(
URI
.
file
(
'/tmp'
)
)
}
,
.
)
;
expect
(
.
isNewSessionId
(
)
)
.
toBe
(
false
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.forkSession'
,
(
)
=>
{
it
(
'delegates to sessionManager.forkSession and returns the new session id'
,
async
(
)
=>
{
const
=
'source-session'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
=
.
spyOn
(
,
'forkSession'
)
;
const
=
await
.
forkSession
(
{
:
,
:
undefined
,
:
workspaceInfoFor
(
URI
.
file
(
'/workspace'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledWith
(
,
undefined
)
;
expect
(
)
.
toBeTruthy
(
)
;
expect
(
)
.
.
toBe
(
)
;
}
)
;
it
(
'stores forked session metadata via storeForkedSessionMetadata'
,
async
(
)
=>
{
const
=
'meta-source'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
=
new
MockChatSessionMetadataStore
(
)
;
const
=
.
spyOn
(
,
'storeForkedSessionMetadata'
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
{
:
,
:
class
{
}
}
,
:
,
,
:
class
{
}
,
:
{
}
}
)
)
,
:
.
fn
(
(
)
=>
undefined
)
,
}
as
unknown
as
;
const
=
.
add
(
createExtensionUnitTestingServices
(
)
)
;
const
=
.
createTestingAccessor
(
)
;
const
=
.
get
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
'test-token'
}
)
)
}
as
unknown
as
;
const
=
.
add
(
new
NullMcpService
(
)
)
;
const
=
new
class
extends
mock< IChatDelegationSummaryService>
(
)
{
extractPrompt
(
)
:
{
:
string
;
:
never
}
|
undefined
{
return
undefined
;
}
}
(
)
;
const
=
.
add
(
new
CopilotCLISessionService
(
,
,
,
new
MockFileSystemService
(
)
,
new
CopilotCLIMCPHandler
(
,
,
,
)
,
new
NullCopilotCLIAgents
(
)
,
new
NullWorkspaceService
(
)
,
new
NullCustomSessionTitleService
(
)
,
,
new
MockSkillLocations
(
)
,
,
,
new
NullAgentSessionsWorkspace
(
)
,
new
NullChatSessionWorkspaceFolderService
(
)
,
new
NullChatSessionWorktreeService
(
)
,
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
new
NullPromptVariablesService
(
)
,
new
NullChatDebugFileLoggerService
(
)
,
.
add
(
new
MockPromptsService
(
)
)
,
new
NullCopilotCLIModels
(
)
,
new
NullExperimentationService
(
)
)
)
;
const
=
await
.
getSessionManager
(
)
as
unknown
as
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
=
await
.
forkSession
(
{
:
,
:
undefined
,
:
workspaceInfoFor
(
URI
.
file
(
'/workspace'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledWith
(
,
,
.
stringContaining
(
'Forked:'
)
)
;
}
)
;
it
(
'fires onDidCreateSession with the forked session id and title'
,
async
(
)
=>
{
const
=
'event-source'
;
.
.
set
(
,
new
MockCliSdkSession
(
,
new
Date
(
)
)
)
;
const
:
[
]
=
[
]
;
.
add
(
.
onDidCreateSession
(
=>
.
push
(
)
)
)
;
const
=
await
.
forkSession
(
{
:
,
:
undefined
,
:
workspaceInfoFor
(
URI
.
file
(
'/workspace'
)
)
}
,
.
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
)
.
toBe
(
)
;
expect
(
[
0
]
.
)
.
toContain
(
'Forked:'
)
;
}
)
;
it
(
'passes toEventId to sessionManager.forkSession when requestId matches a stored copilot request id'
,
async
(
)
=>
{
const
=
'truncate-source'
;
const
=
new
MockCliSdkSession
(
,
new
Date
(
)
)
;
.
.
push
(
{
:
'user.message'
,
:
'sdk-event-1'
,
:
{
:
'hello'
}
,
:
'2024-01-01T00:00:00.000Z'
}
)
;
.
.
set
(
,
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
{
:
,
:
class
{
}
}
,
:
,
,
:
class
{
}
,
:
{
}
}
)
)
,
:
.
fn
(
(
)
=>
(
{
:
'vsc-req-1'
,
:
'sdk-event-1'
}
)
)
,
}
as
unknown
as
;
const
=
.
add
(
createExtensionUnitTestingServices
(
)
)
;
const
=
.
createTestingAccessor
(
)
;
const
=
.
get
(
)
;
const
=
{
:
.
fn
(
async
(
)
=>
(
{
:
'test-token'
}
)
)
}
as
unknown
as
;
const
=
.
add
(
new
NullMcpService
(
)
)
;
const
=
new
class
extends
mock< IChatDelegationSummaryService>
(
)
{
extractPrompt
(
)
:
{
:
string
;
:
never
}
|
undefined
{
return
undefined
;
}
async
summarize
(
)
:
Promise
<
string
|
undefined
>
{
return
undefined
;
}
}
(
)
;
const
=
new
MockChatSessionMetadataStore
(
)
;
await
.
updateRequestDetails
(
,
[
{
:
'vsc-req-1'
,
:
'sdk-event-1'
,
:
{
}
}
]
)
;
const
=
.
add
(
new
CopilotCLISessionService
(
,
,
,
new
MockFileSystemService
(
)
,
new
CopilotCLIMCPHandler
(
,
,
,
)
,
new
NullCopilotCLIAgents
(
)
,
new
NullWorkspaceService
(
)
,
new
NullCustomSessionTitleService
(
)
,
,
new
MockSkillLocations
(
)
,
,
,
new
NullAgentSessionsWorkspace
(
)
,
new
NullChatSessionWorkspaceFolderService
(
)
,
new
NullChatSessionWorktreeService
(
)
,
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
new
NullPromptVariablesService
(
)
,
new
NullChatDebugFileLoggerService
(
)
,
.
add
(
new
MockPromptsService
(
)
)
,
new
NullCopilotCLIModels
(
)
,
new
NullExperimentationService
(
)
)
)
;
const
=
await
.
getSessionManager
(
)
as
unknown
as
;
.
.
set
(
,
)
;
const
=
.
spyOn
(
,
'forkSession'
)
;
await
.
forkSession
(
{
:
,
:
'vsc-req-1'
,
:
workspaceInfoFor
(
URI
.
file
(
'/workspace'
)
)
}
,
.
)
;
expect
(
)
.
toHaveBeenCalledWith
(
,
'sdk-event-1'
)
;
}
)
;
}
)
;
describe
(
'CopilotCLISessionService.auto disposal timeout'
,
(
)
=>
{
.
skip
(
'disposes session after completion timeout and aborts underlying sdk session'
,
async
(
)
=>
{
.
useFakeTimers
(
)
;
const
=
await
.
createSession
(
{
...
sessionOptionsFor
(
)
}
,
.
)
;
.
advanceTimersByTime
(
31000
)
;
await
Promise
.
resolve
(
)
;
expect
(
.
.
)
.
toBe
(
true
)
;
}
)
;
}
)
;
}
)
;