Skip to content

Commit d4b687a

Browse files
committed
fix: duplicate code
1 parent a1a4847 commit d4b687a

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

packages/amazonq/src/inlineChat/provider/inlineChatProvider.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ export class InlineChatProvider {
7474
switch (triggerEvent?.type) {
7575
case 'editor_context_command':
7676
return triggerEvent.command?.triggerType === 'keybinding' ? 'hotkeys' : 'contextMenu'
77-
case 'follow_up':
78-
case 'chat_message':
7977
default:
8078
return 'click'
8179
}
8280
}
8381

8482
public async processPromptMessageLSP(message: PromptMessage): Promise<InlineChatResult> {
85-
const triggerInteraction = this.getTriggerInteractionFromTriggerEvent(
83+
const triggerInteractionLSP = this.getTriggerInteractionFromTriggerEvent(
8684
this.triggerEventsStorage.getLastTriggerEventByTabID(message.tabID)
8785
)
8886
if (!AuthUtil.instance.isSsoSession()) {
@@ -91,7 +89,7 @@ export class InlineChatProvider {
9189
cwsprChatConversationType: 'Chat',
9290
cwsprChatRequestLength: message.message?.length ?? 0,
9391
cwsprChatResponseCode: 401,
94-
cwsprChatTriggerInteraction: triggerInteraction,
92+
cwsprChatTriggerInteraction: triggerInteractionLSP,
9593
reason: 'AuthenticationError',
9694
reasonDesc: 'Inline chat requires SSO authentication, but current session is not',
9795
})

packages/amazonq/test/unit/codewhisperer/util/authUtil.test.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ describe('AuthUtil', async function () {
367367
auth.session = new auth2.SsoLogin(auth.profileName, auth.lspAuth, auth.eventEmitter)
368368
}
369369

370-
const updateProfileStub = sinon.stub((auth as any).session, 'updateProfile').resolves()
370+
const updateProfileStubNew = sinon.stub((auth as any).session, 'updateProfile').resolves()
371371

372372
await auth.migrateSsoConnectionToLsp('test-client')
373373

374-
assert.ok(updateProfileStub.calledOnce)
374+
assert.ok(updateProfileStubNew.calledOnce)
375375
assert.ok(memento.update.calledWith('auth.profiles', undefined))
376-
assert.deepStrictEqual(updateProfileStub.firstCall.args[0], {
376+
assert.deepStrictEqual(updateProfileStubNew.firstCall.args[0], {
377377
startUrl: validProfile.startUrl,
378378
region: validProfile.ssoRegion,
379379
scopes: validProfile.scopes,
@@ -396,12 +396,12 @@ describe('AuthUtil', async function () {
396396
auth.session = new auth2.SsoLogin(auth.profileName, auth.lspAuth, auth.eventEmitter)
397397
}
398398

399-
const updateProfileStub = sinon.stub((auth as any).session, 'updateProfile').resolves()
399+
const updateProfileStubNext = sinon.stub((auth as any).session, 'updateProfile').resolves()
400400

401401
await auth.migrateSsoConnectionToLsp('test-client')
402402

403403
assert.ok(
404-
updateProfileStub.calledWith({
404+
updateProfileStubNext.calledWith({
405405
startUrl: validProfile.startUrl,
406406
region: validProfile.ssoRegion,
407407
scopes: validProfile.scopes,
@@ -450,28 +450,36 @@ describe('AuthUtil', async function () {
450450
accessKeyId: 'encrypted-access-key',
451451
secretAccessKey: 'encrypted-secret-key',
452452
sessionToken: 'encrypted-session-token',
453+
roleArn: 'arn:aws:iam::123456789012:role/TestRole',
453454
},
454455
updateCredentialsParams: {
455456
data: 'credential-data',
456457
},
457458
}
458-
459+
459460
const mockIamLogin = {
460461
login: sinon.stub().resolves(mockResponse),
461462
loginType: 'iam',
462463
}
463-
464+
464465
sinon.stub(auth2, 'IamLogin').returns(mockIamLogin as any)
465-
466-
const response = await auth.loginIam('accessKey', 'secretKey', 'sessionToken', 'arn:aws:iam::123456789012:role/TestRole')
467-
466+
467+
const response = await auth.loginIam(
468+
'accessKey',
469+
'secretKey',
470+
'sessionToken',
471+
'arn:aws:iam::123456789012:role/TestRole'
472+
)
473+
468474
assert.ok(mockIamLogin.login.calledOnce)
469-
assert.ok(mockIamLogin.login.calledWith({
470-
accessKey: 'accessKey',
471-
secretKey: 'secretKey',
472-
sessionToken: 'sessionToken',
473-
roleArn: 'arn:aws:iam::123456789012:role/TestRole',
474-
}))
475+
assert.ok(
476+
mockIamLogin.login.calledWith({
477+
accessKey: 'accessKey',
478+
secretKey: 'secretKey',
479+
sessionToken: 'sessionToken',
480+
roleArn: 'arn:aws:iam::123456789012:role/TestRole',
481+
})
482+
)
475483
assert.strictEqual(response, mockResponse)
476484
})
477485
})
@@ -574,4 +582,4 @@ describe('AuthUtil', async function () {
574582
assert.strictEqual(mockLspAuth.updateIamCredential.firstCall.args[0].data, 'fake-data')
575583
})
576584
})
577-
})
585+
})

packages/core/src/test/amazonq/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ export async function sessionRegisterProvider(session: Session, uri: vscode.Uri,
8787

8888
export function generateVirtualMemoryUri(uploadID: string, filePath: string, scheme: string) {
8989
const generationFilePath = path.join(uploadID, filePath)
90-
const uri = vscode.Uri.from({ scheme, path: generationFilePath })
91-
return uri
90+
const uriNew = vscode.Uri.from({ scheme, path: generationFilePath })
91+
return uriNew
9292
}
9393

9494
export async function sessionWriteFile(session: Session, uri: vscode.Uri, encodedContent: Uint8Array) {

0 commit comments

Comments
 (0)