fix: edit tests

This commit is contained in:
Dallin Romney 2025-08-21 17:25:41 -07:00
parent 52bf0a8114
commit fcd1ec7a15
2 changed files with 8 additions and 35 deletions

View file

@ -1,19 +1,16 @@
import { BuiltInToolNames } from "core/tools/builtIn";
import { generateToolCallButtonTestId } from "../../../components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar";
import {
addAndSelectMockLlm,
triggerConfigUpdate,
} from "../../../util/test/config";
import { renderWithProviders } from "../../../util/test/render";
import { Chat } from "../Chat";
import { generateToolCallButtonTestId } from "../../../components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar";
import { waitFor } from "@testing-library/dom";
import { act } from "@testing-library/react";
import { ChatMessage } from "core";
import {
setToolPolicy,
toggleToolSetting,
} from "../../../redux/slices/uiSlice";
import { setToolPolicy } from "../../../redux/slices/uiSlice";
import {
getElementByTestId,
getElementByText,
@ -63,6 +60,7 @@ test(
ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR];
const messengerPostSpy = vi.spyOn(ideMessenger, "post");
const messengerRequestSpy = vi.spyOn(ideMessenger, "request");
addAndSelectMockLlm(store, ideMessenger);
@ -92,7 +90,7 @@ test(
// Tool call, check that applyToFile was called for edit
await waitFor(() => {
expect(messengerPostSpy).toHaveBeenCalledWith("applyToFile", {
expect(messengerRequestSpy).toHaveBeenCalledWith("applyToFile", {
streamId: expect.any(String),
filepath: EDIT_FILE_URI,
text: EDIT_CHANGES,
@ -101,7 +99,7 @@ test(
});
// Extract stream ID and initiate mock streaming
const streamId = messengerPostSpy.mock.calls.find(
const streamId = messengerRequestSpy.mock.calls.find(
(call) => call[0] === "applyToFile",
)?.[1]?.streamId;
expect(streamId).toBeDefined();
@ -172,6 +170,7 @@ test("Edit run with no policy and yolo mode", { timeout: 15000 }, async () => {
ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR];
const messengerPostSpy = vi.spyOn(ideMessenger, "post");
const messengerRequestSpy = vi.spyOn(ideMessenger, "request");
addAndSelectMockLlm(store, ideMessenger);
@ -219,7 +218,7 @@ test("Edit run with no policy and yolo mode", { timeout: 15000 }, async () => {
);
// Tool call, check that applyToFile was called for edit
await waitFor(() => {
expect(messengerPostSpy).toHaveBeenCalledWith("applyToFile", {
expect(messengerRequestSpy).toHaveBeenCalledWith("applyToFile", {
streamId: expect.any(String),
filepath: EDIT_FILE_URI,
text: EDIT_CHANGES,
@ -228,7 +227,7 @@ test("Edit run with no policy and yolo mode", { timeout: 15000 }, async () => {
});
// Extract stream ID and initiate mock streaming
const streamId = messengerPostSpy.mock.calls.find(
const streamId = messengerRequestSpy.mock.calls.find(
(call) => call[0] === "applyToFile",
)?.[1]?.streamId;
expect(streamId).toBeDefined();

View file

@ -581,32 +581,6 @@ keep this too`;
),
).rejects.toThrow("Failed to apply search and replace: File read error");
});
it("should handle applyToFile errors", async () => {
mockResolveRelativePathInDir.mockResolvedValue("/resolved/path/test.txt");
mockParseAllSearchReplaceBlocks.mockReturnValue([
{
isComplete: true,
searchContent: "content",
replaceContent: "replacement",
},
]);
mockIdeMessenger.ide.readFile.mockResolvedValue("content");
mockFindSearchMatch.mockReturnValue({
startIndex: 0,
endIndex: 7,
strategyName: "exactMatch",
});
mockIdeMessenger.request.mockRejectedValue(new Error("Apply failed"));
await expect(
searchReplaceToolImpl(
{ filepath: "test.txt", diffs: ["mock diff content"] },
"tool-call-id",
mockExtras,
),
).rejects.toThrow("Failed to apply search and replace: Apply failed");
});
});
describe("edge cases", () => {