@@ -26,7 +26,6 @@ import {
2626// import * as supplementalContextUtil from 'aws-core-vscode/codewhisperer'
2727
2828describe ( 'recommendationHandler' , function ( ) {
29- const session = CodeWhispererSessionState . instance . getSession ( )
3029 const config : ConfigurationEntry = {
3130 isShowMethodsEnabled : true ,
3231 isManualTriggerEnabled : true ,
@@ -56,6 +55,7 @@ describe('recommendationHandler', function () {
5655 } )
5756
5857 it ( 'should assign correct recommendations given input' , async function ( ) {
58+ const session = CodeWhispererSessionState . instance . getSession ( )
5959 assert . strictEqual ( CodeWhispererCodeCoverageTracker . instances . size , 0 )
6060 assert . strictEqual (
6161 CodeWhispererCodeCoverageTracker . getTracker ( mockEditor . document . languageId ) ?. serviceInvocationCount ,
@@ -75,7 +75,7 @@ describe('recommendationHandler', function () {
7575 }
7676 const handler = new RecommendationHandler ( )
7777 sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
78- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' , false )
78+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' , false )
7979 const actual = session . recommendations
8080 const expected : RecommendationsList = [ { content : "print('Hello World!')" } , { content : '' } ]
8181 assert . deepStrictEqual ( actual , expected )
@@ -86,6 +86,7 @@ describe('recommendationHandler', function () {
8686 } )
8787
8888 it ( 'should assign request id correctly' , async function ( ) {
89+ const session = CodeWhispererSessionState . instance . getSession ( )
8990 const mockServerResult = {
9091 recommendations : [ { content : "print('Hello World!')" } , { content : '' } ] ,
9192 $response : {
@@ -100,7 +101,7 @@ describe('recommendationHandler', function () {
100101 const handler = new RecommendationHandler ( )
101102 sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
102103 sinon . stub ( handler , 'isCancellationRequested' ) . returns ( false )
103- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' , false )
104+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' , false )
104105 assert . strictEqual ( handler . requestId , 'test_request' )
105106 assert . strictEqual ( session . sessionId , 'test_request' )
106107 assert . strictEqual ( session . triggerType , 'AutoTrigger' )
@@ -129,9 +130,10 @@ describe('recommendationHandler', function () {
129130 strategy : 'empty' ,
130131 } )
131132 sinon . stub ( performance , 'now' ) . returns ( 0.0 )
133+ const session = CodeWhispererSessionState . instance . getSession ( )
132134 session . startPos = new vscode . Position ( 1 , 0 )
133135 session . startCursorOffset = 2
134- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' )
136+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' )
135137 const assertTelemetry = assertTelemetryCurried ( 'codewhisperer_serviceInvocation' )
136138 assertTelemetry ( {
137139 codewhispererRequestId : 'test_request' ,
@@ -168,10 +170,11 @@ describe('recommendationHandler', function () {
168170 const handler = new RecommendationHandler ( )
169171 sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
170172 sinon . stub ( performance , 'now' ) . returns ( 0.0 )
173+ const session = CodeWhispererSessionState . instance . getSession ( )
171174 session . startPos = new vscode . Position ( 1 , 0 )
172175 session . requestIdList = [ 'test_request_empty' ]
173176 session . startCursorOffset = 2
174- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' )
177+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' )
175178 const assertTelemetry = assertTelemetryCurried ( 'codewhisperer_userDecision' )
176179 assertTelemetry ( {
177180 codewhispererRequestId : 'test_request_empty' ,
@@ -193,6 +196,7 @@ describe('recommendationHandler', function () {
193196 sinon . restore ( )
194197 } )
195198 it ( 'should return true if any response is not empty' , function ( ) {
199+ const session = CodeWhispererSessionState . instance . getSession ( )
196200 const handler = new RecommendationHandler ( )
197201 session . recommendations = [
198202 {
@@ -205,12 +209,14 @@ describe('recommendationHandler', function () {
205209 } )
206210
207211 it ( 'should return false if response is empty' , function ( ) {
212+ const session = CodeWhispererSessionState . instance . getSession ( )
208213 const handler = new RecommendationHandler ( )
209214 session . recommendations = [ ]
210215 assert . ok ( ! handler . isValidResponse ( ) )
211216 } )
212217
213218 it ( 'should return false if all response has no string length' , function ( ) {
219+ const session = CodeWhispererSessionState . instance . getSession ( )
214220 const handler = new RecommendationHandler ( )
215221 session . recommendations = [ { content : '' } , { content : '' } ]
216222 assert . ok ( ! handler . isValidResponse ( ) )
@@ -223,6 +229,7 @@ describe('recommendationHandler', function () {
223229 } )
224230
225231 it ( 'should set the completion type to block given a multi-line suggestion' , function ( ) {
232+ const session = CodeWhispererSessionState . instance . getSession ( )
226233 session . setCompletionType ( 0 , { content : 'test\n\n \t\r\nanother test' } )
227234 assert . strictEqual ( session . getCompletionType ( 0 ) , 'Block' )
228235
@@ -234,6 +241,7 @@ describe('recommendationHandler', function () {
234241 } )
235242
236243 it ( 'should set the completion type to line given a single-line suggestion' , function ( ) {
244+ const session = CodeWhispererSessionState . instance . getSession ( )
237245 session . setCompletionType ( 0 , { content : 'test' } )
238246 assert . strictEqual ( session . getCompletionType ( 0 ) , 'Line' )
239247
@@ -242,6 +250,7 @@ describe('recommendationHandler', function () {
242250 } )
243251
244252 it ( 'should set the completion type to line given a multi-line completion but only one-lien of non-blank sequence' , function ( ) {
253+ const session = CodeWhispererSessionState . instance . getSession ( )
245254 session . setCompletionType ( 0 , { content : 'test\n\t' } )
246255 assert . strictEqual ( session . getCompletionType ( 0 ) , 'Line' )
247256
@@ -258,6 +267,7 @@ describe('recommendationHandler', function () {
258267
259268 describe ( 'on event change' , async function ( ) {
260269 beforeEach ( function ( ) {
270+ const session = CodeWhispererSessionState . instance . getSession ( )
261271 const fakeReferences = [
262272 {
263273 message : '' ,
@@ -275,12 +285,14 @@ describe('recommendationHandler', function () {
275285 } )
276286
277287 it ( 'should remove inline reference onEditorChange' , async function ( ) {
288+ const session = CodeWhispererSessionState . instance . getSession ( )
278289 session . sessionId = 'aSessionId'
279290 RecommendationHandler . instance . requestId = 'aRequestId'
280291 await RecommendationHandler . instance . onEditorChange ( )
281292 assert . strictEqual ( ReferenceInlineProvider . instance . refs . length , 0 )
282293 } )
283294 it ( 'should remove inline reference onFocusChange' , async function ( ) {
295+ const session = CodeWhispererSessionState . instance . getSession ( )
284296 session . sessionId = 'aSessionId'
285297 RecommendationHandler . instance . requestId = 'aRequestId'
286298 await RecommendationHandler . instance . onFocusChange ( )
0 commit comments