diff --git a/core/autocomplete/filtering/test/util.ts b/core/autocomplete/filtering/test/util.ts index a052aace2..db8d99131 100644 --- a/core/autocomplete/filtering/test/util.ts +++ b/core/autocomplete/filtering/test/util.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; import path from "node:path"; -import Mock from "../../../llm/llms/Mock"; +import MockLLM from "../../../llm/llms/Mock"; import { testConfigHandler, testIde } from "../../../test/fixtures"; import { CompletionProvider } from "../../CompletionProvider"; import { AutocompleteInput } from "../../util/types"; @@ -30,7 +30,7 @@ export async function testAutocompleteFiltering( const { prefix, suffix } = parseFimExample(test.input); // Setup necessary objects - const llm = new Mock({ + const llm = new MockLLM({ model: "mock", }); llm.completion = test.llmOutput; diff --git a/core/index.d.ts b/core/index.d.ts index 06fbd7275..4e050bb58 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -807,6 +807,7 @@ type ModelProvider = | "nvidia" | "vllm" | "mock" + | "test" | "cerebras" | "askSage" | "vertexai" diff --git a/core/llm/llms/Mock.ts b/core/llm/llms/Mock.ts index 5f3880e3c..6f564cce7 100644 --- a/core/llm/llms/Mock.ts +++ b/core/llm/llms/Mock.ts @@ -1,7 +1,7 @@ import { ChatMessage, CompletionOptions, ModelProvider } from "../../index.js"; import { BaseLLM } from "../index.js"; -class Mock extends BaseLLM { +class MockLLM extends BaseLLM { public completion: string = "Test Completion"; static providerName: ModelProvider = "mock"; @@ -27,4 +27,4 @@ class Mock extends BaseLLM { } } -export default Mock; +export default MockLLM; diff --git a/core/llm/llms/Test.ts b/core/llm/llms/Test.ts new file mode 100644 index 000000000..b35984f3e --- /dev/null +++ b/core/llm/llms/Test.ts @@ -0,0 +1,39 @@ +import { ChatMessage, CompletionOptions, ModelProvider } from "../../index.js"; +import { BaseLLM } from "../index.js"; + +const RESPONSES: Record = { + "How are you?": "I'm fine", +}; + +const HARDCODED_CHAT_RESPONSE = "THIS IS A HARDCODED RESPONSE"; + +class TestLLM extends BaseLLM { + static providerName: ModelProvider = "test"; + + private findResponse(prompt: string) { + return Object.entries(RESPONSES).find(([key]) => prompt.includes(key))?.[1]; + } + + protected async *_streamComplete( + prompt: string, + signal: AbortSignal, + options: CompletionOptions, + ): AsyncGenerator { + yield this.findResponse(prompt) || `PROMPT: ${prompt}`; + } + + protected async *_streamChat( + messages: ChatMessage[], + signal: AbortSignal, + options: CompletionOptions, + ): AsyncGenerator { + for (const char of HARDCODED_CHAT_RESPONSE) { + yield { + role: "assistant", + content: char, + }; + } + } +} + +export default TestLLM; diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index 632607ed1..9604cb9f6 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -31,7 +31,7 @@ import LlamaCpp from "./LlamaCpp"; import Llamafile from "./Llamafile"; import LMStudio from "./LMStudio"; import Mistral from "./Mistral"; -import Mock from "./Mock"; +import MockLLM from "./Mock"; import Moonshot from "./Moonshot"; import Msty from "./Msty"; import Nebius from "./Nebius"; @@ -50,6 +50,7 @@ import Vllm from "./Vllm"; import WatsonX from "./WatsonX"; import xAI from "./xAI"; import SiliconFlow from "./SiliconFlow"; +import TestLLM from "./Test"; const LLMs = [ Anthropic, @@ -87,7 +88,8 @@ const LLMs = [ Nvidia, Vllm, SambaNova, - Mock, + MockLLM, + TestLLM, Cerebras, Asksage, Nebius, diff --git a/extensions/vscode/e2e/GUI.test.ts b/extensions/vscode/e2e/GUI.test.ts deleted file mode 100644 index 0055df1ba..000000000 --- a/extensions/vscode/e2e/GUI.test.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { - Workbench, - EditorView, - WebView, - By, - WebElement, - WebDriver, - Key, -} from "vscode-extension-tester"; -import { expect } from "chai"; - -const switchToReactIframe = async (driver: WebDriver) => { - const iframes = await driver.findElements(By.css("iframe")); - let continueIFrame: WebElement | undefined = undefined; - for (let i = 0; i < iframes.length; i++) { - const iframe = iframes[i]; - const src = await iframe.getAttribute("src"); - if (src.includes("extensionId=Continue.continue")) { - continueIFrame = iframe; - break; - } - } - - if (!continueIFrame) { - throw new Error("Could not find continue iframe"); - } - - await driver.switchTo().frame(continueIFrame); - - await new Promise((res) => { - setTimeout(res, 500); - }); - - const reactIFrame = await driver.findElement(By.css("iframe")); - - if (!reactIFrame) { - throw new Error("Could not find React iframe"); - } - - await driver.switchTo().frame(reactIFrame); -}; - -describe("GUI Test", () => { - let view: WebView; - let driver: WebDriver; - - before(async function () { - this.timeout(10000); - - await new Workbench().executeCommand("continue.focusContinueInput"); - - view = new WebView(); - driver = view.getDriver(); - - await switchToReactIframe(driver); - }); - - after(async () => { - await view.switchBack(); - await new EditorView().closeAllEditors(); - }); - - it("should display correct panel description", async () => { - const description = await view.findWebElement( - By.xpath("//*[contains(text(), 'Quickly')]"), - ); - - expect(await description.getText()).has.string( - "Quickly get up and running using our API keys.", - ); - }); - - it("should allow typing text in the editor", async () => { - const tiptap = await view.findWebElement(By.className("tiptap")); - - await tiptap.sendKeys("Hello world!"); - - expect(await tiptap.getText()).has.string("Hello world!"); - - // Just to show that we can - await tiptap.sendKeys(Key.ENTER); - await new Promise((res) => { - setTimeout(res, 5000); - }); - }).timeout(6000); -}); diff --git a/extensions/vscode/e2e/actions/GUI.actions.ts b/extensions/vscode/e2e/actions/GUI.actions.ts new file mode 100644 index 000000000..1e59f1d15 --- /dev/null +++ b/extensions/vscode/e2e/actions/GUI.actions.ts @@ -0,0 +1,58 @@ +import { + WebDriver, + WebElement, + WebView, + Workbench, +} from "vscode-extension-tester"; +import { GUISelectors } from "../selectors/GUI.selectors"; + +export class GUIActions { + public static switchToReactIframe = async (driver: WebDriver) => { + const iframes = await GUISelectors.getAllIframes(driver); + let continueIFrame: WebElement | undefined = undefined; + for (let i = 0; i < iframes.length; i++) { + const iframe = iframes[i]; + const src = await iframe.getAttribute("src"); + if (src.includes("extensionId=Continue.continue")) { + continueIFrame = iframe; + break; + } + } + + if (!continueIFrame) { + throw new Error("Could not find continue iframe"); + } + + await driver.switchTo().frame(continueIFrame); + + await new Promise((res) => { + setTimeout(res, 500); + }); + + const reactIFrame = await GUISelectors.getReactIframe(driver); + + if (!reactIFrame) { + throw new Error("Could not find React iframe"); + } + + await driver.switchTo().frame(reactIFrame); + }; + + public static openGui = async () => { + return new Workbench().executeCommand("continue.focusContinueInput"); + }; + + public static selectModelFromDropdown = async ( + view: WebView, + option: string, + ) => { + const dropdownButton = await GUISelectors.getModelDropdownButton(view); + await dropdownButton.click(); + + const dropdownOption = await GUISelectors.getModelDropdownOption( + view, + option, + ); + await dropdownOption.click(); + }; +} diff --git a/extensions/vscode/e2e/selectors/GUI.selectors.ts b/extensions/vscode/e2e/selectors/GUI.selectors.ts new file mode 100644 index 000000000..1208d1a04 --- /dev/null +++ b/extensions/vscode/e2e/selectors/GUI.selectors.ts @@ -0,0 +1,44 @@ +import { By, WebDriver, WebView } from "vscode-extension-tester"; +import { SelectorUtils } from "./SelectorUtils"; + +export class GUISelectors { + public static getDescription(view: WebView) { + return view.findWebElement(By.xpath("//*[contains(text(), 'Quickly')]")); + } + + public static getTipTapEditor(view: WebView) { + return view.findWebElement(By.className("tiptap")); + } + + public static getAllIframes(driver: WebDriver) { + return driver.findElements(By.css("iframe")); + } + + public static getReactIframe(driver: WebDriver) { + return driver.findElement(By.css("iframe")); + } + + public static getSubmitInputButton(view: WebView) { + return SelectorUtils.getElementByDataTestId(view, "submit-input-button"); + } + + public static getModelDropdownButton(view: WebView) { + return SelectorUtils.getElementByDataTestId(view, "model-select-button"); + } + + public static getListbox(view: WebView) { + const listbox = view.findWebElement(By.css('[role="listbox"]')); + } + + public static getModelDropdownOption(view: WebView, option: string) { + return view.findWebElement( + By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`), + ); + } + + public static getThreadMessageByText(view: WebView, text: string) { + return view.findWebElement( + By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`), + ); + } +} diff --git a/extensions/vscode/e2e/selectors/SelectorUtils.ts b/extensions/vscode/e2e/selectors/SelectorUtils.ts new file mode 100644 index 000000000..243e1bf44 --- /dev/null +++ b/extensions/vscode/e2e/selectors/SelectorUtils.ts @@ -0,0 +1,16 @@ +import { By, WebElement, WebView } from "vscode-extension-tester"; + +export class SelectorUtils { + /** + * Finds a web element by its data-testid attribute within a WebView. + * @param view - The WebView to search within. + * @param testId - The data-testid value to search for. + * @returns A promise that resolves to the WebElement found. + */ + public static getElementByDataTestId( + view: WebView, + testId: string, + ): Promise { + return view.findWebElement(By.css(`[data-testid='${testId}']`)); + } +} diff --git a/extensions/vscode/e2e/test-files/config.json b/extensions/vscode/e2e/test-files/config.json new file mode 100644 index 000000000..524cd8403 --- /dev/null +++ b/extensions/vscode/e2e/test-files/config.json @@ -0,0 +1,4 @@ +{ + "name": "Untitled.txt", + "content": "Hello, world!" +} diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts new file mode 100644 index 000000000..87837c69c --- /dev/null +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -0,0 +1,61 @@ +import { + EditorView, + WebView, + WebDriver, + Key, + VSBrowser, +} from "vscode-extension-tester"; +import { expect } from "chai"; +import { GUIActions } from "../actions/GUI.actions"; +import { GUISelectors } from "../selectors/GUI.selectors"; +import * as path from "path"; + +describe("GUI Test", () => { + let view: WebView; + let driver: WebDriver; + + before(async function () { + this.timeout(10000000); + + await VSBrowser.instance.openResources(path.join("e2e/test-files")); + + await GUIActions.openGui(); + + view = new WebView(); + driver = view.getDriver(); + + await GUIActions.switchToReactIframe(driver); + // await new Promise((res) => { + // setTimeout(res, 10000000); + // }); + }); + + after(async () => { + await view.switchBack(); + await new EditorView().closeAllEditors(); + }); + + it("should display correct panel description", async () => { + const description = await GUISelectors.getDescription(view); + + expect(await description.getText()).has.string( + "Quickly get up and running using our API keys.", + ); + }); + + it.only("should allow typing text in the editor", async () => { + await GUIActions.selectModelFromDropdown(view, "Mock"); + await GUIActions.selectModelFromDropdown(view, "TEST LLM"); + + const tiptap = await GUISelectors.getTipTapEditor(view); + + await tiptap.sendKeys("How are you?"); + (await GUISelectors.getSubmitInputButton(view)).click(); + + await new Promise((res) => { + setTimeout(res, 600000000); + }); + + await GUISelectors.getThreadMessageByText(view, "I'm fine"); + }).timeout(600000000); +}); diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index acc5b947b..9d353798f 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -2,7 +2,7 @@ "name": "continue", "icon": "media/icon.png", "author": "Continue Dev, Inc", - "version": "0.9.244", + "version": "0.9.251", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" @@ -613,6 +613,7 @@ "quick-test": "npm run build-test && node ./out/runTestOnVSCodeHost.js", "prepackage": "node scripts/prepackage.js", "package": "node scripts/package.js", + "e2e:package": "CONTINUE_GLOBAL_DIR=e2e/test-files node scripts/package.js", "package-all": "node scripts/package-all.js", "package:pre-release": "node scripts/package.js --pre-release", "build:rust": "cargo-cp-artifact -ac sync sync.node -- cargo build --manifest-path ../../sync/Cargo.toml --message-format=json-render-diagnostics", @@ -625,8 +626,10 @@ "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:test": "extest run-tests './e2e/_output/*.test.js' --code_settings settings.json --extensions_dir ./e2e/.test-extensions --storage ./e2e/storage", - "e2e:all": "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:test", + "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: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:test && npm run e2e:clean", + "e2e:quick": "CONTINUE_GLOBAL_DIR=e2e/test-files npm run e2e:compile && 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 && npm run e2e:test" }, "devDependencies": { diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 9348e5262..f83c27d1e 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -208,6 +208,7 @@ function InputToolbar(props: InputToolbarProps) { )} { if (props.onEnter) { props.onEnter({ diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index a4d7fe364..c5edb5d7b 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -316,6 +316,7 @@ function ModelSelect() { >