@@ -2,18 +2,17 @@ import { SendMessageCommandInput, SendMessageCommandOutput, ChatTriggerType } fr
22import * as assert from 'assert'
33import sinon , { StubbedInstance , stubInterface } from 'ts-sinon'
44import { ChatSessionService } from './chatSessionService'
5- import { AmazonQTokenServiceManager } from '../../shared/amazonQServiceManager/AmazonQTokenServiceManager'
6- import { StreamingClientServiceToken , StreamingClientServiceIAM } from '../../shared/streamingClientService'
5+ import { StreamingClientService } from '../../shared/streamingClientService'
76import { AmazonQBaseServiceManager } from '../../shared/amazonQServiceManager/BaseAmazonQServiceManager'
8- import { AmazonQIAMServiceManager } from '../../shared/amazonQServiceManager/AmazonQIAMServiceManager '
7+ import { AmazonQServiceManager } from '../../shared/amazonQServiceManager/AmazonQServiceManager '
98import * as sharedUtils from '../../shared/utils'
109import { Utils } from 'vscode-uri'
1110
1211describe ( 'Chat Session Service' , ( ) => {
1312 let abortStub : sinon . SinonStub < any , any >
1413 let chatSessionService : ChatSessionService
1514 let amazonQServiceManager : StubbedInstance < AmazonQBaseServiceManager >
16- let codeWhispererStreamingClient : StubbedInstance < StreamingClientServiceToken >
15+ let codeWhispererStreamingClient : StubbedInstance < StreamingClientService >
1716 const mockConversationId = 'mockConversationId'
1817
1918 const mockRequestParams : SendMessageCommandInput = {
@@ -33,8 +32,9 @@ describe('Chat Session Service', () => {
3332 }
3433
3534 beforeEach ( ( ) => {
36- codeWhispererStreamingClient = stubInterface < StreamingClientServiceToken > ( )
35+ codeWhispererStreamingClient = stubInterface < StreamingClientService > ( )
3736 codeWhispererStreamingClient . sendMessage . callsFake ( ( ) => Promise . resolve ( mockRequestResponse ) )
37+ codeWhispererStreamingClient . getCredentialsType . returns ( 'bearer' )
3838
3939 amazonQServiceManager = stubInterface < AmazonQBaseServiceManager > ( )
4040 amazonQServiceManager . getStreamingClient . returns ( codeWhispererStreamingClient )
@@ -44,16 +44,16 @@ describe('Chat Session Service', () => {
4444 chatSessionService = new ChatSessionService ( amazonQServiceManager )
4545
4646 // needed to identify the stubs as the actual class when checking 'instanceof' in generateAssistantResponse
47- Object . setPrototypeOf ( amazonQServiceManager , AmazonQTokenServiceManager . prototype )
48- Object . setPrototypeOf ( codeWhispererStreamingClient , StreamingClientServiceToken . prototype )
47+ Object . setPrototypeOf ( amazonQServiceManager , AmazonQServiceManager . prototype )
48+ Object . setPrototypeOf ( codeWhispererStreamingClient , StreamingClientService . prototype )
4949 } )
5050
5151 afterEach ( ( ) => {
5252 abortStub . restore ( )
5353 } )
5454
5555 describe ( 'calling SendMessage' , ( ) => {
56- it ( 'throws error is AmazonQTokenServiceManager is not initialized' , async ( ) => {
56+ it ( 'throws error is AmazonQServiceManager is not initialized' , async ( ) => {
5757 chatSessionService = new ChatSessionService ( undefined )
5858
5959 await assert . rejects (
@@ -114,7 +114,7 @@ describe('Chat Session Service', () => {
114114 } )
115115
116116 describe ( 'calling GenerateAssistantResponse' , ( ) => {
117- it ( 'throws error is AmazonQTokenServiceManager is not initialized' , async ( ) => {
117+ it ( 'throws error is AmazonQServiceManager is not initialized' , async ( ) => {
118118 chatSessionService = new ChatSessionService ( undefined )
119119
120120 await assert . rejects (
@@ -149,10 +149,10 @@ describe('Chat Session Service', () => {
149149 } )
150150
151151 it ( 'abortRequest() in IAM client, aborts request with AbortController' , async ( ) => {
152- const codeWhispererStreamingClientIAM = stubInterface < StreamingClientServiceIAM > ( )
152+ const codeWhispererStreamingClientIAM = stubInterface < StreamingClientService > ( )
153153 codeWhispererStreamingClientIAM . sendMessage . callsFake ( ( ) => Promise . resolve ( mockRequestResponse ) )
154154
155- const amazonQServiceManagerIAM = stubInterface < AmazonQIAMServiceManager > ( )
155+ const amazonQServiceManagerIAM = stubInterface < AmazonQServiceManager > ( )
156156 amazonQServiceManagerIAM . getStreamingClient . returns ( codeWhispererStreamingClientIAM )
157157
158158 const chatSessionServiceIAM = new ChatSessionService ( amazonQServiceManagerIAM )
@@ -164,10 +164,10 @@ describe('Chat Session Service', () => {
164164 } )
165165
166166 it ( 'dispose() in IAM client, calls aborts outgoing requests' , async ( ) => {
167- const codeWhispererStreamingClientIAM = stubInterface < StreamingClientServiceIAM > ( )
167+ const codeWhispererStreamingClientIAM = stubInterface < StreamingClientService > ( )
168168 codeWhispererStreamingClientIAM . sendMessage . callsFake ( ( ) => Promise . resolve ( mockRequestResponse ) )
169169
170- const amazonQServiceManagerIAM = stubInterface < AmazonQIAMServiceManager > ( )
170+ const amazonQServiceManagerIAM = stubInterface < AmazonQServiceManager > ( )
171171 amazonQServiceManagerIAM . getStreamingClient . returns ( codeWhispererStreamingClientIAM )
172172
173173 const chatSessionServiceIAM = new ChatSessionService ( amazonQServiceManagerIAM )
@@ -208,10 +208,10 @@ describe('Chat Session Service', () => {
208208 } )
209209
210210 it ( 'clear() in IAM client, resets conversation id and aborts outgoing request' , async ( ) => {
211- const codeWhispererStreamingClientIAM = stubInterface < StreamingClientServiceIAM > ( )
211+ const codeWhispererStreamingClientIAM = stubInterface < StreamingClientService > ( )
212212 codeWhispererStreamingClientIAM . sendMessage . callsFake ( ( ) => Promise . resolve ( mockRequestResponse ) )
213213
214- const amazonQServiceManagerIAM = stubInterface < AmazonQIAMServiceManager > ( )
214+ const amazonQServiceManagerIAM = stubInterface < AmazonQServiceManager > ( )
215215 amazonQServiceManagerIAM . getStreamingClient . returns ( codeWhispererStreamingClientIAM )
216216
217217 const chatSessionServiceIAM = new ChatSessionService ( amazonQServiceManagerIAM )
@@ -323,18 +323,64 @@ describe('Chat Session Service', () => {
323323 assert . ok ( approvedPaths . has ( unixPath ) )
324324 } )
325325 } )
326+ } )
327+
328+ describe ( 'IAM Chat Session Service' , ( ) => {
329+ let abortStub : sinon . SinonStub < any , any >
330+ let chatSessionService : ChatSessionService
331+ let amazonQServiceManager : StubbedInstance < AmazonQServiceManager >
332+ let codeWhispererStreamingClient : StubbedInstance < StreamingClientService >
333+ const mockConversationId = 'mockConversationId'
334+
335+ const mockRequestParams : SendMessageCommandInput = {
336+ conversationState : {
337+ chatTriggerType : 'MANUAL' ,
338+ currentMessage : {
339+ userInputMessage : {
340+ content : 'hello' ,
341+ } ,
342+ } ,
343+ } ,
344+ }
345+
346+ const mockRequestResponse : SendMessageCommandOutput = {
347+ $metadata : { } ,
348+ sendMessageResponse : undefined ,
349+ }
350+
351+ beforeEach ( ( ) => {
352+ codeWhispererStreamingClient = stubInterface < StreamingClientService > ( )
353+ codeWhispererStreamingClient . sendMessage . callsFake ( ( ) => Promise . resolve ( mockRequestResponse ) )
354+ codeWhispererStreamingClient . getCredentialsType . returns ( 'iam' )
355+
356+ amazonQServiceManager = stubInterface < AmazonQServiceManager > ( )
357+ amazonQServiceManager . getStreamingClient . returns ( codeWhispererStreamingClient )
358+
359+ abortStub = sinon . stub ( AbortController . prototype , 'abort' )
360+
361+ chatSessionService = new ChatSessionService ( amazonQServiceManager )
362+
363+ // needed to identify the stubs as the actual class when checking 'instanceof' in generateAssistantResponse
364+ Object . setPrototypeOf ( amazonQServiceManager , AmazonQServiceManager . prototype )
365+ Object . setPrototypeOf ( codeWhispererStreamingClient , StreamingClientService . prototype )
366+ } )
367+
368+ afterEach ( ( ) => {
369+ abortStub . restore ( )
370+ } )
326371
327372 describe ( 'IAM client source property' , ( ) => {
328- it ( 'sets source to Origin.IDE when using StreamingClientServiceIAM ' , async ( ) => {
329- const codeWhispererStreamingClientIAM = stubInterface < StreamingClientServiceIAM > ( )
373+ it ( 'sets source to Origin.IDE when using StreamingClientService ' , async ( ) => {
374+ const codeWhispererStreamingClientIAM = stubInterface < StreamingClientService > ( )
330375 codeWhispererStreamingClientIAM . sendMessage . callsFake ( ( ) => Promise . resolve ( mockRequestResponse ) )
376+ codeWhispererStreamingClientIAM . getCredentialsType . returns ( 'iam' )
331377
332- const amazonQServiceManagerIAM = stubInterface < AmazonQIAMServiceManager > ( )
378+ const amazonQServiceManagerIAM = stubInterface < AmazonQServiceManager > ( )
333379 amazonQServiceManagerIAM . getStreamingClient . returns ( codeWhispererStreamingClientIAM )
334380
335381 // Set prototype to make instanceof check work
336- Object . setPrototypeOf ( codeWhispererStreamingClientIAM , StreamingClientServiceIAM . prototype )
337- Object . setPrototypeOf ( amazonQServiceManagerIAM , AmazonQIAMServiceManager . prototype )
382+ Object . setPrototypeOf ( codeWhispererStreamingClientIAM , StreamingClientService . prototype )
383+ Object . setPrototypeOf ( amazonQServiceManagerIAM , AmazonQServiceManager . prototype )
338384
339385 const chatSessionServiceIAM = new ChatSessionService ( amazonQServiceManagerIAM )
340386
@@ -361,15 +407,16 @@ describe('Chat Session Service', () => {
361407 . stub ( sharedUtils , 'getOriginFromClientInfo' )
362408 . returns ( 'MD_IDE' as any )
363409
364- const codeWhispererStreamingClientIAM = stubInterface < StreamingClientServiceIAM > ( )
410+ const codeWhispererStreamingClientIAM = stubInterface < StreamingClientService > ( )
365411 codeWhispererStreamingClientIAM . sendMessage . callsFake ( ( ) => Promise . resolve ( mockRequestResponse ) )
412+ codeWhispererStreamingClientIAM . getCredentialsType . returns ( 'iam' )
366413
367- const amazonQServiceManagerIAM = stubInterface < AmazonQIAMServiceManager > ( )
414+ const amazonQServiceManagerIAM = stubInterface < AmazonQServiceManager > ( )
368415 amazonQServiceManagerIAM . getStreamingClient . returns ( codeWhispererStreamingClientIAM )
369416
370417 // Set prototype to make instanceof check work
371- Object . setPrototypeOf ( codeWhispererStreamingClientIAM , StreamingClientServiceIAM . prototype )
372- Object . setPrototypeOf ( amazonQServiceManagerIAM , AmazonQIAMServiceManager . prototype )
418+ Object . setPrototypeOf ( codeWhispererStreamingClientIAM , StreamingClientService . prototype )
419+ Object . setPrototypeOf ( amazonQServiceManagerIAM , AmazonQServiceManager . prototype )
373420
374421 const chatSessionServiceIAM = new ChatSessionService ( amazonQServiceManagerIAM )
375422
0 commit comments