From c792662ac917704f6a71b4c6639242de076769a9 Mon Sep 17 00:00:00 2001 From: NaccOll Date: Wed, 27 Aug 2025 16:01:49 +0800 Subject: [PATCH] fix: user message unit test --- .../checkpoints/__tests__/checkpoint.test.ts | 34 +++++++++---------- src/core/checkpoints/index.ts | 2 +- .../webview/__tests__/ClineProvider.spec.ts | 3 -- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/core/checkpoints/__tests__/checkpoint.test.ts b/src/core/checkpoints/__tests__/checkpoint.test.ts index 49b26a4c2d..0ff228aa45 100644 --- a/src/core/checkpoints/__tests__/checkpoint.test.ts +++ b/src/core/checkpoints/__tests__/checkpoint.test.ts @@ -299,8 +299,8 @@ describe("Checkpoint functionality", () => { }) expect(mockCheckpointService.getDiff).toHaveBeenCalledWith({ - from: undefined, - to: "commit2", + from: "commit2", + to: undefined, }) expect(vscode.commands.executeCommand).toHaveBeenCalledWith( "vscode.changes", @@ -309,7 +309,7 @@ describe("Checkpoint functionality", () => { ) }) - it("should show diff for checkpoint mode with previous commit", async () => { + it("should show diff for checkpoint mode with next commit", async () => { const mockChanges = [ { paths: { absolute: "/test/file.ts", relative: "file.ts" }, @@ -317,11 +317,10 @@ describe("Checkpoint functionality", () => { }, ] mockCheckpointService.getDiff.mockResolvedValue(mockChanges) - + mockCheckpointService.getCheckpoints = vi.fn(() => ["commit1", "commit2"]) await checkpointDiff(mockTask, { ts: 4, - previousCommitHash: "commit1", - commitHash: "commit2", + commitHash: "commit1", mode: "checkpoint", }) @@ -331,12 +330,12 @@ describe("Checkpoint functionality", () => { }) expect(vscode.commands.executeCommand).toHaveBeenCalledWith( "vscode.changes", - "Changes since previous checkpoint", + "Changes compare with next checkpoint", expect.any(Array), ) }) - it("should find previous checkpoint automatically in checkpoint mode", async () => { + it("should find next checkpoint automatically in checkpoint mode", async () => { const mockChanges = [ { paths: { absolute: "/test/file.ts", relative: "file.ts" }, @@ -344,15 +343,16 @@ describe("Checkpoint functionality", () => { }, ] mockCheckpointService.getDiff.mockResolvedValue(mockChanges) + mockCheckpointService.getCheckpoints = vi.fn(() => ["commit1", "commit2"]) await checkpointDiff(mockTask, { ts: 4, - commitHash: "commit2", + commitHash: "commit1", mode: "checkpoint", }) expect(mockCheckpointService.getDiff).toHaveBeenCalledWith({ - from: "commit1", // Should find the previous checkpoint + from: "commit1", // Should find the next checkpoint to: "commit2", }) }) @@ -385,21 +385,21 @@ describe("Checkpoint functionality", () => { }) describe("getCheckpointService", () => { - it("should return existing service if available", () => { - const service = getCheckpointService(mockTask) + it("should return existing service if available", async () => { + const service = await getCheckpointService(mockTask) expect(service).toBe(mockCheckpointService) }) - it("should return undefined if checkpoints are disabled", () => { + it("should return undefined if checkpoints are disabled", async () => { mockTask.enableCheckpoints = false - const service = getCheckpointService(mockTask) + const service = await getCheckpointService(mockTask) expect(service).toBeUndefined() }) - it("should return undefined if service is still initializing", () => { + it("should return undefined if service is still initializing", async () => { mockTask.checkpointService = undefined mockTask.checkpointServiceInitializing = true - const service = getCheckpointService(mockTask) + const service = await getCheckpointService(mockTask) expect(service).toBeUndefined() }) @@ -425,7 +425,7 @@ describe("Checkpoint functionality", () => { mockTask.checkpointService = undefined mockTask.checkpointServiceInitializing = false - const service = getCheckpointService(mockTask) + const service = await getCheckpointService(mockTask) expect(service).toBeUndefined() expect(mockTask.enableCheckpoints).toBe(false) diff --git a/src/core/checkpoints/index.ts b/src/core/checkpoints/index.ts index 1bc2a1d8d9..5056cf53ee 100644 --- a/src/core/checkpoints/index.ts +++ b/src/core/checkpoints/index.ts @@ -292,7 +292,7 @@ export async function checkpointDiff(task: Task, { ts, previousCommitHash, commi await vscode.commands.executeCommand( "vscode.changes", - mode === "full" ? "Changes since task started" : "Changes since previous checkpoint", + mode === "full" ? "Changes since task started" : "Changes compare with next checkpoint", changes.map((change) => [ vscode.Uri.file(change.paths.absolute), vscode.Uri.parse(`${DIFF_VIEW_URI_SCHEME}:${change.paths.relative}`).with({ diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 12d24fb301..b3bc86d58c 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -1242,8 +1242,6 @@ describe("ClineProvider", () => { mockApiHistory[2], ]) - // Verify createTaskWithHistoryItem was called - expect((provider as any).createTaskWithHistoryItem).toHaveBeenCalledWith({ id: "test-task-id" }) // createTaskWithHistoryItem is only called when restoring checkpoints or aborting tasks expect((provider as any).createTaskWithHistoryItem).not.toHaveBeenCalled() }) @@ -3723,7 +3721,6 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => { // Verify successful operation completed expect(mockCline.overwriteClineMessages).toHaveBeenCalled() - expect(provider.createTaskWithHistoryItem).toHaveBeenCalled() // createTaskWithHistoryItem is only called when restoring checkpoints or aborting tasks expect(vscode.window.showErrorMessage).not.toHaveBeenCalled() })