@@ -8,7 +8,7 @@ import * as vscode from 'vscode'
8
8
import * as sinon from 'sinon'
9
9
import {
10
10
ReferenceInlineProvider ,
11
- session ,
11
+ CodeWhispererSessionState ,
12
12
AuthUtil ,
13
13
DefaultCodeWhispererClient ,
14
14
RecommendationsList ,
@@ -55,6 +55,7 @@ describe('recommendationHandler', function () {
55
55
} )
56
56
57
57
it ( 'should assign correct recommendations given input' , async function ( ) {
58
+ const session = CodeWhispererSessionState . instance . getSession ( )
58
59
assert . strictEqual ( CodeWhispererCodeCoverageTracker . instances . size , 0 )
59
60
assert . strictEqual (
60
61
CodeWhispererCodeCoverageTracker . getTracker ( mockEditor . document . languageId ) ?. serviceInvocationCount ,
@@ -74,7 +75,7 @@ describe('recommendationHandler', function () {
74
75
}
75
76
const handler = new RecommendationHandler ( )
76
77
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 )
78
79
const actual = session . recommendations
79
80
const expected : RecommendationsList = [ { content : "print('Hello World!')" } , { content : '' } ]
80
81
assert . deepStrictEqual ( actual , expected )
@@ -85,6 +86,7 @@ describe('recommendationHandler', function () {
85
86
} )
86
87
87
88
it ( 'should assign request id correctly' , async function ( ) {
89
+ const session = CodeWhispererSessionState . instance . getSession ( )
88
90
const mockServerResult = {
89
91
recommendations : [ { content : "print('Hello World!')" } , { content : '' } ] ,
90
92
$response : {
@@ -99,7 +101,7 @@ describe('recommendationHandler', function () {
99
101
const handler = new RecommendationHandler ( )
100
102
sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
101
103
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 )
103
105
assert . strictEqual ( handler . requestId , 'test_request' )
104
106
assert . strictEqual ( session . sessionId , 'test_request' )
105
107
assert . strictEqual ( session . triggerType , 'AutoTrigger' )
@@ -128,9 +130,10 @@ describe('recommendationHandler', function () {
128
130
strategy : 'empty' ,
129
131
} )
130
132
sinon . stub ( performance , 'now' ) . returns ( 0.0 )
133
+ const session = CodeWhispererSessionState . instance . getSession ( )
131
134
session . startPos = new vscode . Position ( 1 , 0 )
132
135
session . startCursorOffset = 2
133
- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' )
136
+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' )
134
137
const assertTelemetry = assertTelemetryCurried ( 'codewhisperer_serviceInvocation' )
135
138
assertTelemetry ( {
136
139
codewhispererRequestId : 'test_request' ,
@@ -167,10 +170,11 @@ describe('recommendationHandler', function () {
167
170
const handler = new RecommendationHandler ( )
168
171
sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
169
172
sinon . stub ( performance , 'now' ) . returns ( 0.0 )
173
+ const session = CodeWhispererSessionState . instance . getSession ( )
170
174
session . startPos = new vscode . Position ( 1 , 0 )
171
175
session . requestIdList = [ 'test_request_empty' ]
172
176
session . startCursorOffset = 2
173
- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' )
177
+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' )
174
178
const assertTelemetry = assertTelemetryCurried ( 'codewhisperer_userDecision' )
175
179
assertTelemetry ( {
176
180
codewhispererRequestId : 'test_request_empty' ,
@@ -192,6 +196,7 @@ describe('recommendationHandler', function () {
192
196
sinon . restore ( )
193
197
} )
194
198
it ( 'should return true if any response is not empty' , function ( ) {
199
+ const session = CodeWhispererSessionState . instance . getSession ( )
195
200
const handler = new RecommendationHandler ( )
196
201
session . recommendations = [
197
202
{
@@ -204,12 +209,14 @@ describe('recommendationHandler', function () {
204
209
} )
205
210
206
211
it ( 'should return false if response is empty' , function ( ) {
212
+ const session = CodeWhispererSessionState . instance . getSession ( )
207
213
const handler = new RecommendationHandler ( )
208
214
session . recommendations = [ ]
209
215
assert . ok ( ! handler . isValidResponse ( ) )
210
216
} )
211
217
212
218
it ( 'should return false if all response has no string length' , function ( ) {
219
+ const session = CodeWhispererSessionState . instance . getSession ( )
213
220
const handler = new RecommendationHandler ( )
214
221
session . recommendations = [ { content : '' } , { content : '' } ]
215
222
assert . ok ( ! handler . isValidResponse ( ) )
@@ -222,6 +229,7 @@ describe('recommendationHandler', function () {
222
229
} )
223
230
224
231
it ( 'should set the completion type to block given a multi-line suggestion' , function ( ) {
232
+ const session = CodeWhispererSessionState . instance . getSession ( )
225
233
session . setCompletionType ( 0 , { content : 'test\n\n \t\r\nanother test' } )
226
234
assert . strictEqual ( session . getCompletionType ( 0 ) , 'Block' )
227
235
@@ -233,6 +241,7 @@ describe('recommendationHandler', function () {
233
241
} )
234
242
235
243
it ( 'should set the completion type to line given a single-line suggestion' , function ( ) {
244
+ const session = CodeWhispererSessionState . instance . getSession ( )
236
245
session . setCompletionType ( 0 , { content : 'test' } )
237
246
assert . strictEqual ( session . getCompletionType ( 0 ) , 'Line' )
238
247
@@ -241,6 +250,7 @@ describe('recommendationHandler', function () {
241
250
} )
242
251
243
252
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 ( )
244
254
session . setCompletionType ( 0 , { content : 'test\n\t' } )
245
255
assert . strictEqual ( session . getCompletionType ( 0 ) , 'Line' )
246
256
@@ -257,6 +267,7 @@ describe('recommendationHandler', function () {
257
267
258
268
describe ( 'on event change' , async function ( ) {
259
269
beforeEach ( function ( ) {
270
+ const session = CodeWhispererSessionState . instance . getSession ( )
260
271
const fakeReferences = [
261
272
{
262
273
message : '' ,
@@ -274,12 +285,14 @@ describe('recommendationHandler', function () {
274
285
} )
275
286
276
287
it ( 'should remove inline reference onEditorChange' , async function ( ) {
288
+ const session = CodeWhispererSessionState . instance . getSession ( )
277
289
session . sessionId = 'aSessionId'
278
290
RecommendationHandler . instance . requestId = 'aRequestId'
279
291
await RecommendationHandler . instance . onEditorChange ( )
280
292
assert . strictEqual ( ReferenceInlineProvider . instance . refs . length , 0 )
281
293
} )
282
294
it ( 'should remove inline reference onFocusChange' , async function ( ) {
295
+ const session = CodeWhispererSessionState . instance . getSession ( )
283
296
session . sessionId = 'aSessionId'
284
297
RecommendationHandler . instance . requestId = 'aRequestId'
285
298
await RecommendationHandler . instance . onFocusChange ( )
0 commit comments