diff --git a/.github/workflows/pr_checks.yaml b/.github/workflows/pr_checks.yaml index cfe67c719..660960077 100644 --- a/.github/workflows/pr_checks.yaml +++ b/.github/workflows/pr_checks.yaml @@ -202,17 +202,24 @@ jobs: - uses: actions/setup-node@v4 with: node-version-file: ".nvmrc" - - uses: actions/cache@v4 with: path: extensions/vscode/node_modules key: ${{ runner.os }}-vscode-node-modules-${{ hashFiles('extensions/vscode/package-lock.json') }} - - uses: actions/cache@v4 with: path: core/node_modules key: ${{ runner.os }}-core-node-modules-${{ hashFiles('core/package-lock.json') }} - + - name: Set up SSH + env: + SSH_KEY: ${{ secrets.GH_ACTIONS_SSH_TEST_KEY_PEM }} + SSH_HOST: ${{ secrets.GH_ACTIONS_SSH_TEST_DNS_NAME }} + run: | + mkdir -p ~/.ssh + echo "$SSH_KEY" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan -H "$SSH_HOST" >> ~/.ssh/known_hosts + echo -e "Host ssh-test-container\n\tHostName $SSH_HOST\n\tUser ec2-user\n\tIdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config - name: Install Xvfb for Linux and run e2e tests run: | sudo apt-get install -y xvfb # Install Xvfb @@ -221,6 +228,12 @@ jobs: cd extensions/vscode npm run package npm run e2e:ci + - name: Upload e2e test screenshots + if: failure() + uses: actions/upload-artifact@v4 + with: + name: e2e-screenshots + path: extensions/vscode/e2e/storage/screenshots gui-tests: needs: [gui-checks, core-checks] diff --git a/extensions/vscode/e2e/TestUtils.ts b/extensions/vscode/e2e/TestUtils.ts index 3afe83df4..653314462 100644 --- a/extensions/vscode/e2e/TestUtils.ts +++ b/extensions/vscode/e2e/TestUtils.ts @@ -1,20 +1,19 @@ import { expect } from "chai"; import { WebElement } from "vscode-extension-tester"; +import { DEFAULT_TIMEOUT } from "./constants"; export class TestUtils { - public static async waitForElement( + public static async waitForSuccess( locatorFn: () => Promise, - timeout: number = 5000, + timeout: number = DEFAULT_TIMEOUT.MD, interval: number = 500, ): Promise { const startTime = Date.now(); while (Date.now() - startTime < timeout) { try { - const element = await locatorFn(); - if (element) { - return element; - } + const result = await locatorFn(); + return result; } catch (e) { if (Date.now() - startTime >= timeout) { throw new Error(`Element not found after ${timeout}ms timeout`); diff --git a/extensions/vscode/e2e/tests/AutocompleteFinal.test.ts b/extensions/vscode/e2e/actions/Autocomplete.actions.ts similarity index 51% rename from extensions/vscode/e2e/tests/AutocompleteFinal.test.ts rename to extensions/vscode/e2e/actions/Autocomplete.actions.ts index 564873f83..d8b43df29 100644 --- a/extensions/vscode/e2e/tests/AutocompleteFinal.test.ts +++ b/extensions/vscode/e2e/actions/Autocomplete.actions.ts @@ -1,44 +1,20 @@ -import { - EditorView, - TextEditor, - InputBox, - Workbench, -} from "vscode-extension-tester"; - +import { TextEditor } from "vscode-extension-tester"; import { TestUtils } from "../TestUtils"; -import { DEFAULT_TIMEOUT } from "../constants"; import { AutocompleteSelectors } from "../selectors/Autocomplete.selectors"; import { expect } from "chai"; -import { GlobalActions } from "../actions/Global.actions"; +import { DEFAULT_TIMEOUT } from "../constants"; -describe("Autocomplete", () => { - let editor: TextEditor; - - beforeEach(async function () { - this.timeout(DEFAULT_TIMEOUT); - - await GlobalActions.openTestWorkspace(); - await new Workbench().executeCommand("Create: New File..."); - await (await InputBox.create()).selectQuickPick("Text File"); - editor = (await new EditorView().openEditor("Untitled-1")) as TextEditor; - }); - - afterEach(async function () { - this.timeout(DEFAULT_TIMEOUT); - await editor.clearText(); - await new EditorView().closeAllEditors(); - }); - - it("Should display completions", async () => { +export class AutocompleteActions { + public static async testCompletions(editor: TextEditor) { const driver = editor.getDriver(); const messagePair0 = TestUtils.generateTestMessagePair(0); await editor.typeTextAt(1, 1, messagePair0.userMessage); await editor.typeTextAt(1, messagePair0.userMessage.length + 1, " "); - const ghostText0 = await TestUtils.waitForElement( + const ghostText0 = await TestUtils.waitForSuccess( () => AutocompleteSelectors.getGhostTextContent(driver), // The first completion takes longer because Continue needs to load - DEFAULT_TIMEOUT, + DEFAULT_TIMEOUT.XL, ); expect(ghostText0).to.equal(messagePair0.llmResponse); @@ -47,9 +23,9 @@ describe("Autocomplete", () => { const messagePair1 = TestUtils.generateTestMessagePair(1); await editor.typeTextAt(1, 1, messagePair1.userMessage); await editor.typeTextAt(1, messagePair1.userMessage.length + 1, " "); - const ghostText1 = await TestUtils.waitForElement(() => + const ghostText1 = await TestUtils.waitForSuccess(() => AutocompleteSelectors.getGhostTextContent(driver), ); expect(ghostText1).to.equal(messagePair1.llmResponse); - }).timeout(DEFAULT_TIMEOUT); -}); + } +} diff --git a/extensions/vscode/e2e/actions/GUI.actions.ts b/extensions/vscode/e2e/actions/GUI.actions.ts index b4afcd1c9..5c5a006c1 100644 --- a/extensions/vscode/e2e/actions/GUI.actions.ts +++ b/extensions/vscode/e2e/actions/GUI.actions.ts @@ -41,7 +41,9 @@ export class GUIActions { }; public static openGui = async () => { - return new Workbench().executeCommand("continue.focusContinueInput"); + return TestUtils.waitForSuccess(() => + new Workbench().executeCommand("continue.focusContinueInput"), + ); }; public static selectModelFromDropdown = async ( @@ -51,7 +53,7 @@ export class GUIActions { const dropdownButton = await GUISelectors.getModelDropdownButton(view); await dropdownButton.click(); - const dropdownOption = await TestUtils.waitForElement(() => { + const dropdownOption = await TestUtils.waitForSuccess(() => { return GUISelectors.getModelDropdownOption(view, option); }); diff --git a/extensions/vscode/e2e/constants.ts b/extensions/vscode/e2e/constants.ts index 30905ae21..e11f7e0db 100644 --- a/extensions/vscode/e2e/constants.ts +++ b/extensions/vscode/e2e/constants.ts @@ -1 +1,8 @@ -export const DEFAULT_TIMEOUT = 30_000; +const BASELINE = 15_000; + +export const DEFAULT_TIMEOUT = { + XS: BASELINE * 0.2, + SM: BASELINE * 0.5, + MD: BASELINE, + XL: BASELINE * 5, +}; diff --git a/extensions/vscode/e2e/selectors/SSH.selectors.ts b/extensions/vscode/e2e/selectors/SSH.selectors.ts new file mode 100644 index 000000000..7f5aad947 --- /dev/null +++ b/extensions/vscode/e2e/selectors/SSH.selectors.ts @@ -0,0 +1,11 @@ +import { By, SideBarView } from "vscode-extension-tester"; + +export class SSHSelectors { + public static async connectedToRemoteConfirmationMessage() { + const view = new SideBarView(); + const element = await view.findElement( + By.xpath('//*[contains(text(), "Connected to remote.")]'), + ); + return element; + } +} diff --git a/extensions/vscode/e2e/tests/Autocomplete.test.ts b/extensions/vscode/e2e/tests/Autocomplete.test.ts new file mode 100644 index 000000000..50ac6c341 --- /dev/null +++ b/extensions/vscode/e2e/tests/Autocomplete.test.ts @@ -0,0 +1,35 @@ +import { + EditorView, + TextEditor, + InputBox, + Workbench, +} from "vscode-extension-tester"; + +import { DEFAULT_TIMEOUT } from "../constants"; +import { GlobalActions } from "../actions/Global.actions"; +import { AutocompleteActions } from "../actions/Autocomplete.actions"; + +describe("Autocomplete", () => { + let editor: TextEditor; + + beforeEach(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + + await GlobalActions.openTestWorkspace(); + await new Workbench().executeCommand("Create: New File..."); + await ( + await InputBox.create(DEFAULT_TIMEOUT.MD) + ).selectQuickPick("Text File"); + editor = (await new EditorView().openEditor("Untitled-1")) as TextEditor; + }); + + afterEach(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + await editor.clearText(); + await new EditorView().closeAllEditors(); + }); + + it("Should display completions", async () => { + await AutocompleteActions.testCompletions(editor); + }).timeout(DEFAULT_TIMEOUT.XL); +}); diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 013c47509..8e84d4fb1 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -11,12 +11,12 @@ describe("GUI Test", () => { let driver: WebDriver; before(async function () { - this.timeout(DEFAULT_TIMEOUT); + this.timeout(DEFAULT_TIMEOUT.XL); await GlobalActions.openTestWorkspace(); }); beforeEach(async function () { - this.timeout(DEFAULT_TIMEOUT); + this.timeout(DEFAULT_TIMEOUT.XL); await GUIActions.openGui(); @@ -25,14 +25,10 @@ describe("GUI Test", () => { await GUIActions.switchToReactIframe(driver); await GUIActions.selectModelFromDropdown(view, "TEST LLM"); - - // await new Promise((res) => { - // setTimeout(res, DEFAULT_TIMEOUT); - // }); }); afterEach(async function () { - this.timeout(DEFAULT_TIMEOUT); + this.timeout(DEFAULT_TIMEOUT.XL); await view.switchBack(); await new EditorView().closeAllEditors(); @@ -45,7 +41,7 @@ describe("GUI Test", () => { expect(await description.getText()).has.string( "Quickly get up and running using our API keys.", ); - }).timeout(DEFAULT_TIMEOUT); + }).timeout(DEFAULT_TIMEOUT.XL); }); describe("Chat", () => { @@ -54,7 +50,7 @@ describe("GUI Test", () => { const messagePair = TestUtils.generateTestMessagePair(); await messageInput.sendKeys(messagePair.userMessage); await messageInput.sendKeys(Key.ENTER); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, messagePair.llmResponse), ); }); @@ -64,7 +60,7 @@ describe("GUI Test", () => { const messagePair = TestUtils.generateTestMessagePair(); await messageInput.sendKeys(messagePair.userMessage); (await GUISelectors.getSubmitInputButton(view)).click(); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, messagePair.llmResponse), ); }); @@ -77,7 +73,7 @@ describe("GUI Test", () => { message: userMessage0, inputFieldIndex: 0, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, llmResponse0), ); @@ -88,7 +84,7 @@ describe("GUI Test", () => { message: userMessage1, inputFieldIndex: 1, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, llmResponse1), ); @@ -99,7 +95,7 @@ describe("GUI Test", () => { message: userMessage2, inputFieldIndex: 2, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, llmResponse2), ); @@ -120,7 +116,7 @@ describe("GUI Test", () => { await TestUtils.expectNoElement(() => GUISelectors.getThreadMessageByText(view, llmResponse2), ); - }).timeout(DEFAULT_TIMEOUT); + }).timeout(DEFAULT_TIMEOUT.XL); it("Can edit messages", async () => { const { userMessage: userMessage0, llmResponse: llmResponse0 } = @@ -130,7 +126,7 @@ describe("GUI Test", () => { message: userMessage0, inputFieldIndex: 0, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, llmResponse0), ); @@ -141,7 +137,7 @@ describe("GUI Test", () => { message: userMessage1, inputFieldIndex: 1, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, llmResponse1), ); @@ -152,7 +148,7 @@ describe("GUI Test", () => { message: userMessage2, inputFieldIndex: 2, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, llmResponse2), ); @@ -172,7 +168,7 @@ describe("GUI Test", () => { }); await GUISelectors.getThreadMessageByText(view, llmResponse0); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, llmResponse3), ); await Promise.all([ @@ -183,7 +179,7 @@ describe("GUI Test", () => { GUISelectors.getThreadMessageByText(view, llmResponse2), ), ]); - }).timeout(DEFAULT_TIMEOUT); + }).timeout(DEFAULT_TIMEOUT.XL); }); describe("Chat Paths", () => { @@ -194,7 +190,7 @@ describe("GUI Test", () => { message: messagePair1.userMessage, inputFieldIndex: 0, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, messagePair1.llmResponse), ); @@ -204,7 +200,7 @@ describe("GUI Test", () => { message: messagePair2.userMessage, inputFieldIndex: 1, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, messagePair2.llmResponse), ); @@ -238,9 +234,9 @@ describe("GUI Test", () => { message: messagePair3.userMessage, inputFieldIndex: 2, }); - await TestUtils.waitForElement(() => + await TestUtils.waitForSuccess(() => GUISelectors.getThreadMessageByText(view, messagePair3.llmResponse), ); - }).timeout(DEFAULT_TIMEOUT); + }).timeout(DEFAULT_TIMEOUT.XL); }); }); diff --git a/extensions/vscode/e2e/tests/SSH.test.ts b/extensions/vscode/e2e/tests/SSH.test.ts new file mode 100644 index 000000000..261f9ab90 --- /dev/null +++ b/extensions/vscode/e2e/tests/SSH.test.ts @@ -0,0 +1,61 @@ +import { + EditorView, + TextEditor, + InputBox, + Workbench, + Key, + VSBrowser, +} from "vscode-extension-tester"; + +import { DEFAULT_TIMEOUT } from "../constants"; +import { TestUtils } from "../TestUtils"; +import { SSHSelectors } from "../selectors/SSH.selectors"; +import { AutocompleteActions } from "../actions/Autocomplete.actions"; + +describe("SSH", function () { + this.retries(2); + + beforeEach(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + + await TestUtils.waitForSuccess(async () => { + await new Workbench().executeCommand( + "Remote-SSH: Connect Current Window to Host...", + ); + await ( + await InputBox.create(DEFAULT_TIMEOUT.MD) + ).selectQuickPick("ssh-test-container"); + }); + + await TestUtils.waitForSuccess( + () => SSHSelectors.connectedToRemoteConfirmationMessage(), + DEFAULT_TIMEOUT.XL, + ); + + // await TestUtils.waitForSuccess(async () => { + // await new Workbench().executeCommand("File: Open Folder..."); + // const inputBox = await InputBox.create(DEFAULT_TIMEOUT.MD); + // await inputBox.setText("/home/ec2-user/test-folder"); + // await inputBox.sendKeys(Key.ENTER); + // }); + + await TestUtils.waitForSuccess(async () => { + await new Workbench().executeCommand("File: Open File..."); + const inputBox = await InputBox.create(DEFAULT_TIMEOUT.MD); + await inputBox.setText("/home/ec2-user/test-folder/main.py"); + await inputBox.selectQuickPick("main.py"); + await inputBox.sendKeys(Key.ENTER); + }, DEFAULT_TIMEOUT.XL); + }); + + it("Should display completions", async () => { + const editor = await TestUtils.waitForSuccess( + async () => (await new EditorView().openEditor("main.py")) as TextEditor, + ); + + const text = await editor.getText(); + await editor.clearText(); + await AutocompleteActions.testCompletions(editor); + await editor.setText(text); + }).timeout(DEFAULT_TIMEOUT.XL); +}); diff --git a/extensions/vscode/e2e/tests/TODO.md b/extensions/vscode/e2e/tests/TODO.md new file mode 100644 index 000000000..ce2be2ac0 --- /dev/null +++ b/extensions/vscode/e2e/tests/TODO.md @@ -0,0 +1,3 @@ +TODO testing scenarios + +- Highlighting code and pressing CMD+L _before_ the GUI was first opened. The highlighted code should be included as chat input. \ No newline at end of file diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 627c0c974..ba3b4e2e2 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -628,11 +628,12 @@ "e2e:sign-vscode": "codesign --entitlements entitlements.plist --deep --force -s - './e2e/storage/Visual Studio Code.app'", "e2e:copy-vsix": "chmod +x ./e2e/get-latest-vsix.sh && bash ./e2e/get-latest-vsix.sh", "e2e:install-vsix": "extest install-vsix -f ./e2e/vsix/continue.vsix --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage", + "e2e:install-extensions": "extest install-from-marketplace ms-vscode-remote.remote-ssh --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage && extest install-from-marketplace ms-vscode-remote.remote-containers --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage && extest install-from-marketplace ms-vscode-remote.remote-wsl --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage", "e2e:test": "extest run-tests './e2e/_output/tests/*.test.js' --code_settings settings.json --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage", "e2e:clean": "rm -rf ./e2e/_output", - "e2e:all": "npm run e2e:build && npm run e2e:compile && npm run e2e:create-storage && npm run e2e:get-chromedriver && npm run e2e:get-vscode && npm run e2e:sign-vscode && npm run e2e:copy-vsix && npm run e2e:install-vsix && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test && npm run e2e:clean", + "e2e:all": "npm run e2e:build && npm run e2e:compile && npm run e2e:create-storage && npm run e2e:get-chromedriver && npm run e2e:get-vscode && npm run e2e:sign-vscode && npm run e2e:copy-vsix && npm run e2e:install-vsix && npm run e2e:install-extensions && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test && npm run e2e:clean", "e2e:quick": "npm run e2e:compile && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test && npm run e2e:clean", - "e2e:ci": "npm run e2e:compile && npm run e2e:create-storage && npm run e2e:get-chromedriver && npm run e2e:get-vscode && npm run e2e:copy-vsix && npm run e2e:install-vsix && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test" + "e2e:ci": "npm run e2e:compile && npm run e2e:create-storage && npm run e2e:get-chromedriver && npm run e2e:get-vscode && npm run e2e:copy-vsix && npm run e2e:install-vsix && npm run e2e:install-extensions && CONTINUE_GLOBAL_DIR=e2e/test-continue npm run e2e:test" }, "devDependencies": { "@biomejs/biome": "1.6.4",