Skip to content

Commit 3caf3e9

Browse files
committed
fix: update tests to match new allowEmpty parameter in overwriteApiConversationHistory
1 parent 5f68516 commit 3caf3e9

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/core/webview/__tests__/ClineProvider.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,11 +1239,10 @@ describe("ClineProvider", () => {
12391239
])
12401240

12411241
// Verify only API messages before the deleted message were kept
1242-
expect(mockCline.overwriteApiConversationHistory).toHaveBeenCalledWith([
1243-
mockApiHistory[0],
1244-
mockApiHistory[1],
1245-
mockApiHistory[2],
1246-
])
1242+
expect(mockCline.overwriteApiConversationHistory).toHaveBeenCalledWith(
1243+
[mockApiHistory[0], mockApiHistory[1], mockApiHistory[2]],
1244+
true,
1245+
)
12471246

12481247
// createTaskWithHistoryItem is only called when restoring checkpoints or aborting tasks
12491248
expect((provider as any).createTaskWithHistoryItem).not.toHaveBeenCalled()
@@ -1339,7 +1338,7 @@ describe("ClineProvider", () => {
13391338
expect(mockCline.overwriteClineMessages).toHaveBeenCalledWith([])
13401339

13411340
// Verify correct API messages were kept
1342-
expect(mockCline.overwriteApiConversationHistory).toHaveBeenCalledWith([])
1341+
expect(mockCline.overwriteApiConversationHistory).toHaveBeenCalledWith([], true)
13431342

13441343
// The new flow calls webviewMessageHandler recursively with askResponse
13451344
// We need to verify the recursive call happened by checking if the handler was called again
@@ -3049,7 +3048,7 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
30493048

30503049
// Verify messages were edited correctly - the ORIGINAL user message and all subsequent messages are removed
30513050
expect(mockCline.overwriteClineMessages).toHaveBeenCalledWith([mockMessages[0]])
3052-
expect(mockCline.overwriteApiConversationHistory).toHaveBeenCalledWith([{ ts: 1000 }])
3051+
expect(mockCline.overwriteApiConversationHistory).toHaveBeenCalledWith([{ ts: 1000 }], true)
30533052
// Verify submitUserMessage was called with the edited content
30543053
expect(mockCline.submitUserMessage).toHaveBeenCalledWith("Edited message with preserved images", undefined)
30553054
})
@@ -3675,7 +3674,10 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => {
36753674

36763675
// Should handle large payloads without issues - keeps messages before the deleted one
36773676
expect(mockCline.overwriteClineMessages).toHaveBeenCalledWith([mockMessages[0], mockMessages[1]])
3678-
expect(mockCline.overwriteApiConversationHistory).toHaveBeenCalledWith([{ ts: 1000 }, { ts: 2000 }])
3677+
expect(mockCline.overwriteApiConversationHistory).toHaveBeenCalledWith(
3678+
[{ ts: 1000 }, { ts: 2000 }],
3679+
true,
3680+
)
36793681
})
36803682
})
36813683

src/core/webview/__tests__/webviewMessageHandler.delete.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe("webviewMessageHandler delete functionality", () => {
112112

113113
// When message is not found in API history (index is -1),
114114
// API history should be truncated from the first API message at/after the deleted timestamp (fallback)
115-
expect(getCurrentTaskMock.overwriteApiConversationHistory).toHaveBeenCalledWith([])
115+
expect(getCurrentTaskMock.overwriteApiConversationHistory).toHaveBeenCalledWith([], true)
116116
})
117117

118118
it("should handle deletion when exact apiConversationHistoryIndex is found", async () => {
@@ -142,9 +142,10 @@ describe("webviewMessageHandler delete functionality", () => {
142142
{ ts: 900, say: "user", text: "Previous message" },
143143
])
144144

145-
expect(getCurrentTaskMock.overwriteApiConversationHistory).toHaveBeenCalledWith([
146-
{ ts: 900, role: "user", content: { type: "text", text: "Previous message" } },
147-
])
145+
expect(getCurrentTaskMock.overwriteApiConversationHistory).toHaveBeenCalledWith(
146+
[{ ts: 900, role: "user", content: { type: "text", text: "Previous message" } }],
147+
true,
148+
)
148149
})
149150

150151
it("should handle deletion when message not found in clineMessages", async () => {
@@ -204,7 +205,7 @@ describe("webviewMessageHandler delete functionality", () => {
204205
expect(getCurrentTaskMock.overwriteClineMessages).toHaveBeenCalledWith([])
205206

206207
// API history should be truncated from first message at/after deleted timestamp (fallback)
207-
expect(getCurrentTaskMock.overwriteApiConversationHistory).toHaveBeenCalledWith([])
208+
expect(getCurrentTaskMock.overwriteApiConversationHistory).toHaveBeenCalledWith([], true)
208209
})
209210

210211
it("should preserve messages before the deleted one", async () => {
@@ -236,10 +237,13 @@ describe("webviewMessageHandler delete functionality", () => {
236237
])
237238

238239
// API history should be truncated at the exact index
239-
expect(getCurrentTaskMock.overwriteApiConversationHistory).toHaveBeenCalledWith([
240-
{ ts: 1000, role: "user", content: { type: "text", text: "First message" } },
241-
{ ts: 1500, role: "assistant", content: { type: "text", text: "First response" } },
242-
])
240+
expect(getCurrentTaskMock.overwriteApiConversationHistory).toHaveBeenCalledWith(
241+
[
242+
{ ts: 1000, role: "user", content: { type: "text", text: "First message" } },
243+
{ ts: 1500, role: "assistant", content: { type: "text", text: "First response" } },
244+
],
245+
true,
246+
)
243247
})
244248
})
245249
})

0 commit comments

Comments
 (0)