Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2985,14 +2985,15 @@
let responseText: string | undefined
let responseImages: string[] | undefined

if (response === "messageResponse") {
// The Continue button (`yesButtonClicked`) can also carry chat box input.
if (response === "messageResponse" || text || (images && images.length > 0)) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
await this.say("user_feedback", text, images)
responseText = text
responseImages = images
}

// Make sure that the api conversation history can be resumed by the API,
// even if it goes out of sync with cline messages.

Check warning on line 2996 in src/core/task/Task.ts

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

src/core/task/Task.ts:2996: 4 mutation test gaps; example: Survived ConditionalExpression mutant (replacement: false). See the job summary for the complete list and resolution guidance.
const existingApiConversationHistory: ApiMessage[] = await this.getSavedApiConversationHistory()

// Tool blocks are always preserved; native tool calling only.
Expand Down
84 changes: 84 additions & 0 deletions src/core/task/__tests__/Task.persistence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,90 @@ describe("Task persistence", () => {
})

describe("resumeTaskFromHistory", () => {
const userMessageBlock = { type: "text", text: "<user_message>\nAlso fix the tests\n</user_message>" }
const imageBlock = { type: "image", source: { type: "base64", media_type: "image/png", data: "AAA" } }

it.each([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a text-only Continue case so removing the independent text predicate would fail this regression test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taltas Fair point, done

{
name: "text and image via Continue",
response: "yesButtonClicked" as const,
text: "Also fix the tests",
images: ["data:image/png;base64,AAA"],
expected: [userMessageBlock, imageBlock],
},
{
name: "text only via Continue",
response: "yesButtonClicked" as const,
text: "Also fix the tests",
images: [],
expected: [userMessageBlock],
},
{
name: "image only via Continue",
response: "yesButtonClicked" as const,
text: "",
images: ["data:image/png;base64,AAA"],
expected: [imageBlock],
},
{
name: "text and image via Send",
response: "messageResponse" as const,
text: "Also fix the tests",
images: ["data:image/png;base64,AAA"],
expected: [userMessageBlock, imageBlock],
},
])("forwards chat box input ($name) to the resumed task", async ({ response, text, images, expected }) => {
mockReadApiMessages.mockResolvedValue([{ role: "assistant", content: [{ type: "text", text: "Working" }] }])
const task = new Task({
provider: mockProvider,
apiConfiguration: mockApiConfig,
historyItem: {
id: "resume-with-input",
number: 1,
ts: Date.now(),
task: "Original task",
tokensIn: 10,
tokensOut: 5,
totalCost: 0.001,
},
startTask: false,
})
vi.spyOn(task, "ask").mockResolvedValue({ response, text, images })
const say = vi.spyOn(task, "say").mockResolvedValue(undefined)
const initiate = vi.spyOn(getTaskPersistenceAccess(task), "initiateTaskLoop").mockResolvedValue(undefined)

await getTaskPersistenceAccess(task).resumeTaskFromHistory()

expect(say).toHaveBeenCalledWith("user_feedback", text, images)
expect(initiate).toHaveBeenCalledWith(expected)
})

it("resumes without user feedback when Continue is clicked with an empty chat box", async () => {
mockReadApiMessages.mockResolvedValue([{ role: "assistant", content: [{ type: "text", text: "Working" }] }])
const task = new Task({
provider: mockProvider,
apiConfiguration: mockApiConfig,
historyItem: {
id: "resume-without-input",
number: 1,
ts: Date.now(),
task: "Original task",
tokensIn: 10,
tokensOut: 5,
totalCost: 0.001,
},
startTask: false,
})
vi.spyOn(task, "ask").mockResolvedValue({ response: "yesButtonClicked" })
const say = vi.spyOn(task, "say").mockResolvedValue(undefined)
const initiate = vi.spyOn(getTaskPersistenceAccess(task), "initiateTaskLoop").mockResolvedValue(undefined)

await getTaskPersistenceAccess(task).resumeTaskFromHistory()

expect(say.mock.calls.filter(([type]) => type === "user_feedback")).toEqual([])
expect(initiate).toHaveBeenCalledWith([{ type: "text", text: "[TASK RESUMPTION] Resuming task..." }])
})

it.each(["not_found", "invalid", "io_error"] as const)(
"does not persist when hydration fails with %s",
async (kind) => {
Expand Down
Loading