Skip to content

Commit 47e9640

Browse files
PierrunoYTclaude
andcommitted
test(task): assert the complete outgoing user content for reordered tool results
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent a038cd2 commit 47e9640

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎src/core/task/__tests__/Task.spec.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,6 +2950,16 @@ describe("Cline", () => {
29502950
startTask: false,
29512951
})
29522952
vi.spyOn(getTaskTestAccess(cline), "getSystemPrompt").mockResolvedValue("mock system prompt")
2953+
// Image-capable model so the image block is kept in the outgoing request.
2954+
vi.spyOn(cline.api, "getModel").mockReturnValue({
2955+
id: "claude-3-sonnet",
2956+
info: {
2957+
supportsImages: true,
2958+
supportsPromptCache: false,
2959+
contextWindow: 200000,
2960+
maxTokens: 4096,
2961+
} as ModelInfo,
2962+
})
29532963
const mockStream = {
29542964
async *[Symbol.asyncIterator]() {
29552965
yield { type: "text", text: "response" }
@@ -2985,11 +2995,13 @@ describe("Cline", () => {
29852995

29862996
const [, sentHistory] = requireDefined(createMessageSpy.mock.calls[0])
29872997
const lastUserContent = requireDefined(sentHistory.at(-1)).content as Array<{ type: string }>
2988-
expect(lastUserContent.slice(0, 2)).toMatchObject([
2989-
{ type: "tool_result", tool_use_id: "read" },
2990-
{ type: "tool_result", tool_use_id: "cmd" },
2998+
// Both results lead, followed by the image and the environment details, none lost.
2999+
expect(lastUserContent).toEqual([
3000+
{ type: "tool_result", tool_use_id: "read", content: "File: logo.jpg" },
3001+
{ type: "tool_result", tool_use_id: "cmd", content: "Exit code: 0" },
3002+
{ type: "image", source: { type: "base64", media_type: "image/jpeg", data: "abc" } },
3003+
{ type: "text", text: "<environment_details>" },
29913004
])
2992-
expect(lastUserContent.slice(2).some((block) => block.type === "tool_result")).toBe(false)
29933005
// The stored history keeps its original shape.
29943006
expect(requireDefined(cline.apiConversationHistory.at(-1)).content).toMatchObject([
29953007
{ type: "tool_result" },

0 commit comments

Comments
 (0)