@@ -19,6 +19,7 @@ import {
1919} from 'aws-core-vscode/test'
2020import { areEqual , normalize } from 'aws-core-vscode/shared'
2121import * as path from 'path'
22+ import { LspController } from 'aws-core-vscode/amazonq'
2223
2324let tempFolder : string
2425
@@ -39,7 +40,7 @@ describe('crossFileContextUtil', function () {
3940 tempFolder = ( await createTestWorkspaceFolder ( ) ) . uri . fsPath
4041 } )
4142
42- it ( 'opentabs context should fetch 3 chunks and each chunk should contains 50 lines' , async function ( ) {
43+ it ( 'for control group, should return opentabs context where there will be 3 chunks and each chunk should contains 50 lines' , async function ( ) {
4344 sinon . stub ( FeatureConfigProvider . instance , 'getProjectContextGroup' ) . alwaysReturned ( 'control' )
4445 await toTextEditor ( aStringWithLineCount ( 200 ) , 'CrossFile.java' , tempFolder , { preview : false } )
4546 const myCurrentEditor = await toTextEditor ( '' , 'TargetFile.java' , tempFolder , {
@@ -53,6 +54,110 @@ describe('crossFileContextUtil', function () {
5354 assert . strictEqual ( actual . supplementalContextItems [ 1 ] . content . split ( '\n' ) . length , 50 )
5455 assert . strictEqual ( actual . supplementalContextItems [ 2 ] . content . split ( '\n' ) . length , 50 )
5556 } )
57+
58+ it ( 'for t1 group, should return repomap + opentabs context' , async function ( ) {
59+ await toTextEditor ( aStringWithLineCount ( 200 ) , 'CrossFile.java' , tempFolder , { preview : false } )
60+ const myCurrentEditor = await toTextEditor ( '' , 'TargetFile.java' , tempFolder , {
61+ preview : false ,
62+ } )
63+ sinon . stub ( FeatureConfigProvider . instance , 'getProjectContextGroup' ) . returns ( 't1' )
64+ sinon
65+ . stub ( LspController . instance , 'queryInlineProjectContext' )
66+ . withArgs ( sinon . match . any , sinon . match . any , 'codemap' )
67+ . resolves ( [
68+ {
69+ content : 'foo' ,
70+ score : 0 ,
71+ filePath : 'q-inline' ,
72+ } ,
73+ ] )
74+
75+ const actual = await crossFile . fetchSupplementalContextForSrc ( myCurrentEditor , fakeCancellationToken )
76+ assert . ok ( actual )
77+ assert . ok ( actual . supplementalContextItems . length === 4 )
78+ assert . strictEqual ( actual ?. strategy , 'codemap' )
79+ assert . deepEqual ( actual ?. supplementalContextItems [ 0 ] , {
80+ content : 'foo' ,
81+ score : 0 ,
82+ filePath : 'q-inline' ,
83+ } )
84+
85+ assert . strictEqual ( actual . supplementalContextItems [ 1 ] . content . split ( '\n' ) . length , 50 )
86+ assert . strictEqual ( actual . supplementalContextItems [ 2 ] . content . split ( '\n' ) . length , 50 )
87+ assert . strictEqual ( actual . supplementalContextItems [ 3 ] . content . split ( '\n' ) . length , 50 )
88+ } )
89+
90+ it ( 'for t2 group, should return global bm25 context and no repomap' , async function ( ) {
91+ await toTextEditor ( aStringWithLineCount ( 200 ) , 'CrossFile.java' , tempFolder , { preview : false } )
92+ const myCurrentEditor = await toTextEditor ( '' , 'TargetFile.java' , tempFolder , {
93+ preview : false ,
94+ } )
95+ sinon . stub ( FeatureConfigProvider . instance , 'getProjectContextGroup' ) . returns ( 't2' )
96+ sinon
97+ . stub ( LspController . instance , 'queryInlineProjectContext' )
98+ . withArgs ( sinon . match . any , sinon . match . any , 'bm25' )
99+ . resolves ( [
100+ {
101+ content : 'foo' ,
102+ score : 5 ,
103+ filePath : 'foo.java' ,
104+ } ,
105+ {
106+ content : 'bar' ,
107+ score : 4 ,
108+ filePath : 'bar.java' ,
109+ } ,
110+ {
111+ content : 'baz' ,
112+ score : 3 ,
113+ filePath : 'baz.java' ,
114+ } ,
115+ {
116+ content : 'qux' ,
117+ score : 2 ,
118+ filePath : 'qux.java' ,
119+ } ,
120+ {
121+ content : 'quux' ,
122+ score : 1 ,
123+ filePath : 'quux.java' ,
124+ } ,
125+ ] )
126+
127+ const actual = await crossFile . fetchSupplementalContextForSrc ( myCurrentEditor , fakeCancellationToken )
128+ assert . ok ( actual )
129+ assert . ok ( actual . supplementalContextItems . length === 5 )
130+ assert . strictEqual ( actual ?. strategy , 'bm25' )
131+
132+ assert . deepEqual ( actual ?. supplementalContextItems [ 0 ] , {
133+ content : 'foo' ,
134+ score : 5 ,
135+ filePath : 'foo.java' ,
136+ } )
137+
138+ assert . deepEqual ( actual ?. supplementalContextItems [ 1 ] , {
139+ content : 'bar' ,
140+ score : 4 ,
141+ filePath : 'bar.java' ,
142+ } )
143+ assert . deepEqual ( actual ?. supplementalContextItems [ 2 ] , {
144+ content : 'baz' ,
145+ score : 3 ,
146+ filePath : 'baz.java' ,
147+ } )
148+
149+ assert . deepEqual ( actual ?. supplementalContextItems [ 3 ] , {
150+ content : 'qux' ,
151+ score : 2 ,
152+ filePath : 'qux.java' ,
153+ } )
154+
155+ assert . deepEqual ( actual ?. supplementalContextItems [ 4 ] , {
156+ content : 'quux' ,
157+ score : 1 ,
158+ filePath : 'quux.java' ,
159+ } )
160+ } )
56161 } )
57162
58163 describe ( 'non supported language should return undefined' , function ( ) {
0 commit comments