ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / workbench / contrib / chat / test / browser / pluginGitCommandService.test.ts 518 строк · изменён 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
import assert from 'assert' ;
import { CancellationToken } from '../../../../../base/common/cancellation.js' ;
import { bufferToStream, VSBuffer } from '../../../../../base/common/buffer.js' ;
import { DisposableStore } from '../../../../../base/common/lifecycle.js' ;
import { Schemas } from '../../../../../base/common/network.js' ;
import { URI } from '../../../../../base/common/uri.js' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js' ;
import { FileService }
InMemoryFileSystemProvider
NullLogService
IRequestContext IRequestOptions
IRequestService
InMemoryStorageService
AuthenticationSession IAuthenticationService
BrowserPluginGitCommandService
parseGitHubCloneUrl
disposables
fileService FileService
requestStub StubRequestService
storage InMemoryStorageService
service BrowserPluginGitCommandService
fileService disposables
disposables fileService Schemas inMemory disposables
requestStub
storage disposables
service
fileService
requestStub IRequestService
storage
disposables
targetDir scheme Schemas inMemory path
assert owner repo
assert owner repo
assert owner repo
assert owner repo
assert
assert
assert
assert
assert
assert
assert
service targetDir
requestStub sha
requestStub
service targetDir
readme fileService targetDir
assert readme value
index fileService targetDir
assert index value
assert service targetDir
requestStub
assert
service targetDir
requestStub VSBuffer
captured
service targetDir
assert
err
captured err
assert captured captured name
state createSessionCalls
service
fileService
requestStub IRequestService
storage
createdAccessToken state
requestStub
requestStub sha
requestStub
service targetDir
file fileService targetDir
assert file value
assert state createSessionCalls
service
fileService
requestStub IRequestService
storage
sessions
requestStub sha
requestStub
service targetDir
assert requestStub requests headers Authorization
assert requestStub requests headers Authorization
assert requestStub requests headers Authorization
state createSessionCalls
service
fileService
requestStub IRequestService
storage
sessions state
requestStub
requestStub sha
requestStub
service targetDir
file fileService targetDir
assert file value
assert requestStub requests headers Authorization
assert requestStub requests headers Authorization
assert requestStub requests headers Authorization
assert state createSessionCalls
requestStub sha
requestStub
service targetDir
requestStub sha
requestStub VSBuffer
assert service targetDir
keep fileService targetDir
assert keep value
assert service targetDir
requestStub sha
requestStub
sha
truncated
tree
path mode type sha size
path mode type sha size
path mode type sha
requestStub content encoding
service targetDir
assert fileService targetDir value
assert fileService targetDir
assert fileService targetDir
requestStub sha
requestStub
service targetDir
requestStub sha
assert service targetDir
requestStub sha
requestStub
service targetDir
requestStub sha
requestStub
assert service targetDir
a fileService targetDir
assert a value
assert service targetDir
assert service targetDir
requestStub sha
requestStub
service targetDir
requestStub sha
requestStub
assert service targetDir
assert fileService targetDir
keep fileService targetDir
assert keep value
requestStub sha
requestStub
sha
truncated
tree
path mode type sha size
path mode type sha size
requestStub content encoding
service targetDir
safe fileService targetDir
assert safe value
escapedSibling scheme targetDir scheme path
assert fileService escapedSibling
requestStub sha
requestStub
sha
truncated
tree
path mode type sha size
path mode type sha size
requestStub content encoding
service targetDir
safe fileService targetDir
assert safe value
assert fileService targetDir
requestStub sha
requestStub
service targetDir
service targetDir
requestStub sha
requestStub
service targetDir
requestStub
service targetDir
a fileService targetDir
assert a value
assert service targetDir
commit
requestStub sha commit
requestStub commit
service targetDir
service targetDir commit
assert service targetDir commit
cachedCommit
pinnedCommit
requestStub sha cachedCommit
requestStub cachedCommit
service targetDir
requestStub sha cachedCommit
assert service targetDir pinnedCommit
assert service targetDir cachedCommit
assert service targetDir
requestStub sha
requestStub
service targetDir
assert service targetDir
assert service targetDir
service targetDir
service targetDir
assert service targetDir
methodMatcher
urlMatcher RegExp
IRequestContext
_serviceBrand
_queue QueuedResponse
requests IRequestOptions
method urlMatcher RegExp IRequestContext
_queue methodMatcher method urlMatcher response
options IRequestOptions _token CancellationToken IRequestContext
requests options
url options url
method options type
idx _queue q q methodMatcher method q urlMatcher url
idx
response _queue idx
statusCode body VSBuffer VSBuffer headers Record IRequestContext
res statusCode headers
stream body
statusCode body IRequestContext
statusCode VSBuffer body
stub StubRequestService sha files Record
entries Object files
tree entries path content i
path
mode
type
sha
size content length
stub sha tree truncated
entries content i
stub tree i sha
content content
encoding
blobSha RegExp
bytes Uint8Array
binary
i i bytes length i
binary String bytes i
binary
value
value
sessions AuthenticationSession
createdAccessToken
state createSessionCalls
options IStubAuthenticationServiceOptions IAuthenticationService
options sessions
options state
options state createSessionCalls
options createdAccessToken
accessToken options createdAccessToken
IAuthenticationService
accessToken scopes AuthenticationSession
id accessToken
accessToken
account label id
scopes
from
'../../../../../platform/files/common/fileService.js'
;
import
{
}
from
'../../../../../platform/files/common/inMemoryFilesystemProvider.js'
;
import
{
}
from
'../../../../../platform/log/common/log.js'
;
import
{
,
}
from
'../../../../../base/parts/request/common/request.js'
;
import
{
}
from
'../../../../../platform/request/common/request.js'
;
import
{
}
from
'../../../../../platform/storage/common/storage.js'
;
import
{
,
}
from
'../../../../services/authentication/common/authentication.js'
;
import
{
}
from
'../../browser/pluginGitCommandService.js'
;
import
{
}
from
'../../browser/githubRepoFetcher.js'
;
suite
(
'BrowserPluginGitCommandService'
,
(
)
=>
{
const
=
new
DisposableStore
(
)
;
let
:
;
let
:
;
let
:
;
let
:
;
setup
(
(
)
=>
{
=
.
add
(
new
FileService
(
new
NullLogService
(
)
)
)
;
.
add
(
.
registerProvider
(
.
,
.
add
(
new
InMemoryFileSystemProvider
(
)
)
)
)
;
=
new
StubRequestService
(
)
;
=
.
add
(
new
InMemoryStorageService
(
)
)
;
=
new
BrowserPluginGitCommandService
(
,
new
NullLogService
(
)
,
as
unknown
as
,
,
stubAuthenticationService
(
)
,
)
;
}
)
;
teardown
(
(
)
=>
.
clear
(
)
)
;
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
const
=
URI
.
from
(
{
:
.
,
:
'/cache/github.com/octocat/hello'
}
)
;
suite
(
'parseGitHubCloneUrl'
,
(
)
=>
{
test
(
'parses canonical github HTTPS clone URL'
,
(
)
=>
{
.
deepStrictEqual
(
parseGitHubCloneUrl
(
'https://github.com/octocat/Hello-World.git'
)
,
{
:
'octocat'
,
:
'Hello-World'
}
)
;
}
)
;
test
(
'strips trailing slash and missing .git suffix'
,
(
)
=>
{
.
deepStrictEqual
(
parseGitHubCloneUrl
(
'https://github.com/octocat/Hello-World/'
)
,
{
:
'octocat'
,
:
'Hello-World'
}
)
;
.
deepStrictEqual
(
parseGitHubCloneUrl
(
'https://github.com/octocat/Hello-World'
)
,
{
:
'octocat'
,
:
'Hello-World'
}
)
;
.
deepStrictEqual
(
parseGitHubCloneUrl
(
'https://github.com/octocat/Hello-World.git/'
)
,
{
:
'octocat'
,
:
'Hello-World'
}
)
;
}
)
;
test
(
'rejects URLs with extra path segments'
,
(
)
=>
{
.
strictEqual
(
parseGitHubCloneUrl
(
'https://github.com/octocat/Hello-World/issues/42'
)
,
undefined
)
;
.
strictEqual
(
parseGitHubCloneUrl
(
'https://github.com/octocat/Hello-World/tree/main'
)
,
undefined
)
;
}
)
;
test
(
'rejects non-HTTPS, non-GitHub, and malformed URLs'
,
(
)
=>
{
.
strictEqual
(
parseGitHubCloneUrl
(
'git@github.com:octocat/repo.git'
)
,
undefined
)
;
.
strictEqual
(
parseGitHubCloneUrl
(
'https://gitlab.com/octocat/repo.git'
)
,
undefined
)
;
.
strictEqual
(
parseGitHubCloneUrl
(
'https://github.com/octocat'
)
,
undefined
)
;
.
strictEqual
(
parseGitHubCloneUrl
(
'not-a-url'
)
,
undefined
)
;
}
)
;
}
)
;
suite
(
'cloneRepository'
,
(
)
=>
{
test
(
'rejects non-GitHub clone URLs with an actionable message'
,
async
(
)
=>
{
await
.
rejects
(
(
)
=>
.
cloneRepository
(
'https://gitlab.com/foo/bar.git'
,
)
,
/ can only be installed from GitHub HTTPS URLs /
,
)
;
}
)
;
test
(
'downloads tree + blobs and persists SHA metadata'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'deadbeef'
}
)
)
;
queueRepoFetch
(
,
'deadbeef'
,
{
'README.md'
:
'hello\n'
,
'src/index.js'
:
'console.log(1);'
,
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'README.md'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'hello\n'
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'src/index.js'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'console.log(1);'
)
;
.
strictEqual
(
await
.
revParse
(
,
'HEAD'
)
,
'deadbeef'
)
;
}
)
;
test
(
'surfaces a sign-in message on 401 when auth is unavailable'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
plainResponse
(
401
)
)
;
await
.
rejects
(
(
)
=>
.
cloneRepository
(
'https://github.com/octocat/Private.git'
,
,
'main'
)
,
/ Sign in to GitHub /
,
)
;
}
)
;
test
(
'surfaces a GitHubRateLimitError on 403 with X-RateLimit-Remaining: 0'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
plainResponse
(
403
,
.
fromString
(
'rate limit'
)
,
{
'x-ratelimit-remaining'
:
'0'
,
'retry-after'
:
'60'
,
}
)
)
;
let
:
unknown
;
try
{
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
.
fail
(
'expected rejection'
)
;
}
catch
(
)
{
=
;
}
.
ok
(
instanceof
Error
&&
.
===
'GitHubRateLimitError'
,
` expected GitHubRateLimitError, got ${ ( captured as Error) ?. name} `
)
;
}
)
;
test
(
'requests GitHub auth and retries when GitHub returns 403'
,
async
(
)
=>
{
const
=
{
:
0
}
;
=
new
BrowserPluginGitCommandService
(
,
new
NullLogService
(
)
,
as
unknown
as
,
,
stubAuthenticationService
(
{
:
'repo-token'
,
}
)
,
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
plainResponse
(
403
)
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
queueRepoFetch
(
,
'sha1'
,
{
'private.txt'
:
'secret'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Private.git'
,
,
'main'
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'private.txt'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'secret'
)
;
.
strictEqual
(
.
,
1
)
;
}
)
;
test
(
'uses an existing signed-in GitHub session before falling back to anonymous requests'
,
async
(
)
=>
{
=
new
BrowserPluginGitCommandService
(
,
new
NullLogService
(
)
,
as
unknown
as
,
,
stubAuthenticationService
(
{
:
[
createAuthenticationSession
(
'signed-in-token'
)
]
}
)
,
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
queueRepoFetch
(
,
'sha1'
,
{
'auth.txt'
:
'authed'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Private.git'
,
,
'main'
)
;
.
strictEqual
(
.
[
0
]
.
?.
,
'Bearer signed-in-token'
)
;
.
strictEqual
(
.
[
1
]
.
?.
,
'Bearer signed-in-token'
)
;
.
strictEqual
(
.
[
2
]
.
?.
,
'Bearer signed-in-token'
)
;
}
)
;
test
(
'falls back to anonymous when the signed-in GitHub session is rejected'
,
async
(
)
=>
{
const
=
{
:
0
}
;
=
new
BrowserPluginGitCommandService
(
,
new
NullLogService
(
)
,
as
unknown
as
,
,
stubAuthenticationService
(
{
:
[
createAuthenticationSession
(
'sso-blocked-token'
)
]
,
}
)
,
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
plainResponse
(
403
)
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
queueRepoFetch
(
,
'sha1'
,
{
'public.txt'
:
'public'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Public.git'
,
,
'main'
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'public.txt'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'public'
)
;
.
strictEqual
(
.
[
0
]
.
?.
,
'Bearer sso-blocked-token'
)
;
.
strictEqual
(
.
[
1
]
.
?.
,
undefined
)
;
.
strictEqual
(
.
[
2
]
.
?.
,
undefined
)
;
.
strictEqual
(
.
,
0
)
;
}
)
;
test
(
'failed extraction leaves the previous targetDir intact'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
queueRepoFetch
(
,
'sha1'
,
{
'keep.txt'
:
'preserved'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha2'
}
)
)
;
.
queue
(
'GET'
,
/ \/ git\/ trees\/ sha2/
,
plainResponse
(
500
,
.
fromString
(
'boom'
)
)
)
;
await
.
rejects
(
(
)
=>
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'keep.txt'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'preserved'
)
;
.
strictEqual
(
await
.
revParse
(
,
'HEAD'
)
,
'sha1'
)
;
}
)
;
test
(
'skips symlink and submodule entries'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
.
queue
(
'GET'
,
/ \/ git\/ trees\/ sha1/
,
jsonResponse
(
200
,
{
:
'sha1'
,
:
false
,
:
[
{
:
'README.md'
,
:
'100644'
,
:
'blob'
,
:
'b-readme'
,
:
3
}
,
{
:
'link.txt'
,
:
'120000'
,
:
'blob'
,
:
'b-link'
,
:
8
}
,
{
:
'subrepo'
,
:
'160000'
,
:
'commit'
,
:
'b-sub'
}
,
]
,
}
)
)
;
.
queue
(
'GET'
,
/ \/ git\/ blobs\/ b-readme$ /
,
jsonResponse
(
200
,
{
:
encodeBase64
(
new
TextEncoder
(
)
.
encode
(
'hi\n'
)
)
,
:
'base64'
}
)
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
.
strictEqual
(
(
await
.
readFile
(
URI
.
joinPath
(
,
'README.md'
)
)
)
.
.
toString
(
)
,
'hi\n'
)
;
.
strictEqual
(
await
.
exists
(
URI
.
joinPath
(
,
'link.txt'
)
)
,
false
)
;
.
strictEqual
(
await
.
exists
(
URI
.
joinPath
(
,
'subrepo'
)
)
,
false
)
;
}
)
;
}
)
;
suite
(
'pull'
,
(
)
=>
{
test
(
'returns false when upstream SHA is unchanged'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
queueRepoFetch
(
,
'sha1'
,
{
'a.txt'
:
'a'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
.
strictEqual
(
await
.
pull
(
)
,
false
)
;
}
)
;
test
(
're-downloads tree and returns true when SHA moves'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
queueRepoFetch
(
,
'sha1'
,
{
'a.txt'
:
'old'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha2'
}
)
)
;
queueRepoFetch
(
,
'sha2'
,
{
'a.txt'
:
'new'
}
)
;
.
strictEqual
(
await
.
pull
(
)
,
true
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'a.txt'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'new'
)
;
.
strictEqual
(
await
.
revParse
(
,
'HEAD'
)
,
'sha2'
)
;
}
)
;
test
(
'throws when called for a target with no cached metadata'
,
async
(
)
=>
{
await
.
rejects
(
(
)
=>
.
pull
(
)
,
/ no cached metadata /
)
;
}
)
;
test
(
'clears stale files from a prior extraction'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
queueRepoFetch
(
,
'sha1'
,
{
'keep.txt'
:
'k1'
,
'removed.txt'
:
'will be deleted'
,
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha2'
}
)
)
;
queueRepoFetch
(
,
'sha2'
,
{
'keep.txt'
:
'k2'
}
)
;
.
strictEqual
(
await
.
pull
(
)
,
true
)
;
.
strictEqual
(
await
.
exists
(
URI
.
joinPath
(
,
'removed.txt'
)
)
,
false
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'keep.txt'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'k2'
)
;
}
)
;
test
(
'rejects path-traversal entries in the tree'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
.
queue
(
'GET'
,
/ \/ git\/ trees\/ sha1/
,
jsonResponse
(
200
,
{
:
'sha1'
,
:
false
,
:
[
{
:
'safe.txt'
,
:
'100644'
,
:
'blob'
,
:
'b-safe'
,
:
4
}
,
{
:
'../escaped.txt'
,
:
'100644'
,
:
'blob'
,
:
'b-escape'
,
:
4
}
,
]
,
}
)
)
;
.
queue
(
'GET'
,
/ \/ git\/ blobs\/ b-safe$ /
,
jsonResponse
(
200
,
{
:
encodeBase64
(
new
TextEncoder
(
)
.
encode
(
'safe'
)
)
,
:
'base64'
}
)
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'safe.txt'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'safe'
)
;
const
=
URI
.
from
(
{
:
.
,
:
'/cache/github.com/octocat/escaped.txt'
}
)
;
.
strictEqual
(
await
.
exists
(
)
,
false
)
;
}
)
;
test
(
'rejects backslash-traversal entries (Windows path separator)'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'sha1'
}
)
)
;
.
queue
(
'GET'
,
/ \/ git\/ trees\/ sha1/
,
jsonResponse
(
200
,
{
:
'sha1'
,
:
false
,
:
[
{
:
'safe.txt'
,
:
'100644'
,
:
'blob'
,
:
'b-safe'
,
:
4
}
,
{
:
'..\\..\\escaped.txt'
,
:
'100644'
,
:
'blob'
,
:
'b-escape'
,
:
4
}
,
]
,
}
)
)
;
.
queue
(
'GET'
,
/ \/ git\/ blobs\/ b-safe$ /
,
jsonResponse
(
200
,
{
:
encodeBase64
(
new
TextEncoder
(
)
.
encode
(
'safe'
)
)
,
:
'base64'
}
)
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'safe.txt'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'safe'
)
;
.
strictEqual
(
await
.
exists
(
URI
.
joinPath
(
,
'..\\..\\escaped.txt'
)
)
,
false
)
;
}
)
;
}
)
;
suite
(
'checkout'
,
(
)
=>
{
test
(
'no-ops when the requested SHA matches the cached SHA'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'aabbccddeeff00112233445566778899aabbccdd'
}
)
)
;
queueRepoFetch
(
,
'aabbccddeeff00112233445566778899aabbccdd'
,
{
'a.txt'
:
'a'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
await
.
checkout
(
,
'aabbccddeeff00112233445566778899aabbccdd'
,
true
)
;
}
)
;
test
(
're-extracts when the SHA differs'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'1111111111111111111111111111111111111111'
}
)
)
;
queueRepoFetch
(
,
'1111111111111111111111111111111111111111'
,
{
'a.txt'
:
'old'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
queueRepoFetch
(
,
'2222222222222222222222222222222222222222'
,
{
'a.txt'
:
'new'
}
)
;
await
.
checkout
(
,
'2222222222222222222222222222222222222222'
,
true
)
;
const
=
await
.
readFile
(
URI
.
joinPath
(
,
'a.txt'
)
)
;
.
strictEqual
(
.
.
toString
(
)
,
'new'
)
;
.
strictEqual
(
await
.
revParse
(
,
'HEAD'
)
,
'2222222222222222222222222222222222222222'
)
;
}
)
;
test
(
'checkoutCommit accepts a cached exact SHA without a request'
,
async
(
)
=>
{
const
=
'aabbccddeeff00112233445566778899aabbccdd'
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
}
)
)
;
queueRepoFetch
(
,
,
{
'a.txt'
:
'a'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
await
.
checkoutCommit
(
,
.
toUpperCase
(
)
)
;
.
strictEqual
(
await
.
revParse
(
,
'HEAD'
)
,
)
;
}
)
;
test
(
'checkoutCommit rejects when a SHA resolves to another commit'
,
async
(
)
=>
{
const
=
'1111111111111111111111111111111111111111'
;
const
=
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
;
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
}
)
)
;
queueRepoFetch
(
,
,
{
'a.txt'
:
'a'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
.
queue
(
'GET'
,
new
RegExp
(
` /commits/ ${ pinnedCommit} $ `
)
,
jsonResponse
(
200
,
{
:
}
)
)
;
await
.
rejects
(
(
)
=>
.
checkoutCommit
(
,
)
,
/ resolved to a different commit /
)
;
.
strictEqual
(
await
.
revParse
(
,
'HEAD'
)
,
)
;
}
)
;
test
(
'throws when called for a target with no cached metadata'
,
async
(
)
=>
{
await
.
rejects
(
(
)
=>
.
checkout
(
,
'abc'
)
,
/ no cached metadata /
)
;
}
)
;
}
)
;
suite
(
'revParse'
,
(
)
=>
{
test
(
'throws when asked for an unrelated full SHA'
,
async
(
)
=>
{
.
queue
(
'GET'
,
/ \/ commits\/ main$ /
,
jsonResponse
(
200
,
{
:
'aabbccddeeff00112233445566778899aabbccdd'
}
)
)
;
queueRepoFetch
(
,
'aabbccddeeff00112233445566778899aabbccdd'
,
{
'a.txt'
:
'a'
}
)
;
await
.
cloneRepository
(
'https://github.com/octocat/Hello-World.git'
,
,
'main'
)
;
.
strictEqual
(
await
.
revParse
(
,
'aabbccddeeff00112233445566778899aabbccdd'
)
,
'aabbccddeeff00112233445566778899aabbccdd'
)
;
await
.
rejects
(
(
)
=>
.
revParse
(
,
'1111111111111111111111111111111111111111'
)
,
/ only HEAD /
)
;
}
)
;
}
)
;
test
(
'fetch / fetchRepository / revListCount are inert'
,
async
(
)
=>
{
await
.
fetch
(
)
;
await
.
fetchRepository
(
)
;
.
strictEqual
(
await
.
revListCount
(
,
'HEAD'
,
'@{u}'
)
,
0
)
;
}
)
;
}
)
;
interface
QueuedResponse
{
readonly
:
string
;
readonly
:
;
readonly
response
:
(
)
=>
;
}
class
StubRequestService
implements
Partial< IRequestService>
{
declare
readonly
:
undefined
;
private
readonly
:
[
]
=
[
]
;
readonly
:
[
]
=
[
]
;
queue
(
:
string
,
:
,
response
:
(
)
=>
)
:
void
{
this
.
.
push
(
{
:
,
,
}
)
;
}
async
request
(
:
,
:
)
:
Promise
<
>
{
this
.
.
push
(
)
;
const
=
.
??
''
;
const
=
.
??
'GET'
;
const
=
this
.
.
findIndex
(
=>
.
===
&&
.
.
test
(
)
)
;
if
(
===
-
1
)
{
throw
new
Error
(
` No queued response for ${ method} ${ url} `
)
;
}
const
[
{
}
]
=
this
.
.
splice
(
,
1
)
;
return
response
(
)
;
}
}
function
plainResponse
(
:
number
,
:
=
.
alloc
(
0
)
,
:
<
string
,
string
>
=
{
}
)
:
(
)
=>
{
return
(
)
=>
(
{
:
{
,
}
,
:
bufferToStream
(
)
,
}
)
;
}
function
jsonResponse
(
:
number
,
:
unknown
)
:
(
)
=>
{
return
plainResponse
(
,
.
fromString
(
JSON
.
stringify
(
)
)
)
;
}
function
queueRepoFetch
(
:
,
:
string
,
:
<
string
,
string
>
)
:
void
{
const
=
.
entries
(
)
;
const
=
.
map
(
(
[
,
]
,
)
=>
(
{
,
:
'100644'
,
:
'blob'
as
const
,
:
` b ${ i} `
,
:
.
,
}
)
)
;
.
queue
(
'GET'
,
new
RegExp
(
` /git/trees/ ${ escapeForRegExp ( sha) } \\?recursive=1$ `
)
,
jsonResponse
(
200
,
{
,
,
:
false
}
)
)
;
.
forEach
(
(
[
,
]
,
)
=>
{
.
queue
(
'GET'
,
blobShaMatcher
(
[
]
.
)
,
jsonResponse
(
200
,
{
:
encodeBase64
(
new
TextEncoder
(
)
.
encode
(
)
)
,
:
'base64'
,
}
)
)
;
}
)
;
}
function
blobShaMatcher
(
:
string
)
:
{
return
new
RegExp
(
` /git/blobs/ ${ escapeForRegExp ( blobSha) } $ `
)
;
}
function
encodeBase64
(
:
)
:
string
{
let
=
''
;
for
(
let
=
0
;
<
.
;
++
)
{
+=
.
fromCharCode
(
[
]
)
;
}
return
btoa
(
)
;
}
function
escapeForRegExp
(
:
string
)
:
string
{
return
.
replace
(
/ [ .*+?^${}()|[\] \\ ] / g
,
'\\$&'
)
;
}
interface
IStubAuthenticationServiceOptions
{
readonly
?
:
readonly
[
]
;
readonly
?
:
string
;
readonly
?
:
{
:
number
}
;
}
function
stubAuthenticationService
(
:
=
{
}
)
:
{
return
{
getSessions
:
async
(
)
=>
.
??
[
]
,
createSession
:
async
(
)
=>
{
if
(
.
)
{
.
.
++
;
}
if
(
!
.
)
{
throw
new
Error
(
'No GitHub session available'
)
;
}
return
{
:
.
}
;
}
,
}
as
unknown
as
;
}
function
createAuthenticationSession
(
:
string
,
:
readonly
string
[
]
=
[
]
)
:
{
return
{
:
,
,
:
{
:
'octocat'
,
:
'octocat'
}
,
,
}
;
}