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 / agents / vscode-node / test / githubOrgChatResourcesService.spec.ts 911 строк · изменён 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
import { assert } from 'chai' ;
import { afterEach, beforeEach, suite, test } from 'vitest' ;
import type { ExtensionContext } from 'vscode' ;
import { AGENT_FILE_EXTENSION , INSTRUCTION_FILE_EXTENSION , PromptsType } from '../../../../platform/customInstructions/common/promptTypes' ;
import { FileType } from '../../../../platform/filesystem/common/fileTypes' ;
import { MockFileSystemService } from '../../../../platform/filesystem/node/test/mockFileSystemService' ;
import MockAuthenticationService
MockGitService
MockWorkspaceService
ILogService
DisposableStore
createExtensionUnitTestingServices
GitHubOrgChatResourcesService
MockOctoKitService
disposables DisposableStore
mockExtensionContext Partial ExtensionContext
mockFileSystem MockFileSystemService
mockGitService MockGitService
mockOctoKitService MockOctoKitService
mockWorkspaceService MockWorkspaceService
mockAuthService MockAuthenticationService
logService ILogService
service GitHubOrgChatResourcesService
storagePath
storageUri storagePath
disposables
mockExtensionContext
globalStorageUri storageUri
mockFileSystem
mockGitService
mockOctoKitService
mockWorkspaceService
mockAuthService
testingServiceCollection disposables
accessor disposables testingServiceCollection
logService accessor ILogService
disposables
mockOctoKitService
GitHubOrgChatResourcesService
service
mockAuthService
mockExtensionContext
mockFileSystem
mockGitService
logService
mockOctoKitService
mockWorkspaceService
disposables service
service
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
orgName service
assert orgName
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
orgName service
assert orgName
mockWorkspaceService
mockOctoKitService
service
orgName service
assert orgName
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
orgName service
assert orgName
mockWorkspaceService
mockOctoKitService
service
orgName service
assert orgName
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
orgName1 service
assert orgName1
mockGitService
rootUri
remoteFetchUrls
orgName2 service
assert orgName2
mockWorkspaceService
mockOctoKitService
service
orgName service
assert orgName
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
orgName service
assert orgName
mockWorkspaceService
mockOctoKitService
mockAuthService copilotToken
organizationLoginList
service
orgName service
assert orgName
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
mockAuthService copilotToken
organizationLoginList
service
orgName service
assert orgName
mockWorkspaceService
mockOctoKitService
mockAuthService copilotToken
organizationLoginList
service
orgName service
assert orgName
mockWorkspaceService
mockOctoKitService
mockAuthService copilotToken
service
orgName service
assert orgName
mockWorkspaceService
mockOctoKitService
mockAuthService copilotToken
organizationLoginList
service
orgName service
assert orgName
suite
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
capturedOrg
subscription service orgName
capturedOrg orgName
disposables subscription
resolve resolve
assert capturedOrg
mockWorkspaceService
mockOctoKitService
service
callbackInvoked
subscription service
callbackInvoked
disposables subscription
resolve resolve
assert callbackInvoked
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
service
callCount
subscription service
callCount
resolve resolve
initialCount callCount
subscription
resolve resolve
assert callCount initialCount
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
concurrentCalls
maxConcurrentCalls
subscription service
concurrentCalls
maxConcurrentCalls Math maxConcurrentCalls concurrentCalls
resolve resolve
concurrentCalls
disposables subscription
resolve resolve
assert maxConcurrentCalls
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
callCount
subscription service
callCount
callCount
disposables subscription
resolve resolve
assert callCount
cacheUri
mockFileSystem cacheUri
service
content service PromptsType instructions
assert content
cacheUri
mockFileSystem cacheUri
service
content service PromptsType agent
assert content
service
content service PromptsType instructions
assert content
cacheUri
mockFileSystem cacheUri
service
content service PromptsType instructions
assert content
service
result service
PromptsType instructions
assert result
cacheUri
content mockFileSystem cacheUri
assert content
service
result service
PromptsType agent
assert result
cacheUri
content mockFileSystem cacheUri
assert content
cacheUri
mockFileSystem cacheUri
service
result service
PromptsType instructions
checkForChanges
assert result
cacheUri
mockFileSystem cacheUri
service
result service
PromptsType instructions
checkForChanges
assert result
service
result service
PromptsType instructions
checkForChanges
assert result
cacheUri
mockFileSystem cacheUri
service
result service
PromptsType instructions
checkForChanges
assert result
service
service
PromptsType agent
cacheUri
content mockFileSystem cacheUri
assert content
error
loggedErrors error Error message
mockFileSystem
error
logService loggedError message
loggedErrors error loggedError message
service
rethrewOriginalError
service PromptsType instructions
caughtError
rethrewOriginalError caughtError error
assert
rethrewOriginalError
loggedErrors
rethrewOriginalError
loggedErrors
error
message
error
loggedErrors error Error message
mockFileSystem
error
logService loggedError message
loggedErrors error loggedError message
service
rethrewOriginalError
service PromptsType instructions
caughtError
rethrewOriginalError caughtError error
assert
rethrewOriginalError
loggedErrors
rethrewOriginalError
loggedErrors
error
message
service
service
PromptsType instructions
cacheUri
content mockFileSystem cacheUri
assert content
cacheDir
mockFileSystem cacheDir
FileType File
FileType File
mockFileSystem cacheDir
mockFileSystem cacheDir
service
service PromptsType instructions
file1Exists
file2Exists
mockFileSystem cacheDir
file1Exists
mockFileSystem cacheDir
file2Exists
assert file1Exists
assert file2Exists
cacheDir
mockFileSystem cacheDir
FileType File
FileType File
mockFileSystem cacheDir
mockFileSystem cacheDir
service
service PromptsType instructions
keepContent mockFileSystem cacheDir
assert keepContent
deleteExists
mockFileSystem cacheDir
deleteExists
assert deleteExists
cacheDir
mockFileSystem cacheDir
FileType File
FileType File
mockFileSystem cacheDir
mockFileSystem cacheDir
service
service PromptsType instructions
validExists
mockFileSystem cacheDir
validExists
assert validExists
invalidContent mockFileSystem cacheDir
assert invalidContent
service
service PromptsType instructions
cacheDir
mockFileSystem cacheDir
FileType File
FileType Directory
mockFileSystem cacheDir
mockFileSystem cacheDir
service
service PromptsType instructions
dirStat mockFileSystem cacheDir
assert dirStat
cacheDir
mockFileSystem cacheDir
FileType File
FileType File
service
files service PromptsType instructions
assert files length
fileNames files f f uri path
assert fileNames
assert fileNames
cacheDir
mockFileSystem cacheDir
FileType File
FileType File
service
files service PromptsType agent
assert files length
fileNames files f f uri path
assert fileNames
assert fileNames
service
files service PromptsType instructions
assert files
cacheDir
mockFileSystem cacheDir
FileType File
FileType File
FileType File
service
files service PromptsType instructions
assert files length
assert files uri path
cacheDir
mockFileSystem cacheDir
FileType File
FileType Directory
service
files service PromptsType agent
assert files length
assert files uri path
cacheDir
mockFileSystem cacheDir
FileType File
service
files service PromptsType instructions
assert files length
assert files uri path
assert files uri path
assert files uri path
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
mockOctoKitService
service
orgName1 service
assert orgName1
mockWorkspaceService
mockGitService
rootUri
remoteFetchUrls
service
service
service
PromptsType instructions
files service PromptsType instructions
assert files uri path
service
service
PromptsType agent
files service PromptsType agent
assert files uri path
cacheDir
mockFileSystem cacheDir
FileType File
FileType File
service
files service PromptsType instructions
assert files length
assert files uri path
cacheDir
mockFileSystem cacheDir
FileType File
FileType File
service
files service PromptsType agent
assert files length
assert files uri path
{
}
from
'../../../../platform/ignore/node/test/mockAuthenticationService'
;
import
{
}
from
'../../../../platform/ignore/node/test/mockGitService'
;
import
{
}
from
'../../../../platform/ignore/node/test/mockWorkspaceService'
;
import
{
}
from
'../../../../platform/log/common/logService'
;
import
{
}
from
'../../../../util/vs/base/common/lifecycle'
;
import
{
URI
}
from
'../../../../util/vs/base/common/uri'
;
import
{
}
from
'../../../test/node/services'
;
import
{
}
from
'../githubOrgChatResourcesService'
;
import
{
}
from
'./mockOctoKitService'
;
suite
(
'GitHubOrgChatResourcesService'
,
(
)
=>
{
let
:
;
let
:
<
>
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
;
const
=
'/test/storage'
;
const
=
URI
.
file
(
)
;
beforeEach
(
(
)
=>
{
=
new
DisposableStore
(
)
;
=
{
:
,
}
;
=
new
MockFileSystemService
(
)
;
=
new
MockGitService
(
)
;
=
new
MockOctoKitService
(
)
;
=
new
MockWorkspaceService
(
)
;
=
new
MockAuthenticationService
(
)
;
const
=
createExtensionUnitTestingServices
(
)
;
const
=
.
add
(
.
createTestingAccessor
(
)
)
;
=
.
get
(
)
;
}
)
;
afterEach
(
(
)
=>
{
.
dispose
(
)
;
?.
reset
(
)
;
}
)
;
function
createService
(
)
:
{
=
new
GitHubOrgChatResourcesService
(
as
any
,
as
any
,
,
,
,
,
,
)
;
.
add
(
)
;
return
;
}
suite
(
'getPreferredOrganizationName'
,
(
)
=>
{
test
(
'returns organization from workspace repository when available'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://github.com/myorg/myrepo.git'
]
}
)
;
.
setUserOrganizations
(
[
'myorg'
]
)
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'myorg'
)
;
}
)
;
test
(
'returns organization from SSH URL format'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'git@github.com:sshorg/myrepo.git'
]
}
)
;
.
setUserOrganizations
(
[
'sshorg'
]
)
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'sshorg'
)
;
}
)
;
test
(
'falls back to user organizations when no workspace repo'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
]
)
;
.
setUserOrganizations
(
[
'fallbackorg'
,
'anotherorg'
]
)
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'fallbackorg'
)
;
}
)
;
test
(
'falls back to user organizations when repo has no GitHub remote'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://gitlab.com/someorg/repo.git'
]
}
)
;
.
setUserOrganizations
(
[
'fallbackorg'
]
)
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'fallbackorg'
)
;
}
)
;
test
(
'returns undefined when user has no organizations'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
]
)
;
.
setUserOrganizations
(
[
]
)
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
isUndefined
(
)
;
}
)
;
test
(
'caches result on subsequent calls'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://github.com/cachedorg/repo.git'
]
}
)
;
.
setUserOrganizations
(
[
'cachedorg'
]
)
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'cachedorg'
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://github.com/neworg/repo.git'
]
}
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'cachedorg'
)
;
}
)
;
test
(
'handles error in getUserOrganizations gracefully'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
]
)
;
.
getUserOrganizations
=
async
(
)
=>
{
throw
new
Error
(
'API Error'
)
;
}
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
isUndefined
(
)
;
}
)
;
test
(
'tries multiple remote URLs to find GitHub repo'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://gitlab.com/notgithub/repo.git'
,
undefined
as
any
,
'https://github.com/foundorg/repo.git'
]
}
)
;
.
setUserOrganizations
(
[
'foundorg'
]
)
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'foundorg'
)
;
}
)
;
test
(
'prefers Copilot sign-in org over arbitrary first org when no workspace repo'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
]
)
;
.
setUserOrganizations
(
[
'firstorg'
,
'copilotorg'
,
'thirdorg'
]
)
;
.
=
{
:
[
'copilotorg'
]
,
}
as
any
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'copilotorg'
)
;
}
)
;
test
(
'prefers workspace repo org over Copilot sign-in org'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://github.com/workspaceorg/repo.git'
]
}
)
;
.
setUserOrganizations
(
[
'workspaceorg'
,
'copilotorg'
]
)
;
.
=
{
:
[
'copilotorg'
]
,
}
as
any
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'workspaceorg'
)
;
}
)
;
test
(
'uses Copilot org even when not in paginated user org list'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
]
)
;
.
setUserOrganizations
(
[
'firstorg'
,
'secondorg'
]
)
;
.
=
{
:
[
'copilotorg'
]
,
}
as
any
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'copilotorg'
)
;
}
)
;
test
(
'falls back to first org when no Copilot token available'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
]
)
;
.
setUserOrganizations
(
[
'firstorg'
,
'secondorg'
]
)
;
.
=
undefined
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'firstorg'
)
;
}
)
;
test
(
'uses first matching Copilot org when multiple are available'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
]
)
;
.
setUserOrganizations
(
[
'thirdorg'
,
'secondcopilotorg'
,
'firstcopilotorg'
]
)
;
.
=
{
:
[
'firstcopilotorg'
,
'secondcopilotorg'
]
,
}
as
any
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'firstcopilotorg'
)
;
}
)
;
}
)
;
.
skip
(
'startPolling'
,
(
)
=>
{
test
(
'invokes callback immediately with org name'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://github.com/pollingorg/repo.git'
]
}
)
;
.
setUserOrganizations
(
[
'pollingorg'
]
)
;
const
=
createService
(
)
;
let
:
string
|
undefined
;
const
=
.
startPolling
(
10000
,
async
(
)
=>
{
=
;
}
)
;
.
add
(
)
;
await
new
Promise
(
=>
setTimeout
(
,
50
)
)
;
.
equal
(
,
'pollingorg'
)
;
}
)
;
test
(
'does not invoke callback when no organization'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
]
)
;
.
setUserOrganizations
(
[
]
)
;
const
=
createService
(
)
;
let
=
false
;
const
=
.
startPolling
(
10000
,
async
(
)
=>
{
=
true
;
}
)
;
.
add
(
)
;
await
new
Promise
(
=>
setTimeout
(
,
50
)
)
;
.
isFalse
(
)
;
}
)
;
test
(
'stops polling when subscription is disposed'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://github.com/testorg/repo.git'
]
}
)
;
const
=
createService
(
)
;
let
=
0
;
const
=
.
startPolling
(
50
,
async
(
)
=>
{
++
;
}
)
;
await
new
Promise
(
=>
setTimeout
(
,
30
)
)
;
const
=
;
.
dispose
(
)
;
await
new
Promise
(
=>
setTimeout
(
,
100
)
)
;
.
isAtMost
(
-
,
1
)
;
}
)
;
test
(
'prevents concurrent polling'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://github.com/concurrent/repo.git'
]
}
)
;
.
setUserOrganizations
(
[
'concurrent'
]
)
;
const
=
createService
(
)
;
let
=
0
;
let
=
0
;
const
=
.
startPolling
(
10
,
async
(
)
=>
{
++
;
=
.
max
(
,
)
;
await
new
Promise
(
=>
setTimeout
(
,
50
)
)
;
--
;
}
)
;
.
add
(
)
;
await
new
Promise
(
=>
setTimeout
(
,
100
)
)
;
.
equal
(
,
1
)
;
}
)
;
test
(
'handles callback errors gracefully'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace'
)
,
:
[
'https://github.com/errororg/repo.git'
]
}
)
;
.
setUserOrganizations
(
[
'errororg'
]
)
;
const
=
createService
(
)
;
let
=
0
;
const
=
.
startPolling
(
30
,
async
(
)
=>
{
++
;
if
(
===
1
)
{
throw
new
Error
(
'Callback error'
)
;
}
}
)
;
.
add
(
)
;
await
new
Promise
(
=>
setTimeout
(
,
100
)
)
;
.
isAtLeast
(
,
2
)
;
}
)
;
}
)
;
suite
(
'readCacheFile'
,
(
)
=>
{
test
(
'reads instruction file from cache'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions/default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
.
mockFile
(
,
'# Custom Instructions'
)
;
const
=
createService
(
)
;
const
=
await
.
readCacheFile
(
.
,
'testorg'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
.
equal
(
,
'# Custom Instructions'
)
;
}
)
;
test
(
'reads agent file from cache'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/agents/myagent ${ AGENT_FILE_EXTENSION } `
)
;
.
mockFile
(
,
'---\nname: My Agent\n---\nPrompt'
)
;
const
=
createService
(
)
;
const
=
await
.
readCacheFile
(
.
,
'testorg'
,
` myagent ${ AGENT_FILE_EXTENSION } `
)
;
.
equal
(
,
'---\nname: My Agent\n---\nPrompt'
)
;
}
)
;
test
(
'returns undefined for missing file'
,
async
(
)
=>
{
const
=
createService
(
)
;
const
=
await
.
readCacheFile
(
.
,
'testorg'
,
'nonexistent.instructions.md'
)
;
.
isUndefined
(
)
;
}
)
;
test
(
'sanitizes org name in path'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/test-org/instructions/default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
.
mockFile
(
,
'Sanitized content'
)
;
const
=
createService
(
)
;
const
=
await
.
readCacheFile
(
.
,
'Test-Org'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
.
equal
(
,
'Sanitized content'
)
;
}
)
;
}
)
;
suite
(
'writeCacheFile'
,
(
)
=>
{
test
(
'writes instruction file to cache'
,
async
(
)
=>
{
const
=
createService
(
)
;
const
=
await
.
writeCacheFile
(
.
,
'testorg'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
,
'# New Instructions'
)
;
.
isTrue
(
)
;
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions/default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
const
=
await
.
readFile
(
)
;
.
equal
(
new
TextDecoder
(
)
.
decode
(
)
,
'# New Instructions'
)
;
}
)
;
test
(
'writes agent file to cache'
,
async
(
)
=>
{
const
=
createService
(
)
;
const
=
await
.
writeCacheFile
(
.
,
'testorg'
,
` myagent ${ AGENT_FILE_EXTENSION } `
,
'---\nname: Agent\n---\nPrompt'
)
;
.
isTrue
(
)
;
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/agents/myagent ${ AGENT_FILE_EXTENSION } `
)
;
const
=
await
.
readFile
(
)
;
.
equal
(
new
TextDecoder
(
)
.
decode
(
)
,
'---\nname: Agent\n---\nPrompt'
)
;
}
)
;
test
(
'returns false when content unchanged with checkForChanges'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions/default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
.
mockFile
(
,
'Same content'
)
;
const
=
createService
(
)
;
const
=
await
.
writeCacheFile
(
.
,
'testorg'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
,
'Same content'
,
{
:
true
}
)
;
.
isFalse
(
)
;
}
)
;
test
(
'returns true when content changed with checkForChanges'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions/default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
.
mockFile
(
,
'Old content'
)
;
const
=
createService
(
)
;
const
=
await
.
writeCacheFile
(
.
,
'testorg'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
,
'New content'
,
{
:
true
}
)
;
.
isTrue
(
)
;
}
)
;
test
(
'returns true when file does not exist with checkForChanges'
,
async
(
)
=>
{
const
=
createService
(
)
;
const
=
await
.
writeCacheFile
(
.
,
'neworg'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
,
'Content'
,
{
:
true
}
)
;
.
isTrue
(
)
;
}
)
;
test
(
'returns true when file size differs with checkForChanges'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions/default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
.
mockFile
(
,
'Short'
)
;
const
=
createService
(
)
;
const
=
await
.
writeCacheFile
(
.
,
'testorg'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
,
'Much longer content that differs in size'
,
{
:
true
}
)
;
.
isTrue
(
)
;
}
)
;
test
(
'creates directory structure if not exists'
,
async
(
)
=>
{
const
=
createService
(
)
;
await
.
writeCacheFile
(
.
,
'neworg'
,
` agent ${ AGENT_FILE_EXTENSION } `
,
'Content'
)
;
const
=
URI
.
file
(
` ${ storagePath} /github/neworg/agents/agent ${ AGENT_FILE_EXTENSION } `
)
;
const
=
await
.
readFile
(
)
;
.
equal
(
new
TextDecoder
(
)
.
decode
(
)
,
'Content'
)
;
}
)
;
test
(
'logs and rethrows directory creation failures'
,
async
(
)
=>
{
const
=
new
Error
(
'Create directory failed'
)
;
const
:
{
:
string
|
;
?
:
string
}
[
]
=
[
]
;
.
createDirectory
=
async
(
)
=>
{
throw
;
}
;
.
error
=
(
,
)
=>
{
.
push
(
{
:
,
}
)
;
}
;
const
=
createService
(
)
;
let
=
false
;
try
{
await
.
writeCacheFile
(
.
,
'testorg'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
,
'Content'
)
;
}
catch
(
)
{
=
===
;
}
.
deepEqual
(
{
,
,
}
,
{
:
true
,
:
[
{
,
:
'[GitHubOrgChatResourcesService] Failed to create cache directory'
,
}
]
,
}
)
;
}
)
;
test
(
'logs and rethrows cache file write failures'
,
async
(
)
=>
{
const
=
new
Error
(
'Write file failed'
)
;
const
:
{
:
string
|
;
?
:
string
}
[
]
=
[
]
;
.
writeFile
=
async
(
)
=>
{
throw
;
}
;
.
error
=
(
,
)
=>
{
.
push
(
{
:
,
}
)
;
}
;
const
=
createService
(
)
;
let
=
false
;
try
{
await
.
writeCacheFile
(
.
,
'testorg'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
,
'Content'
)
;
}
catch
(
)
{
=
===
;
}
.
deepEqual
(
{
,
,
}
,
{
:
true
,
:
[
{
,
:
'[GitHubOrgChatResourcesService] Failed to write cache file'
,
}
]
,
}
)
;
}
)
;
test
(
'sanitizes org name before writing'
,
async
(
)
=>
{
const
=
createService
(
)
;
await
.
writeCacheFile
(
.
,
'My-Org!@#'
,
` default ${ INSTRUCTION_FILE_EXTENSION } `
,
'Content'
)
;
const
=
URI
.
file
(
` ${ storagePath} /github/my-org___/instructions/default ${ INSTRUCTION_FILE_EXTENSION } `
)
;
const
=
await
.
readFile
(
)
;
.
equal
(
new
TextDecoder
(
)
.
decode
(
)
,
'Content'
)
;
}
)
;
}
)
;
suite
(
'clearCache'
,
(
)
=>
{
test
(
'deletes all instruction files for organization'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions `
)
;
.
mockDirectory
(
,
[
[
` file1 ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
[
` file2 ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
]
)
;
.
mockFile
(
URI
.
joinPath
(
,
` file1 ${ INSTRUCTION_FILE_EXTENSION } `
)
,
'Content 1'
)
;
.
mockFile
(
URI
.
joinPath
(
,
` file2 ${ INSTRUCTION_FILE_EXTENSION } `
)
,
'Content 2'
)
;
const
=
createService
(
)
;
await
.
clearCache
(
.
,
'testorg'
)
;
let
=
true
;
let
=
true
;
try
{
await
.
readFile
(
URI
.
joinPath
(
,
` file1 ${ INSTRUCTION_FILE_EXTENSION } `
)
)
;
}
catch
{
=
false
;
}
try
{
await
.
readFile
(
URI
.
joinPath
(
,
` file2 ${ INSTRUCTION_FILE_EXTENSION } `
)
)
;
}
catch
{
=
false
;
}
.
isFalse
(
)
;
.
isFalse
(
)
;
}
)
;
test
(
'excludes specified files from deletion'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions `
)
;
.
mockDirectory
(
,
[
[
` keep ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
[
` delete ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
]
)
;
.
mockFile
(
URI
.
joinPath
(
,
` keep ${ INSTRUCTION_FILE_EXTENSION } `
)
,
'Keep this'
)
;
.
mockFile
(
URI
.
joinPath
(
,
` delete ${ INSTRUCTION_FILE_EXTENSION } `
)
,
'Delete this'
)
;
const
=
createService
(
)
;
await
.
clearCache
(
.
,
'testorg'
,
new
Set
(
[
` keep ${ INSTRUCTION_FILE_EXTENSION } `
]
)
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
` keep ${ INSTRUCTION_FILE_EXTENSION } `
)
)
;
.
equal
(
new
TextDecoder
(
)
.
decode
(
)
,
'Keep this'
)
;
let
=
true
;
try
{
await
.
readFile
(
URI
.
joinPath
(
,
` delete ${ INSTRUCTION_FILE_EXTENSION } `
)
)
;
}
catch
{
=
false
;
}
.
isFalse
(
)
;
}
)
;
test
(
'skips non-matching file extensions'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions `
)
;
.
mockDirectory
(
,
[
[
` valid ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
[
'invalid.txt'
,
.
]
,
]
)
;
.
mockFile
(
URI
.
joinPath
(
,
` valid ${ INSTRUCTION_FILE_EXTENSION } `
)
,
'Valid'
)
;
.
mockFile
(
URI
.
joinPath
(
,
'invalid.txt'
)
,
'Invalid'
)
;
const
=
createService
(
)
;
await
.
clearCache
(
.
,
'testorg'
)
;
let
=
true
;
try
{
await
.
readFile
(
URI
.
joinPath
(
,
` valid ${ INSTRUCTION_FILE_EXTENSION } `
)
)
;
}
catch
{
=
false
;
}
.
isFalse
(
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'invalid.txt'
)
)
;
.
equal
(
new
TextDecoder
(
)
.
decode
(
)
,
'Invalid'
)
;
}
)
;
test
(
'handles non-existent cache directory gracefully'
,
async
(
)
=>
{
const
=
createService
(
)
;
await
.
clearCache
(
.
,
'nonexistentorg'
)
;
}
)
;
test
(
'skips directories in cache folder'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions `
)
;
.
mockDirectory
(
,
[
[
` file ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
[
'subfolder'
,
.
]
,
]
)
;
.
mockFile
(
URI
.
joinPath
(
,
` file ${ INSTRUCTION_FILE_EXTENSION } `
)
,
'Content'
)
;
.
mockDirectory
(
URI
.
joinPath
(
,
'subfolder'
)
,
[
]
)
;
const
=
createService
(
)
;
await
.
clearCache
(
.
,
'testorg'
)
;
const
=
await
.
stat
(
URI
.
joinPath
(
,
'subfolder'
)
)
;
.
ok
(
)
;
}
)
;
}
)
;
suite
(
'listCachedFiles'
,
(
)
=>
{
test
(
'lists all instruction files for organization'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions `
)
;
.
mockDirectory
(
,
[
[
` file1 ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
[
` file2 ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
]
)
;
const
=
createService
(
)
;
const
=
await
.
listCachedFiles
(
.
,
'testorg'
)
;
.
equal
(
.
,
2
)
;
const
=
.
map
(
=>
.
.
.
split
(
'/'
)
.
pop
(
)
)
;
.
include
(
,
` file1 ${ INSTRUCTION_FILE_EXTENSION } `
)
;
.
include
(
,
` file2 ${ INSTRUCTION_FILE_EXTENSION } `
)
;
}
)
;
test
(
'lists all agent files for organization'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/agents `
)
;
.
mockDirectory
(
,
[
[
` agent1 ${ AGENT_FILE_EXTENSION } `
,
.
]
,
[
` agent2 ${ AGENT_FILE_EXTENSION } `
,
.
]
,
]
)
;
const
=
createService
(
)
;
const
=
await
.
listCachedFiles
(
.
,
'testorg'
)
;
.
equal
(
.
,
2
)
;
const
=
.
map
(
=>
.
.
.
split
(
'/'
)
.
pop
(
)
)
;
.
include
(
,
` agent1 ${ AGENT_FILE_EXTENSION } `
)
;
.
include
(
,
` agent2 ${ AGENT_FILE_EXTENSION } `
)
;
}
)
;
test
(
'returns empty array for non-existent directory'
,
async
(
)
=>
{
const
=
createService
(
)
;
const
=
await
.
listCachedFiles
(
.
,
'nonexistent'
)
;
.
deepEqual
(
,
[
]
)
;
}
)
;
test
(
'filters out non-matching file extensions'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions `
)
;
.
mockDirectory
(
,
[
[
` valid ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
[
'invalid.txt'
,
.
]
,
[
'readme.md'
,
.
]
,
]
)
;
const
=
createService
(
)
;
const
=
await
.
listCachedFiles
(
.
,
'testorg'
)
;
.
equal
(
.
,
1
)
;
.
ok
(
[
0
]
.
.
.
endsWith
(
INSTRUCTION_FILE_EXTENSION
)
)
;
}
)
;
test
(
'filters out directories'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/agents `
)
;
.
mockDirectory
(
,
[
[
` agent ${ AGENT_FILE_EXTENSION } `
,
.
]
,
[
'subfolder'
,
.
]
,
]
)
;
const
=
createService
(
)
;
const
=
await
.
listCachedFiles
(
.
,
'testorg'
)
;
.
equal
(
.
,
1
)
;
.
ok
(
[
0
]
.
.
.
endsWith
(
AGENT_FILE_EXTENSION
)
)
;
}
)
;
test
(
'returns correct URI structure for files'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/myorg/instructions `
)
;
.
mockDirectory
(
,
[
[
` custom ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
]
)
;
const
=
createService
(
)
;
const
=
await
.
listCachedFiles
(
.
,
'myorg'
)
;
.
equal
(
.
,
1
)
;
.
ok
(
[
0
]
.
.
.
includes
(
'/github/'
)
)
;
.
ok
(
[
0
]
.
.
.
includes
(
'/myorg/'
)
)
;
.
ok
(
[
0
]
.
.
.
includes
(
'/instructions/'
)
)
;
}
)
;
}
)
;
suite
(
'workspace folder change handling'
,
(
)
=>
{
test
(
'invalidates org cache when workspace folders change'
,
async
(
)
=>
{
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace1'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace1'
)
,
:
[
'https://github.com/org1/repo.git'
]
}
)
;
.
setUserOrganizations
(
[
'org1'
,
'org2'
]
)
;
const
=
createService
(
)
;
const
=
await
.
getPreferredOrganizationName
(
)
;
.
equal
(
,
'org1'
)
;
.
setWorkspaceFolders
(
[
URI
.
file
(
'/workspace2'
)
]
)
;
.
setRepositoryFetchUrls
(
{
:
URI
.
file
(
'/workspace2'
)
,
:
[
'https://github.com/org2/repo.git'
]
}
)
;
.
dispose
(
)
;
}
)
;
}
)
;
suite
(
'getCacheSubdirectory helper'
,
(
)
=>
{
test
(
'uses instructions subdirectory for instructions type'
,
async
(
)
=>
{
const
=
createService
(
)
;
await
.
writeCacheFile
(
.
,
'testorg'
,
` file ${ INSTRUCTION_FILE_EXTENSION } `
,
'Content'
)
;
const
=
await
.
listCachedFiles
(
.
,
'testorg'
)
;
.
ok
(
[
0
]
.
.
.
includes
(
'/instructions/'
)
)
;
}
)
;
test
(
'uses agents subdirectory for agent type'
,
async
(
)
=>
{
const
=
createService
(
)
;
await
.
writeCacheFile
(
.
,
'testorg'
,
` file ${ AGENT_FILE_EXTENSION } `
,
'Content'
)
;
const
=
await
.
listCachedFiles
(
.
,
'testorg'
)
;
.
ok
(
[
0
]
.
.
.
includes
(
'/agents/'
)
)
;
}
)
;
}
)
;
suite
(
'file validation'
,
(
)
=>
{
test
(
'validates instruction file extension'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/instructions `
)
;
.
mockDirectory
(
,
[
[
` valid ${ INSTRUCTION_FILE_EXTENSION } `
,
.
]
,
[
'valid.agent.md'
,
.
]
,
]
)
;
const
=
createService
(
)
;
const
=
await
.
listCachedFiles
(
.
,
'testorg'
)
;
.
equal
(
.
,
1
)
;
.
ok
(
[
0
]
.
.
.
endsWith
(
INSTRUCTION_FILE_EXTENSION
)
)
;
}
)
;
test
(
'validates agent file extension'
,
async
(
)
=>
{
const
=
URI
.
file
(
` ${ storagePath} /github/testorg/agents `
)
;
.
mockDirectory
(
,
[
[
` valid ${ AGENT_FILE_EXTENSION } `
,
.
]
,
[
'valid.instructions.md'
,
.
]
,
]
)
;
const
=
createService
(
)
;
const
=
await
.
listCachedFiles
(
.
,
'testorg'
)
;
.
equal
(
.
,
1
)
;
.
ok
(
[
0
]
.
.
.
endsWith
(
AGENT_FILE_EXTENSION
)
)
;
}
)
;
}
)
;
}
)
;