@@ -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,8 +40,12 @@ 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- sinon . stub ( FeatureConfigProvider . instance , 'isNewProjectContextGroup' ) . alwaysReturned ( false )
43+ afterEach ( async function ( ) {
44+ sinon . restore ( )
45+ } )
46+
47+ it ( 'for control group, should return opentabs context where there will be 3 chunks and each chunk should contains 50 lines' , async function ( ) {
48+ sinon . stub ( FeatureConfigProvider . instance , 'getProjectContextGroup' ) . returns ( 'control' )
4449 await toTextEditor ( aStringWithLineCount ( 200 ) , 'CrossFile.java' , tempFolder , { preview : false } )
4550 const myCurrentEditor = await toTextEditor ( '' , 'TargetFile.java' , tempFolder , {
4651 preview : false ,
@@ -53,6 +58,110 @@ describe('crossFileContextUtil', function () {
5358 assert . strictEqual ( actual . supplementalContextItems [ 1 ] . content . split ( '\n' ) . length , 50 )
5459 assert . strictEqual ( actual . supplementalContextItems [ 2 ] . content . split ( '\n' ) . length , 50 )
5560 } )
61+
62+ it ( 'for t1 group, should return repomap + opentabs context' , async function ( ) {
63+ await toTextEditor ( aStringWithLineCount ( 200 ) , 'CrossFile.java' , tempFolder , { preview : false } )
64+ const myCurrentEditor = await toTextEditor ( '' , 'TargetFile.java' , tempFolder , {
65+ preview : false ,
66+ } )
67+ sinon . stub ( FeatureConfigProvider . instance , 'getProjectContextGroup' ) . returns ( 't1' )
68+ sinon
69+ . stub ( LspController . instance , 'queryInlineProjectContext' )
70+ . withArgs ( sinon . match . any , sinon . match . any , 'codemap' )
71+ . resolves ( [
72+ {
73+ content : 'foo' ,
74+ score : 0 ,
75+ filePath : 'q-inline' ,
76+ } ,
77+ ] )
78+
79+ const actual = await crossFile . fetchSupplementalContextForSrc ( myCurrentEditor , fakeCancellationToken )
80+ assert . ok ( actual )
81+ assert . ok ( actual . supplementalContextItems . length === 4 )
82+ assert . strictEqual ( actual ?. strategy , 'codemap' )
83+ assert . deepEqual ( actual ?. supplementalContextItems [ 0 ] , {
84+ content : 'foo' ,
85+ score : 0 ,
86+ filePath : 'q-inline' ,
87+ } )
88+
89+ assert . strictEqual ( actual . supplementalContextItems [ 1 ] . content . split ( '\n' ) . length , 50 )
90+ assert . strictEqual ( actual . supplementalContextItems [ 2 ] . content . split ( '\n' ) . length , 50 )
91+ assert . strictEqual ( actual . supplementalContextItems [ 3 ] . content . split ( '\n' ) . length , 50 )
92+ } )
93+
94+ it ( 'for t2 group, should return global bm25 context and no repomap' , async function ( ) {
95+ await toTextEditor ( aStringWithLineCount ( 200 ) , 'CrossFile.java' , tempFolder , { preview : false } )
96+ const myCurrentEditor = await toTextEditor ( '' , 'TargetFile.java' , tempFolder , {
97+ preview : false ,
98+ } )
99+ sinon . stub ( FeatureConfigProvider . instance , 'getProjectContextGroup' ) . returns ( 't2' )
100+ sinon
101+ . stub ( LspController . instance , 'queryInlineProjectContext' )
102+ . withArgs ( sinon . match . any , sinon . match . any , 'bm25' )
103+ . resolves ( [
104+ {
105+ content : 'foo' ,
106+ score : 5 ,
107+ filePath : 'foo.java' ,
108+ } ,
109+ {
110+ content : 'bar' ,
111+ score : 4 ,
112+ filePath : 'bar.java' ,
113+ } ,
114+ {
115+ content : 'baz' ,
116+ score : 3 ,
117+ filePath : 'baz.java' ,
118+ } ,
119+ {
120+ content : 'qux' ,
121+ score : 2 ,
122+ filePath : 'qux.java' ,
123+ } ,
124+ {
125+ content : 'quux' ,
126+ score : 1 ,
127+ filePath : 'quux.java' ,
128+ } ,
129+ ] )
130+
131+ const actual = await crossFile . fetchSupplementalContextForSrc ( myCurrentEditor , fakeCancellationToken )
132+ assert . ok ( actual )
133+ assert . ok ( actual . supplementalContextItems . length === 5 )
134+ assert . strictEqual ( actual ?. strategy , 'bm25' )
135+
136+ assert . deepEqual ( actual ?. supplementalContextItems [ 0 ] , {
137+ content : 'foo' ,
138+ score : 5 ,
139+ filePath : 'foo.java' ,
140+ } )
141+
142+ assert . deepEqual ( actual ?. supplementalContextItems [ 1 ] , {
143+ content : 'bar' ,
144+ score : 4 ,
145+ filePath : 'bar.java' ,
146+ } )
147+ assert . deepEqual ( actual ?. supplementalContextItems [ 2 ] , {
148+ content : 'baz' ,
149+ score : 3 ,
150+ filePath : 'baz.java' ,
151+ } )
152+
153+ assert . deepEqual ( actual ?. supplementalContextItems [ 3 ] , {
154+ content : 'qux' ,
155+ score : 2 ,
156+ filePath : 'qux.java' ,
157+ } )
158+
159+ assert . deepEqual ( actual ?. supplementalContextItems [ 4 ] , {
160+ content : 'quux' ,
161+ score : 1 ,
162+ filePath : 'quux.java' ,
163+ } )
164+ } )
56165 } )
57166
58167 describe ( 'non supported language should return undefined' , function ( ) {
@@ -212,7 +321,7 @@ describe('crossFileContextUtil', function () {
212321
213322 fileExtLists . forEach ( ( fileExt ) => {
214323 it ( 'should be non empty' , async function ( ) {
215- sinon . stub ( FeatureConfigProvider . instance , 'isNewProjectContextGroup ' ) . alwaysReturned ( false )
324+ sinon . stub ( FeatureConfigProvider . instance , 'getProjectContextGroup ' ) . returns ( 'control' )
216325 const editor = await toTextEditor ( 'content-1' , `file-1.${ fileExt } ` , tempFolder )
217326 await toTextEditor ( 'content-2' , `file-2.${ fileExt } ` , tempFolder , { preview : false } )
218327 await toTextEditor ( 'content-3' , `file-3.${ fileExt } ` , tempFolder , { preview : false } )
0 commit comments