fix failing tests
This commit is contained in:
parent
7190dce3b7
commit
7e90887e2b
8 changed files with 81 additions and 21 deletions
7
extensions/vscode/package-lock.json
generated
7
extensions/vscode/package-lock.json
generated
|
|
@ -2544,9 +2544,10 @@
|
|||
"integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g=="
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "16.18.119",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.119.tgz",
|
||||
"integrity": "sha512-ia7V9a2FnhUFfetng4/sRPBMTwHZUkPFY736rb1cg9AgG7MZdR97q7/nLR9om+sq5f1la9C857E0l/nrI0RiFQ=="
|
||||
"version": "16.18.126",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.126.tgz",
|
||||
"integrity": "sha512-OTcgaiwfGFBKacvfwuHzzn1KLxH/er8mluiy8/uM3sGXHaRe73RrSIj01jow9t4kJEW633Ov+cOexXeiApTyAw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node-fetch": {
|
||||
"version": "2.6.12",
|
||||
|
|
|
|||
|
|
@ -95,7 +95,15 @@ describe("get rendered v1 prompt file", () => {
|
|||
});
|
||||
|
||||
it("should render file read errors within prompt", async () => {
|
||||
// Mock console.error to prevent error output during test
|
||||
const originalConsoleError = console.error;
|
||||
console.error = vi.fn();
|
||||
|
||||
ideMessenger.responses["fileExists"] = false;
|
||||
// Mock readFile to throw an error for nonexistent files
|
||||
ideMessenger.responseHandlers["readFile"] = async (filepath) => {
|
||||
throw new Error(`File not found: ${filepath}`);
|
||||
};
|
||||
const rawContent = "Content with provider {{{ nonexistent }}}";
|
||||
const command = getTestPromptV1Command(rawContent);
|
||||
const rendered = await getRenderedV1Prompt(
|
||||
|
|
@ -107,6 +115,9 @@ describe("get rendered v1 prompt file", () => {
|
|||
expect(rendered).toBe(
|
||||
`Content with provider [Error reading file "nonexistent"]\n\nUser input`,
|
||||
);
|
||||
|
||||
// Restore console.error
|
||||
console.error = originalConsoleError;
|
||||
});
|
||||
|
||||
it("should handle multiple attachments", async () => {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|||
<button
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"my-1.5 cursor-pointer rounded font-sans transition-all duration-200",
|
||||
"my-1.5 cursor-pointer rounded transition-all duration-200",
|
||||
"hover:enabled:cursor-pointer",
|
||||
"disabled:text-description-muted disabled:pointer-events-none disabled:opacity-50",
|
||||
buttonVariants[variant],
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import { TabBar } from "../../components/TabBar/TabBar";
|
|||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectPendingToolCalls } from "../../redux/selectors/selectToolCalls";
|
||||
import { selectDoneApplyStates, selectPendingToolCalls } from "../../redux/selectors/selectToolCalls";
|
||||
import {
|
||||
cancelToolCall,
|
||||
ChatHistoryItemWithMessageId,
|
||||
|
|
@ -139,11 +139,7 @@ export function Chat() {
|
|||
);
|
||||
|
||||
const pendingToolCalls = useAppSelector(selectPendingToolCalls);
|
||||
const pendingApplyStates = useAppSelector((state) =>
|
||||
state.session.codeBlockApplyStates.states.filter(
|
||||
(applyState) => applyState.status === "done",
|
||||
),
|
||||
);
|
||||
const pendingApplyStates = useAppSelector(selectDoneApplyStates);
|
||||
|
||||
const sendInput = useCallback(
|
||||
(
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { renderWithProviders } from "../../../util/test/render";
|
|||
import { Chat } from "../Chat";
|
||||
|
||||
import { waitFor } from "@testing-library/dom";
|
||||
import { act } from "@testing-library/react";
|
||||
import { ChatMessage } from "core";
|
||||
import { toggleToolSetting } from "../../../redux/slices/uiSlice";
|
||||
import {
|
||||
|
|
@ -22,6 +23,10 @@ const EDIT_FILE_URI = `${EDIT_WORKSPACE_DIR}/${EDIT_FILEPATH}`;
|
|||
const EDIT_CHANGES = "New content";
|
||||
const EDIT_TOOL_CALL_ID = "known-id";
|
||||
const EDIT_MESSAGES: ChatMessage[] = [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "I'll edit the file for you.",
|
||||
},
|
||||
{
|
||||
role: "assistant",
|
||||
content: "",
|
||||
|
|
@ -45,7 +50,7 @@ beforeEach(() => {
|
|||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
test("Edit run with ask first policy and no auto apply", async () => {
|
||||
test("Edit run with ask first policy and no auto apply", { timeout: 10000 }, async () => {
|
||||
// Setup
|
||||
const { ideMessenger, store, user } = await renderWithProviders(<Chat />);
|
||||
|
||||
|
|
@ -61,6 +66,11 @@ test("Edit run with ask first policy and no auto apply", async () => {
|
|||
EDIT_MESSAGES,
|
||||
);
|
||||
|
||||
// Wait for streaming to complete and tool calls to be set to generated
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
});
|
||||
|
||||
// Toggle the codeblock and make sure the changes show
|
||||
const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock");
|
||||
|
||||
|
|
@ -69,7 +79,7 @@ test("Edit run with ask first policy and no auto apply", async () => {
|
|||
|
||||
// Pending tool call - find and click the accept button
|
||||
const acceptToolCallButton = await getElementByTestId(
|
||||
"accept-tool-call-button",
|
||||
`accept-tool-call-button-${EDIT_TOOL_CALL_ID}`,
|
||||
);
|
||||
await user.click(acceptToolCallButton);
|
||||
|
||||
|
|
@ -112,6 +122,9 @@ test("Edit run with ask first policy and no auto apply", async () => {
|
|||
const acceptButton = await getElementByTestId("edit-accept-button");
|
||||
await getElementByTestId("edit-reject-button");
|
||||
|
||||
// Set the chat response text before accepting changes
|
||||
ideMessenger.setChatResponseText(POST_EDIT_RESPONSE);
|
||||
|
||||
// Accept the changes, which should trigger a response after the tool call
|
||||
await user.click(acceptButton);
|
||||
|
||||
|
|
@ -120,7 +133,7 @@ test("Edit run with ask first policy and no auto apply", async () => {
|
|||
filepath: EDIT_FILE_URI,
|
||||
});
|
||||
|
||||
ideMessenger.setChatResponseText(POST_EDIT_RESPONSE);
|
||||
// Close the stream - this should trigger the streaming response
|
||||
ideMessenger.mockMessageToWebview("updateApplyState", {
|
||||
status: "closed",
|
||||
streamId,
|
||||
|
|
@ -128,13 +141,18 @@ test("Edit run with ask first policy and no auto apply", async () => {
|
|||
filepath: EDIT_FILE_URI,
|
||||
});
|
||||
|
||||
// Allow time for the auto-streaming to complete
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
await verifyNotPresentByTestId("edit-accept-button");
|
||||
await verifyNotPresentByTestId("edit-reject-button");
|
||||
|
||||
await getElementByText(POST_EDIT_RESPONSE);
|
||||
await waitFor(() => getElementByText(POST_EDIT_RESPONSE), {
|
||||
timeout: 5000,
|
||||
});
|
||||
});
|
||||
|
||||
test("Edit run with no policy and yolo mode", async () => {
|
||||
test("Edit run with no policy and yolo mode", { timeout: 10000 }, async () => {
|
||||
// Setup
|
||||
const { ideMessenger, store, user } = await renderWithProviders(<Chat />);
|
||||
|
||||
|
|
@ -165,6 +183,11 @@ test("Edit run with no policy and yolo mode", async () => {
|
|||
EDIT_MESSAGES,
|
||||
);
|
||||
|
||||
// Wait for streaming to complete and tool calls to be processed
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
});
|
||||
|
||||
// Toggle the codeblock and make sure the changes show
|
||||
const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock");
|
||||
|
||||
|
|
@ -172,7 +195,7 @@ test("Edit run with no policy and yolo mode", async () => {
|
|||
await getElementByText(EDIT_CHANGES);
|
||||
|
||||
// Make sure there's no pending tool call
|
||||
verifyNotPresentByTestId("accept-tool-call-button");
|
||||
verifyNotPresentByTestId(`accept-tool-call-button-${EDIT_TOOL_CALL_ID}`);
|
||||
// Tool call, check that applyToFile was called for edit
|
||||
await waitFor(() => {
|
||||
expect(messengerPostSpy).toHaveBeenCalledWith("applyToFile", {
|
||||
|
|
@ -208,6 +231,9 @@ test("Edit run with no policy and yolo mode", async () => {
|
|||
filepath: EDIT_FILE_URI,
|
||||
});
|
||||
|
||||
// Set the chat response text before the auto-accept triggers
|
||||
ideMessenger.setChatResponseText(POST_EDIT_RESPONSE);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", {
|
||||
streamId,
|
||||
|
|
@ -216,7 +242,6 @@ test("Edit run with no policy and yolo mode", async () => {
|
|||
});
|
||||
|
||||
// Close the stream, ensure response is shown and diff buttons are not present
|
||||
ideMessenger.setChatResponseText(POST_EDIT_RESPONSE);
|
||||
ideMessenger.mockMessageToWebview("updateApplyState", {
|
||||
status: "closed",
|
||||
streamId,
|
||||
|
|
@ -224,8 +249,13 @@ test("Edit run with no policy and yolo mode", async () => {
|
|||
filepath: EDIT_FILE_URI,
|
||||
});
|
||||
|
||||
// Allow time for the auto-streaming to complete
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
await verifyNotPresentByTestId("edit-accept-button");
|
||||
await verifyNotPresentByTestId("edit-reject-button");
|
||||
|
||||
await getElementByText(POST_EDIT_RESPONSE);
|
||||
await waitFor(() => getElementByText(POST_EDIT_RESPONSE), {
|
||||
timeout: 5000,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ describe("Parallel Tool Calls", () => {
|
|||
{
|
||||
role: "assistant",
|
||||
content: "I'll call both tools in parallel.",
|
||||
},
|
||||
{
|
||||
role: "assistant",
|
||||
content: "",
|
||||
toolCalls: [
|
||||
{
|
||||
id: "tool-call-1",
|
||||
|
|
@ -47,8 +51,9 @@ describe("Parallel Tool Calls", () => {
|
|||
PARALLEL_TOOL_CALL_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for streaming to complete and tool calls to be set to generated
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
});
|
||||
|
||||
const state = store.getState();
|
||||
|
|
@ -63,6 +68,7 @@ describe("Parallel Tool Calls", () => {
|
|||
item.message.role === "assistant" && item.toolCallStates?.length,
|
||||
);
|
||||
|
||||
|
||||
expect(assistantMessage).toBeDefined();
|
||||
expect(assistantMessage!.toolCallStates).toHaveLength(2);
|
||||
expect(assistantMessage!.toolCallStates![0].toolCallId).toBe("tool-call-1");
|
||||
|
|
@ -82,8 +88,9 @@ describe("Parallel Tool Calls", () => {
|
|||
PARALLEL_TOOL_CALL_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for streaming to complete and tool calls to be set to generated
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
});
|
||||
|
||||
const { findAllCurToolCallsByStatus } = await import("../../../redux/util");
|
||||
|
|
@ -187,8 +194,9 @@ describe("Parallel Tool Calls", () => {
|
|||
STREAMING_RESPONSE,
|
||||
);
|
||||
|
||||
// Wait for streaming to complete and tool calls to be set to generated
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
});
|
||||
|
||||
const state = store.getState();
|
||||
|
|
|
|||
|
|
@ -59,3 +59,8 @@ export const selectPendingToolCalls = createSelector(
|
|||
(store: RootState) => store.session.history,
|
||||
(history) => findAllCurToolCallsByStatus(history, "generated"),
|
||||
);
|
||||
|
||||
export const selectDoneApplyStates = createSelector(
|
||||
(store: RootState) => store.session.codeBlockApplyStates.states,
|
||||
(states) => states.filter((applyState) => applyState.status === "done"),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,15 @@ export function addToolCallDeltaToState(
|
|||
): ToolCallState {
|
||||
const currentCall = currentState?.toolCall;
|
||||
|
||||
// If we have a current state and the delta has a different ID, ignore the delta
|
||||
if (
|
||||
currentState &&
|
||||
toolCallDelta.id &&
|
||||
currentCall?.id !== toolCallDelta.id
|
||||
) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
// These will/should not be partially streamed
|
||||
const callType = toolCallDelta.type ?? "function";
|
||||
const callId = currentCall?.id || toolCallDelta.id || "";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue