-
Notifications
You must be signed in to change notification settings - Fork 746
fix(amazonq): Inline test after function addition, writeToTextEditor fix, and package.json pathing fix #7800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| import '../utils/setup' | ||
| import { Workbench, EditorView, InputBox, TextEditor, WebviewView, Key } from 'vscode-extension-tester' | ||
| import { testContext } from '../utils/testContext' | ||
| import { pressKey, createNewTextFile, writeToTextEditor } from '../utils/generalUtils' | ||
| import { createNewTextFile, writeToTextEditor, sleep } from '../utils/generalUtils' | ||
| import assert from 'assert' | ||
|
|
||
| describe('Amazon Q Inline Completion / Chat Functionality', function () { | ||
|
|
@@ -20,25 +20,31 @@ describe('Amazon Q Inline Completion / Chat Functionality', function () { | |
| webviewView = testContext.webviewView | ||
| await webviewView.switchBack() | ||
| workbench = testContext.workbench | ||
|
|
||
| editorView = new EditorView() | ||
| testContext.editorView = editorView | ||
|
|
||
| textEditor = await createNewTextFile(workbench, editorView) | ||
| }) | ||
|
|
||
| it('Inline Test', async () => { | ||
| await writeToTextEditor(textEditor, 'Select Me') | ||
| after(async function () { | ||
| // Switch back to Webview Iframe when dealing with external webviews from Amazon Q. | ||
| await editorView.closeAllEditors() | ||
| await webviewView.switchToFrame() | ||
| }) | ||
| it('Inline Test Shortcut', async () => { | ||
| await writeToTextEditor(textEditor, 'def factorial(n):') | ||
| const text = await textEditor.getText() | ||
| assert.equal(text, 'Select Me') | ||
| assert.equal(text, 'def factorial(n): ') | ||
| await textEditor.clearText() | ||
|
|
||
| const textBefore = await textEditor.getText() | ||
| await workbench.executeCommand('Amazon Q: Inline Chat') | ||
| const input = new InputBox() | ||
| await input.sendKeys('Write a simple sentece') | ||
| await input.sendKeys('Generate the fibonacci sequence through iteration') | ||
| await input.sendKeys(Key.ENTER) | ||
| const driver = textEditor.getDriver() | ||
| await pressKey(driver, 'ENTER') | ||
| await pressKey(driver, 'TAB') | ||
| await sleep(8000) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this sleep for? 8 seconds sounds like a lot
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, the sleep is for waiting for the AmazonQ response to be generated. I realized its never always the same and can take sometime to either reason or just start coding right away. 8 seconds seems like the sweet spot for leeway for waiting for a response to be generated fully on other devices as well.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Is there a way we can wait dynamically with a cap? Like basically poll every 1 second until the response shows up the in the DOM. I think this general util will be helpful for other areas as well.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, will look into it! |
||
|
|
||
| const textAfter = await textEditor.getText() | ||
| assert(textAfter.length > textBefore.length, 'Amazon Q should have generated code') | ||
| assert(textAfter.includes('fibonacci'), 'Generated code should contain fibonacci logic') | ||
|
||
| await textEditor.clearText() | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,9 +157,11 @@ export async function createNewTextFile(workbench: Workbench, editorView: Editor | |
| * @returns Promise<void> | ||
| */ | ||
| export async function writeToTextEditor(textEditor: TextEditor, text: string): Promise<void> { | ||
| // We require a "dummy" space to be written such that we can properly index the | ||
| // number of lines to register the textEditor. | ||
| await textEditor.typeTextAt(1, 1, ' ') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know the reason why we need a space, but should we add a comment since its not obvious?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
| const currentLines = await textEditor.getNumberOfLines() | ||
| const nextLine = currentLines + 1 | ||
| await textEditor.typeTextAt(nextLine, 1, text) | ||
| await textEditor.typeTextAt(currentLines, 1, text) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this enter now accept the generation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it does not, but it is required for us to get out of the suggestion decision messing up any following clean ups