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 / xtab / test / common / recentFilesForPrompt.spec.ts 1053 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
import { expect, suite, test } from 'vitest' ;
import { DocumentId } from '../../../../platform/inlineEdits/common/dataTypes/documentId' ;
import { RootedEdit } from '../../../../platform/inlineEdits/common/dataTypes/edit' ;
import { LanguageContextResponse } from '../../../../platform/inlineEdits/common/dataTypes/languageContext' ;
import { DEFAULT_OPTIONS , IncludeLineNumbersOption, PromptOptions, RecentFileClippingStrategy } from '../../../../platform/inlineEdits/common/dataTypes/xtabPromptOptions' ;
import { IXtabHistoryEditEntry, IXtabHistoryVisibleRangesEntry } from '../../../../platform/inlineEdits/common/workspaceEditTracker/nesXtabHistoryTracker'
ContextKind
splitLines
StringEdit
OffsetRange
StringText
Uri
LineRange0Based
appendLanguageContextSnippets appendNeighborFileSnippets buildCodeSnippetsUsingPagedClipping computeFocalPageCost historyEntriesToCodeSnippet selectFocalRangesWithinSpanCap
INeighborFileSnippet
n StringText
n _ i
s
Math s length
overrides
maxTokens
recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption
includeViewedFiles
pageSize
clippingStrategy RecentFileClippingStrategy
PromptOptions
recentlyViewedDocuments
recentlyViewedDocuments
overrides maxTokens maxTokens overrides maxTokens
overrides recentlyViewedFilesIncludeLineNumbers includeLineNumbers overrides recentlyViewedFilesIncludeLineNumbers
overrides includeViewedFiles includeViewedFiles overrides includeViewedFiles
overrides clippingStrategy clippingStrategy overrides clippingStrategy
pagedClipping
pageSize overrides pageSize pagedClipping pageSize
id DocumentId
content StringText
focalRanges OffsetRange
editEntryCount
files FileEntry
opts PromptOptions
snippets docsInPrompt Set DocumentId
files computeTokens opts
id DocumentId
id2 DocumentId
snippets
id content
maxTokens pageSize
snippets
snippets
id content
maxTokens pageSize
snippets
snippets
id content
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize
snippets
snippets
id content
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize
snippets
content
focalRanges
snippets
id content focalRanges
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
snippets
lines length _ i
content lines
lineLength length
line10Start lineLength
focalRanges line10Start line10Start lineLength
snippets
id content focalRanges
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
snippets
snippets
id content
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption None pageSize
snippets
snippets
id content
id id2 content
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize
snippets
snippets
id content
id id2 content
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize
snippets
snippets
id content
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize
snippets splitLines
snippets
id content
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize
snippets
snippets
id content
maxTokens recentlyViewedFilesIncludeLineNumbers IncludeLineNumbersOption WithSpaceAfter pageSize
snippets
lines length _ i
content lines
lineLen length
focalRanges lineLen lineLen
snippets
id content focalRanges
maxTokens pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
snippet snippets
snippet
snippet not
snippets
id content
maxTokens pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
snippet snippets
snippet
lines1 length _ i
content1 lines1
lineLen1 length
focalRanges1 lineLen1 lineLen1
lines2 length _ i
content2 lines2
lineLen2 length
focalRanges2 lineLen2 lineLen2
snippets docsInPrompt
id content content1 focalRanges focalRanges1
id id2 content content2 focalRanges focalRanges2
maxTokens pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
docsInPrompt size
snippets s s
snippets s s
content1 length _ i
lineLen1 length
content2 length _ i
lineLen2 length
snippets docsInPrompt
id content content1 focalRanges lineLen1 editEntryCount
id id2 content content2 focalRanges lineLen2 editEntryCount
maxTokens pageSize clippingStrategy RecentFileClippingStrategy Proportional
docsInPrompt size
snippets length
content length _ i
lineLen length
snippets
id content focalRanges lineLen editEntryCount
id id2 content focalRanges lineLen editEntryCount
maxTokens pageSize clippingStrategy RecentFileClippingStrategy Proportional
snippets length
fileASnippet snippets s s
fileBSnippet snippets s s
fileASnippet length fileBSnippet length
smallContent
snippets docsInPrompt
id content focalRanges editEntryCount
id id2 content smallContent focalRanges editEntryCount
maxTokens pageSize clippingStrategy RecentFileClippingStrategy Proportional
docsInPrompt size
snippets length
content length _ i
lineLen length
focalRanges lineLen lineLen
snippets docsInPrompt
id content focalRanges
maxTokens pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
snippets length
docsInPrompt size
bigLine
bigContent length bigLine
bigLineLen bigLine length
bigFocalRanges bigLineLen
smallContent length _ i
smallLineLen length
smallFocalRanges smallLineLen
snippets
id content bigContent focalRanges bigFocalRanges
id id2 content smallContent focalRanges smallFocalRanges
maxTokens pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
snippets length
bigLine
bigContent length bigLine
bigLineLen bigLine length
smallContent length _ i
smallLineLen length
snippets docsInPrompt
id content bigContent focalRanges bigLineLen editEntryCount
id id2 content smallContent focalRanges smallLineLen editEntryCount
maxTokens pageSize clippingStrategy RecentFileClippingStrategy Proportional
docsInPrompt size
snippets length
id3 DocumentId
prefix
length _ i
lineLen length
maxTokens
snippets
id content focalRanges lineLen editEntryCount
id id2 content focalRanges lineLen editEntryCount
id id3 content focalRanges lineLen editEntryCount
maxTokens pageSize clippingStrategy RecentFileClippingStrategy Proportional
totalTokens snippets sum s sum s
totalTokens maxTokens
id3 DocumentId
content length _ i
lineLen length
focalCost content lineLen computeTokens
maxTokens focalCost
docsInPrompt
id content focalRanges lineLen editEntryCount
id id2 content focalRanges lineLen editEntryCount
id id3 content focalRanges lineLen editEntryCount
maxTokens pageSize clippingStrategy RecentFileClippingStrategy Proportional
docsInPrompt size
docsInPrompt id
docsInPrompt id2
docsInPrompt id3
content length _ i
lineLen length
snippets docsInPrompt
id content focalRanges lineLen editEntryCount
maxTokens pageSize clippingStrategy RecentFileClippingStrategy Proportional
docsInPrompt size
snippets length
snippets
lines length _ i
content lines
lineLen length
focalRanges
lineLen lineLen
lineLen lineLen
snippets
id content focalRanges
maxTokens pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
snippet snippets
snippet
snippet not
lines length _ i
content lines
lineLen length
focalRanges
lineLen lineLen
lineLen lineLen
snippets
id content focalRanges
maxTokens pageSize clippingStrategy RecentFileClippingStrategy AroundEditRange
snippet snippets
snippet
snippet
charsPerLine
offset Math offset charsPerLine
ranges
result ranges getLineNumber
result ranges
ranges
result ranges getLineNumber
result ranges
ranges
result ranges getLineNumber
result ranges ranges ranges
ranges
result ranges getLineNumber
result ranges
result getLineNumber
result
docId DocumentId
base edit StringEdit IXtabHistoryEditEntry
kind
docId
ordinal
edit base edit
content visibleRanges OffsetRange IXtabHistoryVisibleRangesEntry
kind
docId
ordinal
documentContent content
visibleRanges
edit StringEdit
entry edit
result entry
result content value
result focalRanges
result editEntryCount
olderEdit StringEdit
newerEdit StringEdit
olderEntry olderEdit
newerEntry newerEdit
result newerEntry olderEntry
result content value
result focalRanges
result editEntryCount
e2 StringEdit
e1 StringEdit
e0 StringEdit
result e0 e1 e2
result content value
result focalRanges
result editEntryCount
edit StringEdit
editEntry edit
visibleEntry
result visibleEntry editEntry
result content value
result focalRanges
result editEntryCount
entry
result entry
result content value
result focalRanges
result editEntryCount
olderEdit StringEdit
newerEdit StringEdit
olderEntry olderEdit
newerEntry newerEdit
result newerEntry olderEntry
result content value
result focalRanges
languageContext LanguageContextResponse
start
end
items
context
kind ContextKind Snippet
priority
uri Uri
value
timeStamp
onTimeout
snippets
languageContext snippets computeTokens
snippets
uri snippet startLine score isFromRelatedFile INeighborFileSnippet
lineCount snippet length
uri relativePath uri snippet lineRange startLine startLine lineCount score isFromRelatedFile
snippets
docsInPrompt
snippets
docsInPrompt
computeTokens
IncludeLineNumbersOption WithSpaceAfter
snippets
docsInPrompt DocumentId
snippets
snippets
computeTokens
IncludeLineNumbersOption WithoutSpace
snippets
snippets
snippets
computeTokens
IncludeLineNumbersOption WithSpaceAfter
snippets
snippets
docsInPrompt
snippets
docsInPrompt
computeTokens
IncludeLineNumbersOption None
snippets
snippets
dupDoc DocumentId
docsInPrompt dupDoc
snippets
snippets
docsInPrompt
computeTokens
IncludeLineNumbersOption None
snippets
snippets
snippets
docsInPrompt
result snippets docsInPrompt computeTokens IncludeLineNumbersOption None
snippets
result nComputed nIncluded includedIndices tokensConsumed
snippets
docsInPrompt
snippets
docsInPrompt
computeTokens
IncludeLineNumbersOption None
snippets
snippets
snippets
docsInPrompt
snippets
docsInPrompt
computeTokens
IncludeLineNumbersOption None
snippets
snippets
snippets
snippets
snippets
docsInPrompt
result
snippets
docsInPrompt
computeTokens
IncludeLineNumbersOption None
result nComputed nIncluded includedIndices tokensConsumed
;
import
{
}
from
'../../../../platform/languageServer/common/languageContextService'
;
import
{
}
from
'../../../../util/vs/base/common/strings'
;
import
{
}
from
'../../../../util/vs/editor/common/core/edits/stringEdit'
;
import
{
}
from
'../../../../util/vs/editor/common/core/ranges/offsetRange'
;
import
{
}
from
'../../../../util/vs/editor/common/core/text/abstractText'
;
import
{
}
from
'../../../../vscodeTypes'
;
import
{
}
from
'../../common/lineRange'
;
import
{
,
,
,
,
,
}
from
'../../common/recentFilesForPrompt'
;
import
{
}
from
'../../common/similarFilesContextService'
;
function
nLines
(
:
number
)
:
{
return
new
StringText
(
new
Array
(
)
.
fill
(
0
)
.
map
(
(
,
)
=>
` ${ i + 1 } `
)
.
join
(
'\n'
)
)
;
}
function
computeTokens
(
:
string
)
{
return
.
ceil
(
.
/
4
)
;
}
function
makeOpts
(
:
{
?
:
number
;
?
:
;
?
:
boolean
;
?
:
number
;
?
:
;
}
)
:
{
return
{
...
DEFAULT_OPTIONS
,
:
{
...
DEFAULT_OPTIONS
.
,
...
(
.
!==
undefined
&&
{
:
.
}
)
,
...
(
.
!==
undefined
&&
{
:
.
}
)
,
...
(
.
!==
undefined
&&
{
:
.
}
)
,
...
(
.
!==
undefined
&&
{
:
.
}
)
,
}
,
:
{
:
.
??
DEFAULT_OPTIONS
.
.
,
}
,
}
;
}
suite
(
'Paged clipping - recently viewed files'
,
(
)
=>
{
type
FileEntry
=
{
:
;
:
;
?
:
readonly
[
]
;
?
:
number
;
}
;
function
buildSnippets
(
:
[
]
,
:
,
)
:
{
:
string
[
]
;
:
<
>
}
{
return
buildCodeSnippetsUsingPagedClipping
(
,
,
)
;
}
const
=
.
create
(
'file:///src/first.txt'
)
;
const
=
.
create
(
'file:///src/second.txt'
)
;
test
(
'can page correctly by lines of 2'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
4
)
}
]
,
makeOpts
(
{
:
4
,
:
2
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt (truncated)
1
2
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'can page correctly by lines of 4'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
4
)
}
]
,
makeOpts
(
{
:
2000
,
:
2
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt
1
2
3
4
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
suite
(
'includeLineNumbers'
,
(
)
=>
{
test
(
'includes line numbers starting from 0 when enabled and not truncated'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
4
)
}
]
,
makeOpts
(
{
:
2000
,
:
.
,
:
2
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt
0| 1
1| 2
2| 3
3| 4
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'includes line numbers starting from 0 when truncated from beginning'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
10
)
}
]
,
makeOpts
(
{
:
4
,
:
.
,
:
2
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt (truncated)
0| 1
1| 2
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'includes line numbers with correct offset when using visible ranges'
,
(
)
=>
{
const
=
new
StringText
(
'line0\nline1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9'
)
;
const
=
[
new
OffsetRange
(
24
,
30
)
]
;
const
{
}
=
buildSnippets
(
[
{
,
,
}
]
,
makeOpts
(
{
:
15
,
:
.
,
:
2
,
:
.
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt (truncated)
4| line4
5| line5
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'includes line numbers with offset when visible range is in middle of file'
,
(
)
=>
{
const
=
Array
.
from
(
{
:
20
}
,
(
,
)
=>
` content_line_ ${ i} `
)
;
const
=
new
StringText
(
.
join
(
'\n'
)
)
;
const
=
'content_line_0\n'
.
;
const
=
10
*
;
const
=
[
new
OffsetRange
(
,
+
)
]
;
const
{
}
=
buildSnippets
(
[
{
,
,
}
]
,
makeOpts
(
{
:
50
,
:
.
,
:
5
,
:
.
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt (truncated)
10| content_line_10
11| content_line_11
12| content_line_12
13| content_line_13
14| content_line_14
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'does not include line numbers when disabled'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
4
)
}
]
,
makeOpts
(
{
:
2000
,
:
.
,
:
2
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt
1
2
3
4
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'includes line numbers for multiple files'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
3
)
}
,
{
:
,
:
nLines
(
3
)
}
,
]
,
makeOpts
(
{
:
2000
,
:
.
,
:
10
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/second.txt
0| 1
1| 2
2| 3
<|/recently_viewed_code_snippet|>",
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt
0| 1
1| 2
2| 3
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'includes line numbers with partial truncation for first file only'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
6
)
}
,
{
:
,
:
nLines
(
4
)
}
,
]
,
makeOpts
(
{
:
10
,
:
.
,
:
2
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt (truncated)
0| 1
1| 2
2| 3
3| 4
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'handles empty content gracefully with line numbers enabled'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
new
StringText
(
''
)
}
]
,
makeOpts
(
{
:
2000
,
:
.
,
:
2
}
)
,
)
;
expect
(
.
map
(
)
)
.
toMatchInlineSnapshot
(
`
[
[
"<|recently_viewed_code_snippet|>",
"code_snippet_file_path: /src/first.txt",
"0| ",
"<|/recently_viewed_code_snippet|>",
],
]
`
)
;
}
)
;
test
(
'handles single line content with line numbers'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
new
StringText
(
'single line'
)
}
]
,
makeOpts
(
{
:
2000
,
:
.
,
:
2
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt
0| single line
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'line numbers are formatted correctly for double-digit line numbers'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
15
)
}
]
,
makeOpts
(
{
:
2000
,
:
.
,
:
20
}
)
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/first.txt
0| 1
1| 2
2| 3
3| 4
4| 5
5| 6
6| 7
7| 8
8| 9
9| 10
10| 11
11| 12
12| 13
13| 14
14| 15
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
}
)
;
suite
(
'AroundEditRange strategy'
,
(
)
=>
{
test
(
'centers snippet on focal range instead of top of file'
,
(
)
=>
{
const
=
Array
.
from
(
{
:
100
}
,
(
,
)
=>
` line_ ${ String ( i) . padStart ( 3 , '0' ) } `
)
;
const
=
new
StringText
(
.
join
(
'\n'
)
)
;
const
=
'line_000\n'
.
;
const
=
[
new
OffsetRange
(
80
*
,
81
*
)
]
;
const
{
}
=
buildSnippets
(
[
{
,
,
}
]
,
makeOpts
(
{
:
30
,
:
5
,
:
.
}
)
,
)
;
const
=
[
0
]
;
expect
(
)
.
toContain
(
'line_080'
)
;
expect
(
)
.
.
toContain
(
'line_000'
)
;
}
)
;
test
(
'falls back to top-to-bottom for entries without focal ranges'
,
(
)
=>
{
const
{
}
=
buildSnippets
(
[
{
,
:
nLines
(
20
)
}
]
,
makeOpts
(
{
:
10
,
:
5
,
:
.
}
)
,
)
;
const
=
[
0
]
;
expect
(
)
.
toContain
(
'1\n2\n3\n4\n5'
)
;
}
)
;
test
(
'clips multiple files around their respective focal ranges'
,
(
)
=>
{
const
=
Array
.
from
(
{
:
50
}
,
(
,
)
=>
` fileA_ ${ i} `
)
;
const
=
new
StringText
(
.
join
(
'\n'
)
)
;
const
=
'fileA_0\n'
.
;
const
=
[
new
OffsetRange
(
40
*
,
41
*
)
]
;
const
=
Array
.
from
(
{
:
50
}
,
(
,
)
=>
` fileB_ ${ i} `
)
;
const
=
new
StringText
(
.
join
(
'\n'
)
)
;
const
=
'fileB_0\n'
.
;
const
=
[
new
OffsetRange
(
10
*
,
11
*
)
]
;
const
{
,
}
=
buildSnippets
(
[
{
,
:
,
:
}
,
{
:
,
:
,
:
}
,
]
,
makeOpts
(
{
:
200
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
2
)
;
expect
(
.
find
(
=>
.
includes
(
'fileA_40'
)
)
)
.
toBeDefined
(
)
;
expect
(
.
find
(
=>
.
includes
(
'fileB_10'
)
)
)
.
toBeDefined
(
)
;
}
)
;
}
)
;
suite
(
'Proportional strategy'
,
(
)
=>
{
test
(
'distributes budget across files instead of greedily consuming'
,
(
)
=>
{
const
=
new
StringText
(
Array
.
from
(
{
:
50
}
,
(
,
)
=>
` A ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
'A0\n'
.
;
const
=
new
StringText
(
Array
.
from
(
{
:
50
}
,
(
,
)
=>
` B ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
'B0\n'
.
;
const
{
,
}
=
buildSnippets
(
[
{
,
:
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
{
:
,
:
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
]
,
makeOpts
(
{
:
40
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
2
)
;
expect
(
.
)
.
toBe
(
2
)
;
}
)
;
test
(
'gives more budget to files with more edit locations'
,
(
)
=>
{
const
=
new
StringText
(
Array
.
from
(
{
:
40
}
,
(
,
)
=>
` x ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
'x0\n'
.
;
const
{
}
=
buildSnippets
(
[
{
,
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
3
}
,
{
:
,
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
]
,
makeOpts
(
{
:
60
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
2
)
;
const
=
.
find
(
=>
.
includes
(
'/src/first.txt'
)
)
!
;
const
=
.
find
(
=>
.
includes
(
'/src/second.txt'
)
)
!
;
expect
(
.
)
.
toBeGreaterThan
(
.
)
;
}
)
;
test
(
'ensures minimum budget per file'
,
(
)
=>
{
const
=
new
StringText
(
'hello\nworld'
)
;
const
{
,
}
=
buildSnippets
(
[
{
,
:
nLines
(
50
)
,
:
[
new
OffsetRange
(
0
,
5
)
]
,
:
10
}
,
{
:
,
:
,
:
[
new
OffsetRange
(
0
,
3
)
]
,
:
1
}
,
]
,
makeOpts
(
{
:
100
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
2
)
;
expect
(
.
)
.
toBe
(
2
)
;
}
)
;
}
)
;
suite
(
'RC1: budget enforcement in clipAroundFocalRanges'
,
(
)
=>
{
test
(
'does not include content when budget is exhausted'
,
(
)
=>
{
const
=
new
StringText
(
Array
.
from
(
{
:
20
}
,
(
,
)
=>
` line ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
'line0\n'
.
;
const
=
[
new
OffsetRange
(
5
*
,
6
*
)
]
;
const
{
,
}
=
buildSnippets
(
[
{
,
,
}
]
,
makeOpts
(
{
:
0
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
0
)
;
expect
(
.
)
.
toBe
(
0
)
;
}
)
;
test
(
'does not cascade negative budget to subsequent files'
,
(
)
=>
{
const
=
'x'
.
repeat
(
400
)
;
const
=
new
StringText
(
Array
.
from
(
{
:
50
}
,
(
)
=>
)
.
join
(
'\n'
)
)
;
const
=
.
+
1
;
const
=
[
new
OffsetRange
(
0
,
)
]
;
const
=
new
StringText
(
Array
.
from
(
{
:
10
}
,
(
,
)
=>
` small ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
'small0\n'
.
;
const
=
[
new
OffsetRange
(
0
,
)
]
;
const
{
}
=
buildSnippets
(
[
{
,
:
,
:
}
,
{
:
,
:
,
:
}
,
]
,
makeOpts
(
{
:
5
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
0
)
;
}
)
;
test
(
'proportional strategy drops oldest files when focal costs exceed budget'
,
(
)
=>
{
const
=
'x'
.
repeat
(
400
)
;
const
=
new
StringText
(
Array
.
from
(
{
:
50
}
,
(
)
=>
)
.
join
(
'\n'
)
)
;
const
=
.
+
1
;
const
=
new
StringText
(
Array
.
from
(
{
:
10
}
,
(
,
)
=>
` s ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
's0\n'
.
;
const
{
,
}
=
buildSnippets
(
[
{
,
:
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
{
:
,
:
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
]
,
makeOpts
(
{
:
100
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
0
)
;
expect
(
.
)
.
toBe
(
0
)
;
}
)
;
test
(
'proportional strategy total tokens never exceed budget'
,
(
)
=>
{
const
=
.
create
(
'file:///src/third.txt'
)
;
const
makeContent
=
(
:
string
)
=>
new
StringText
(
Array
.
from
(
{
:
30
}
,
(
,
)
=>
` ${ prefix} ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
'A0\n'
.
;
const
=
300
;
const
{
}
=
buildSnippets
(
[
{
,
:
makeContent
(
'A'
)
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
2
}
,
{
:
,
:
makeContent
(
'B'
)
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
{
:
,
:
makeContent
(
'C'
)
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
]
,
makeOpts
(
{
,
:
5
,
:
.
}
)
,
)
;
const
=
.
reduce
(
(
,
)
=>
+
computeTokens
(
)
,
0
)
;
expect
(
)
.
toBeLessThanOrEqual
(
)
;
}
)
;
test
(
'proportional strategy drops oldest files first when over budget'
,
(
)
=>
{
const
=
.
create
(
'file:///src/third.txt'
)
;
const
=
new
StringText
(
Array
.
from
(
{
:
20
}
,
(
,
)
=>
` line ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
'line0\n'
.
;
const
=
computeFocalPageCost
(
,
[
new
OffsetRange
(
0
,
)
]
,
5
,
)
!
;
const
=
*
2
+
1
;
const
{
}
=
buildSnippets
(
[
{
,
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
{
:
,
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
{
:
,
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
,
]
,
makeOpts
(
{
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
2
)
;
expect
(
.
has
(
)
)
.
toBe
(
true
)
;
expect
(
.
has
(
)
)
.
toBe
(
true
)
;
expect
(
.
has
(
)
)
.
toBe
(
false
)
;
}
)
;
test
(
'single file gets full budget'
,
(
)
=>
{
const
=
new
StringText
(
Array
.
from
(
{
:
50
}
,
(
,
)
=>
` x ${ i} `
)
.
join
(
'\n'
)
)
;
const
=
'x0\n'
.
;
const
{
,
}
=
buildSnippets
(
[
{
,
,
:
[
new
OffsetRange
(
0
,
)
]
,
:
1
}
]
,
makeOpts
(
{
:
200
,
:
5
,
:
.
}
)
,
)
;
expect
(
.
)
.
toBe
(
1
)
;
expect
(
.
)
.
toBe
(
1
)
;
expect
(
[
0
]
)
.
toContain
(
'x20'
)
;
}
)
;
}
)
;
suite
(
'RC3: focal range span capping'
,
(
)
=>
{
test
(
'wide-scatter focal ranges are capped to prioritize the most recent'
,
(
)
=>
{
const
=
Array
.
from
(
{
:
100
}
,
(
,
)
=>
` line_ ${ String ( i) . padStart ( 3 , '0' ) } `
)
;
const
=
new
StringText
(
.
join
(
'\n'
)
)
;
const
=
'line_000\n'
.
;
const
=
[
new
OffsetRange
(
5
*
,
6
*
)
,
new
OffsetRange
(
95
*
,
96
*
)
,
]
;
const
{
}
=
buildSnippets
(
[
{
,
,
}
]
,
makeOpts
(
{
:
30
,
:
5
,
:
.
}
)
,
)
;
const
=
[
0
]
;
expect
(
)
.
toContain
(
'line_005'
)
;
expect
(
)
.
.
toContain
(
'line_095'
)
;
}
)
;
test
(
'nearby focal ranges are all included within span cap'
,
(
)
=>
{
const
=
Array
.
from
(
{
:
100
}
,
(
,
)
=>
` line_ ${ String ( i) . padStart ( 3 , '0' ) } `
)
;
const
=
new
StringText
(
.
join
(
'\n'
)
)
;
const
=
'line_000\n'
.
;
const
=
[
new
OffsetRange
(
50
*
,
51
*
)
,
new
OffsetRange
(
52
*
,
53
*
)
,
]
;
const
{
}
=
buildSnippets
(
[
{
,
,
}
]
,
makeOpts
(
{
:
50
,
:
5
,
:
.
}
)
,
)
;
const
=
[
0
]
;
expect
(
)
.
toContain
(
'line_050'
)
;
expect
(
)
.
toContain
(
'line_052'
)
;
}
)
;
}
)
;
}
)
;
suite
(
'selectFocalRangesWithinSpanCap'
,
(
)
=>
{
const
=
10
;
const
getLineNumber
=
(
:
number
)
=>
.
floor
(
/
)
+
1
;
test
(
'returns all ranges when span fits within cap'
,
(
)
=>
{
const
=
[
new
OffsetRange
(
10
,
20
)
,
new
OffsetRange
(
20
,
30
)
,
]
;
const
=
selectFocalRangesWithinSpanCap
(
,
,
10
)
;
expect
(
)
.
toEqual
(
)
;
}
)
;
test
(
'returns only the first range when adding the second exceeds span cap'
,
(
)
=>
{
const
=
[
new
OffsetRange
(
10
,
20
)
,
new
OffsetRange
(
500
,
510
)
,
]
;
const
=
selectFocalRangesWithinSpanCap
(
,
,
10
)
;
expect
(
)
.
toEqual
(
[
[
0
]
]
)
;
}
)
;
test
(
'includes ranges greedily until cap is exceeded'
,
(
)
=>
{
const
=
[
new
OffsetRange
(
100
,
110
)
,
new
OffsetRange
(
120
,
130
)
,
new
OffsetRange
(
150
,
160
)
,
new
OffsetRange
(
500
,
510
)
,
]
;
const
=
selectFocalRangesWithinSpanCap
(
,
,
10
)
;
expect
(
)
.
toEqual
(
[
[
0
]
,
[
1
]
,
[
2
]
]
)
;
}
)
;
test
(
'single range is always returned'
,
(
)
=>
{
const
=
[
new
OffsetRange
(
100
,
110
)
]
;
const
=
selectFocalRangesWithinSpanCap
(
,
,
1
)
;
expect
(
)
.
toEqual
(
)
;
}
)
;
test
(
'empty ranges are handled'
,
(
)
=>
{
const
=
selectFocalRangesWithinSpanCap
(
[
]
,
,
10
)
;
expect
(
)
.
toEqual
(
[
]
)
;
}
)
;
}
)
;
suite
(
'historyEntriesToCodeSnippet'
,
(
)
=>
{
const
=
.
create
(
'file:///src/example.txt'
)
;
function
makeEditEntry
(
:
string
,
:
)
:
{
return
{
:
'edit'
,
,
:
0
,
:
new
RootedEdit
(
new
StringText
(
)
,
)
,
}
;
}
function
makeVisibleEntry
(
:
string
,
:
readonly
[
]
)
:
{
return
{
:
'visibleRanges'
,
,
:
0
,
:
new
StringText
(
)
,
,
}
;
}
test
(
'single edit entry returns its new ranges directly'
,
(
)
=>
{
const
=
.
insert
(
5
,
' world'
)
;
const
=
makeEditEntry
(
'hello'
,
)
;
const
=
historyEntriesToCodeSnippet
(
[
]
)
;
expect
(
.
.
)
.
toBe
(
'hello world'
)
;
expect
(
.
)
.
toEqual
(
[
new
OffsetRange
(
5
,
11
)
]
)
;
expect
(
.
)
.
toBe
(
1
)
;
}
)
;
test
(
'two edit entries: older ranges are transformed through the newer edit'
,
(
)
=>
{
const
=
.
replace
(
new
OffsetRange
(
0
,
2
)
,
'XXX'
)
;
const
=
.
insert
(
0
,
'YY'
)
;
const
=
makeEditEntry
(
'AABB'
,
)
;
const
=
makeEditEntry
(
'XXXBB'
,
)
;
const
=
historyEntriesToCodeSnippet
(
[
,
]
)
;
expect
(
.
.
)
.
toBe
(
'YYXXXBB'
)
;
expect
(
.
)
.
toEqual
(
[
new
OffsetRange
(
0
,
2
)
,
new
OffsetRange
(
2
,
5
)
,
]
)
;
expect
(
.
)
.
toBe
(
2
)
;
}
)
;
test
(
'three edit entries: ranges chain through two edits'
,
(
)
=>
{
const
=
makeEditEntry
(
'abcdef'
,
.
delete
(
new
OffsetRange
(
0
,
3
)
)
)
;
const
=
makeEditEntry
(
'def'
,
.
insert
(
0
,
'XY'
)
)
;
const
=
makeEditEntry
(
'XYdef'
,
.
insert
(
5
,
'Z'
)
)
;
const
=
historyEntriesToCodeSnippet
(
[
,
,
]
)
;
expect
(
.
.
)
.
toBe
(
'XYdefZ'
)
;
expect
(
.
)
.
toEqual
(
[
new
OffsetRange
(
5
,
6
)
,
new
OffsetRange
(
0
,
2
)
,
new
OffsetRange
(
2
,
2
)
,
]
)
;
expect
(
.
)
.
toBe
(
3
)
;
}
)
;
test
(
'visibleRanges entries are skipped for focal range collection'
,
(
)
=>
{
const
=
.
insert
(
5
,
' world'
)
;
const
=
makeEditEntry
(
'hello'
,
)
;
const
=
makeVisibleEntry
(
'hello world'
,
[
new
OffsetRange
(
0
,
5
)
]
)
;
const
=
historyEntriesToCodeSnippet
(
[
,
]
)
;
expect
(
.
.
)
.
toBe
(
'hello world'
)
;
expect
(
.
)
.
toEqual
(
[
new
OffsetRange
(
5
,
11
)
]
)
;
expect
(
.
)
.
toBe
(
1
)
;
}
)
;
test
(
'only visibleRanges entries produce no focal ranges'
,
(
)
=>
{
const
=
makeVisibleEntry
(
'hello'
,
[
new
OffsetRange
(
0
,
3
)
]
)
;
const
=
historyEntriesToCodeSnippet
(
[
]
)
;
expect
(
.
.
)
.
toBe
(
'hello'
)
;
expect
(
.
)
.
toBeUndefined
(
)
;
expect
(
.
)
.
toBe
(
1
)
;
}
)
;
test
(
'edit after deletion: ranges are correctly shifted'
,
(
)
=>
{
const
=
.
delete
(
new
OffsetRange
(
3
,
8
)
)
;
const
=
.
replace
(
new
OffsetRange
(
0
,
3
)
,
'XX'
)
;
const
=
makeEditEntry
(
'aaa_bbb_ccc'
,
)
;
const
=
makeEditEntry
(
'aaaccc'
,
)
;
const
=
historyEntriesToCodeSnippet
(
[
,
]
)
;
expect
(
.
.
)
.
toBe
(
'XXccc'
)
;
expect
(
.
)
.
toEqual
(
[
new
OffsetRange
(
0
,
2
)
,
new
OffsetRange
(
2
,
2
)
,
]
)
;
}
)
;
}
)
;
suite
(
'appendLanguageContextSnippets'
,
(
)
=>
{
test
(
'does not add line numbers without a source range'
,
(
)
=>
{
const
:
=
{
:
0
,
:
0
,
:
[
{
:
{
:
.
,
:
1
,
:
.
parse
(
'file:///src/context.ts'
)
,
:
'first line\nsecond line'
,
}
,
:
0
,
:
false
,
}
]
,
}
;
const
:
string
[
]
=
[
]
;
appendLanguageContextSnippets
(
,
,
100
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/context.ts
first line
second line
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
}
)
;
suite
(
'appendNeighborFileSnippets'
,
(
)
=>
{
function
makeNeighbor
(
:
string
,
:
string
,
:
number
,
=
0.5
,
=
false
)
:
{
const
=
.
split
(
/ \r ? \n /
)
.
;
return
{
,
:
,
,
:
new
LineRange0Based
(
,
+
)
,
,
}
;
}
test
(
'uses the original source line range when adding line numbers'
,
(
)
=>
{
const
:
string
[
]
=
[
]
;
const
=
new
Set< DocumentId>
(
)
;
appendNeighborFileSnippets
(
[
makeNeighbor
(
'file:///src/n1.ts'
,
'a\nb'
,
5
)
]
,
,
,
100
,
,
.
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/n1.ts
5| a
6| b
<|/recently_viewed_code_snippet|>",
]
`
)
;
expect
(
.
has
(
.
create
(
'file:///src/n1.ts'
)
)
)
.
toBe
(
true
)
;
}
)
;
test
(
'uses the original source line range without spacing after line numbers'
,
(
)
=>
{
const
:
string
[
]
=
[
]
;
appendNeighborFileSnippets
(
[
makeNeighbor
(
'file:///src/n1.ts'
,
'a\nb'
,
12
)
]
,
,
new
Set< DocumentId>
(
)
,
100
,
,
.
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/n1.ts
12|a
13|b
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'omits line numbers for related-file snippets even when line numbers are requested'
,
(
)
=>
{
const
:
string
[
]
=
[
]
;
appendNeighborFileSnippets
(
[
makeNeighbor
(
'file:///src/related.ts'
,
'a\nb'
,
5
,
0.5
,
true
)
]
,
,
new
Set< DocumentId>
(
)
,
100
,
,
.
,
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
[
"<|recently_viewed_code_snippet|>
code_snippet_file_path: /src/related.ts
a
b
<|/recently_viewed_code_snippet|>",
]
`
)
;
}
)
;
test
(
'skips oversize snippets but keeps trying smaller ones'
,
(
)
=>
{
const
:
string
[
]
=
[
]
;
const
=
new
Set< DocumentId>
(
)
;
appendNeighborFileSnippets
(
[
makeNeighbor
(
'file:///src/big.ts'
,
'b'
.
repeat
(
32
)
,
0
)
,
makeNeighbor
(
'file:///src/small.ts'
,
'aa'
,
0
)
,
]
,
,
,
5
,
,
.
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
)
.
toContain
(
'/src/small.ts'
)
;
}
)
;
test
(
'skips snippets whose document is already in the prompt'
,
(
)
=>
{
const
=
.
create
(
'file:///src/dup.ts'
)
;
const
=
new
Set< DocumentId>
(
[
]
)
;
const
:
string
[
]
=
[
]
;
appendNeighborFileSnippets
(
[
makeNeighbor
(
'file:///src/dup.ts'
,
'duplicated'
,
0
)
,
makeNeighbor
(
'file:///src/fresh.ts'
,
'fresh'
,
0
)
,
]
,
,
,
100
,
,
.
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
)
.
toContain
(
'/src/fresh.ts'
)
;
}
)
;
test
(
'no-op when no snippets provided'
,
(
)
=>
{
const
:
string
[
]
=
[
]
;
const
=
new
Set< DocumentId>
(
)
;
const
=
appendNeighborFileSnippets
(
[
]
,
,
,
100
,
,
.
)
;
expect
(
)
.
toEqual
(
[
]
)
;
expect
(
)
.
toEqual
(
{
:
0
,
:
0
,
:
[
]
,
:
0
}
)
;
}
)
;
test
(
'selects highest-score snippets first when budget is tight'
,
(
)
=>
{
const
:
string
[
]
=
[
]
;
const
=
new
Set< DocumentId>
(
)
;
appendNeighborFileSnippets
(
[
makeNeighbor
(
'file:///src/low.ts'
,
'l'
.
repeat
(
32
)
,
0
,
0.1
)
,
makeNeighbor
(
'file:///src/high.ts'
,
'h'
.
repeat
(
32
)
,
0
,
0.9
)
,
]
,
,
,
10
,
,
.
,
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
)
.
toContain
(
'/src/high.ts'
)
;
}
)
;
test
(
'places highest-score snippet last (closest to current file)'
,
(
)
=>
{
const
:
string
[
]
=
[
]
;
const
=
new
Set< DocumentId>
(
)
;
appendNeighborFileSnippets
(
[
makeNeighbor
(
'file:///src/low.ts'
,
'low'
,
0
,
0.1
)
,
makeNeighbor
(
'file:///src/mid.ts'
,
'mid'
,
0
,
0.5
)
,
makeNeighbor
(
'file:///src/high.ts'
,
'high'
,
0
,
0.9
)
,
]
,
,
,
100
,
,
.
,
)
;
expect
(
)
.
toHaveLength
(
3
)
;
expect
(
[
0
]
)
.
toContain
(
'/src/low.ts'
)
;
expect
(
[
1
]
)
.
toContain
(
'/src/mid.ts'
)
;
expect
(
[
2
]
)
.
toContain
(
'/src/high.ts'
)
;
}
)
;
test
(
'reports included indices, skipping oversize and budget-exhausted entries'
,
(
)
=>
{
const
:
string
[
]
=
[
]
;
const
=
new
Set< DocumentId>
(
)
;
const
=
appendNeighborFileSnippets
(
[
makeNeighbor
(
'file:///src/i0.ts'
,
'a'
,
0
,
0.1
)
,
makeNeighbor
(
'file:///src/i1.ts'
,
'b'
,
0
,
0.2
)
,
makeNeighbor
(
'file:///src/i2.ts'
,
'c'
,
0
,
0.3
)
,
makeNeighbor
(
'file:///src/i3.ts'
,
'd'
,
0
,
0.4
)
,
makeNeighbor
(
'file:///src/i4.ts'
,
'e'
,
0
,
0.5
)
,
makeNeighbor
(
'file:///src/i5.ts'
,
'h'
.
repeat
(
64
)
,
0
,
0.6
)
,
makeNeighbor
(
'file:///src/i6.ts'
,
'g'
,
0
,
0.9
)
,
]
,
,
,
4
,
,
.
,
)
;
expect
(
)
.
toEqual
(
{
:
7
,
:
4
,
:
[
2
,
3
,
4
,
6
]
,
:
4
}
)
;
}
)
;
}
)
;