ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / platform / authentication / test / node / copilotToken.spec.ts 749 строк · изменён 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
import { afterEach, beforeEach, describe, expect, it } from 'vitest' ;
import { DeferredPromise } from '../../../../util/vs/base/common/async' ;
import { Event } from '../../../../util/vs/base/common/event' ;
import { DisposableStore } from '../../../../util/vs/base/common/lifecycle' ;
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation' ;
import { ICAPIClientService } from '../../../endpoint/common/capiClient' ;
import { IDomainService } from '../../../endpoint/common/domainService'
IEnvService
NullBaseOctoKitService
ILogService
FetchOptions IAbortController IFetcherService IHeaders PaginationOptions Response WebSocketConnection
ITelemetryService
createFakeResponse
createPlatformServices ITestingServicesAccessor
CopilotToken createTestExtendedTokenInfo isErrorEnvelope isStandardErrorEnvelope isTokenEnvelope validateTokenEnvelope
BaseCopilotTokenManager CopilotTokenManagerFromGitHubToken
calls
throwErrorCount
logService ILogService
telemetryService ITelemetryService
domainService IDomainService
capiClientService ICAPIClientService
fetcherService IFetcherService
envService IEnvService
capiClientService fetcherService logService telemetryService logService telemetryService domainService capiClientService fetcherService envService
force CopilotToken
calls
resolve resolve
calls throwErrorCount
force copilotToken
copilotToken
copilotToken token username copilot_plan
copilotToken
accessor ITestingServicesAccessor
disposables DisposableStore
disposables
accessor disposables
disposables
fetcher
token
expires_at
refresh_in
testingServiceCollection
testingServiceCollection IFetcherService fetcher
accessor disposables testingServiceCollection
tokenManager disposables accessor IInstantiationService RefreshFakeCopilotTokenManager
tokenManager
fetcher requests size
tokenManager disposables accessor IInstantiationService RefreshFakeCopilotTokenManager
deferredTokenPromise
tokenManager
notifiedValue tokenManager
deferredTokenPromise notifiedValue
tokenManager
notifiedValue deferredTokenPromise p
notifiedValue token
fetcher
can_signup_for_limited
message
error_details
message
url
notification_id
title
testingServiceCollection
testingServiceCollection IFetcherService fetcher
accessor disposables testingServiceCollection
tokenManager accessor IInstantiationService CopilotTokenManagerFromGitHubToken
result tokenManager
result
kind
reason
message
notification_id
url
title
fetcher
testingServiceCollection
testingServiceCollection IFetcherService fetcher
accessor disposables testingServiceCollection
tokenManager accessor IInstantiationService CopilotTokenManagerFromGitHubToken
result tokenManager
result
kind
message
reason
fetcher
testingServiceCollection
testingServiceCollection IFetcherService fetcher
accessor disposables testingServiceCollection
tokenManager accessor IInstantiationService CopilotTokenManagerFromGitHubToken
result tokenManager
result
kind
message
reason
expectedError
testingServiceCollection
testingServiceCollection IFetcherService expectedError
accessor disposables testingServiceCollection
tokenManager accessor IInstantiationService CopilotTokenManagerFromGitHubToken
tokenManager
err
err expectedError
token
copilotToken token username copilot_plan
copilotToken
token
copilotToken token username copilot_plan
copilotToken
token
copilotToken token username copilot_plan
copilotToken
copilotToken
copilotToken
ghecConfig IDomainService
_serviceBrand
onDidChangeDomains Event None
fetcher
token
expires_at
refresh_in
testingServiceCollection
testingServiceCollection IDomainService ghecConfig
testingServiceCollection IFetcherService fetcher
accessor disposables testingServiceCollection
tokenManager disposables accessor IInstantiationService RefreshFakeCopilotTokenManager
tokenManager
fetcher requests size
fetcher
message
documentation_url
status
testingServiceCollection
testingServiceCollection IFetcherService fetcher
accessor disposables testingServiceCollection
tokenManager accessor IInstantiationService CopilotTokenManagerFromGitHubToken
result tokenManager
result
kind
reason
fetcher
testingServiceCollection
testingServiceCollection IFetcherService fetcher
accessor disposables testingServiceCollection
tokenManager accessor IInstantiationService CopilotTokenManagerFromGitHubToken
result tokenManager
result
kind
reason
retryAfterMs
fetcher
testingServiceCollection
testingServiceCollection IFetcherService fetcher
accessor disposables testingServiceCollection
tokenManager accessor IInstantiationService CopilotTokenManagerFromGitHubToken
result tokenManager
result
kind
reason
validToken
token
expires_at
refresh_in
sku
individual
blackbird_clientside_indexing
code_quote_enabled
code_review_enabled
codesearch
copilotignore_enabled
public_suggestions
telemetry
validToken
validToken
token
expires_at
refresh_in
sku
individual
blackbird_clientside_indexing
code_quote_enabled
code_review_enabled
codesearch
copilotignore_enabled
public_suggestions
telemetry
limited_user_quotas
limited_user_reset_date
validToken
token
token expires_at
validError
can_signup_for_limited
message
error_details
message
notification_id
title
url
validError
message
error_details
rateLimitError
message
documentation_url
status
rateLimitError
message
validToken
token
expires_at
refresh_in
sku
individual
blackbird_clientside_indexing
code_quote_enabled
code_review_enabled
codesearch
copilotignore_enabled
public_suggestions
telemetry
result validToken
result valid
result strategy
result strategy
result envelope
result envelope token
result envelope expires_at
result envelope refresh_in
result envelope sku
minimalToken
token
expires_at
refresh_in
result minimalToken
result valid
result strategy
result strategy
result envelope
result envelope token
result envelope expires_at
result envelope refresh_in
tokenWithWrongOptionalType
token
expires_at
refresh_in
sku
result tokenWithWrongOptionalType
result valid
result strategy
result strategy
result strictError
result fallbackError
result envelope
result envelope token
result envelope expires_at
result envelope refresh_in
tokenWithNewEnumValue
token
expires_at
refresh_in
public_suggestions
result tokenWithNewEnumValue
result valid
result strategy
result strategy
result strictError
result envelope
result envelope token
missingToken
expires_at
refresh_in
result missingToken
result valid
result strategy
result strategy
result strictError
result fallbackError
missingExpiresAt
token
refresh_in
result missingExpiresAt
result valid
result strategy
result strategy
result fallbackError
missingRefreshIn
token
expires_at
result missingRefreshIn
result valid
result strategy
result strategy
result fallbackError
result
result valid
result strategy
result
result valid
result strategy
wrongTypeToken
token
expires_at
refresh_in
result wrongTypeToken
result valid
result strategy
result strategy
result fallbackError
token sku
token isFreeUser
token isNoAuthUser
token sku
token isFreeUser
token isNoAuthUser
enabledToken telemetry
disabledToken telemetry
enabledToken
disabledToken
enabledToken public_suggestions
disabledToken public_suggestions
unconfiguredToken public_suggestions
enabledToken
disabledToken
unconfiguredToken
freeToken sku copilot_plan
individualToken sku copilot_plan
businessToken sku copilot_plan
enterpriseToken sku copilot_plan
freeToken copilotPlan
individualToken copilotPlan
businessToken copilotPlan
enterpriseToken copilotPlan
exceededToken
sku
limited_user_quotas chat completions
notExceededToken
sku
limited_user_quotas chat completions
nonFreeToken
sku
limited_user_quotas chat completions
exceededToken isChatQuotaExceeded
notExceededToken isChatQuotaExceeded
nonFreeToken isChatQuotaExceeded
exceededToken
sku
limited_user_quotas chat completions
notExceededToken
sku
limited_user_quotas chat completions
exceededToken isCompletionsQuotaExceeded
notExceededToken isCompletionsQuotaExceeded
githubOrgToken
organization_list
microsoftOrgToken
organization_list
externalToken
organization_list
noOrgToken
organization_list
githubOrgToken isInternal
githubOrgToken isGitHubInternal
githubOrgToken isMicrosoftInternal
microsoftOrgToken isInternal
microsoftOrgToken isGitHubInternal
microsoftOrgToken isMicrosoftInternal
externalToken isInternal
noOrgToken isInternal
enabledToken code_quote_enabled
disabledToken code_quote_enabled
enabledToken codeQuoteEnabled
disabledToken codeQuoteEnabled
enabledToken code_review_enabled
disabledToken code_review_enabled
enabledToken isCopilotCodeReviewEnabled
disabledToken isCopilotCodeReviewEnabled
enabledToken blackbird_clientside_indexing
disabledToken blackbird_clientside_indexing
enabledToken
disabledToken
token token
token
token token
token
token token
token
_serviceBrand
onDidFetch Event None
onDidCompleteFetch Event None
requests
tokenResponse
baseUrl options PaginationOptions
url options FetchOptions Response
requests url options
url
tokenResponse
tokenResponse
url
_url WebSocketConnection
IAbortController
e
e
err
err
err
error
override url options FetchOptions Response
error
status
override url options FetchOptions Response
requests url options
status
override url options FetchOptions Response
requests url options
Response
message
headers Record
name
headers name
Symbol iterator Iterator
Object headers
;
import
{
}
from
'../../../env/common/envService'
;
import
{
}
from
'../../../github/common/nullOctokitServiceImpl'
;
import
{
}
from
'../../../log/common/logService'
;
import
{
,
,
,
,
,
,
}
from
'../../../networking/common/fetcherService'
;
import
{
}
from
'../../../telemetry/common/telemetry'
;
import
{
}
from
'../../../test/node/fetcher'
;
import
{
,
}
from
'../../../test/node/services'
;
import
{
,
,
,
,
,
}
from
'../../common/copilotToken'
;
import
{
,
}
from
'../../node/copilotTokenManager'
;
class
RefreshFakeCopilotTokenManager
extends
BaseCopilotTokenManager
{
=
0
;
constructor
(
private
readonly
:
number
,
@ ILogService
:
,
@ ITelemetryService
:
,
@ IDomainService
:
,
@ ICAPIClientService
:
,
@ IFetcherService
:
,
@ IEnvService
:
,
)
{
super
(
new
NullBaseOctoKitService
(
,
,
,
)
,
,
,
,
,
,
)
;
}
async
getCopilotToken
(
?
:
boolean
)
:
Promise
<
>
{
this
.
++
;
await
new
Promise
(
=>
setTimeout
(
,
10
)
)
;
if
(
this
.
===
this
.
)
{
throw
new
Error
(
'fake error'
)
;
}
if
(
!
&&
this
.
)
{
return
new
CopilotToken
(
this
.
)
;
}
this
.
=
createTestExtendedTokenInfo
(
{
:
'done'
,
:
'fake'
,
:
'unknown'
}
)
;
return
new
CopilotToken
(
this
.
)
;
}
}
describe
(
'Copilot token unit tests'
,
function
(
)
{
let
:
;
let
:
;
beforeEach
(
(
)
=>
{
=
new
DisposableStore
(
)
;
=
.
add
(
createPlatformServices
(
)
.
createTestingAccessor
(
)
)
;
}
)
;
afterEach
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
it
(
'includes editor information in token request'
,
async
function
(
)
{
const
=
new
StaticFetcherService
(
{
:
'token'
,
:
1
,
:
1
,
}
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
add
(
.
get
(
)
.
createInstance
(
,
1
)
)
;
await
.
authFromGitHubToken
(
'fake-token'
,
'fake-user'
)
;
expect
(
.
.
)
.
toBe
(
2
)
;
}
)
;
it
(
` notifies about token on token retrieval `
,
async
function
(
)
{
const
=
.
add
(
.
get
(
)
.
createInstance
(
,
3
)
)
;
const
=
new
DeferredPromise< CopilotToken>
(
)
;
.
onDidCopilotTokenRefresh
(
async
(
)
=>
{
const
=
await
.
getCopilotToken
(
)
;
.
complete
(
)
;
}
)
;
await
.
getCopilotToken
(
true
)
;
const
=
await
.
;
expect
(
.
)
.
toBe
(
'done'
)
;
}
)
;
it
(
'invalid GitHub token'
,
async
function
(
)
{
const
=
new
StaticFetcherService
(
{
:
false
,
:
'You do not have access to Copilot'
,
:
{
:
'fake error message'
,
:
'https://github.com/settings?param={EDITOR}'
,
:
'fake-notification-id'
,
:
'Access Denied'
,
}
,
}
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
get
(
)
.
createInstance
(
,
'invalid'
,
'invalid-user'
)
;
const
=
await
.
checkCopilotToken
(
)
;
expect
(
)
.
toEqual
(
{
:
'failure'
,
:
'NotAuthorized'
,
:
'fake error message'
,
:
'fake-notification-id'
,
:
'https://github.com/settings?param={EDITOR}'
,
:
'Access Denied'
,
}
)
;
}
)
;
it
(
'network request failed'
,
async
function
(
)
{
const
=
new
StaticFetcherService
(
'NETWORK_FAILURE'
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
get
(
)
.
createInstance
(
,
'valid'
,
'valid-user'
)
;
const
=
await
.
checkCopilotToken
(
)
;
expect
(
)
.
toEqual
(
{
:
'failure'
,
:
'Network request failed'
,
:
'RequestFailed'
,
}
)
;
}
)
;
it
(
'JSON parse failed'
,
async
function
(
)
{
const
=
new
StaticFetcherService
(
null
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
get
(
)
.
createInstance
(
,
'valid'
,
'valid-user'
)
;
const
=
await
.
checkCopilotToken
(
)
;
expect
(
)
.
toEqual
(
{
:
'failure'
,
:
'Response is not valid: null'
,
:
'ParseFailed'
,
}
)
;
}
)
;
it
(
'properly propagates errors'
,
async
function
(
)
{
const
=
new
Error
(
'to be handled'
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
new
ErrorFetcherService
(
)
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
get
(
)
.
createInstance
(
,
'invalid'
,
'invalid-user'
)
;
try
{
await
.
checkCopilotToken
(
)
;
}
catch
(
:
any
)
{
expect
(
)
.
toBe
(
)
;
}
}
)
;
it
(
'ignore v1 token'
,
async
function
(
)
{
const
=
'0123456789abcdef0123456789abcdef:org1.com:1674258990:0000000000000000000000000000000000000000000000000000000000000000'
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
,
:
'fake'
,
:
'unknown'
}
)
)
;
expect
(
.
getTokenValue
(
'tid'
)
)
.
toBeUndefined
(
)
;
}
)
;
it
(
'parsing v2 token'
,
async
function
(
)
{
const
=
'tid=0123456789abcdef0123456789abcdef;dom=org1.com;ol=org1,org2;exp=1674258990:0000000000000000000000000000000000000000000000000000000000000000'
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
,
:
'fake'
,
:
'unknown'
}
)
)
;
expect
(
.
getTokenValue
(
'tid'
)
)
.
toBe
(
'0123456789abcdef0123456789abcdef'
)
;
}
)
;
it
(
'parsing v2 token, multiple values'
,
async
function
(
)
{
const
=
'tid=0123456789abcdef0123456789abcdef;rt=1;ssc=0;dom=org1.com;ol=org1,org2;exp=1674258990:0000000000000000000000000000000000000000000000000000000000000000'
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
,
:
'fake'
,
:
'unknown'
}
)
)
;
expect
(
.
getTokenValue
(
'rt'
)
)
.
toBe
(
'1'
)
;
expect
(
.
getTokenValue
(
'ssc'
)
)
.
toBe
(
'0'
)
;
expect
(
.
getTokenValue
(
'foo'
)
)
.
toBeUndefined
(
)
;
}
)
;
it
(
'With a GitHub Enterprise configuration, retrieves token from the GHEC server'
,
async
(
)
=>
{
const
:
=
{
:
undefined
,
:
.
,
}
;
const
=
new
StaticFetcherService
(
{
:
'token'
,
:
1
,
:
1
,
}
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
)
;
.
define
(
,
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
add
(
.
get
(
)
.
createInstance
(
,
1
)
)
;
await
.
authFromGitHubToken
(
'fake-token'
,
'invalid-user'
)
;
expect
(
.
.
)
.
toBe
(
2
)
;
}
)
;
it
(
'rate limiting (StandardErrorEnvelope)'
,
async
function
(
)
{
const
=
new
StaticFetcherService
(
{
:
'API rate limit exceeded for user ID 12345.'
,
:
'https://developer.github.com/rest/overview/rate-limits-for-the-rest-api'
,
:
'403'
,
}
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
get
(
)
.
createInstance
(
,
'valid'
,
'valid-user'
)
;
const
=
await
.
checkCopilotToken
(
)
;
expect
(
)
.
toEqual
(
{
:
'failure'
,
:
'RateLimited'
,
}
)
;
}
)
;
it
(
'rate limiting honors Retry-After'
,
async
function
(
)
{
const
=
new
RateLimitedFetcherService
(
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
get
(
)
.
createInstance
(
,
'valid'
,
'valid-user'
)
;
const
=
await
.
checkCopilotToken
(
)
;
expect
(
)
.
toEqual
(
{
:
'failure'
,
:
'RateLimited'
,
:
120_000
,
}
)
;
}
)
;
it
(
'HTTP 401 unauthorized'
,
async
function
(
)
{
const
=
new
HttpStatusFetcherService
(
401
)
;
const
=
createPlatformServices
(
)
;
.
define
(
,
)
;
=
.
add
(
.
createTestingAccessor
(
)
)
;
const
=
.
get
(
)
.
createInstance
(
,
'bad-token'
,
'bad-user'
)
;
const
=
await
.
checkCopilotToken
(
)
;
expect
(
)
.
toEqual
(
{
:
'failure'
,
:
'HTTP401'
,
}
)
;
}
)
;
}
)
;
describe
(
'Token envelope validators'
,
function
(
)
{
it
(
'isTokenEnvelope returns true for valid token'
,
function
(
)
{
const
=
{
:
'test-token'
,
:
1234567890
,
:
300
,
:
'free_limited_copilot'
,
:
true
,
:
false
,
:
false
,
:
false
,
:
false
,
:
false
,
:
'enabled'
,
:
'enabled'
,
}
;
expect
(
isTokenEnvelope
(
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'isTokenEnvelope returns true when limited_user_quotas and limited_user_reset_date are null'
,
function
(
)
{
const
=
{
:
'test-token'
,
:
1234567890
,
:
300
,
:
'free_limited_copilot'
,
:
true
,
:
false
,
:
false
,
:
false
,
:
false
,
:
false
,
:
'enabled'
,
:
'enabled'
,
:
null
,
:
null
,
}
;
expect
(
isTokenEnvelope
(
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'isTokenEnvelope returns false for missing required fields'
,
function
(
)
{
expect
(
isTokenEnvelope
(
{
}
)
)
.
toBe
(
false
)
;
expect
(
isTokenEnvelope
(
{
:
'test'
}
)
)
.
toBe
(
false
)
;
expect
(
isTokenEnvelope
(
{
:
'test'
,
:
123
}
)
)
.
toBe
(
false
)
;
expect
(
isTokenEnvelope
(
null
)
)
.
toBe
(
false
)
;
expect
(
isTokenEnvelope
(
undefined
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'isErrorEnvelope returns true for valid error envelope'
,
function
(
)
{
const
=
{
:
false
,
:
'Access denied'
,
:
{
:
'You do not have access'
,
:
'no_copilot_access'
,
:
'No Access'
,
:
'https://github.com/settings/copilot'
,
}
,
}
;
expect
(
isErrorEnvelope
(
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'isErrorEnvelope returns false for invalid structures'
,
function
(
)
{
expect
(
isErrorEnvelope
(
{
}
)
)
.
toBe
(
false
)
;
expect
(
isErrorEnvelope
(
{
:
'error'
}
)
)
.
toBe
(
false
)
;
expect
(
isErrorEnvelope
(
{
:
{
}
}
)
)
.
toBe
(
false
)
;
expect
(
isErrorEnvelope
(
null
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'isStandardErrorEnvelope returns true for rate limit response'
,
function
(
)
{
const
=
{
:
'API rate limit exceeded for user ID 12345.'
,
:
'https://developer.github.com/rest/overview/rate-limits-for-the-rest-api'
,
:
'403'
,
}
;
expect
(
isStandardErrorEnvelope
(
)
)
.
toBe
(
true
)
;
}
)
;
it
(
'isStandardErrorEnvelope returns false for invalid structures'
,
function
(
)
{
expect
(
isStandardErrorEnvelope
(
{
}
)
)
.
toBe
(
false
)
;
expect
(
isStandardErrorEnvelope
(
{
:
'error'
}
)
)
.
toBe
(
false
)
;
expect
(
isStandardErrorEnvelope
(
null
)
)
.
toBe
(
false
)
;
}
)
;
describe
(
'validateTokenEnvelope'
,
function
(
)
{
it
(
'returns strict strategy for fully valid token envelope'
,
function
(
)
{
const
=
{
:
'test-token'
,
:
1234567890
,
:
300
,
:
'free_limited_copilot'
,
:
true
,
:
false
,
:
false
,
:
false
,
:
false
,
:
false
,
:
'enabled'
,
:
'enabled'
,
}
;
const
=
validateTokenEnvelope
(
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
'strict'
)
;
if
(
.
===
'strict'
)
{
expect
(
.
)
.
toBeDefined
(
)
;
expect
(
.
.
)
.
toBe
(
'test-token'
)
;
expect
(
.
.
)
.
toBe
(
1234567890
)
;
expect
(
.
.
)
.
toBe
(
300
)
;
expect
(
.
.
)
.
toBe
(
'free_limited_copilot'
)
;
}
}
)
;
it
(
'returns strict strategy for minimal token with only required fields'
,
function
(
)
{
const
=
{
:
'test-token'
,
:
1234567890
,
:
300
,
}
;
const
=
validateTokenEnvelope
(
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
'strict'
)
;
if
(
.
===
'strict'
)
{
expect
(
.
)
.
toBeDefined
(
)
;
expect
(
.
.
)
.
toBe
(
'test-token'
)
;
expect
(
.
.
)
.
toBe
(
1234567890
)
;
expect
(
.
.
)
.
toBe
(
300
)
;
}
}
)
;
it
(
'returns fallback strategy when optional field has wrong type'
,
function
(
)
{
const
=
{
:
'test-token'
,
:
1234567890
,
:
300
,
:
12345
,
}
;
const
=
validateTokenEnvelope
(
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
'fallback'
)
;
if
(
.
===
'fallback'
)
{
expect
(
.
)
.
toContain
(
'sku'
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
expect
(
.
)
.
toBeDefined
(
)
;
expect
(
.
.
)
.
toBe
(
'test-token'
)
;
expect
(
.
.
)
.
toBe
(
1234567890
)
;
expect
(
.
.
)
.
toBe
(
300
)
;
}
}
)
;
it
(
'returns fallback strategy when server changes enum values'
,
function
(
)
{
const
=
{
:
'test-token'
,
:
1234567890
,
:
300
,
:
'new_unknown_value'
,
}
;
const
=
validateTokenEnvelope
(
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
'fallback'
)
;
if
(
.
===
'fallback'
)
{
expect
(
.
)
.
toContain
(
'public_suggestions'
)
;
expect
(
.
)
.
toBeDefined
(
)
;
expect
(
.
.
)
.
toBe
(
'test-token'
)
;
}
}
)
;
it
(
'returns failed strategy when missing critical token field'
,
function
(
)
{
const
=
{
:
1234567890
,
:
300
,
}
;
const
=
validateTokenEnvelope
(
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
'failed'
)
;
if
(
.
===
'failed'
)
{
expect
(
.
)
.
toBeDefined
(
)
;
expect
(
.
)
.
toContain
(
'token'
)
;
}
}
)
;
it
(
'returns failed strategy when missing critical expires_at field'
,
function
(
)
{
const
=
{
:
'test-token'
,
:
300
,
}
;
const
=
validateTokenEnvelope
(
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
'failed'
)
;
if
(
.
===
'failed'
)
{
expect
(
.
)
.
toContain
(
'expires_at'
)
;
}
}
)
;
it
(
'returns failed strategy when missing critical refresh_in field'
,
function
(
)
{
const
=
{
:
'test-token'
,
:
1234567890
,
}
;
const
=
validateTokenEnvelope
(
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
'failed'
)
;
if
(
.
===
'failed'
)
{
expect
(
.
)
.
toContain
(
'refresh_in'
)
;
}
}
)
;
it
(
'returns failed strategy for null input'
,
function
(
)
{
const
=
validateTokenEnvelope
(
null
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
'failed'
)
;
}
)
;
it
(
'returns failed strategy for undefined input'
,
function
(
)
{
const
=
validateTokenEnvelope
(
undefined
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
'failed'
)
;
}
)
;
it
(
'returns failed strategy when critical field has wrong type'
,
function
(
)
{
const
=
{
:
12345
,
:
1234567890
,
:
300
,
}
;
const
=
validateTokenEnvelope
(
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
'failed'
)
;
if
(
.
===
'failed'
)
{
expect
(
.
)
.
toContain
(
'token'
)
;
}
}
)
;
}
)
;
}
)
;
describe
(
'CopilotToken class'
,
function
(
)
{
it
(
'isFreeUser returns true for free_limited_copilot sku'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'free_limited_copilot'
}
)
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'isNoAuthUser returns true for no_auth_limited_copilot sku'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'no_auth_limited_copilot'
}
)
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
true
)
;
}
)
;
it
(
'isTelemetryEnabled reflects token state'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'enabled'
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'disabled'
}
)
)
;
expect
(
.
isTelemetryEnabled
(
)
)
.
toBe
(
true
)
;
expect
(
.
isTelemetryEnabled
(
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'isPublicSuggestionsEnabled reflects token state'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'enabled'
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'disabled'
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'unconfigured'
}
)
)
;
expect
(
.
isPublicSuggestionsEnabled
(
)
)
.
toBe
(
true
)
;
expect
(
.
isPublicSuggestionsEnabled
(
)
)
.
toBe
(
false
)
;
expect
(
.
isPublicSuggestionsEnabled
(
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'copilotPlan returns correct plan type'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'free_limited_copilot'
,
:
'free'
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'copilot_individual'
,
:
'individual'
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'copilot_business'
,
:
'business'
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'copilot_enterprise'
,
:
'enterprise'
}
)
)
;
expect
(
.
)
.
toBe
(
'free'
)
;
expect
(
.
)
.
toBe
(
'individual'
)
;
expect
(
.
)
.
toBe
(
'business'
)
;
expect
(
.
)
.
toBe
(
'enterprise'
)
;
}
)
;
it
(
'isChatQuotaExceeded for free users with zero quota'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'free_limited_copilot'
,
:
{
:
0
,
:
10
}
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'free_limited_copilot'
,
:
{
:
5
,
:
10
}
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'copilot_individual'
,
:
{
:
0
,
:
0
}
}
)
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'isCompletionsQuotaExceeded for free users with zero quota'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'free_limited_copilot'
,
:
{
:
10
,
:
0
}
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'free_limited_copilot'
,
:
{
:
10
,
:
5
}
}
)
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'isInternal detects GitHub and Microsoft organizations'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
[
'4535c7beffc844b46bb1ed4aa04d759a'
]
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
[
'a5db0bcaae94032fe715fb34a5e4bce2'
]
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
[
'some-other-org'
]
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
[
]
}
)
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
false
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'codeQuoteEnabled reflects token state'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
true
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
false
}
)
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'isCopilotCodeReviewEnabled reflects token state'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
true
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
false
}
)
)
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toBe
(
false
)
;
}
)
;
it
(
'isExpandedClientSideIndexingEnabled reflects token state'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
true
}
)
)
;
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
false
}
)
)
;
expect
(
.
isExpandedClientSideIndexingEnabled
(
)
)
.
toBe
(
true
)
;
expect
(
.
isExpandedClientSideIndexingEnabled
(
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'isBlackbirdExternalIndexingEnabled returns false when flag is absent'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'tid=test'
}
)
)
;
expect
(
.
isBlackbirdExternalIndexingEnabled
(
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'isBlackbirdExternalIndexingEnabled returns false when flag is 0'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'blackbird_external_indexing=0;tid=test'
}
)
)
;
expect
(
.
isBlackbirdExternalIndexingEnabled
(
)
)
.
toBe
(
false
)
;
}
)
;
it
(
'isBlackbirdExternalIndexingEnabled returns true when flag is 1'
,
function
(
)
{
const
=
new
CopilotToken
(
createTestExtendedTokenInfo
(
{
:
'blackbird_external_indexing=1;tid=test'
}
)
)
;
expect
(
.
isBlackbirdExternalIndexingEnabled
(
)
)
.
toBe
(
true
)
;
}
)
;
}
)
;
class
StaticFetcherService
implements
IFetcherService
{
declare
readonly
:
undefined
;
readonly
=
.
;
readonly
=
.
;
public
=
new
Map< string , FetchOptions>
(
)
;
constructor
(
readonly
:
any
)
{
}
fetchWithPagination < T >
(
:
string
,
:
<
T
>
)
:
Promise
<
T
[
]
>
{
throw
new
Error
(
'Method not implemented.'
)
;
}
getUserAgentLibrary
(
)
:
string
{
return
'test'
;
}
async
fetch
(
:
string
,
:
)
:
Promise
<
>
{
this
.
.
set
(
,
)
;
if
(
.
endsWith
(
'copilot_internal/v2/token'
)
)
{
if
(
this
.
===
'NETWORK_FAILURE'
)
{
throw
new
Error
(
'Network request failed'
)
;
}
return
createFakeResponse
(
200
,
this
.
)
;
}
else
if
(
.
endsWith
(
'copilot_internal/notification'
)
)
{
return
createFakeResponse
(
200
,
''
)
;
}
return
createFakeResponse
(
404
,
''
)
;
}
createWebSocket
(
:
string
)
:
{
throw
new
Error
(
'Method not implemented.'
)
;
}
disconnectAll
(
)
:
Promise
<
unknown
>
{
throw
new
Error
(
'Method not implemented.'
)
;
}
makeAbortController
(
)
:
{
throw
new
Error
(
'Method not implemented.'
)
;
}
isAbortError
(
:
any
)
:
boolean
{
throw
new
Error
(
'Method not implemented.'
)
;
}
isInternetDisconnectedError
(
:
any
)
:
boolean
{
throw
new
Error
(
'Method not implemented.'
)
;
}
isFetcherError
(
:
any
)
:
boolean
{
throw
new
Error
(
'Method not implemented.'
)
;
}
isNetworkProcessCrashedError
(
:
any
)
:
boolean
{
throw
new
Error
(
'Method not implemented.'
)
;
}
getUserMessageForFetcherError
(
:
any
)
:
string
{
throw
new
Error
(
'Method not implemented.'
)
;
}
}
class
ErrorFetcherService
extends
StaticFetcherService
{
constructor
(
private
readonly
:
any
)
{
super
(
{
}
)
;
}
fetch
(
:
string
,
:
)
:
Promise
<
>
{
throw
this
.
;
}
}
class
HttpStatusFetcherService
extends
StaticFetcherService
{
constructor
(
private
readonly
:
number
)
{
super
(
{
}
)
;
}
async
fetch
(
:
string
,
:
)
:
Promise
<
>
{
this
.
.
set
(
,
)
;
return
createFakeResponse
(
this
.
,
{
}
)
;
}
}
class
RateLimitedFetcherService
extends
StaticFetcherService
{
constructor
(
)
{
super
(
{
}
)
;
}
async
fetch
(
:
string
,
:
)
:
Promise
<
>
{
this
.
.
set
(
,
)
;
return
.
fromText
(
429
,
'Too Many Requests'
,
new
TestHeaders
(
{
'retry-after'
:
'120'
}
)
,
JSON
.
stringify
(
{
:
'rate limited'
}
)
,
'test-stub'
,
)
;
}
}
class
TestHeaders
implements
IHeaders
{
constructor
(
private
readonly
:
<
string
,
string
>
)
{
}
get
(
:
string
)
:
string
|
null
{
return
this
.
[
.
toLowerCase
(
)
]
??
null
;
}
*
[
.
]
(
)
:
<
[
string
,
string
]
>
{
yield
*
.
entries
(
this
.
)
;
}
}