ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / platform / agentHost / test / node / agentHostGitStateService.test.ts 1085 строк · изменён 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
import assert from 'assert' ;
import { Event } from '../../../../base/common/event.js' ;
import { URI } from '../../../../base/common/uri.js' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js' ;
import { runWithFakedTimers } from '../../../../base/test/common/timeTravelScheduler.js' ;
import { NullLogService } from '../../../log/common/log.js' ;
import { IAgentHostGitService, META_DIFF_BASE_BRANCH } from '../../common/agentHostGitService.js' ;
import { getSessionRelatedPullRequestUrls readSessionGitHubState readSessionGitState readSessionSourceControlState SessionSourceControlOutcome withInitialSessionPullRequest withMostRecentRelatedSessionPullRequest withMostRecentSessionPullRequest withSessionGitHubState withSessionGitState SessionStatus
AgentHostGitStateService
createTestGitHubEndpointService
AgentHostStateManager
CreatedPullRequest IAgentHostOctoKitService
TestSessionDatabase createNoopGitService createSessionDataService
SessionConfigKey
IAgentHostAuthenticationService
disposables
assert
owner
repo
pullRequestUrl
owner
repo
pullRequestUrls
assert
pullRequestUrls
pullRequestUrls
state ISessionGitHubState
state state
state state
assert state
pullRequestUrls
pullRequestBranchName
initial
state
pullRequestUrls initial
initialPullRequestUrls initial
initial
assert
state
related state
state
pullRequestUrls initial
associatedPullRequestUrls initial
pullRequestBranchName
initialPullRequestUrls
related initial
current
referenced
assert
pullRequestUrls current referenced
initialPullRequestUrls referenced
associatedPullRequestUrls referenced
current referenced
state ISessionGitHubState
state state state
assert state initialPullRequestUrls
options octoKitService IAgentHostOctoKitService authenticationService IAgentHostAuthenticationService enterpriseUri
stateManager disposables
db
sessionDataService db
gitCalls
gitBaseBranches
gitResult ISessionGitState
gitError Error
headSha
gitService IAgentHostGitService
workingDirectory baseBranchName
gitCalls workingDirectory
gitBaseBranches baseBranchName
gitError
gitError
gitResult
headSha
pullRequestCalls
pullRequestShaCalls
pullRequestsByBranch
pullRequestsBySha
onPullRequestLookup branch
octoKitService
_owner _repo branch
pullRequestCalls branch
onPullRequestLookup branch
pullRequestsByBranch branch
_owner _repo sha
pullRequestShaCalls sha
pullRequestsBySha sha
IAgentHostOctoKitService
authenticationService IAgentHostAuthenticationService
_serviceBrand
onDidChangeAuthToken Event None
service disposables
stateManager
gitService
options octoKitService octoKitService
options authenticationService authenticationService
options enterpriseUri
sessionDataService
runEvents
disposables service key runEvents key
gitHubStateEvents
disposables service key gitHubStateEvents key
stateManager
db
service
gitCalls
gitBaseBranches
runEvents
gitHubStateEvents
pullRequestCalls
pullRequestShaCalls
state ISessionGitState gitResult state
error Error gitError error
sha headSha sha
branch pullRequest CreatedPullRequest pullRequestsByBranch branch pullRequest
sha pullRequest CreatedPullRequest pullRequestsBySha sha pullRequest
branch onPullRequestLookup fn
stateManager AgentHostStateManager options workingDirectory project gitState ISessionGitState gitHubState ISessionGitHubState isolation baseBranch createNewBranch createdAt
summary SessionSummary
resource
provider
title
status SessionStatus Idle
createdAt options createdAt
modifiedAt
workingDirectories options workingDirectory options workingDirectory
project options project uri options project displayName
stateManager summary
options isolation
stateManager
schema type properties
values
SessionConfigKey Isolation options isolation
options baseBranch SessionConfigKey Branch options baseBranch
options createNewBranch SessionConfigKey WorktreeCreateNewBranch options createNewBranch
options gitState
stateManager options gitState
options gitHubState
stateManager stateManager _meta options gitHubState
h
h stateManager workingDirectory
h service
afterMerge h stateManager _meta
persistedAfterMerge h db
h service
owner
repo
pullRequestUrls
pullRequestBranchName
afterPullRequest h stateManager _meta
persistedAfterPullRequest h db
assert
afterMerge
persistedAfterMerge persistedAfterMerge persistedAfterMerge
afterPullRequest
gitHubStateEvents h gitHubStateEvents
persistedAfterPullRequest persistedAfterPullRequest persistedAfterPullRequest
afterMerge
merge commit
latestOutcome SessionSourceControlOutcome Merge
persistedAfterMerge
merge commit
latestOutcome SessionSourceControlOutcome Merge
afterPullRequest
merge commit
latestOutcome SessionSourceControlOutcome PullRequest
gitHubStateEvents
persistedAfterPullRequest
merge commit
latestOutcome SessionSourceControlOutcome PullRequest
h
h stateManager
h service
assert
gitCalls h gitCalls
runEvents h runEvents
gitCalls
runEvents
useFakeTimers
h
h stateManager
workingDirectory
isolation
baseBranch
h branchName baseBranchName
h service
assert h gitBaseBranches
useFakeTimers
h
h stateManager
workingDirectory
project
isolation
baseBranch
createNewBranch
h db
h branchName baseBranchName
h service
assert h gitBaseBranches
useFakeTimers
h
h stateManager
workingDirectory
project
isolation
gitState branchName baseBranchName
h db
h branchName baseBranchName
h service
assert h gitBaseBranches
useFakeTimers
h
h stateManager
resource
provider
title
status SessionStatus Idle
createdAt
modifiedAt
workingDirectories
emitNotification
next ISessionGitState branchName uncommittedChanges
h next
h service
assert
gitCalls h gitCalls
gitState h stateManager _meta
persistedGit h db
runEvents h runEvents
gitCalls
gitState next
persistedGit
runEvents
useFakeTimers
h
h stateManager workingDirectory
h branchName
h service
assert h gitCalls
useFakeTimers
h
h stateManager workingDirectory
h branchName
h service
assert h gitCalls
useFakeTimers
gitState ISessionGitState branchName uncommittedChanges
h
h stateManager workingDirectory gitState
h gitState
h service
assert h runEvents
useFakeTimers
gitState ISessionGitState
branchName
githubOwner
githubRepo
h
h stateManager workingDirectory gitState
h gitState
h service
persistedGitHubState h db
assert
github h stateManager _meta
persistedGitHub persistedGitHubState persistedGitHubState
github owner repo
persistedGitHub owner repo
useFakeTimers
h
h stateManager workingDirectory
next ISessionGitState branchName baseBranchName uncommittedChanges
h next
h service
assert
gitState h stateManager _meta
runEvents h runEvents
gitState next
runEvents
useFakeTimers
h
h stateManager workingDirectory
next ISessionGitState branchName githubOwner githubRepo
h next
h service
assert
github h stateManager _meta
persistedGit h db
github owner repo
persistedGit next
useFakeTimers
calls owner repo branch headOwner
octoKitService
owner repo branch _token _signal AbortSignal headOwner
calls owner repo branch headOwner
url
IAgentHostOctoKitService
authenticationService IAgentHostAuthenticationService
_serviceBrand
onDidChangeAuthToken Event None
h octoKitService authenticationService
h stateManager
workingDirectory
gitState
branchName
baseBranchName
githubOwner
githubRepo
h
branchName
baseBranchName
upstreamBranchName
githubOwner
githubHeadOwner
githubRepo
h service
h service
h service
assert
gitCalls h gitCalls length
calls
github h stateManager _meta
gitCalls
calls owner repo branch headOwner
github
owner
repo
pullRequestUrls
pullRequestBranchName
useFakeTimers
gitState ISessionGitState
branchName
baseBranchName
upstreamBranchName
githubHeadOwner
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
h gitState
h url
h service
assert
pullRequestCalls h pullRequestCalls
pullRequestShaCalls h pullRequestShaCalls
github h stateManager _meta
pullRequestCalls
pullRequestShaCalls
github owner repo pullRequestUrls pullRequestBranchName
useFakeTimers
gitState ISessionGitState
branchName
baseBranchName
githubHeadOwner
calls branch headOwner
h
octoKitService
_owner _repo branch _token _signal AbortSignal headOwner
calls branch headOwner
url
IAgentHostOctoKitService
h stateManager
workingDirectory
gitState
gitHubState owner repo
h gitState
h service
assert
pullRequestCalls calls
pullRequestShaCalls h pullRequestShaCalls
github h stateManager _meta
pullRequestCalls branch headOwner
pullRequestShaCalls
github
owner
repo
pullRequestUrls
pullRequestBranchName
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
h gitState
h
h url
h service
assert
pullRequestCalls h pullRequestCalls
pullRequestShaCalls h pullRequestShaCalls
github h stateManager _meta
pullRequestCalls
pullRequestShaCalls
github owner repo pullRequestUrls pullRequestBranchName
useFakeTimers
gitState ISessionGitState
branchName
baseBranchName
upstreamBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
h gitState
h service
assert h pullRequestCalls
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
isolation
createdAt
h gitState
h
url
createdAt
h service
github h stateManager _meta
assert
github
related github
persistedGitHub h db
github
owner
repo
pullRequestUrls
initialPullRequestUrls
pullRequestBranchName
related
persistedGitHub
owner
repo
pullRequestUrls
initialPullRequestUrls
pullRequestBranchName
useFakeTimers
pullRequestUrl
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
createdAt
h gitState
h url pullRequestUrl createdAt
h
h stateManager
schema type properties
values SessionConfigKey Isolation
h service
github h stateManager _meta
assert
github
related github
github
owner
repo
pullRequestUrls pullRequestUrl
initialPullRequestUrls pullRequestUrl
pullRequestBranchName
related
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
isolation
createdAt
h gitState
h service
h
url
createdAt
h service
github h stateManager _meta
assert
github
related github
github
owner
repo
pullRequestUrls
initialPullRequestUrls
pullRequestBranchName
related
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
isolation
createdAt
h gitState
h
url
createdAt
h service
github h stateManager _meta
assert
github
related github
github
owner
repo
pullRequestUrls
pullRequestBranchName
related
persisted initialPullRequestUrls
assert persisted
initialPullRequestUrls
h
h stateManager workingDirectory
h
h service
assert
runEvents h runEvents
runEvents
useFakeTimers maxTaskCount
h
h stateManager workingDirectory
h branchName
h service
h service
h service
assert h gitCalls length
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
h gitState
h url
h service
h service
assert
pullRequestCalls h pullRequestCalls
github h stateManager _meta
pullRequestCalls
github owner repo pullRequestUrls pullRequestBranchName
useFakeTimers
nextGitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState branchName baseBranchName
gitHubState owner repo pullRequestUrls pullRequestBranchName
h stateManager h stateManager _meta nextGitState
h nextGitState
h service
githubBeforePullRequestExists h stateManager _meta
h url
h service
assert
pullRequestCalls h pullRequestCalls
githubBeforePullRequestExists
github h stateManager _meta
persistedGitHub h db
pullRequestCalls
githubBeforePullRequestExists owner repo pullRequestUrls pullRequestBranchName
github owner repo pullRequestUrls pullRequestBranchName
persistedGitHub owner repo pullRequestUrls pullRequestBranchName
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
h gitState
h url
h
currentState h stateManager _meta
h service currentState
h service
assert h stateManager _meta
owner
repo
pullRequestUrls
pullRequestBranchName
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo pullRequestUrls
h gitState
h url
h service
assert
pullRequestCalls h pullRequestCalls
github h stateManager _meta
pullRequestCalls
github owner repo pullRequestUrls pullRequestBranchName
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo pullRequestUrls
h gitState
h service
h service
assert
pullRequestCalls h pullRequestCalls
github h stateManager _meta
pullRequestCalls
github owner repo pullRequestUrls
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
h gitState
h url
h
h stateManager h stateManager _meta branchName baseBranchName
h service
assert
pullRequestCalls h pullRequestCalls
github h stateManager _meta
pullRequestCalls
github owner repo
useFakeTimers
gitState ISessionGitState branchName baseBranchName
h
h stateManager
workingDirectory
gitState
gitHubState owner repo
isolation
h gitState
h
h stateManager h stateManager _meta branchName baseBranchName
h service
assert h stateManager _meta
owner
repo
useFakeTimers
h
h stateManager
workingDirectory
gitState branchName baseBranchName githubOwner githubRepo
gitHubState owner repo pullRequestUrls pullRequestBranchName
h branchName baseBranchName githubOwner githubRepo
h url
githubOnRefreshEvent ISessionGitHubState
disposables h service
githubOnRefreshEvent h stateManager _meta
h service
assert
pullRequestCalls h pullRequestCalls
githubOnRefreshEvent
pullRequestCalls
githubOnRefreshEvent owner repo pullRequestUrls pullRequestBranchName
,
,
,
,
SESSION_META_GITHUB_KEY
,
,
,
,
,
,
,
,
type
ISessionGitHubState
,
type
ISessionGitState
,
type
SessionSummary
}
from
'../../common/state/sessionState.js'
;
import
{
META_GIT_STATE
,
META_GITHUB_STATE
,
META_SOURCE_CONTROL_STATE
}
from
'../../common/agentHostGitStateService.js'
;
import
{
}
from
'../../node/agentHostGitStateService.js'
;
import
{
}
from
'./testGitHubEndpointService.js'
;
import
{
}
from
'../../node/agentHostStateManager.js'
;
import
type
{
,
}
from
'../../node/shared/agentHostOctoKitService.js'
;
import
{
,
,
}
from
'../common/sessionTestHelpers.js'
;
import
{
}
from
'../../common/sessionConfigKeys.js'
;
import
type
{
}
from
'../../node/agentHostAuthenticationService.js'
;
const
SESSION
=
'mock:/session-1'
;
const
WORKING_DIRECTORY
=
'file:///wd'
;
suite
(
'AgentHostGitStateService'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'migrates legacy singular pull request metadata on read'
,
(
)
=>
{
.
deepStrictEqual
(
readSessionGitHubState
(
{
[
SESSION_META_GITHUB_KEY
]
:
{
:
'microsoft'
,
:
'vscode'
,
:
'https://github.com/microsoft/vscode/pull/1'
,
}
}
)
,
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
}
)
;
}
)
;
test
(
'preserves stored pull request recency order while deduplicating'
,
(
)
=>
{
.
deepStrictEqual
(
readSessionGitHubState
(
{
[
SESSION_META_GITHUB_KEY
]
:
{
:
[
'https://github.com/microsoft/vscode/pull/3'
,
'https://github.com/microsoft/vscode/pull/1'
,
'https://github.com/microsoft/vscode/pull/2'
,
'https://github.com/microsoft/vscode/pull/1/'
,
]
,
}
}
)
,
{
:
[
'https://github.com/microsoft/vscode/pull/3'
,
'https://github.com/microsoft/vscode/pull/1'
,
'https://github.com/microsoft/vscode/pull/2'
,
]
,
}
)
;
}
)
;
test
(
'keeps ten deduplicated pull requests in most-recent order'
,
(
)
=>
{
let
:
|
undefined
;
for
(
let
number
=
1
;
number
<=
11
;
number
++
)
{
=
withMostRecentSessionPullRequest
(
,
` https://github.com/microsoft/vscode/pull/ ${ number } `
,
` feature- ${ number } `
)
;
}
=
withMostRecentSessionPullRequest
(
,
'https://github.com/microsoft/vscode/pull/5/'
,
'feature-5'
)
;
.
deepStrictEqual
(
,
{
:
[
'https://github.com/microsoft/vscode/pull/5'
,
'https://github.com/microsoft/vscode/pull/11'
,
'https://github.com/microsoft/vscode/pull/10'
,
'https://github.com/microsoft/vscode/pull/9'
,
'https://github.com/microsoft/vscode/pull/8'
,
'https://github.com/microsoft/vscode/pull/7'
,
'https://github.com/microsoft/vscode/pull/6'
,
'https://github.com/microsoft/vscode/pull/4'
,
'https://github.com/microsoft/vscode/pull/3'
,
'https://github.com/microsoft/vscode/pull/2'
,
]
,
:
'feature-5'
,
}
)
;
}
)
;
test
(
'promotes an initial pull request into the session'
,
(
)
=>
{
const
=
'https://github.com/microsoft/vscode/pull/1'
;
const
=
withMostRecentRelatedSessionPullRequest
(
{
:
[
]
,
:
[
]
,
}
,
,
'feature'
)
;
.
deepStrictEqual
(
{
,
:
getSessionRelatedPullRequestUrls
(
)
,
}
,
{
:
{
:
[
]
,
:
[
]
,
:
'feature'
,
:
[
]
,
}
,
:
[
]
,
}
)
;
}
)
;
test
(
'keeps checkout recency when combining discovered and associated pull requests'
,
(
)
=>
{
const
=
'https://github.com/microsoft/vscode/pull/2'
;
const
=
'https://github.com/microsoft/vscode/pull/1'
;
.
deepStrictEqual
(
getSessionRelatedPullRequestUrls
(
{
:
[
,
]
,
:
[
]
,
:
[
]
,
}
)
,
[
,
]
)
;
}
)
;
test
(
'keeps the most recently discovered pull requests in the bounded baseline'
,
(
)
=>
{
let
:
|
undefined
;
for
(
let
number
=
1
;
number
<=
11
;
number
++
)
{
=
{
...
,
...
withInitialSessionPullRequest
(
,
` https://github.com/microsoft/vscode/pull/ ${ number } `
)
}
;
}
.
deepStrictEqual
(
?.
,
[
'https://github.com/microsoft/vscode/pull/11'
,
'https://github.com/microsoft/vscode/pull/10'
,
'https://github.com/microsoft/vscode/pull/9'
,
'https://github.com/microsoft/vscode/pull/8'
,
'https://github.com/microsoft/vscode/pull/7'
,
'https://github.com/microsoft/vscode/pull/6'
,
'https://github.com/microsoft/vscode/pull/5'
,
'https://github.com/microsoft/vscode/pull/4'
,
'https://github.com/microsoft/vscode/pull/3'
,
'https://github.com/microsoft/vscode/pull/2'
,
]
)
;
}
)
;
function
createHarness
(
?
:
{
?
:
;
?
:
;
?
:
string
}
)
{
const
=
.
add
(
new
AgentHostStateManager
(
new
NullLogService
(
)
)
)
;
const
=
new
TestSessionDatabase
(
)
;
const
=
createSessionDataService
(
)
;
const
:
string
[
]
=
[
]
;
const
:
Array
<
string
|
undefined
>
=
[
]
;
let
:
|
undefined
;
let
:
|
undefined
;
let
:
string
|
undefined
;
const
:
=
{
...
createNoopGitService
(
)
,
getSessionGitState
:
async
(
:
URI
,
?
:
string
)
=>
{
.
push
(
.
toString
(
)
)
;
.
push
(
)
;
if
(
)
{
throw
;
}
return
;
}
,
revParse
:
async
(
)
=>
,
}
;
const
:
string
[
]
=
[
]
;
const
:
string
[
]
=
[
]
;
const
=
new
Map< string , CreatedPullRequest>
(
)
;
const
=
new
Map< string , CreatedPullRequest>
(
)
;
let
:
(
(
:
string
)
=>
Promise
<
void
>
)
|
undefined
;
const
=
{
findPullRequestByHeadBranch
:
async
(
:
string
,
:
string
,
:
string
)
=>
{
.
push
(
)
;
await
?.
(
)
;
return
.
get
(
)
;
}
,
findPullRequestByHeadSha
:
async
(
:
string
,
:
string
,
:
string
)
=>
{
.
push
(
)
;
return
.
get
(
)
;
}
,
}
as
unknown
as
;
const
:
=
{
:
undefined
,
:
.
,
getAuthToken
:
(
)
=>
'token'
,
}
;
const
=
.
add
(
new
AgentHostGitStateService
(
,
,
?.
??
,
?.
??
,
createTestGitHubEndpointService
(
?.
)
,
new
NullLogService
(
)
,
,
)
)
;
const
:
string
[
]
=
[
]
;
.
add
(
.
onDidRefreshSessionGitState
(
=>
.
push
(
)
)
)
;
const
:
string
[
]
=
[
]
;
.
add
(
.
onDidChangeSessionGitHubState
(
=>
.
push
(
)
)
)
;
return
{
,
,
,
,
,
,
,
,
,
setGitResult
:
(
:
|
undefined
)
=>
{
=
;
}
,
setGitError
:
(
:
)
=>
{
=
;
}
,
setHeadSha
:
(
:
string
|
undefined
)
=>
{
=
;
}
,
setPullRequest
:
(
:
string
,
:
)
=>
{
.
set
(
,
)
;
}
,
setPullRequestForSha
:
(
:
string
,
:
)
=>
{
.
set
(
,
)
;
}
,
setOnPullRequestLookup
:
(
fn
:
(
:
string
)
=>
Promise
<
void
>
)
=>
{
=
;
}
,
}
;
}
function
seedSession
(
:
,
?
:
{
?
:
string
;
?
:
string
;
?
:
;
?
:
;
?
:
'folder'
|
'worktree'
;
?
:
string
;
?
:
boolean
;
?
:
number
}
)
:
void
{
const
:
=
{
:
SESSION
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
?.
??
0
)
.
toISOString
(
)
,
:
new
Date
(
0
)
.
toISOString
(
)
,
:
?.
?
[
.
]
:
undefined
,
:
?.
?
{
:
.
,
:
'Project'
}
:
undefined
,
}
;
.
restoreSession
(
,
[
]
)
;
if
(
?.
)
{
.
setSessionConfig
(
SESSION
,
{
:
{
:
'object'
,
:
{
}
}
,
:
{
[
.
]
:
.
,
...
(
.
?
{
[
.
]
:
.
}
:
{
}
)
,
...
(
.
!==
undefined
?
{
[
.
]
:
.
}
:
{
}
)
,
}
,
}
)
;
}
if
(
?.
)
{
.
setSessionMeta
(
SESSION
,
withSessionGitState
(
undefined
,
.
)
)
;
}
if
(
?.
)
{
.
setSessionMeta
(
SESSION
,
withSessionGitHubState
(
.
getSessionState
(
SESSION
)
?.
,
.
)
)
;
}
}
test
(
'preserves merge provenance when a later pull request becomes the latest outcome'
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
}
)
;
await
.
.
recordSessionMerge
(
SESSION
,
'merge-commit'
)
;
const
=
readSessionSourceControlState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
const
=
await
.
.
getMetadata
(
META_SOURCE_CONTROL_STATE
)
;
await
.
.
setSessionGitHubState
(
SESSION
,
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/42'
]
,
:
'feature'
,
}
)
;
const
=
readSessionSourceControlState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
const
=
await
.
.
getMetadata
(
META_SOURCE_CONTROL_STATE
)
;
.
deepStrictEqual
(
{
,
:
?
JSON
.
parse
(
)
:
undefined
,
,
:
.
,
:
?
JSON
.
parse
(
)
:
undefined
,
}
,
{
:
{
:
{
:
'merge-commit'
}
,
:
.
,
}
,
:
{
:
{
:
'merge-commit'
}
,
:
.
,
}
,
:
{
:
{
:
'merge-commit'
}
,
:
.
,
}
,
:
[
SESSION
]
,
:
{
:
{
:
'merge-commit'
}
,
:
.
,
}
,
}
)
;
}
)
;
test
(
'does nothing when no working directory can be resolved'
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
{
:
.
,
:
.
}
,
{
:
[
]
,
:
[
]
}
)
;
}
)
;
test
(
'uses the selected worktree base branch when refreshing git state'
,
(
)
=>
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
:
'worktree'
,
:
'release'
,
}
)
;
.
setGitResult
(
{
:
'agents/session'
,
:
'release'
}
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
.
,
[
'release'
]
)
;
}
)
)
;
test
(
'uses the persisted base branch when the selected branch is checked out directly'
,
(
)
=>
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
:
'file:///repo'
,
:
'worktree'
,
:
'feature/pr'
,
:
false
,
}
)
;
await
.
.
setMetadata
(
META_DIFF_BASE_BRANCH
,
'origin/main'
)
;
.
setGitResult
(
{
:
'feature/pr'
,
:
'main'
}
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
.
,
[
'main'
]
)
;
}
)
)
;
test
(
'uses the persisted worktree base branch for an adopted linked worktree'
,
(
)
=>
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
:
'file:///repo'
,
:
'folder'
,
:
{
:
'agents/session'
,
:
'main'
}
,
}
)
;
await
.
.
setMetadata
(
META_DIFF_BASE_BRANCH
,
'origin/release'
)
;
.
setGitResult
(
{
:
'agents/session'
,
:
'release'
}
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
.
,
[
'release'
]
)
;
}
)
)
;
test
(
'refreshes git state in memory while a session is creating'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
.
.
createSession
(
{
:
SESSION
,
:
'mock'
,
:
'Test'
,
:
.
,
:
new
Date
(
0
)
.
toISOString
(
)
,
:
new
Date
(
0
)
.
toISOString
(
)
,
:
[
'file:///original'
]
,
}
,
{
:
false
}
)
;
const
:
=
{
:
'feature'
,
:
1
}
;
.
setGitResult
(
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
URI
.
parse
(
'file:///explicit'
)
)
;
.
deepStrictEqual
(
{
:
.
,
:
readSessionGitState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
:
await
.
.
getMetadata
(
META_GIT_STATE
)
,
:
.
,
}
,
{
:
[
'file:///explicit'
]
,
:
,
:
undefined
,
:
[
SESSION
]
,
}
)
;
}
)
;
}
)
;
test
(
'resolves the working directory from the session summary when none is provided'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
}
)
;
.
setGitResult
(
{
:
'feature'
}
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
.
,
[
WORKING_DIRECTORY
]
)
;
}
)
;
}
)
;
test
(
'prefers an explicitly provided working directory over the session summary'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
}
)
;
.
setGitResult
(
{
:
'feature'
}
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
URI
.
parse
(
'file:///explicit'
)
)
;
.
deepStrictEqual
(
.
,
[
'file:///explicit'
]
)
;
}
)
;
}
)
;
test
(
'unchanged git state still fires the run-refresh event'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
1
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
}
)
;
.
setGitResult
(
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
.
,
[
SESSION
]
)
;
}
)
;
}
)
;
test
(
'unchanged git state backfills missing GitHub state'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'microsoft'
,
:
'vscode'
,
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
}
)
;
.
setGitResult
(
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
const
=
await
.
.
getMetadata
(
META_GITHUB_STATE
)
;
.
deepStrictEqual
(
{
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
:
?
JSON
.
parse
(
)
:
undefined
,
}
,
{
:
{
:
'microsoft'
,
:
'vscode'
}
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
}
)
;
}
)
;
test
(
'changed git state updates the session meta and fires the run-refresh event'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
}
)
;
const
:
=
{
:
'feature'
,
:
'main'
,
:
2
}
;
.
setGitResult
(
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
{
:
readSessionGitState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
:
.
,
}
,
{
:
,
:
[
SESSION
]
,
}
)
;
}
)
;
}
)
;
test
(
'persists git state and derives GitHub state when git reports a GitHub repo'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
}
)
;
const
:
=
{
:
'feature'
,
:
'microsoft'
,
:
'vscode'
}
;
.
setGitResult
(
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
{
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
:
await
.
.
getMetadata
(
META_GIT_STATE
)
,
}
,
{
:
{
:
'microsoft'
,
:
'vscode'
}
,
:
JSON
.
stringify
(
)
,
}
)
;
}
)
;
}
)
;
test
(
'preserves pull request attachment when a later refresh replaces its queued refresh'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
{
:
string
;
:
string
;
:
string
;
:
string
|
undefined
}
[
]
=
[
]
;
const
=
{
findPullRequestByHeadBranch
:
async
(
:
string
,
:
string
,
:
string
,
:
string
,
:
,
?
:
string
)
=>
{
.
push
(
{
,
,
,
}
)
;
return
{
:
'https://github.com/microsoft/vscode/pull/1'
,
number
:
1
}
;
}
,
}
as
unknown
as
;
const
:
=
{
:
undefined
,
:
.
,
getAuthToken
:
(
)
=>
'token'
,
}
;
const
=
createHarness
(
{
,
}
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
:
{
:
'feature'
,
:
'main'
,
:
'microsoft'
,
:
'vscode'
,
}
,
}
)
;
.
setGitResult
(
{
:
'feature'
,
:
'main'
,
:
'fork/feature'
,
:
'microsoft'
,
:
'fork-owner'
,
:
'vscode'
,
}
)
;
await
Promise
.
all
(
[
.
.
refreshSessionGitState
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
,
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
,
.
.
refreshSessionGitState
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
,
]
)
;
.
deepStrictEqual
(
{
:
.
.
,
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
}
,
{
:
2
,
:
[
{
:
'microsoft'
,
:
'vscode'
,
:
'feature'
,
:
'fork-owner'
}
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
,
}
,
}
)
;
}
)
;
}
)
;
test
(
'looks a pull request up by the upstream branch rather than the local branch name'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'local-name'
,
:
'main'
,
:
'origin/remote-name'
,
:
'microsoft'
,
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
.
setGitResult
(
)
;
.
setPullRequest
(
'remote-name'
,
{
:
'https://github.com/microsoft/vscode/pull/1'
,
number
:
1
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
{
:
.
,
:
.
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
}
,
{
:
[
'remote-name'
]
,
:
[
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'local-name'
}
,
}
)
;
}
)
;
}
)
;
test
(
'looks a fork pull request up by the local branch name when git inferred the fork head owner from the push remote'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature/alt-click-close-other-tabs'
,
:
'main'
,
:
'jadefr'
,
}
;
const
:
Array
<
{
:
string
;
:
string
|
undefined
}
>
=
[
]
;
const
=
createHarness
(
{
:
{
findPullRequestByHeadBranch
:
async
(
:
string
,
:
string
,
:
string
,
:
string
,
:
,
?
:
string
)
=>
{
.
push
(
{
,
}
)
;
return
{
:
'https://github.com/microsoft/vscode/pull/328975'
,
number
:
328975
,
}
;
}
,
}
as
unknown
as
,
}
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
.
setGitResult
(
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
{
:
,
:
.
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
}
,
{
:
[
{
:
'feature/alt-click-close-other-tabs'
,
:
'jadefr'
}
]
,
:
[
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/328975'
]
,
:
'feature/alt-click-close-other-tabs'
,
}
,
}
)
;
}
)
;
}
)
;
test
(
'falls back to the commit at HEAD when the branch name matches no pull request'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'local-only'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
.
setGitResult
(
)
;
.
setHeadSha
(
'1ce2c20d3dcb593273f604b077240543d494e276'
)
;
.
setPullRequestForSha
(
'1ce2c20d3dcb593273f604b077240543d494e276'
,
{
:
'https://github.com/microsoft/vscode/pull/2'
,
number
:
2
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
{
:
.
,
:
.
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
}
,
{
:
[
'local-only'
]
,
:
[
'1ce2c20d3dcb593273f604b077240543d494e276'
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/2'
]
,
:
'local-only'
}
,
}
)
;
}
)
;
}
)
;
test
(
'ignores an upstream branch that does not resolve to a GitHub remote'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'local-name'
,
:
'main'
,
:
'gitlab/remote-name'
,
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
.
setGitResult
(
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
.
,
[
'local-name'
]
)
;
}
)
;
}
)
;
test
(
'keeps a pre-existing folder-session pull request out of the related set'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
:
'folder'
,
:
600_000
,
}
)
;
.
setGitResult
(
)
;
.
setPullRequest
(
'feature'
,
{
:
'https://github.com/microsoft/vscode/pull/1'
,
number
:
1
,
:
1_000
,
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
const
=
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
.
deepStrictEqual
(
{
,
:
[
...
getSessionRelatedPullRequestUrls
(
)
]
,
:
JSON
.
parse
(
(
await
.
.
getMetadata
(
META_GITHUB_STATE
)
)
!
)
,
}
,
{
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
,
}
,
:
[
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
,
}
,
}
)
;
}
)
;
}
)
;
test
(
'uses folder isolation that resolves while a pull request lookup is in flight'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
'https://github.com/microsoft/vscode/pull/1'
;
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
:
600_000
,
}
)
;
.
setGitResult
(
)
;
.
setPullRequest
(
'feature'
,
{
:
,
number
:
1
,
:
1_000
}
)
;
.
setOnPullRequestLookup
(
async
(
)
=>
{
.
.
setSessionConfig
(
SESSION
,
{
:
{
:
'object'
,
:
{
}
}
,
:
{
[
.
]
:
'folder'
}
,
}
)
;
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
const
=
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
.
deepStrictEqual
(
{
,
:
[
...
getSessionRelatedPullRequestUrls
(
)
]
,
}
,
{
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
]
,
:
[
]
,
:
'feature'
,
}
,
:
[
]
,
}
)
;
}
)
;
}
)
;
test
(
'relates a pull request created after a folder session began'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
:
'folder'
,
:
600_000
,
}
)
;
.
setGitResult
(
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
setPullRequest
(
'feature'
,
{
:
'https://github.com/microsoft/vscode/pull/2'
,
number
:
2
,
:
600_500
,
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
const
=
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
.
deepStrictEqual
(
{
,
:
[
...
getSessionRelatedPullRequestUrls
(
)
]
,
}
,
{
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/2'
]
,
:
[
]
,
:
'feature'
,
}
,
:
[
'https://github.com/microsoft/vscode/pull/2'
]
,
}
)
;
}
)
;
}
)
;
test
(
'keeps worktree pull request behavior unchanged'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
:
'worktree'
,
:
2_000
,
}
)
;
.
setGitResult
(
)
;
.
setPullRequest
(
'feature'
,
{
:
'https://github.com/microsoft/vscode/pull/1'
,
number
:
1
,
:
1_000
,
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
const
=
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
.
deepStrictEqual
(
{
,
:
[
...
getSessionRelatedPullRequestUrls
(
)
]
,
}
,
{
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
,
}
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
}
)
;
}
)
;
}
)
;
test
(
'round-trips an empty folder-session baseline through persisted metadata'
,
(
)
=>
{
const
=
JSON
.
parse
(
JSON
.
stringify
(
{
:
[
]
}
)
)
;
.
deepStrictEqual
(
readSessionGitHubState
(
{
[
SESSION_META_GITHUB_KEY
]
:
}
)
,
{
:
[
]
,
}
)
;
}
)
;
test
(
'swallows git errors and fires no events'
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
}
)
;
.
setGitError
(
new
Error
(
'git command failed'
)
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
{
:
.
}
,
{
:
[
]
}
)
;
}
)
;
test
(
'coalesces concurrent refreshes for the same session'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
,
:
10_000
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
}
)
;
.
setGitResult
(
{
:
'feature'
}
)
;
await
Promise
.
all
(
[
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
,
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
,
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
,
]
)
;
.
strictEqual
(
.
.
,
2
)
;
}
)
;
}
)
;
test
(
'stops looking for a pull request once one is known for the current branch'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
.
setGitResult
(
)
;
.
setPullRequest
(
'feature'
,
{
:
'https://github.com/microsoft/vscode/pull/1'
,
number
:
1
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
{
:
.
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
}
,
{
:
[
'feature'
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
}
,
}
)
;
}
)
;
}
)
;
test
(
'keeps the known pull request but resumes looking after the branch changed'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature-2'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
:
{
:
'feature'
,
:
'main'
}
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
}
,
}
)
;
.
.
setSessionMeta
(
SESSION
,
withSessionGitState
(
.
.
getSessionState
(
SESSION
)
?.
,
)
)
;
.
setGitResult
(
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
const
=
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
.
setPullRequest
(
'feature-2'
,
{
:
'https://github.com/microsoft/vscode/pull/2'
,
number
:
2
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
{
:
.
,
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
:
JSON
.
parse
(
(
await
.
.
getMetadata
(
META_GITHUB_STATE
)
)
!
)
,
}
,
{
:
[
'feature-2'
,
'feature-2'
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
}
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/2'
,
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature-2'
}
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/2'
,
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature-2'
}
,
}
)
;
}
)
;
test
(
'preserves GitHub state updated while a pull request lookup is in flight'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
.
setGitResult
(
)
;
.
setPullRequest
(
'feature'
,
{
:
'https://github.com/microsoft/vscode/pull/1'
,
number
:
1
}
)
;
.
setOnPullRequestLookup
(
async
(
)
=>
{
const
=
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
await
.
.
setSessionGitHubState
(
SESSION
,
withMostRecentSessionPullRequest
(
,
'https://github.com/microsoft/vscode/pull/2'
,
'feature-2'
)
)
;
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
,
'https://github.com/microsoft/vscode/pull/2'
,
]
,
:
'feature'
,
}
)
;
}
)
;
}
)
;
}
)
;
test
(
'verifies a pull request that predates branch tracking against the current branch'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
}
,
}
)
;
.
setGitResult
(
)
;
.
setPullRequest
(
'feature'
,
{
:
'https://github.com/microsoft/vscode/pull/1'
,
number
:
1
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
{
:
.
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
}
,
{
:
[
'feature'
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
}
,
}
)
;
}
)
;
}
)
;
test
(
'does not bind a pull request that predates branch tracking to a branch without one'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature-2'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
}
,
}
)
;
.
setGitResult
(
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
{
:
.
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
}
,
{
:
[
'feature-2'
,
'feature-2'
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
}
,
}
)
;
}
)
;
}
)
;
test
(
'discards a pull request lookup whose branch is no longer checked out'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
.
setGitResult
(
)
;
.
setPullRequest
(
'feature'
,
{
:
'https://github.com/microsoft/vscode/pull/1'
,
number
:
1
}
)
;
.
setOnPullRequestLookup
(
async
(
)
=>
{
.
.
setSessionMeta
(
SESSION
,
withSessionGitState
(
.
.
getSessionState
(
SESSION
)
?.
,
{
:
'feature-2'
,
:
'main'
}
)
)
;
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
{
:
.
,
:
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
}
,
{
:
[
'feature'
]
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
}
)
;
}
)
;
test
(
'does not capture an empty baseline for a stale branch lookup'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
:
=
{
:
'feature'
,
:
'main'
}
;
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
,
:
{
:
'microsoft'
,
:
'vscode'
}
,
:
'folder'
,
}
)
;
.
setGitResult
(
)
;
.
setOnPullRequestLookup
(
async
(
)
=>
{
.
.
setSessionMeta
(
SESSION
,
withSessionGitState
(
.
.
getSessionState
(
SESSION
)
?.
,
{
:
'feature-2'
,
:
'main'
}
)
)
;
}
)
;
await
.
.
attachSessionGitHubPullRequest
(
SESSION
,
URI
.
parse
(
WORKING_DIRECTORY
)
)
;
.
deepStrictEqual
(
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
,
{
:
'microsoft'
,
:
'vscode'
,
}
)
;
}
)
;
}
)
;
}
)
;
test
(
'looks for a pull request before reporting a refresh that observed a branch change'
,
async
(
)
=>
{
await
runWithFakedTimers
(
{
:
true
}
,
async
(
)
=>
{
const
=
createHarness
(
)
;
seedSession
(
.
,
{
:
WORKING_DIRECTORY
,
:
{
:
'feature'
,
:
'main'
,
:
'microsoft'
,
:
'vscode'
}
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature'
}
,
}
)
;
.
setGitResult
(
{
:
'feature-2'
,
:
'main'
,
:
'microsoft'
,
:
'vscode'
}
)
;
.
setPullRequest
(
'feature-2'
,
{
:
'https://github.com/microsoft/vscode/pull/2'
,
number
:
2
}
)
;
let
:
|
undefined
;
.
add
(
.
.
onDidRefreshSessionGitState
(
(
)
=>
{
=
readSessionGitHubState
(
.
.
getSessionState
(
SESSION
)
?.
)
;
}
)
)
;
await
.
.
refreshSessionGitState
(
SESSION
,
undefined
)
;
.
deepStrictEqual
(
{
:
.
,
,
}
,
{
:
[
'feature-2'
]
,
:
{
:
'microsoft'
,
:
'vscode'
,
:
[
'https://github.com/microsoft/vscode/pull/2'
,
'https://github.com/microsoft/vscode/pull/1'
]
,
:
'feature-2'
}
,
}
)
;
}
)
;
}
)
;
}
)
;