@@ -8,7 +8,7 @@ import * as vscode from 'vscode'
88import * as sinon from 'sinon'
99import {
1010 ReferenceInlineProvider ,
11- session ,
11+ CodeWhispererSessionState ,
1212 AuthUtil ,
1313 DefaultCodeWhispererClient ,
1414 RecommendationsList ,
@@ -55,6 +55,7 @@ describe('recommendationHandler', function () {
5555 } )
5656
5757 it ( 'should assign correct recommendations given input' , async function ( ) {
58+ const session = CodeWhispererSessionState . instance . getSession ( )
5859 assert . strictEqual ( CodeWhispererCodeCoverageTracker . instances . size , 0 )
5960 assert . strictEqual (
6061 CodeWhispererCodeCoverageTracker . getTracker ( mockEditor . document . languageId ) ?. serviceInvocationCount ,
@@ -74,7 +75,7 @@ describe('recommendationHandler', function () {
7475 }
7576 const handler = new RecommendationHandler ( )
7677 sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
77- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' , false )
78+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' , false )
7879 const actual = session . recommendations
7980 const expected : RecommendationsList = [ { content : "print('Hello World!')" } , { content : '' } ]
8081 assert . deepStrictEqual ( actual , expected )
@@ -85,6 +86,7 @@ describe('recommendationHandler', function () {
8586 } )
8687
8788 it ( 'should assign request id correctly' , async function ( ) {
89+ const session = CodeWhispererSessionState . instance . getSession ( )
8890 const mockServerResult = {
8991 recommendations : [ { content : "print('Hello World!')" } , { content : '' } ] ,
9092 $response : {
@@ -99,7 +101,7 @@ describe('recommendationHandler', function () {
99101 const handler = new RecommendationHandler ( )
100102 sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
101103 sinon . stub ( handler , 'isCancellationRequested' ) . returns ( false )
102- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' , false )
104+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' , false )
103105 assert . strictEqual ( handler . requestId , 'test_request' )
104106 assert . strictEqual ( session . sessionId , 'test_request' )
105107 assert . strictEqual ( session . triggerType , 'AutoTrigger' )
@@ -128,9 +130,10 @@ describe('recommendationHandler', function () {
128130 strategy : 'empty' ,
129131 } )
130132 sinon . stub ( performance , 'now' ) . returns ( 0.0 )
133+ const session = CodeWhispererSessionState . instance . getSession ( )
131134 session . startPos = new vscode . Position ( 1 , 0 )
132135 session . startCursorOffset = 2
133- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' )
136+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' )
134137 const assertTelemetry = assertTelemetryCurried ( 'codewhisperer_serviceInvocation' )
135138 assertTelemetry ( {
136139 codewhispererRequestId : 'test_request' ,
@@ -167,10 +170,11 @@ describe('recommendationHandler', function () {
167170 const handler = new RecommendationHandler ( )
168171 sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
169172 sinon . stub ( performance , 'now' ) . returns ( 0.0 )
173+ const session = CodeWhispererSessionState . instance . getSession ( )
170174 session . startPos = new vscode . Position ( 1 , 0 )
171175 session . requestIdList = [ 'test_request_empty' ]
172176 session . startCursorOffset = 2
173- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' )
177+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' )
174178 const assertTelemetry = assertTelemetryCurried ( 'codewhisperer_userDecision' )
175179 assertTelemetry ( {
176180 codewhispererRequestId : 'test_request_empty' ,
@@ -192,6 +196,7 @@ describe('recommendationHandler', function () {
192196 sinon . restore ( )
193197 } )
194198 it ( 'should return true if any response is not empty' , function ( ) {
199+ const session = CodeWhispererSessionState . instance . getSession ( )
195200 const handler = new RecommendationHandler ( )
196201 session . recommendations = [
197202 {
@@ -204,12 +209,14 @@ describe('recommendationHandler', function () {
204209 } )
205210
206211 it ( 'should return false if response is empty' , function ( ) {
212+ const session = CodeWhispererSessionState . instance . getSession ( )
207213 const handler = new RecommendationHandler ( )
208214 session . recommendations = [ ]
209215 assert . ok ( ! handler . isValidResponse ( ) )
210216 } )
211217
212218 it ( 'should return false if all response has no string length' , function ( ) {
219+ const session = CodeWhispererSessionState . instance . getSession ( )
213220 const handler = new RecommendationHandler ( )
214221 session . recommendations = [ { content : '' } , { content : '' } ]
215222 assert . ok ( ! handler . isValidResponse ( ) )
@@ -222,6 +229,7 @@ describe('recommendationHandler', function () {
222229 } )
223230
224231 it ( 'should set the completion type to block given a multi-line suggestion' , function ( ) {
232+ const session = CodeWhispererSessionState . instance . getSession ( )
225233 session . setCompletionType ( 0 , { content : 'test\n\n \t\r\nanother test' } )
226234 assert . strictEqual ( session . getCompletionType ( 0 ) , 'Block' )
227235
@@ -233,6 +241,7 @@ describe('recommendationHandler', function () {
233241 } )
234242
235243 it ( 'should set the completion type to line given a single-line suggestion' , function ( ) {
244+ const session = CodeWhispererSessionState . instance . getSession ( )
236245 session . setCompletionType ( 0 , { content : 'test' } )
237246 assert . strictEqual ( session . getCompletionType ( 0 ) , 'Line' )
238247
@@ -241,6 +250,7 @@ describe('recommendationHandler', function () {
241250 } )
242251
243252 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 ( )
244254 session . setCompletionType ( 0 , { content : 'test\n\t' } )
245255 assert . strictEqual ( session . getCompletionType ( 0 ) , 'Line' )
246256
@@ -257,6 +267,7 @@ describe('recommendationHandler', function () {
257267
258268 describe ( 'on event change' , async function ( ) {
259269 beforeEach ( function ( ) {
270+ const session = CodeWhispererSessionState . instance . getSession ( )
260271 const fakeReferences = [
261272 {
262273 message : '' ,
@@ -274,12 +285,14 @@ describe('recommendationHandler', function () {
274285 } )
275286
276287 it ( 'should remove inline reference onEditorChange' , async function ( ) {
288+ const session = CodeWhispererSessionState . instance . getSession ( )
277289 session . sessionId = 'aSessionId'
278290 RecommendationHandler . instance . requestId = 'aRequestId'
279291 await RecommendationHandler . instance . onEditorChange ( )
280292 assert . strictEqual ( ReferenceInlineProvider . instance . refs . length , 0 )
281293 } )
282294 it ( 'should remove inline reference onFocusChange' , async function ( ) {
295+ const session = CodeWhispererSessionState . instance . getSession ( )
283296 session . sessionId = 'aSessionId'
284297 RecommendationHandler . instance . requestId = 'aRequestId'
285298 await RecommendationHandler . instance . onFocusChange ( )
0 commit comments