diff --git a/core/llm/llms/Mock.ts b/core/llm/llms/Mock.ts index 811ecba94..236af9824 100644 --- a/core/llm/llms/Mock.ts +++ b/core/llm/llms/Mock.ts @@ -1,10 +1,19 @@ -import { ChatMessage, CompletionOptions } from "../../index.js"; +import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js"; import { BaseLLM } from "../index.js"; +type MockMessage = ChatMessage | "REPEAT_LAST_MSG"; + class MockLLM extends BaseLLM { public completion: string = "Test Completion"; + public chatStreams: MockMessage[][] | undefined; static providerName = "mock"; + constructor(options: LLMOptions) { + super(options); + this.templateMessages = undefined; + this.chatStreams = options.requestOptions?.extraBodyProperties?.chatStream; + } + protected async *_streamComplete( prompt: string, signal: AbortSignal, @@ -18,6 +27,29 @@ class MockLLM extends BaseLLM { signal: AbortSignal, options: CompletionOptions, ): AsyncGenerator { + if (this.chatStreams) { + const chatStream = + this.chatStreams?.[ + messages.filter((m) => m.role === "user" || m.role === "tool") + .length - 1 + ]; + if (chatStream) { + for (const message of chatStream) { + switch (message) { + case "REPEAT_LAST_MSG": + yield { + role: "assistant", + content: messages[messages.length - 1].content, + }; + break; + default: + yield message; + } + } + } + return; + } + for (const char of this.completion) { yield { role: "assistant", diff --git a/extensions/vscode/e2e/README.md b/extensions/vscode/e2e/README.md new file mode 100644 index 000000000..2af3c5312 --- /dev/null +++ b/extensions/vscode/e2e/README.md @@ -0,0 +1,23 @@ +### Setup + +When running e2e tests for the first time, or after changing non-test source code: + +```bash +npm run e2e:all +``` + +### Run + +Afterward, you can run the tests with as long as you've only changed the e2e test code: + +```bash +npm run e2e:quick +``` + +### Writing tests + +All e2e tests are separated (by folder) into + +- `selectors` - functions that return elements +- `actions` - functions that perform actions on the editor +- `tests` - the actual tests, which are typically longer paths of functionality rather than individual actions diff --git a/extensions/vscode/e2e/selectors/GUI.selectors.ts b/extensions/vscode/e2e/selectors/GUI.selectors.ts index e7f8c78d0..16c7b39d9 100644 --- a/extensions/vscode/e2e/selectors/GUI.selectors.ts +++ b/extensions/vscode/e2e/selectors/GUI.selectors.ts @@ -1,5 +1,4 @@ import { By, WebDriver, WebView } from "vscode-extension-tester"; - import { SelectorUtils } from "./SelectorUtils"; export class GUISelectors { @@ -31,6 +30,13 @@ export class GUISelectors { return SelectorUtils.getElementByDataTestId(view, "submit-input-button"); } + public static getAcceptToolCallButton(view: WebView) { + return SelectorUtils.getElementByDataTestId( + view, + "accept-tool-call-button", + ); + } + public static getModelDropdownButton(view: WebView) { return SelectorUtils.getElementByDataTestId(view, "model-select-button"); } diff --git a/extensions/vscode/e2e/test-continue/config.json b/extensions/vscode/e2e/test-continue/config.json index 0160335f5..a8932322a 100644 --- a/extensions/vscode/e2e/test-continue/config.json +++ b/extensions/vscode/e2e/test-continue/config.json @@ -12,6 +12,38 @@ "title": "Mock", "provider": "mock", "model": "this field is not used" + }, + { + "provider": "mock", + "title": "TOOL MOCK LLM", + "model": "claude-3-5-sonnet-latest", + "requestOptions": { + "extraBodyProperties": { + "chatStream": [ + [ + { + "role": "assistant", + "content": "I'm going to call a tool:" + }, + { + "role": "assistant", + "content": "", + "toolCalls": [ + { + "id": "test_id", + "type": "function", + "function": { + "name": "builtin_exact_search", + "arguments": "{\"query\": \"\\\" won't be matched because of escaped quotes \\\"\"}" + } + } + ] + } + ], + ["REPEAT_LAST_MSG"] + ] + } + } } ], "analytics": { diff --git a/extensions/vscode/e2e/tests/Autocomplete.test.ts b/extensions/vscode/e2e/tests/Autocomplete.test.ts index 836c2c60e..e6444c80c 100644 --- a/extensions/vscode/e2e/tests/Autocomplete.test.ts +++ b/extensions/vscode/e2e/tests/Autocomplete.test.ts @@ -1,4 +1,9 @@ -import { EditorView, TextEditor } from "vscode-extension-tester"; +import { + EditorView, + InputBox, + TextEditor, + Workbench, +} from "vscode-extension-tester"; import { AutocompleteActions } from "../actions/Autocomplete.actions"; import { GlobalActions } from "../actions/Global.actions"; diff --git a/extensions/vscode/e2e/tests/GUI.test.ts b/extensions/vscode/e2e/tests/GUI.test.ts index 644cbaf64..e2545148a 100644 --- a/extensions/vscode/e2e/tests/GUI.test.ts +++ b/extensions/vscode/e2e/tests/GUI.test.ts @@ -1,11 +1,11 @@ import { expect } from "chai"; import { EditorView, - WebView, - WebDriver, Key, - WebElement, VSBrowser, + WebDriver, + WebElement, + WebView, until, } from "vscode-extension-tester"; @@ -193,6 +193,20 @@ describe("GUI Test", () => { }).timeout(DEFAULT_TIMEOUT.XL); }); + describe.skip("Chat with tools", () => { + it("should render tool call", async () => { + await GUIActions.selectModelFromDropdown(view, "TOOL MOCK LLM"); + + const [messageInput] = await GUISelectors.getMessageInputFields(view); + await messageInput.sendKeys("Hello"); + await messageInput.sendKeys(Key.ENTER); + + await TestUtils.waitForSuccess( + () => GUISelectors.getThreadMessageByText(view, "No matches found"), // Defined in extensions/vscode/e2e/test-continue/config.json's TOOL MOCK LLM that we are calling the exact search tool + ); + }); + }); + describe("Chat Paths", () => { it("Send many messages → chat auto scrolls → go to history → open previous chat → it is scrolled to the bottom", async () => { for (let i = 0; i <= 20; i++) { diff --git a/extensions/vscode/e2e/tests/PromptFile.test.ts b/extensions/vscode/e2e/tests/PromptFile.test.ts new file mode 100644 index 000000000..7cf87fd54 --- /dev/null +++ b/extensions/vscode/e2e/tests/PromptFile.test.ts @@ -0,0 +1,65 @@ +import { expect } from "chai"; +import { + EditorView, + InputBox, + Key, + TextEditor, + Workbench, +} from "vscode-extension-tester"; + +import { GlobalActions } from "../actions/Global.actions"; +import { DEFAULT_TIMEOUT } from "../constants"; + +describe("Prompt file", () => { + let editor: TextEditor; + + beforeEach(async function () { + this.timeout(DEFAULT_TIMEOUT.XL); + + await GlobalActions.openTestWorkspace(); + await new Workbench().executeCommand("File: New Untitled Text File"); + await new Workbench().executeCommand("Change Language Mode"); + const inputBox = await new InputBox(); + await inputBox.setText("Prompt Language"); + await inputBox.confirm(); + 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 intellisense for default context providers and preamble", async () => { + // Check that "@" dropdown in body works + const providers = [ + "currentFile", + "open", + "os", + "problems", + "repo-map", + "terminal", + "tree", + ]; + for (const provider of providers) { + await editor.typeText("@" + provider.slice(0, 2)); + await editor.typeText(Key.ENTER); + const text = await editor.getText(); + expect(text).equals("@" + provider); + await editor.clearText(); + } + + // Check that dropdown for properties in preamble works + // await editor.typeText(Key.ENTER); + // await editor.typeText(Key.ENTER); + // await editor.typeText("---"); + // await editor.typeText(Key.UP); + // await editor.typeText(Key.UP); + // await editor.typeText(Key.SPACE); + // await editor.typeText(Key.BACK_SPACE); + // await editor.typeText(Key.ENTER); + // const text = await editor.getText(); + // expect(text).equals("description: \n\n---"); + }).timeout(DEFAULT_TIMEOUT.XL); +}); diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx index 9d4528f33..956b98158 100644 --- a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx +++ b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx @@ -7,10 +7,10 @@ import { vscButtonForeground, } from "../../../components"; import Spinner from "../../../components/gui/Spinner"; +import { useAppDispatch } from "../../../redux/hooks"; import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall"; import { callTool } from "../../../redux/thunks/callTool"; import { cancelTool } from "../../../redux/thunks/cancelTool"; -import { useAppDispatch } from "../../../redux/hooks"; const ButtonContainer = styled.div` display: flex; @@ -75,7 +75,10 @@ export function ToolCallButtons(props: ToolCallButtonsProps) { dispatch(cancelTool())}> Cancel - dispatch(callTool())}> + dispatch(callTool())} + data-testid="accept-tool-call-button" + > Continue