ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / platform / agentHost / test / node / agentHostGitService.test.ts 571 строк · изменён 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
import assert from 'assert' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js' ;
import { formatGitError, getRemoteTrackingRef, GitCheckoutProgressParser, isRetryableWorktreeRemovalError, parseChangedPaths, parseDefaultBranchRef, parseFetchRemoteUrls, parseGitDiffRawNumstat, parseGitHubRepoFromRemote, parseGitStatusV2, parseHasGitHubRemote, parseSingleLsTreeEntry, parseUntrackedPaths, summarizeStderrForError } from '../../node/agentHostGitService.js' ;
import { buildGitBlobUri } from '../../node/gitDiffContent.js' ;
import { URI } from '../../../../base/common/uri.js' ;
getBranchCompletions resolveDiffBaseBranchName
needsSessionGitStateRefresh
assert
branch
pullRequest
branch
branchName
remoteBranch
remoteRef
sourceRef
pullRequest
branchName
remoteBranch
remoteRef
sourceRef
assert
currentBranch defaultBranch limit
assert
currentBranch defaultBranch
assert
currentBranch defaultBranch query
chunks filesDone filesTotal
reported filesDone filesTotal
parser progress reported progress
chunk chunks
parser chunk
reported
assert
filesDone filesTotal
filesDone filesTotal
filesDone filesTotal
filesDone filesTotal
assert
filesDone filesTotal
out
assert out
branchName
isDetachedHead
upstreamBranchName
outgoingChanges
incomingChanges
uncommittedChanges
out
assert out
branchName
isDetachedHead
upstreamBranchName
outgoingChanges
incomingChanges
uncommittedChanges
out
assert out
branchName
isDetachedHead
upstreamBranchName
outgoingChanges
incomingChanges
uncommittedChanges
assert
assert
neverComputed
probeFailureRemnant baseBranchName
detachedHead isDetachedHead baseBranchName
onABranch branchName baseBranchName
neverComputed
probeFailureRemnant
detachedHead
onABranch
assert
assert
assert
assert
assert
assert
assert
assert
assert
out
assert out owner repo
out
assert out
out
assert out owner repo
out
assert out owner repo
out
assert out owner repo
out
assert out owner repo
out
assert out owner repo
assert
assert
out
assert out
assert
assert
assert
assert
out
assert out
out
assert out
out
assert out
root
sessionUri
sha
segments
out segments
diffs out root sessionUri sha
assert diffs
before uri content uri sessionUri sha
after uri content uri
diff added removed
after uri content uri
diff added removed
before uri content uri sessionUri sha
diff added removed
before uri content uri sessionUri sha
after uri content uri
diff added removed
out
diffs out root sessionUri sha
assert diffs length
assert diffs diff added removed
assert root sessionUri sha
toSha
segments
diffs segments root sessionUri sha toSha
assert diffs
before uri content uri sessionUri sha
after uri content uri sessionUri toSha
diff added removed
after uri content uri sessionUri toSha
diff added removed
before uri content uri sessionUri sha
diff added removed
before uri content uri sessionUri sha
after uri content uri sessionUri toSha
diff added removed
assert
err Object killed signal
progress
assert
err progress
err Object killed signal
assert
err
err Object code
assert
err
err Object code
stderr
assert
err stderr
err
assert
err
assert
dirNotEmpty
indexLock
couldNotLock
dirtyTree
notAWorktree
nonError
dirNotEmpty
indexLock
couldNotLock
dirtyTree
notAWorktree
nonError
assert
assert
progress
assert progress
assert
long
result long
assert result length
assert result
assert
assert
mode oid
mode oid
import
{
EMPTY_TREE_OBJECT
,
,
}
from
'../../common/agentHostGitService.js'
;
import
{
}
from
'../../common/state/sessionState.js'
;
suite
(
'AgentHostGitService'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'maps branches and GitHub pull request refs to origin tracking refs'
,
(
)
=>
{
.
deepStrictEqual
(
{
:
getRemoteTrackingRef
(
'feature'
)
,
:
getRemoteTrackingRef
(
'refs/pull/42/head'
)
,
}
,
{
:
{
:
'feature'
,
:
'origin/feature'
,
:
'refs/remotes/origin/feature'
,
:
'refs/heads/feature'
,
}
,
:
{
:
'pull/42/head'
,
:
'origin/pull/42/head'
,
:
'refs/remotes/origin/pull/42/head'
,
:
'refs/pull/42/head'
,
}
,
}
)
;
}
)
;
test
(
'sorts the current and default branches before recent branches and applying the limit'
,
(
)
=>
{
.
deepStrictEqual
(
getBranchCompletions
(
[
'feature/recent'
,
'dev'
,
'feature/current'
,
'main'
,
'feature/older'
]
,
{
:
'feature/current'
,
:
'dev'
,
:
3
}
,
)
,
[
'feature/current'
,
'dev'
,
'feature/recent'
]
,
)
;
}
)
;
test
(
'preserves git order for branches other than the current and default branches'
,
(
)
=>
{
.
deepStrictEqual
(
getBranchCompletions
(
[
'feature/recent'
,
'release'
,
'feature/older'
]
,
{
:
'other'
,
:
'main'
}
,
)
,
[
'feature/recent'
,
'release'
,
'feature/older'
]
,
)
;
}
)
;
test
(
'filters before prioritizing the current and default branches'
,
(
)
=>
{
.
deepStrictEqual
(
getBranchCompletions
(
[
'feature/recent'
,
'maintenance'
,
'main'
,
'feature/current'
]
,
{
:
'feature/current'
,
:
'maintenance'
,
:
'ma'
}
,
)
,
[
'maintenance'
,
'main'
]
,
)
;
}
)
;
suite
(
'GitCheckoutProgressParser'
,
(
)
=>
{
function
collect
(
:
readonly
string
[
]
)
:
{
:
number
;
:
number
}
[
]
{
const
:
{
:
number
;
:
number
}
[
]
=
[
]
;
const
=
new
GitCheckoutProgressParser
(
=>
.
push
(
)
)
;
for
(
const
of
)
{
.
push
(
)
;
}
return
;
}
test
(
'forwards every complete sample and ignores non-progress output'
,
(
)
=>
{
.
deepStrictEqual
(
collect
(
[
'Preparing worktree (new branch agents/foo)\n'
,
'Updating files: 1% (8/800)\rUpdating files: 2% (16/800)\r'
,
'Updating files: 2% (20/800)\r'
,
'Updating files: 100% (800/800), done.\n'
,
]
)
,
[
{
:
8
,
:
800
}
,
{
:
16
,
:
800
}
,
{
:
20
,
:
800
}
,
{
:
800
,
:
800
}
,
]
)
;
}
)
;
test
(
'holds back a sample split across chunk boundaries until it completes'
,
(
)
=>
{
.
deepStrictEqual
(
collect
(
[
'Updating files: 42% (33'
,
'6/800)\r'
]
)
,
[
{
:
336
,
:
800
}
,
]
)
;
}
)
;
}
)
;
suite
(
'parseGitStatusV2'
,
(
)
=>
{
test
(
'parses a clean checkout with upstream'
,
(
)
=>
{
const
=
[
'# branch.oid 0123456789abcdef0123456789abcdef01234567'
,
'# branch.head main'
,
'# branch.upstream origin/main'
,
'# branch.ab +0 -0'
,
]
.
join
(
'\n'
)
;
.
deepStrictEqual
(
parseGitStatusV2
(
)
,
{
:
'main'
,
:
undefined
,
:
'origin/main'
,
:
0
,
:
0
,
:
0
,
}
)
;
}
)
;
test
(
'parses a dirty branch ahead and behind upstream'
,
(
)
=>
{
const
=
[
'# branch.oid 0123456789abcdef0123456789abcdef01234567'
,
'# branch.head feature'
,
'# branch.upstream origin/feature'
,
'# branch.ab +3 -2'
,
'1 .M N... 100644 100644 100644 abc abc src/a.ts'
,
'2 R. N... 100644 100644 100644 abc abc R100 src/b.ts\tsrc/old-b.ts'
,
'? src/untracked.ts'
,
]
.
join
(
'\n'
)
;
.
deepStrictEqual
(
parseGitStatusV2
(
)
,
{
:
'feature'
,
:
undefined
,
:
'origin/feature'
,
:
3
,
:
2
,
:
3
,
}
)
;
}
)
;
test
(
'treats (detached) HEAD as no branch and omits upstream/ab when absent'
,
(
)
=>
{
const
=
[
'# branch.oid 0123456789abcdef0123456789abcdef01234567'
,
'# branch.head (detached)'
,
]
.
join
(
'\n'
)
;
.
deepStrictEqual
(
parseGitStatusV2
(
)
,
{
:
undefined
,
:
true
,
:
undefined
,
:
undefined
,
:
undefined
,
:
0
,
}
)
;
}
)
;
test
(
'returns empty object for undefined input'
,
(
)
=>
{
.
deepStrictEqual
(
parseGitStatusV2
(
undefined
)
,
{
}
)
;
}
)
;
}
)
;
suite
(
'needsSessionGitStateRefresh'
,
(
)
=>
{
test
(
'separates a branch-less probe failure from a detached HEAD'
,
(
)
=>
{
.
deepStrictEqual
(
{
:
needsSessionGitStateRefresh
(
undefined
)
,
:
needsSessionGitStateRefresh
(
{
:
'main'
}
)
,
:
needsSessionGitStateRefresh
(
{
:
true
,
:
'main'
}
)
,
:
needsSessionGitStateRefresh
(
{
:
'feature'
,
:
'main'
}
)
,
}
,
{
:
true
,
:
true
,
:
false
,
:
false
,
}
)
;
}
)
;
}
)
;
suite
(
'parseHasGitHubRemote'
,
(
)
=>
{
test
(
'detects ssh github remote'
,
(
)
=>
{
.
strictEqual
(
parseHasGitHubRemote
(
'origin\tgit@github.com:owner/repo.git (fetch)\n'
)
,
true
)
;
}
)
;
test
(
'detects https github remote'
,
(
)
=>
{
.
strictEqual
(
parseHasGitHubRemote
(
'origin\thttps://github.com/owner/repo.git (fetch)\n'
)
,
true
)
;
}
)
;
test
(
'returns false for non-github remotes'
,
(
)
=>
{
.
strictEqual
(
parseHasGitHubRemote
(
'origin\thttps://gitlab.com/owner/repo.git (fetch)\n'
)
,
false
)
;
}
)
;
test
(
'returns false when there are no remotes'
,
(
)
=>
{
.
strictEqual
(
parseHasGitHubRemote
(
''
)
,
false
)
;
}
)
;
test
(
'returns undefined when probe failed (output absent)'
,
(
)
=>
{
.
strictEqual
(
parseHasGitHubRemote
(
undefined
)
,
undefined
)
;
}
)
;
}
)
;
suite
(
'parseDefaultBranchRef'
,
(
)
=>
{
test
(
'strips refs/remotes/origin/ prefix'
,
(
)
=>
{
.
strictEqual
(
parseDefaultBranchRef
(
'refs/remotes/origin/main\n'
)
,
'main'
)
;
}
)
;
test
(
'returns the ref as-is when prefix is not present'
,
(
)
=>
{
.
strictEqual
(
parseDefaultBranchRef
(
'main'
)
,
'main'
)
;
}
)
;
test
(
'returns undefined for empty/missing output'
,
(
)
=>
{
.
strictEqual
(
parseDefaultBranchRef
(
undefined
)
,
undefined
)
;
.
strictEqual
(
parseDefaultBranchRef
(
' '
)
,
undefined
)
;
}
)
;
}
)
;
suite
(
'parseGitHubRepoFromRemote'
,
(
)
=>
{
test
(
'parses only the requested fork remote'
,
(
)
=>
{
const
=
[
'origin\tgit@github.com:base-owner/repo.git (fetch)'
,
'fork\thttps://github.com/fork-owner/repo.git (fetch)'
,
]
.
join
(
'\n'
)
;
.
deepStrictEqual
(
parseGitHubRepoFromRemote
(
,
'fork'
)
,
{
:
'fork-owner'
,
:
'repo'
}
)
;
}
)
;
test
(
'does not fall back when the requested remote is not GitHub'
,
(
)
=>
{
const
=
[
'origin\tgit@github.com:base-owner/repo.git (fetch)'
,
'fork\thttps://gitlab.com/fork-owner/repo.git (fetch)'
,
]
.
join
(
'\n'
)
;
.
strictEqual
(
parseGitHubRepoFromRemote
(
,
'fork'
)
,
undefined
)
;
}
)
;
test
(
'parses ssh (scp-like) origin remote'
,
(
)
=>
{
const
=
'origin\tgit@github.com:microsoft/vscode.git (fetch)\norigin\tgit@github.com:microsoft/vscode.git (push)\n'
;
.
deepStrictEqual
(
parseGitHubRepoFromRemote
(
)
,
{
:
'microsoft'
,
:
'vscode'
}
)
;
}
)
;
test
(
'parses https origin remote without .git suffix'
,
(
)
=>
{
const
=
'origin\thttps://github.com/microsoft/vscode (fetch)\n'
;
.
deepStrictEqual
(
parseGitHubRepoFromRemote
(
)
,
{
:
'microsoft'
,
:
'vscode'
}
)
;
}
)
;
test
(
'parses ssh:// scheme remote'
,
(
)
=>
{
const
=
'origin\tssh://git@github.com/microsoft/vscode.git (fetch)\n'
;
.
deepStrictEqual
(
parseGitHubRepoFromRemote
(
)
,
{
:
'microsoft'
,
:
'vscode'
}
)
;
}
)
;
test
(
'prefers origin over other remotes'
,
(
)
=>
{
const
=
'fork\tgit@github.com:me/vscode.git (fetch)\n'
+
'origin\tgit@github.com:microsoft/vscode.git (fetch)\n'
;
.
deepStrictEqual
(
parseGitHubRepoFromRemote
(
)
,
{
:
'microsoft'
,
:
'vscode'
}
)
;
}
)
;
test
(
'falls back to first github remote when origin is not github'
,
(
)
=>
{
const
=
'origin\tgit@gitlab.com:foo/bar.git (fetch)\n'
+
'upstream\thttps://github.com/microsoft/vscode.git (fetch)\n'
;
.
deepStrictEqual
(
parseGitHubRepoFromRemote
(
)
,
{
:
'microsoft'
,
:
'vscode'
}
)
;
}
)
;
test
(
'returns undefined when no remotes are present'
,
(
)
=>
{
.
strictEqual
(
parseGitHubRepoFromRemote
(
''
)
,
undefined
)
;
.
strictEqual
(
parseGitHubRepoFromRemote
(
undefined
)
,
undefined
)
;
}
)
;
test
(
'returns undefined when no GitHub remote is present'
,
(
)
=>
{
const
=
'origin\thttps://gitlab.com/foo/bar.git (fetch)\n'
;
.
strictEqual
(
parseGitHubRepoFromRemote
(
)
,
undefined
)
;
}
)
;
}
)
;
test
(
'orders fetch remote URLs with origin first and excludes push URLs'
,
(
)
=>
{
.
deepStrictEqual
(
parseFetchRemoteUrls
(
[
'upstream\tgit@github.com:microsoft/vscode.git (fetch)'
,
'origin\thttps://github.com/me/vscode.git (push)'
,
'origin\thttps://github.com/me/vscode.git (fetch)'
,
]
.
join
(
'\n'
)
)
,
[
'https://github.com/me/vscode.git'
,
'git@github.com:microsoft/vscode.git'
,
]
)
;
}
)
;
test
(
'prefers the branch upstream remote before origin'
,
(
)
=>
{
.
deepStrictEqual
(
parseFetchRemoteUrls
(
[
'origin\thttps://github.com/me/vscode.git (fetch)'
,
'upstream\thttps://github.com/microsoft/vscode.git (fetch)'
,
]
.
join
(
'\n'
)
,
'upstream'
)
,
[
'https://github.com/microsoft/vscode.git'
,
'https://github.com/me/vscode.git'
,
]
)
;
}
)
;
suite
(
'parseUntrackedPaths'
,
(
)
=>
{
test
(
'returns empty for empty/undefined output'
,
(
)
=>
{
.
deepStrictEqual
(
parseUntrackedPaths
(
undefined
)
,
[
]
)
;
.
deepStrictEqual
(
parseUntrackedPaths
(
''
)
,
[
]
)
;
}
)
;
test
(
'extracts untracked entries and skips others'
,
(
)
=>
{
const
=
'?? new.txt\x00 M edited.txt\x00R to.txt\x00from.txt\x00?? other.txt\x00'
;
.
deepStrictEqual
(
parseUntrackedPaths
(
)
,
[
'new.txt'
,
'other.txt'
]
)
;
}
)
;
}
)
;
suite
(
'parseChangedPaths'
,
(
)
=>
{
test
(
'returns every changed path including delete and index rename/copy sources'
,
(
)
=>
{
const
=
[
' M modified.txt'
,
'A added.txt'
,
' D deleted.txt'
,
'?? untracked.txt'
,
'R renamed-new.txt'
,
'renamed-old.txt'
,
' C copied-new.txt'
,
'copied-old.txt'
,
'AD deleted-index-addition.txt'
,
'RD deleted-rename-destination.txt'
,
'rename-source.txt'
,
' M modified.txt'
,
''
,
]
.
join
(
'\x00'
)
;
.
deepStrictEqual
(
parseChangedPaths
(
)
,
[
'modified.txt'
,
'added.txt'
,
'deleted.txt'
,
'untracked.txt'
,
'renamed-new.txt'
,
'renamed-old.txt'
,
'copied-new.txt'
,
'copied-old.txt'
,
'rename-source.txt'
,
]
)
;
}
)
;
test
(
'returns worktree rename/copy source paths too'
,
(
)
=>
{
const
=
[
' R worktree-renamed-new.txt'
,
'worktree-renamed-old.txt'
,
' C worktree-copied-new.txt'
,
'worktree-copied-old.txt'
,
''
,
]
.
join
(
'\x00'
)
;
.
deepStrictEqual
(
parseChangedPaths
(
)
,
[
'worktree-renamed-new.txt'
,
'worktree-renamed-old.txt'
,
'worktree-copied-new.txt'
,
'worktree-copied-old.txt'
,
]
)
;
}
)
;
}
)
;
suite
(
'parseGitDiffRawNumstat'
,
(
)
=>
{
const
=
URI
.
file
(
'/repo'
)
;
const
=
'copilot:/abc'
;
const
=
'cafe1234cafe1234cafe1234cafe1234cafe1234'
;
test
(
'parses an add, modify, delete and rename in a single stream'
,
(
)
=>
{
const
:
string
[
]
=
[
':100644 100644 0000000 1111111 M'
,
'modified.ts'
,
':000000 100644 0000000 2222222 A'
,
'added.ts'
,
':100644 000000 3333333 0000000 D'
,
'deleted.ts'
,
':100644 100644 4444444 5555555 R100'
,
'old/path.ts'
,
'new/path.ts'
,
'5\t2\tmodified.ts'
,
'10\t0\tadded.ts'
,
'0\t7\tdeleted.ts'
,
'3\t3\t'
,
'old/path.ts'
,
'new/path.ts'
,
''
,
]
;
const
=
.
join
(
'\x00'
)
;
const
=
parseGitDiffRawNumstat
(
,
,
,
)
;
.
deepStrictEqual
(
,
[
{
:
{
:
'file:///repo/modified.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'modified.ts'
,
'/repo/modified.ts'
)
}
}
,
:
{
:
'file:///repo/modified.ts'
,
:
{
:
'file:///repo/modified.ts'
}
}
,
:
{
:
5
,
:
2
}
,
}
,
{
:
{
:
'file:///repo/added.ts'
,
:
{
:
'file:///repo/added.ts'
}
}
,
:
{
:
10
,
:
0
}
,
}
,
{
:
{
:
'file:///repo/deleted.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'deleted.ts'
,
'/repo/deleted.ts'
)
}
}
,
:
{
:
0
,
:
7
}
,
}
,
{
:
{
:
'file:///repo/old/path.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'old/path.ts'
,
'/repo/old/path.ts'
)
}
}
,
:
{
:
'file:///repo/new/path.ts'
,
:
{
:
'file:///repo/new/path.ts'
}
}
,
:
{
:
3
,
:
3
}
,
}
,
]
)
;
}
)
;
test
(
'treats `-` numstat values (binary) as zero'
,
(
)
=>
{
const
=
[
':100644 100644 0 0 M'
,
'image.png'
,
'-\t-\timage.png'
,
''
]
.
join
(
'\x00'
)
;
const
=
parseGitDiffRawNumstat
(
,
,
,
)
;
.
strictEqual
(
.
,
1
)
;
.
deepStrictEqual
(
[
0
]
.
,
{
:
0
,
:
0
}
)
;
}
)
;
test
(
'returns empty for empty input'
,
(
)
=>
{
.
deepStrictEqual
(
parseGitDiffRawNumstat
(
''
,
,
,
)
,
[
]
)
;
}
)
;
test
(
'anchors after side to afterRef when provided (ref->ref diffs)'
,
(
)
=>
{
const
=
'beef5678beef5678beef5678beef5678beef5678'
;
const
:
string
[
]
=
[
':100644 100644 0000000 1111111 M'
,
'modified.ts'
,
':000000 100644 0000000 2222222 A'
,
'added.ts'
,
':100644 000000 3333333 0000000 D'
,
'deleted.ts'
,
':100644 100644 4444444 5555555 R100'
,
'old/path.ts'
,
'new/path.ts'
,
'5\t2\tmodified.ts'
,
'10\t0\tadded.ts'
,
'0\t7\tdeleted.ts'
,
'3\t3\t'
,
'old/path.ts'
,
'new/path.ts'
,
''
,
]
;
const
=
parseGitDiffRawNumstat
(
.
join
(
'\x00'
)
,
,
,
,
)
;
.
deepStrictEqual
(
,
[
{
:
{
:
'file:///repo/modified.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'modified.ts'
,
'/repo/modified.ts'
)
}
}
,
:
{
:
'file:///repo/modified.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'modified.ts'
,
'/repo/modified.ts'
)
}
}
,
:
{
:
5
,
:
2
}
,
}
,
{
:
{
:
'file:///repo/added.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'added.ts'
,
'/repo/added.ts'
)
}
}
,
:
{
:
10
,
:
0
}
,
}
,
{
:
{
:
'file:///repo/deleted.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'deleted.ts'
,
'/repo/deleted.ts'
)
}
}
,
:
{
:
0
,
:
7
}
,
}
,
{
:
{
:
'file:///repo/old/path.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'old/path.ts'
,
'/repo/old/path.ts'
)
}
}
,
:
{
:
'file:///repo/new/path.ts'
,
:
{
:
buildGitBlobUri
(
,
,
'new/path.ts'
,
'/repo/new/path.ts'
)
}
}
,
:
{
:
3
,
:
3
}
,
}
,
]
)
;
}
)
;
}
)
;
test
(
'exports the well-known empty-tree object SHA'
,
(
)
=>
{
.
strictEqual
(
EMPTY_TREE_OBJECT
,
'4b825dc642cb6eb9a060e54bf8d69288fbee4904'
)
;
}
)
;
suite
(
'formatGitError'
,
(
)
=>
{
test
(
'reports timeout when our timer fired and summarises progress-meter stderr'
,
(
)
=>
{
const
=
.
assign
(
new
Error
(
'Command failed'
)
,
{
:
true
,
:
'SIGTERM'
as
const
}
)
;
const
=
'Updating files: 0% (7/14834)\rUpdating files: 0% (149/14834)\r'
;
.
strictEqual
(
formatGitError
(
[
'worktree'
,
'add'
,
'-b'
,
'x'
,
'/tmp/y'
,
'origin/main'
]
,
30_000
,
true
,
,
)
,
'git worktree timed out after 30000ms: Updating files: 0% (149/14834)'
,
)
;
}
)
;
test
(
'reports kill signal when killed but not by our timer'
,
(
)
=>
{
const
=
.
assign
(
new
Error
(
'Command failed'
)
,
{
:
true
,
:
'SIGTERM'
as
const
}
)
;
.
strictEqual
(
formatGitError
(
[
'worktree'
,
'add'
]
,
30_000
,
false
,
,
''
)
,
'git worktree killed by SIGTERM'
,
)
;
}
)
;
test
(
'reports numeric exit code when git failed normally'
,
(
)
=>
{
const
=
.
assign
(
new
Error
(
'Command failed'
)
,
{
:
128
}
)
;
.
strictEqual
(
formatGitError
(
[
'worktree'
,
'add'
,
'/tmp/y'
,
'missing-branch'
]
,
30_000
,
false
,
,
'fatal: invalid reference: missing-branch\n'
)
,
'git worktree exited with code 128: fatal: invalid reference: missing-branch'
,
)
;
}
)
;
test
(
'keeps missing git-lfs error over the later generic fatal line'
,
(
)
=>
{
const
=
.
assign
(
new
Error
(
'Command failed'
)
,
{
:
128
}
)
;
const
=
[
'Preparing worktree (new branch \'agents/example\')'
,
'git-lfs filter-process: git-lfs: command not found'
,
'fatal: the remote end hung up unexpectedly'
,
]
.
join
(
'\n'
)
;
.
strictEqual
(
formatGitError
(
[
'worktree'
,
'add'
,
'--no-track'
,
'-b'
,
'agents/example'
,
'/tmp/worktree'
,
'origin/main'
]
,
60_000
,
false
,
,
)
,
'git worktree exited with code 128: git-lfs filter-process: git-lfs: command not found'
,
)
;
}
)
;
test
(
'falls back to error message when there is no signal or exit code'
,
(
)
=>
{
const
=
new
Error
(
'spawn git ENOENT'
)
;
.
strictEqual
(
formatGitError
(
[
'status'
]
,
5_000
,
false
,
,
''
)
,
'spawn git ENOENT'
,
)
;
}
)
;
}
)
;
suite
(
'isRetryableWorktreeRemovalError'
,
(
)
=>
{
test
(
'retries transient lock / dir-not-empty races but not fatal removal errors'
,
(
)
=>
{
.
deepStrictEqual
(
{
:
isRetryableWorktreeRemovalError
(
new
Error
(
` git worktree exited with code 255: error: failed to delete '.git/worktrees/reply-exactly-materialized': Directory not empty `
)
)
,
:
isRetryableWorktreeRemovalError
(
new
Error
(
'git worktree exited with code 128: fatal: Unable to create \'.git/worktrees/x/index.lock\': File exists'
)
)
,
:
isRetryableWorktreeRemovalError
(
new
Error
(
'git worktree exited with code 1: fatal: could not lock config file'
)
)
,
:
isRetryableWorktreeRemovalError
(
new
Error
(
` git worktree exited with code 1: fatal: 'wt' contains modified or untracked files, use --force to delete it `
)
)
,
:
isRetryableWorktreeRemovalError
(
new
Error
(
` git worktree exited with code 128: fatal: 'wt' is not a working tree `
)
)
,
:
isRetryableWorktreeRemovalError
(
'boom'
)
,
}
,
{
:
true
,
:
true
,
:
true
,
:
false
,
:
false
,
:
false
,
}
)
;
}
)
;
}
)
;
suite
(
'summarizeStderrForError'
,
(
)
=>
{
test
(
'returns empty string for empty input'
,
(
)
=>
{
.
strictEqual
(
summarizeStderrForError
(
''
)
,
''
)
;
}
)
;
test
(
'returns empty string for whitespace-only input'
,
(
)
=>
{
.
strictEqual
(
summarizeStderrForError
(
' \r\n\r\n '
)
,
''
)
;
}
)
;
test
(
'keeps the last non-empty line of a multi-line progress meter'
,
(
)
=>
{
const
=
'Updating files: 0% (7/14834)\rUpdating files: 0% (149/14834)\r'
;
.
strictEqual
(
summarizeStderrForError
(
)
,
'Updating files: 0% (149/14834)'
)
;
}
)
;
test
(
'passes through a normal single-line message'
,
(
)
=>
{
.
strictEqual
(
summarizeStderrForError
(
'fatal: invalid reference: x\n'
)
,
'fatal: invalid reference: x'
)
;
}
)
;
test
(
'truncates very long lines with an ellipsis'
,
(
)
=>
{
const
=
` fatal: ${ 'a' . repeat ( 500 ) } `
;
const
=
summarizeStderrForError
(
)
;
.
strictEqual
(
.
,
200
)
;
.
ok
(
.
endsWith
(
'…'
)
,
'expected trailing ellipsis'
)
;
}
)
;
}
)
;
suite
(
'resolveDiffBaseBranchName'
,
(
)
=>
{
test
(
'prefers the persisted base branch, then git state, then undefined'
,
(
)
=>
{
.
deepStrictEqual
(
[
resolveDiffBaseBranchName
(
'persisted'
,
'gitState'
)
,
resolveDiffBaseBranchName
(
undefined
,
'gitState'
)
,
resolveDiffBaseBranchName
(
'persisted'
,
undefined
)
,
resolveDiffBaseBranchName
(
'origin/main'
,
undefined
)
,
resolveDiffBaseBranchName
(
'refs/remotes/origin/release'
,
undefined
)
,
resolveDiffBaseBranchName
(
undefined
,
undefined
)
,
]
,
[
'persisted'
,
'gitState'
,
'persisted'
,
'main'
,
'release'
,
undefined
]
,
)
;
}
)
;
}
)
;
suite
(
'parseSingleLsTreeEntry'
,
(
)
=>
{
test
(
'parses mode/oid and treats empty output as absent'
,
(
)
=>
{
.
deepStrictEqual
(
[
parseSingleLsTreeEntry
(
'100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\ta.txt\x00'
)
,
parseSingleLsTreeEntry
(
'100755 blob abc123\tdir/with space.txt\x00'
)
,
parseSingleLsTreeEntry
(
''
)
,
parseSingleLsTreeEntry
(
undefined
)
,
]
,
[
{
:
'100644'
,
:
'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'
}
,
{
:
'100755'
,
:
'abc123'
}
,
undefined
,
undefined
,
]
,
)
;
}
)
;
}
)
;
}
)
;