Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26,332 changes: 11,902 additions & 14,430 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 34 additions & 16 deletions packages/amazonq/test/e2e/amazonq/testGen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { qTestingFramework } from './framework/framework'
import sinon from 'sinon'
import { Messenger } from './framework/messenger'
import { FollowUpTypes } from 'aws-core-vscode/amazonq'
import { registerAuthHook, using, TestFolder, closeAllEditors } from 'aws-core-vscode/test'
import { registerAuthHook, using, TestFolder, closeAllEditors, getTestWorkspaceFolder } from 'aws-core-vscode/test'
import { loginToIdC } from './utils/setup'
import { waitUntil, workspaceUtils } from 'aws-core-vscode/shared'
import * as path from 'path'

describe('Amazon Q Test Generation', function () {
let framework: qTestingFramework
Expand All @@ -20,11 +21,13 @@ describe('Amazon Q Test Generation', function () {
const testFiles = [
{
language: 'python',
filePath: 'python3.7-image-sam-app/hello_world/app.py',
filePath: 'testGenFolder/src/main/math.py',
testFilePath: 'testGenFolder/src/test/test_math.py',
},
{
language: 'java',
filePath: 'java17-gradle/HelloWorldFunction/src/main/java/helloworld/App.java',
filePath: 'testGenFolder/src/main/Math.java',
testFilePath: 'testGenFolder/src/test/MathTest.java',
},
]

Expand All @@ -33,14 +36,15 @@ describe('Amazon Q Test Generation', function () {
// must be atleast one unsupported language here for testing
{
language: 'typescript',
filePath: 'ts-plain-sam-app/src/app.ts',
filePath: 'testGenFolder/src/main/math.ts',
},
{
language: 'javascript',
filePath: 'js-plain-sam-app/src/app.js',
filePath: 'testGenFolder/src/main/math.js',
},
]

// handles opening the file since /test must be called on an active file
async function setupTestDocument(filePath: string, language: string) {
const document = await waitUntil(async () => {
const doc = await workspaceUtils.openTextDocument(filePath)
Expand All @@ -57,7 +61,7 @@ describe('Amazon Q Test Generation', function () {

const activeEditor = vscode.window.activeTextEditor
if (!activeEditor || activeEditor.document.uri.fsPath !== document.uri.fsPath) {
assert.fail(`Failed to make temp file active`)
assert.fail(`Failed to make ${language} file active`)
}
}

Expand All @@ -68,6 +72,15 @@ describe('Amazon Q Test Generation', function () {
})
}

// clears test file to a blank file
// not cleaning up test file may possibly cause bloat in CI since testFixtures does not get reset
async function cleanupTestFile(testFilePath: string) {
const workspaceFolder = getTestWorkspaceFolder()
const absoluteTestFilePath = path.join(workspaceFolder, testFilePath)
const testFileUri = vscode.Uri.file(absoluteTestFilePath)
await vscode.workspace.fs.writeFile(testFileUri, Buffer.from('', 'utf-8'))
}

before(async function () {
await using(registerAuthHook('amazonq-test-account'), async () => {
await loginToIdC()
Expand Down Expand Up @@ -112,7 +125,7 @@ describe('Amazon Q Test Generation', function () {
})

describe('/test entry', () => {
describe('Unsupported language', () => {
describe('Unsupported language file', () => {
const { language, filePath } = unsupportedLanguages[0]

beforeEach(async () => {
Expand All @@ -134,13 +147,13 @@ describe('Amazon Q Test Generation', function () {
})
})

describe('External file', async () => {
describe('External file out of project', async () => {
let testFolder: TestFolder
let fileName: string

beforeEach(async () => {
testFolder = await TestFolder.create()
fileName = 'test.py'
fileName = 'math.py'
const filePath = await testFolder.write(fileName, 'def add(a, b): return a + b')

const document = await vscode.workspace.openTextDocument(filePath)
Expand All @@ -162,10 +175,8 @@ describe('Amazon Q Test Generation', function () {
})
})

for (const { language, filePath } of testFiles) {
// skipping for now since this test is flaky. passes locally, but only half the time in CI
// have tried retries for setupTestDocument, openTextDocument, and showTextDocument
describe.skip(`${language} file`, () => {
for (const { language, filePath, testFilePath } of testFiles) {
describe(`/test on ${language} file`, () => {
beforeEach(async () => {
await waitUntil(async () => await setupTestDocument(filePath, language), {})

Expand All @@ -177,7 +188,7 @@ describe('Amazon Q Test Generation', function () {
await tab.waitForChatFinishesLoading()
})

describe('View diff', async () => {
describe('View diff of test file', async () => {
it('Clicks on view diff', async () => {
const chatItems = tab.getChatItems()
const viewDiffMessage = chatItems[5]
Expand All @@ -190,7 +201,14 @@ describe('Amazon Q Test Generation', function () {
})
})

describe('Accept code', async () => {
describe('Accept unit tests', async () => {
afterEach(async () => {
// this e2e test generates unit tests, so we want to clean them up after this test is done
await waitUntil(async () => {
await cleanupTestFile(testFilePath)
}, {})
})

it('Clicks on accept', async () => {
await tab.waitForButtons([FollowUpTypes.AcceptCode, FollowUpTypes.RejectCode])
tab.clickButton(FollowUpTypes.AcceptCode)
Expand All @@ -204,7 +222,7 @@ describe('Amazon Q Test Generation', function () {
})
})

describe('Reject code', async () => {
describe('Reject unit tests', async () => {
it('Clicks on reject', async () => {
await tab.waitForButtons([FollowUpTypes.AcceptCode, FollowUpTypes.RejectCode])
tab.clickButton(FollowUpTypes.RejectCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ import {
SecurityScanTimedOutError,
UploadArtifactToS3Error,
} from '../models/errors'
import { getTelemetryReasonDesc } from '../../shared/errors'
import { getTelemetryReasonDesc, isAwsError } from '../../shared/errors'
import { CodeWhispererSettings } from '../util/codewhispererSettings'
import { detectCommentAboveLine } from '../../shared/utilities/commentUtils'
import { runtimeLanguageContext } from '../util/runtimeLanguageContext'
import { FeatureUseCase } from '../models/constants'
import { UploadTestArtifactToS3Error } from '../../amazonqTest/error'
import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession'

export async function listScanResults(
client: DefaultCodeWhispererClient,
Expand Down Expand Up @@ -386,6 +387,9 @@ export async function uploadArtifactToS3(
} else {
errorMessage = errorDesc ?? defaultMessage
}
if (isAwsError(error) && featureUseCase === FeatureUseCase.TEST_GENERATION) {
ChatSessionManager.Instance.getSession().startTestGenerationRequestId = error.requestId
}
throw isCodeScan ? new UploadArtifactToS3Error(errorMessage) : new UploadTestArtifactToS3Error(errorMessage)
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/lambda/vue/configEditor/samInvokeBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
AwsSamDebuggerConfiguration,
isCodeTargetProperties,
isTemplateTargetProperties,
TemplateTargetProperties,
} from '../../../shared/sam/debugger/awsSamDebugConfiguration'
import {
DefaultAwsSamDebugConfigurationValidator,
Expand Down Expand Up @@ -433,15 +434,19 @@ export async function registerSamDebugInvokeVueCommand(
context: vscode.ExtensionContext,
params: { resource: ResourceNode }
) {
const launchConfig: AwsSamDebuggerConfiguration | undefined = undefined
const resource = params?.resource.resource
const source = 'AppBuilderLocalInvoke'
const launchConfigs = await new LaunchConfiguration(resource.location).getSamDebugConfigurations()
const launchConfig = launchConfigs.find(
(config) => (config.invokeTarget as TemplateTargetProperties).logicalId === resource.resource.Id
)

const webview = new WebviewPanel(context, launchConfig, {
logicalId: resource.resource.Id ?? '',
region: resource.region ?? '',
location: resource.location.fsPath,
handler: resource.resource.Handler!,
runtime: resource.resource.Runtime!,
runtime: launchConfig?.lambda?.runtime ?? resource.resource.Runtime!,
arn: resource.functionArn ?? '',
stackName: resource.stackName ?? '',
environment: resource.resource.Environment,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Math functions
*/
public class Math {
public int add(int a, int b) {
return a + b;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function addNum(num1, num2) {
return num1 + num2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# adds two numbers
def add(a, b):
return a + b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function addTwoNums(a: number, b: number): number {
return a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "App Builder: Autoload debug configuration for local invoke webview"
}
21 changes: 21 additions & 0 deletions src.gen/@amzn/codewhisperer-streaming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ CreateProfile
</details>
<details>
<summary>
CreateWorkspace
</summary>

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/codewhispererstreaming/command/CreateWorkspaceCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-codewhispererstreaming/Interface/CreateWorkspaceCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-codewhispererstreaming/Interface/CreateWorkspaceCommandOutput/)
</details>
<details>
<summary>
DeleteCustomization
</summary>

Expand Down Expand Up @@ -297,6 +304,13 @@ ListTagsForResource
</details>
<details>
<summary>
ListWorkspaceMetadata
</summary>

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/codewhispererstreaming/command/ListWorkspaceMetadataCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-codewhispererstreaming/Interface/ListWorkspaceMetadataCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-codewhispererstreaming/Interface/ListWorkspaceMetadataCommandOutput/)
</details>
<details>
<summary>
TagResource
</summary>

Expand Down Expand Up @@ -416,6 +430,13 @@ ListAvailableCustomizations
</details>
<details>
<summary>
ListAvailableProfiles
</summary>

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/codewhispererstreaming/command/ListAvailableProfilesCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-codewhispererstreaming/Interface/ListAvailableProfilesCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-codewhispererstreaming/Interface/ListAvailableProfilesCommandOutput/)
</details>
<details>
<summary>
ListCodeAnalysisFindings
</summary>

Expand Down
7 changes: 3 additions & 4 deletions src.gen/@amzn/codewhisperer-streaming/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,36 @@ export interface GenerateAssistantResponseCommandOutput extends GenerateAssistan
* userSettings: { // UserSettings
* hasConsentedToCrossRegionCalls: true || false,
* },
* additionalContext: [ // AdditionalContentList
* { // AdditionalContentEntry
* name: "STRING_VALUE", // required
* description: "STRING_VALUE", // required
* innerContext: "STRING_VALUE",
* },
* ],
* toolResults: [ // ToolResults
* { // ToolResult
* toolUseId: "STRING_VALUE", // required
* content: [ // ToolResultContent // required
* { // ToolResultContentBlock Union: only one key present
* text: "STRING_VALUE",
* json: "DOCUMENT_VALUE",
* },
* ],
* status: "success" || "error",
* },
* ],
* tools: [ // Tools
* { // Tool Union: only one key present
* toolSpecification: { // ToolSpecification
* inputSchema: { // ToolInputSchema
* json: "DOCUMENT_VALUE",
* },
* name: "STRING_VALUE", // required
* description: "STRING_VALUE",
* },
* },
* ],
* },
* userIntent: "SUGGEST_ALTERNATE_IMPLEMENTATION" || "APPLY_COMMON_BEST_PRACTICES" || "IMPROVE_CODE" || "SHOW_EXAMPLES" || "CITE_SOURCES" || "EXPLAIN_LINE_BY_LINE" || "EXPLAIN_CODE_SELECTION" || "GENERATE_CLOUDFORMATION_TEMPLATE" || "GENERATE_UNIT_TESTS" || "CODE_GENERATION",
* },
Expand Down Expand Up @@ -302,6 +332,36 @@ export interface GenerateAssistantResponseCommandOutput extends GenerateAssistan
* userSettings: {
* hasConsentedToCrossRegionCalls: true || false,
* },
* additionalContext: [
* {
* name: "STRING_VALUE", // required
* description: "STRING_VALUE", // required
* innerContext: "STRING_VALUE",
* },
* ],
* toolResults: [
* {
* toolUseId: "STRING_VALUE", // required
* content: [ // required
* {// Union: only one key present
* text: "STRING_VALUE",
* json: "DOCUMENT_VALUE",
* },
* ],
* status: "success" || "error",
* },
* ],
* tools: [
* {// Union: only one key present
* toolSpecification: {
* inputSchema: {
* json: "DOCUMENT_VALUE",
* },
* name: "STRING_VALUE", // required
* description: "STRING_VALUE",
* },
* },
* ],
* },
* userIntent: "SUGGEST_ALTERNATE_IMPLEMENTATION" || "APPLY_COMMON_BEST_PRACTICES" || "IMPROVE_CODE" || "SHOW_EXAMPLES" || "CITE_SOURCES" || "EXPLAIN_LINE_BY_LINE" || "EXPLAIN_CODE_SELECTION" || "GENERATE_CLOUDFORMATION_TEMPLATE" || "GENERATE_UNIT_TESTS" || "CODE_GENERATION",
* },
Expand Down Expand Up @@ -585,6 +645,12 @@ export interface GenerateAssistantResponseCommandOutput extends GenerateAssistan
* // },
* // ],
* // },
* // toolUseEvent: { // ToolUseEvent
* // toolUseId: "STRING_VALUE", // required
* // name: "STRING_VALUE", // required
* // input: "STRING_VALUE",
* // stop: true || false,
* // },
* // invalidStateEvent: { // InvalidStateEvent
* // reason: "INVALID_TASK_ASSIST_PLAN", // required
* // message: "STRING_VALUE", // required
Expand Down
Loading
Loading