Skip to content

Commit 7c6995a

Browse files
committed
Merge branch 'master' into ec2/tryRun
2 parents 56d98c7 + cc0455f commit 7c6995a

File tree

22 files changed

+432
-254
lines changed

22 files changed

+432
-254
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q /test: Fixing the issue of target file does not exist."
4+
}

packages/amazonq/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
142142
// Give time for the extension to finish initializing.
143143
globals.clock.setTimeout(async () => {
144144
CommonAuthWebview.authSource = ExtStartUpSources.firstStartUp
145-
void focusAmazonQPanel.execute(placeholder, 'firstStartUp')
145+
void focusAmazonQPanel.execute(placeholder, ExtStartUpSources.firstStartUp)
146146
}, 1000)
147147
}
148148
}

packages/core/src/amazonq/webview/ui/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ export const createMynahUI = (
609609
mynahUI.addChatItem(tabID, {
610610
type: ChatItemType.ANSWER_STREAM,
611611
})
612-
} else if (tabType === 'gumby' || tabType === 'testgen') {
612+
} else if (tabType === 'gumby') {
613613
connector.requestAnswer(tabID, {
614614
chatMessage: prompt.prompt ?? '',
615615
})

packages/core/src/amazonqTest/chat/controller/controller.ts

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ import {
6363
} from '../../../codewhisperer/models/constants'
6464
import { UserWrittenCodeTracker } from '../../../codewhisperer/tracker/userWrittenCodeTracker'
6565
import { ReferenceLogViewProvider } from '../../../codewhisperer/service/referenceLogViewProvider'
66-
import { Auth } from '../../../auth/auth'
6766

6867
export interface TestChatControllerEventEmitters {
6968
readonly tabOpened: vscode.EventEmitter<any>
@@ -801,10 +800,8 @@ export class TestController {
801800
session.linesOfCodeGenerated
802801
)
803802

804-
if (!Auth.instance.isInternalAmazonUser()) {
805-
await this.endSession(message, FollowUpTypes.SkipBuildAndFinish)
806-
return
807-
}
803+
await this.endSession(message, FollowUpTypes.SkipBuildAndFinish)
804+
return
808805

809806
if (session.listOfTestGenerationJobId.length === 1) {
810807
this.startInitialBuild(message)
@@ -944,17 +941,12 @@ export class TestController {
944941

945942
private startInitialBuild(data: any) {
946943
// TODO: Remove the fallback build command after stable version of backend build command.
947-
const userMessage = `Would you like me to help build and execute the test? I’ll run following commands.\n\`\`\`sh\n${this.sessionStorage.getSession().shortAnswer?.buildCommand}\n`
944+
const userMessage = `Would you like me to help build and execute the test? I will need you to let me know what build command to run if you do.`
948945
const followUps: FollowUps = {
949946
text: '',
950947
options: [
951948
{
952-
pillText: `Build and execute`,
953-
type: FollowUpTypes.BuildAndExecute,
954-
status: 'primary',
955-
},
956-
{
957-
pillText: `Modify command`,
949+
pillText: `Specify command then build and execute`,
958950
type: FollowUpTypes.ModifyCommands,
959951
status: 'primary',
960952
},
@@ -984,6 +976,7 @@ export class TestController {
984976
const listOfInstallationDependencies = ['']
985977
const installationDependencies = listOfInstallationDependencies.join('\n')
986978

979+
this.messenger.sendMessage('Build and execute', data.tabID, 'prompt')
987980
telemetry.ui_click.emit({ elementId: 'unitTestGeneration_buildAndExecute' })
988981

989982
if (installationDependencies.length > 0) {
@@ -1032,6 +1025,11 @@ export class TestController {
10321025
// const installationDependencies = session.shortAnswer?.installationDependencies ?? []
10331026
// MOCK: ignoring the installation case until backend send response
10341027
const installationDependencies: string[] = []
1028+
const buildCommands = session.updatedBuildCommands
1029+
if (!buildCommands) {
1030+
throw new Error('Build command not found')
1031+
return
1032+
}
10351033

10361034
this.messenger.sendBuildProgressMessage({
10371035
tabID: data.tabID,
@@ -1103,7 +1101,7 @@ export class TestController {
11031101
messageId: TestNamedMessages.TEST_GENERATION_BUILD_STATUS_MESSAGE,
11041102
})
11051103

1106-
const buildStatus = await runBuildCommand(this.getBuildCommands())
1104+
const buildStatus = await runBuildCommand(buildCommands)
11071105
session.buildStatus = buildStatus
11081106

11091107
if (buildStatus === BuildStatus.FAILURE) {
@@ -1231,17 +1229,10 @@ export class TestController {
12311229
fileList: this.checkCodeDiffLengthAndBuildStatus({ codeDiffLength, buildStatus: session.buildStatus })
12321230
? {
12331231
fileTreeTitle: 'READY FOR REVIEW',
1234-
rootFolderTitle: path.basename(session.projectRootPath),
1232+
rootFolderTitle: 'tests',
12351233
filePaths: [session.generatedFilePath],
12361234
}
12371235
: undefined,
1238-
codeReference: session.references.map(
1239-
(ref: ShortAnswerReference) =>
1240-
({
1241-
...ref,
1242-
information: `${ref.licenseName} - <a href="${ref.url}">${ref.repository}</a>`,
1243-
}) as CodeReference
1244-
),
12451236
})
12461237
this.messenger.sendBuildProgressMessage({
12471238
tabID: data.tabID,
@@ -1270,7 +1261,7 @@ export class TestController {
12701261

12711262
private modifyBuildCommand(data: any) {
12721263
this.sessionStorage.getSession().conversationState = ConversationState.WAITING_FOR_BUILD_COMMMAND_INPUT
1273-
this.messenger.sendMessage('Modify Command', data.tabID, 'prompt')
1264+
this.messenger.sendMessage('Specify commands then build', data.tabID, 'prompt')
12741265
telemetry.ui_click.emit({ elementId: 'unitTestGeneration_modifyCommand' })
12751266
this.messenger.sendMessage(
12761267
'Sure, provide all command lines you’d like me to run to build.',
@@ -1383,16 +1374,21 @@ export class TestController {
13831374
}
13841375

13851376
// TODO: return build command when product approves
1386-
private getBuildCommands = (): string[] => {
1387-
const session = this.sessionStorage.getSession()
1388-
if (session.updatedBuildCommands?.length) {
1389-
return [...session.updatedBuildCommands]
1390-
}
1391-
1392-
if (session.shortAnswer && session.shortAnswer?.buildCommand) {
1393-
return [session.shortAnswer.buildCommand]
1394-
}
1395-
// TODO: Add a generic command here for external launch according to the build system.
1396-
return ['brazil-build release']
1397-
}
1377+
// private getBuildCommands = (): string[] => {
1378+
// const session = this.sessionStorage.getSession()
1379+
// if (session.updatedBuildCommands?.length) {
1380+
// return [...session.updatedBuildCommands]
1381+
// }
1382+
1383+
// // For Internal amazon users only
1384+
// if (Auth.instance.isInternalAmazonUser()) {
1385+
// return ['brazil-build release']
1386+
// }
1387+
1388+
// if (session.shortAnswer && Array.isArray(session.shortAnswer?.buildCommands)) {
1389+
// return [...session.shortAnswer.buildCommands]
1390+
// }
1391+
1392+
// return ['source qdev-wbr/.venv/bin/activate && pytest --continue-on-collection-errors']
1393+
// }
13981394
}

packages/core/src/auth/activation.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import * as vscode from 'vscode'
77
import { Auth } from './auth'
88
import { LoginManager } from './deprecated/loginManager'
99
import { fromString } from './providers/credentials'
10-
import { getLogger } from '../shared/logger/logger'
11-
import { ExtensionUse, initializeCredentialsProviderManager } from './utils'
12-
import { isAmazonQ, isCloud9, isSageMaker } from '../shared/extensionUtilities'
13-
import { isInDevEnv } from '../shared/vscode/env'
14-
import { isWeb } from '../shared/extensionGlobals'
10+
import { initializeCredentialsProviderManager } from './utils'
11+
import { isAmazonQ, isSageMaker } from '../shared/extensionUtilities'
1512

1613
interface SagemakerCookie {
1714
authMode?: 'Sso' | 'Iam'
@@ -33,28 +30,4 @@ export async function initialize(loginManager: LoginManager): Promise<void> {
3330
await loginManager.logout()
3431
}
3532
})
36-
37-
await showManageConnectionsOnStartup()
38-
}
39-
40-
/**
41-
* Show the Manage Connections page when the extension starts up, if it should be shown.
42-
*/
43-
async function showManageConnectionsOnStartup() {
44-
// Do not show connection management to user in certain scenarios.
45-
let reason: string = ''
46-
if (isWeb()) {
47-
// TODO: Figure out how we want users to connect to auth in browser mode
48-
reason = 'We are in the browser'
49-
} else if (!ExtensionUse.instance.isFirstUse()) {
50-
reason = 'This is not the users first use of the extension'
51-
} else if (isInDevEnv()) {
52-
reason = 'The user is in a Dev Evironment'
53-
} else if (isCloud9('any')) {
54-
reason = 'The user is in Cloud9'
55-
}
56-
if (reason) {
57-
getLogger().debug(`firstStartup: ${reason}. Skipped showing Add Connections page.`)
58-
return
59-
}
6033
}

packages/core/src/auth/utils.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import { EcsCredentialsProvider } from './providers/ecsCredentialsProvider'
5858
import { EnvVarsCredentialsProvider } from './providers/envVarsCredentialsProvider'
5959
import { showMessageWithUrl } from '../shared/utilities/messages'
6060
import { credentialHelpUrl } from '../shared/constants'
61-
import { ExtStartUpSources, ExtStartUpSource } from '../shared/telemetry/util'
61+
import { ExtStartUpSources, ExtStartUpSource, hadClientIdOnStartup } from '../shared/telemetry/util'
6262

6363
// iam-only excludes Builder ID and IAM Identity Center from the list of valid connections
6464
// TODO: Understand if "iam" should include these from the list at all
@@ -688,17 +688,43 @@ export class ExtensionUse {
688688
return this.isFirstUseCurrentSession
689689
}
690690

691-
this.isFirstUseCurrentSession = globals.globalState.get('isExtensionFirstUse')
692-
if (this.isFirstUseCurrentSession === undefined) {
691+
// This is for sure not their first use
692+
const isFirstUse = globals.globalState.tryGet('isExtensionFirstUse', Boolean)
693+
if (isFirstUse === false) {
694+
this.isFirstUseCurrentSession = isFirstUse
695+
return this.isFirstUseCurrentSession
696+
}
697+
698+
/**
699+
* SANITY CHECK: If the clientId already existed on startup, then isFirstUse MUST be false. So
700+
* there is a bug in the state.
701+
*/
702+
if (hadClientIdOnStartup(globals.globalState)) {
703+
telemetry.function_call.emit({
704+
result: 'Failed',
705+
functionName: 'isFirstUse',
706+
reason: 'ClientIdAlreadyExisted',
707+
})
708+
}
709+
710+
if (isAmazonQ()) {
711+
this.isFirstUseCurrentSession = true
712+
if (hasExistingConnections()) {
713+
telemetry.function_call.emit({
714+
result: 'Failed',
715+
functionName: 'isFirstUse',
716+
reason: 'UnexpectedConnections',
717+
})
718+
}
719+
} else {
693720
// The variable in the store is not defined yet, fallback to checking if they have existing connections.
694721
this.isFirstUseCurrentSession = !hasExistingConnections()
695-
696-
getLogger().debug(
697-
`isFirstUse: State not found, marking user as '${
698-
this.isFirstUseCurrentSession ? '' : 'NOT '
699-
}first use' since they 'did ${this.isFirstUseCurrentSession ? 'NOT ' : ''}have existing connections'.`
700-
)
701722
}
723+
getLogger().debug(
724+
`isFirstUse: State not found, marking user as '${
725+
this.isFirstUseCurrentSession ? '' : 'NOT '
726+
}first use' since they 'did ${this.isFirstUseCurrentSession ? 'NOT ' : ''}have existing connections'.`
727+
)
702728

703729
// Update state, so next time it is not first use
704730
this.updateMemento('isExtensionFirstUse', false)

packages/core/src/codewhisperer/commands/startTestGeneration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function runLocalBuild(
212212
if (spawnResult.stderr) {
213213
spawnResult.stderr.on('data', async (data) => {
214214
const output = data.toString().trim()
215-
getLogger().warn(`${output}`)
215+
getLogger().warn(`BUILD ERROR: ${output}`)
216216
buildLogs += output
217217
})
218218
}

packages/core/src/codewhisperer/models/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ export interface ShortAnswerReference {
11771177

11781178
export interface ShortAnswer {
11791179
testFilePath: string
1180-
buildCommand: string
1180+
buildCommands: string[]
11811181
planSummary: string
11821182
sourceFilePath?: string
11831183
testFramework?: string

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ export function addTableMarkdown(plan: string, stepId: string, tableMapping: { [
506506
return plan
507507
}
508508
const table = JSON.parse(tableObj)
509+
if (table.rows.length === 0) {
510+
// empty table
511+
plan += `\n\nThere are no ${table.name.toLowerCase()} to display.\n\n`
512+
return plan
513+
}
509514
plan += `\n\n\n${table.name}\n|`
510515
const columns = table.columnNames
511516
// eslint-disable-next-line unicorn/no-array-for-each

packages/core/src/codewhisperer/util/zipUtil.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,14 @@ export class ZipUtil {
410410
return
411411
}
412412

413-
const sourceFiles = await collectFiles(projectPaths, vscode.workspace.workspaceFolders as CurrentWsFolders, {
414-
maxSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(),
415-
})
413+
const sourceFiles = await collectFiles(
414+
projectPaths,
415+
vscode.workspace.workspaceFolders as CurrentWsFolders,
416+
{
417+
maxSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(),
418+
},
419+
useCase
420+
)
416421
for (const file of sourceFiles) {
417422
const projectName = path.basename(file.workspaceFolder.uri.fsPath)
418423
const zipEntryPath = this.getZipEntryPath(projectName, file.relativeFilePath)

0 commit comments

Comments
 (0)