successful tool call test

This commit is contained in:
Nate 2024-12-22 10:22:05 -05:00
parent b0dbdfbb69
commit f83206a37b
7 changed files with 101 additions and 13 deletions

View file

@ -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<ChatMessage> {
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",

View file

@ -1,6 +1,6 @@
### Setup
When running e2e tests for the first time:
When running e2e tests for the first time, or after changing non-test source code:
```bash
npm run e2e:all
@ -8,7 +8,7 @@ npm run e2e:all
### Run
Afterward, you can run the tests with:
Afterward, you can run the tests with as long as you've only changed the e2e test code:
```bash
npm run e2e:quick

View file

@ -1,4 +1,4 @@
import { By, until, WebDriver, WebView } from "vscode-extension-tester";
import { By, WebDriver, WebView } from "vscode-extension-tester";
import { SelectorUtils } from "./SelectorUtils";
export class GUISelectors {
@ -30,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");
}

View file

@ -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": {

View file

@ -1,17 +1,17 @@
import { expect } from "chai";
import {
EditorView,
WebView,
WebDriver,
Key,
WebElement,
VSBrowser,
WebDriver,
WebElement,
WebView,
} from "vscode-extension-tester";
import { expect } from "chai";
import { GlobalActions } from "../actions/Global.actions";
import { GUIActions } from "../actions/GUI.actions";
import { DEFAULT_TIMEOUT } from "../constants";
import { GUISelectors } from "../selectors/GUI.selectors";
import { TestUtils } from "../TestUtils";
import { DEFAULT_TIMEOUT } from "../constants";
import { GlobalActions } from "../actions/Global.actions";
describe("GUI Test", () => {
let view: WebView;
@ -191,6 +191,20 @@ describe("GUI Test", () => {
}).timeout(DEFAULT_TIMEOUT.XL);
});
describe("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("Open chat and type → open history → cmd+l → chat opens, empty and in focus", async () => {
const originalTextInput = await GUISelectors.getMessageInputFieldAtIndex(

View file

@ -10,7 +10,7 @@ import {
import { GlobalActions } from "../actions/Global.actions";
import { DEFAULT_TIMEOUT } from "../constants";
describe.only("Prompt file", () => {
describe("Prompt file", () => {
let editor: TextEditor;
beforeEach(async function () {

View file

@ -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) {
<RejectButton onClick={() => dispatch(cancelTool())}>
Cancel
</RejectButton>
<AcceptButton onClick={() => dispatch(callTool())}>
<AcceptButton
onClick={() => dispatch(callTool())}
data-testid="accept-tool-call-button"
>
Continue
</AcceptButton>
</>