Skip to content

Commit 6b5b6f1

Browse files
committed
test(openai-format): cover getReasoningBlockText non-object guard
Add a regression test that passes a non-object content part (a stray string) through convertToOpenAiMessages, exercising the defensive early-return in getReasoningBlockText (line 276). This was the only uncovered line in the PR patch, causing the codecov/patch check to fail.
1 parent a5ff3b3 commit 6b5b6f1

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎src/api/transform/__tests__/openai-format.spec.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,25 @@ describe("convertToOpenAiMessages", () => {
12151215
expect(result).toHaveLength(1)
12161216
expect((result[0] as any).reasoning_content).toBeUndefined()
12171217
})
1218+
1219+
it("should ignore non-object content parts without crashing (defensive guard)", () => {
1220+
// getReasoningBlockText guards against non-object parts (e.g. a stray
1221+
// string in the content array). Such parts are not reasoning blocks and
1222+
// must be skipped rather than crashing or being misread as reasoning.
1223+
const anthropicMessages = [
1224+
{
1225+
role: "assistant" as const,
1226+
content: ["not-a-block" as any, { type: "text", text: "answer" }],
1227+
},
1228+
] as any as Anthropic.Messages.MessageParam[]
1229+
1230+
const result = convertToOpenAiMessages(anthropicMessages)
1231+
1232+
expect(result).toHaveLength(1)
1233+
const msg = result[0] as any
1234+
expect(msg.content).toBe("answer")
1235+
expect(msg.reasoning_content).toBeUndefined()
1236+
})
12181237
})
12191238
})
12201239

0 commit comments

Comments
 (0)