Skip to content
Open
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
69 changes: 5 additions & 64 deletions packages/amazonq/test/e2e/inline/inline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,10 @@

import * as vscode from 'vscode'
import assert from 'assert'
import {
closeAllEditors,
getTestWindow,
registerAuthHook,
resetCodeWhispererGlobalVariables,
TestFolder,
toTextEditor,
using,
} from 'aws-core-vscode/test'
import { RecommendationHandler, RecommendationService, session } from 'aws-core-vscode/codewhisperer'
import { closeAllEditors, registerAuthHook, TestFolder, toTextEditor, using } from 'aws-core-vscode/test'
import { Commands, globals, sleep, waitUntil, collectionUtil } from 'aws-core-vscode/shared'
import { loginToIdC } from '../amazonq/utils/setup'
import { vsCodeState } from 'aws-core-vscode/codewhisperer'

describe('Amazon Q Inline', async function () {
const retries = 3
Expand All @@ -40,7 +32,6 @@ describe('Amazon Q Inline', async function () {
const folder = await TestFolder.create()
tempFolder = folder.path
await closeAllEditors()
await resetCodeWhispererGlobalVariables()
})

afterEach(async function () {
Expand All @@ -54,7 +45,6 @@ describe('Amazon Q Inline', async function () {
const events = getUserTriggerDecision()
console.table({
'telemetry events': JSON.stringify(events),
'recommendation service status': RecommendationService.instance.isRunning,
})
}

Expand All @@ -71,31 +61,6 @@ describe('Amazon Q Inline', async function () {
})
}

async function waitForRecommendations() {
const suggestionShown = await waitUntil(async () => session.getSuggestionState(0) === 'Showed', waitOptions)
if (!suggestionShown) {
throw new Error(`Suggestion did not show. Suggestion States: ${JSON.stringify(session.suggestionStates)}`)
}
const suggestionVisible = await waitUntil(
async () => RecommendationHandler.instance.isSuggestionVisible(),
waitOptions
)
if (!suggestionVisible) {
throw new Error(
`Suggestions failed to become visible. Suggestion States: ${JSON.stringify(session.suggestionStates)}`
)
}
console.table({
'suggestions states': JSON.stringify(session.suggestionStates),
'valid recommendation': RecommendationHandler.instance.isValidResponse(),
'recommendation service status': RecommendationService.instance.isRunning,
recommendations: session.recommendations,
})
if (!RecommendationHandler.instance.isValidResponse()) {
throw new Error('Did not find a valid response')
}
}

/**
* Waits for a specific telemetry event to be emitted with the expected suggestion state.
* It looks like there might be a potential race condition in codewhisperer causing telemetry
Expand Down Expand Up @@ -149,8 +114,9 @@ describe('Amazon Q Inline', async function () {
await invokeCompletion()
originalEditorContents = vscode.window.activeTextEditor?.document.getText()

// wait until the ghost text appears
await waitForRecommendations()
// wait until all the recommendations have finished
await waitUntil(() => Promise.resolve(vsCodeState.isRecommendationsActive === true), waitOptions)
await waitUntil(() => Promise.resolve(vsCodeState.isRecommendationsActive === false), waitOptions)
}

beforeEach(async () => {
Expand All @@ -163,14 +129,12 @@ describe('Amazon Q Inline', async function () {
try {
await setup()
console.log(`test run ${attempt} succeeded`)
logUserDecisionStatus()
break
} catch (e) {
console.log(`test run ${attempt} failed`)
console.log(e)
logUserDecisionStatus()
attempt++
await resetCodeWhispererGlobalVariables()
}
}
if (attempt === retries) {
Expand Down Expand Up @@ -216,29 +180,6 @@ describe('Amazon Q Inline', async function () {
assert.deepStrictEqual(vscode.window.activeTextEditor?.document.getText(), originalEditorContents)
})
})

it(`${name} invoke on unsupported filetype`, async function () {
await setupEditor({
name: 'test.zig',
contents: `fn doSomething() void {

}`,
})

/**
* Add delay between editor loading and invoking completion
* @see beforeEach in supported filetypes for more information
*/
await sleep(1000)
await invokeCompletion()

if (name === 'automatic') {
// It should never get triggered since its not a supported file type
assert.deepStrictEqual(RecommendationService.instance.isRunning, false)
} else {
await getTestWindow().waitForMessage('currently not supported by Amazon Q inline suggestions')
}
})
})
}
})
Loading