Elffuss BraidHub

kikocis/continue public

eca53d6fa452 · 2.1 KiBRawPermalink
1import { ApplyState, ToolCallState } from "core";
2import { describe, expect, it, vi } from "vitest";
3import { assembleEditOutcomeData } from "./editOutcomeLogger";
4
5vi.mock("../redux/store", () => ({
6 store: {
7 getState: vi.fn(() => ({
8 session: { history: [] },
9 config: {
10 config: {
11 selectedModelByRole: {
12 chat: { provider: "test", model: "test-model" },
13 },
14 },
15 },
16 })),
17 },
18}));
19
20describe("assembleEditOutcomeData", () => {
21 it("should assemble complete edit outcome data correctly", () => {
22 const toolCallState: ToolCallState = {
23 status: "generating",
24 toolCallId: "test-id",
25 toolCall: {
26 id: "test-id",
27 type: "function",
28 function: { name: "test", arguments: "{}" },
29 },
30 parsedArgs: {},
31 };
32
33 const applyState: ApplyState = {
34 streamId: "stream-123",
35 filepath: "/test/file.ts",
36 originalFileContent: "const old = 1;",
37 fileContent: "const new = 2;\nconst another = 3;",
38 };
39
40 const result = assembleEditOutcomeData(toolCallState, applyState, true);
41 console.log(result);
42
43 expect(result).toMatchObject({
44 streamId: "stream-123",
45 filepath: "/test/file.ts",
46 previousCode: "const old = 1;",
47 newCode: "const new = 2;\nconst another = 3;",
48 previousCodeLines: 1,
49 newCodeLines: 2,
50 lineChange: 1,
51 accepted: true,
52 });
53 });
54
55 it("should handle empty code content", () => {
56 const toolCallState: ToolCallState = {
57 status: "generating",
58 toolCallId: "test-id",
59 toolCall: {
60 id: "test-id",
61 type: "function",
62 function: { name: "test", arguments: "{}" },
63 },
64 parsedArgs: {},
65 };
66
67 const applyState: ApplyState = {
68 streamId: "stream-123",
69 filepath: "/test/empty.ts",
70 originalFileContent: "",
71 fileContent: "",
72 };
73
74 const result = assembleEditOutcomeData(toolCallState, applyState, false);
75
76 expect(result.previousCodeLines).toBe(0);
77 expect(result.newCodeLines).toBe(0);
78 expect(result.lineChange).toBe(0);
79 expect(result.accepted).toBe(false);
80 });
81});