Skip to content

Commit 712c22d

Browse files
committed
fix: increase coverage of vscode-lm-format.spec.ts
1 parent fdaf3ab commit 712c22d

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

src/api/providers/__tests__/vscode-lm.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ describe("VsCodeLmHandler", () => {
9090
beforeEach(() => {
9191
vi.clearAllMocks()
9292
// Set up a default successful mock for selectChatModels before creating the handler
93-
const mockModel = { ...mockLanguageModelChat }
94-
;(vscode.lm.selectChatModels as Mock).mockResolvedValue([mockModel])
93+
const mockModels = [{ ...mockLanguageModelChat }]
94+
;(vscode.lm.selectChatModels as Mock).mockResolvedValue(mockModels)
9595
handler = new VsCodeLmHandler(defaultOptions)
9696
})
9797

src/api/transform/__tests__/vscode-lm-format.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,61 @@ describe("convertToVsCodeLmMessages", () => {
154154
expect(toolCall.type).toBe("tool_call")
155155
})
156156

157+
it("should handle tool_use with non-object non-string input", () => {
158+
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {})
159+
160+
const messages: Anthropic.Messages.MessageParam[] = [
161+
{
162+
role: "assistant",
163+
content: [
164+
{
165+
type: "tool_use",
166+
id: "tool-num",
167+
name: "numericTool",
168+
input: 42 as any, // number is valid JSON
169+
},
170+
],
171+
},
172+
]
173+
174+
const result = convertToVsCodeLmMessages(messages)
175+
176+
expect(result).toHaveLength(1)
177+
expect(result[0].role).toBe("assistant")
178+
// asObjectSafe returns {} for non-object/non-string, no console.warn triggered
179+
expect(consoleWarnSpy).not.toHaveBeenCalled()
180+
181+
consoleWarnSpy.mockRestore()
182+
})
183+
184+
it("should log Zoo Code branded warning when asObjectSafe fails to parse invalid JSON string", () => {
185+
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {})
186+
187+
const messages: Anthropic.Messages.MessageParam[] = [
188+
{
189+
role: "assistant",
190+
content: [
191+
{
192+
type: "tool_use",
193+
id: "tool-bad",
194+
name: "badJsonTool",
195+
input: "not-valid-json{{{",
196+
},
197+
],
198+
},
199+
]
200+
201+
const result = convertToVsCodeLmMessages(messages)
202+
203+
expect(result).toHaveLength(1)
204+
expect(consoleWarnSpy).toHaveBeenCalledWith(
205+
"Zoo Code <Language Model API>: Failed to parse object:",
206+
expect.any(Error),
207+
)
208+
209+
consoleWarnSpy.mockRestore()
210+
})
211+
157212
it("should handle image blocks with appropriate placeholders", () => {
158213
const messages: Anthropic.Messages.MessageParam[] = [
159214
{

src/eslint-suppressions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@
541541
},
542542
"api/transform/__tests__/vscode-lm-format.spec.ts": {
543543
"@typescript-eslint/no-explicit-any": {
544-
"count": 23
544+
"count": 24
545545
}
546546
},
547547
"api/transform/__tests__/zai-format.spec.ts": {

0 commit comments

Comments
 (0)