Skip to content

Commit e49d055

Browse files
committed
Merge remote-tracking branch 'upstream/master' into chat-custom
2 parents ea99065 + ee2c934 commit e49d055

File tree

22 files changed

+787
-467
lines changed

22 files changed

+787
-467
lines changed

docs/TESTPLAN.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Checking the state works well if user interactions are not required by the code
104104
To handle this, test code can register event handler that listen for when a certain type of UI element is shown. For example, if we wanted to always accept the first item of a quick pick we can do this:
105105

106106
```ts
107-
getTestWindow().onDidShowQuickPick(async picker => {
107+
getTestWindow().onDidShowQuickPick(async (picker) => {
108108
// Some pickers load items asychronously
109109
// Wait until the picker is not busy before accepting an item
110110
await picker.untilReady()
@@ -121,3 +121,9 @@ const secondPicker = await pickers.next()
121121
```
122122

123123
Exceptions thrown within one of these handlers will cause the current test to fail. This allows you to make assertions within the callback without worrying about causing the test to hang.
124+
125+
## Common issues
126+
127+
### Stubbing VSCode outside of core
128+
129+
- Stubbing VSCode imports (like executeCommand) does not work outside of core. For now you will need to put any tests that require spying/stubbing VSCode imports in core until we move more source files into the amazon q package

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ describe('AuthUtil', async function () {
278278
assert.strictEqual(authUtil.reformatStartUrl(expected + '/#/'), expected)
279279
assert.strictEqual(authUtil.reformatStartUrl(expected + '####'), expected)
280280
})
281+
282+
it(`clearExtraConnections()`, async function () {
283+
const conn1 = await auth.createConnection(createBuilderIdProfile())
284+
const conn2 = await auth.createConnection(createSsoProfile({ startUrl: enterpriseSsoStartUrl }))
285+
const conn3 = await auth.createConnection(createSsoProfile({ startUrl: enterpriseSsoStartUrl + 1 }))
286+
// validate listConnections shows all connections
287+
assert.deepStrictEqual(
288+
(await authUtil.auth.listConnections()).map((conn) => conn.id).sort((a, b) => a.localeCompare(b)),
289+
[conn1, conn2, conn3].map((conn) => conn.id).sort((a, b) => a.localeCompare(b))
290+
)
291+
await authUtil.secondaryAuth.useNewConnection(conn3)
292+
293+
await authUtil.clearExtraConnections() // method under test
294+
295+
// Only the conn that AuthUtil is using is remaining
296+
assert.deepStrictEqual(
297+
(await authUtil.auth.listConnections()).map((conn) => conn.id),
298+
[conn3.id]
299+
)
300+
})
281301
})
282302

283303
describe('getChatAuthState()', function () {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { existsSync } from 'fs'
7+
import * as vscode from 'vscode'
8+
import { featureDevScheme } from '../../amazonqFeatureDev/constants'
9+
10+
export async function openDiff(leftPath: string, rightPath: string, tabId: string) {
11+
const { left, right } = getFileDiffUris(leftPath, rightPath, tabId)
12+
await vscode.commands.executeCommand('vscode.diff', left, right)
13+
}
14+
15+
export async function openDeletedDiff(filePath: string, name: string, tabId: string) {
16+
const fileUri = getOriginalFileUri(filePath, tabId)
17+
await vscode.commands.executeCommand('vscode.open', fileUri, {}, `${name} (Deleted)`)
18+
}
19+
20+
export function getOriginalFileUri(fullPath: string, tabId: string) {
21+
return existsSync(fullPath) ? vscode.Uri.file(fullPath) : createAmazonQUri('empty', tabId)
22+
}
23+
24+
export function getFileDiffUris(leftPath: string, rightPath: string, tabId: string) {
25+
const left = getOriginalFileUri(leftPath, tabId)
26+
const right = createAmazonQUri(rightPath, tabId)
27+
28+
return { left, right }
29+
}
30+
31+
export function createAmazonQUri(path: string, tabId: string) {
32+
// TODO change the featureDevScheme to a more general amazon q scheme
33+
return vscode.Uri.from({ scheme: featureDevScheme, path, query: `tabID=${tabId}` })
34+
}

packages/core/src/amazonq/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export { amazonQHelpUrl } from '../shared/constants'
2727
export { listCodeWhispererCommandsWalkthrough } from '../codewhisperer/ui/statusBarMenu'
2828
export { focusAmazonQPanel, focusAmazonQPanelKeybinding } from '../codewhispererChat/commands/registerCommands'
2929
export { TryChatCodeLensProvider, tryChatCodeLensCommand } from '../codewhispererChat/editor/codelens'
30+
export { createAmazonQUri, openDiff, openDeletedDiff, getOriginalFileUri, getFileDiffUris } from './commons/diff'
3031

3132
/**
3233
* main from createMynahUI is a purely browser dependency. Due to this

packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
*/
55

66
import { ChatItemAction, MynahIcons } from '@aws/mynah-ui'
7-
import { existsSync } from 'fs'
87
import * as path from 'path'
98
import * as vscode from 'vscode'
109
import { EventEmitter } from 'vscode'
1110
import { telemetry } from '../../../shared/telemetry/telemetry'
1211
import { createSingleFileDialog } from '../../../shared/ui/common/openDialog'
13-
import { featureDevScheme } from '../../constants'
1412
import {
1513
CodeIterationLimitError,
1614
ContentLengthError,
@@ -53,6 +51,7 @@ import {
5351
} from '../../userFacingText'
5452
import { getWorkspaceFoldersByPrefixes } from '../../../shared/utilities/workspaceUtils'
5553
import { ErrorMessages } from './messenger/constants'
54+
import { openDeletedDiff, openDiff } from '../../../amazonq/commons/diff'
5655

5756
export interface ChatControllerEventEmitters {
5857
readonly processHumanChatMessage: EventEmitter<any>
@@ -744,24 +743,6 @@ export class FeatureDevController {
744743
})
745744
}
746745

747-
private getOriginalFileUri(fullPath: string, tabID: string) {
748-
const originalPath = fullPath
749-
return existsSync(originalPath)
750-
? vscode.Uri.file(originalPath)
751-
: vscode.Uri.from({ scheme: featureDevScheme, path: 'empty', query: `tabID=${tabID}` })
752-
}
753-
754-
private getFileDiffUris(zipFilePath: string, fullFilePath: string, tabId: string, session: Session) {
755-
const left = this.getOriginalFileUri(fullFilePath, tabId)
756-
const right = vscode.Uri.from({
757-
scheme: featureDevScheme,
758-
path: path.join(session.uploadId, zipFilePath),
759-
query: `tabID=${tabId}`,
760-
})
761-
762-
return { left, right }
763-
}
764-
765746
private async fileClicked(message: fileClickedMessage) {
766747
// TODO: add Telemetry here
767748
const tabId: string = message.tabID
@@ -804,12 +785,11 @@ export class FeatureDevController {
804785
const pathInfos = getPathsFromZipFilePath(zipFilePath, workspacePrefixMapping, session.config.workspaceFolders)
805786

806787
if (message.deleted) {
807-
const fileUri = this.getOriginalFileUri(pathInfos.absolutePath, tabId)
808-
const basename = path.basename(pathInfos.relativePath)
809-
await vscode.commands.executeCommand('vscode.open', fileUri, {}, `${basename} (Deleted)`)
788+
const name = path.basename(pathInfos.relativePath)
789+
await openDeletedDiff(pathInfos.absolutePath, name, tabId)
810790
} else {
811-
const { left, right } = this.getFileDiffUris(zipFilePath, pathInfos.absolutePath, tabId, session)
812-
await vscode.commands.executeCommand('vscode.diff', left, right)
791+
const rightPath = path.join(session.uploadId, zipFilePath)
792+
await openDiff(pathInfos.absolutePath, rightPath, tabId)
813793
}
814794
}
815795

packages/core/src/amazonqFeatureDev/types.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { VirtualFileSystem } from '../shared/virtualFilesystem'
88
import type { CancellationTokenSource } from 'vscode'
99
import { Messenger } from './controllers/chat/messenger/messenger'
1010
import { FeatureDevClient } from './client/featureDev'
11-
import { featureDevScheme } from './constants'
1211
import { TelemetryHelper } from './util/telemetryHelper'
1312
import { CodeReference } from '../amazonq/webview/ui/connector'
1413
import { DiffTreeFileInfo } from '../amazonq/webview/ui/diffTree/types'
@@ -107,12 +106,4 @@ export interface SessionStorage {
107106
[key: string]: SessionInfo
108107
}
109108

110-
export function createUri(filePath: string, tabID?: string) {
111-
return vscode.Uri.from({
112-
scheme: featureDevScheme,
113-
path: filePath,
114-
...(tabID ? { query: `tabID=${tabID}` } : {}),
115-
})
116-
}
117-
118109
export type LLMResponseType = 'EMPTY' | 'INVALID_STATE' | 'VALID'

packages/core/src/amazonqFeatureDev/util/fileExtension.ts

Lines changed: 0 additions & 208 deletions
This file was deleted.

0 commit comments

Comments
 (0)