Skip to content

Commit 449af9a

Browse files
committed
test: bump test coverage
1 parent 57af5f1 commit 449af9a

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,47 @@ describe("VsCodeLmHandler", () => {
432432
expect.anything(),
433433
)
434434
})
435+
436+
it("should throw a Zoo Code branded error when request is cancelled", async () => {
437+
const systemPrompt = "You are a helpful assistant"
438+
const messages: Anthropic.Messages.MessageParam[] = [
439+
{
440+
role: "user" as const,
441+
content: "Hello",
442+
},
443+
]
444+
445+
mockLanguageModelChat.sendRequest.mockRejectedValueOnce(new vscode.CancellationError())
446+
447+
await expect(handler.createMessage(systemPrompt, messages).next()).rejects.toThrow(
448+
"Zoo Code <Language Model API>: Request cancelled by user",
449+
)
450+
})
451+
452+
it("should throw a Zoo Code branded error on stream error with error-like object", async () => {
453+
const systemPrompt = "You are a helpful assistant"
454+
const messages: Anthropic.Messages.MessageParam[] = [
455+
{
456+
role: "user" as const,
457+
content: "Hello",
458+
},
459+
]
460+
461+
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {})
462+
463+
mockLanguageModelChat.sendRequest.mockRejectedValueOnce({ code: "STREAM_ERROR", details: "broken" })
464+
465+
await expect(handler.createMessage(systemPrompt, messages).next()).rejects.toThrow(
466+
"Zoo Code <Language Model API>: Response stream error:",
467+
)
468+
469+
expect(consoleErrorSpy).toHaveBeenCalledWith(
470+
"Zoo Code <Language Model API>: Stream error object:",
471+
expect.stringContaining("STREAM_ERROR"),
472+
)
473+
474+
consoleErrorSpy.mockRestore()
475+
})
435476
})
436477

437478
describe("initializeClient", () => {
@@ -461,11 +502,18 @@ describe("VsCodeLmHandler", () => {
461502
})
462503

463504
it("should return fallback model info when no client exists", () => {
505+
const consoleDebugSpy = vi.spyOn(console, "debug").mockImplementation(() => {})
506+
464507
// Clear the client first
465508
handler["client"] = null
466509
const model = handler.getModel()
467510
expect(model.id).toBe("test-vendor/test-family")
468511
expect(model.info).toBeDefined()
512+
expect(consoleDebugSpy).toHaveBeenCalledWith(
513+
"Zoo Code <Language Model API>: No client available, using fallback model info",
514+
)
515+
516+
consoleDebugSpy.mockRestore()
469517
})
470518

471519
it("should return basic model info when client exists", async () => {
@@ -609,10 +657,17 @@ describe("VsCodeLmHandler", () => {
609657
handler["client"] = null
610658
handler["currentRequestCancellation"] = null
611659

660+
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {})
661+
612662
const content: Anthropic.Messages.ContentBlockParam[] = [{ type: "text", text: "Hello" }]
613663
const result = await handler.countTokens(content)
614664

615665
expect(result).toBe(0)
666+
expect(consoleWarnSpy).toHaveBeenCalledWith(
667+
"Zoo Code <Language Model API>: No client available for token counting",
668+
)
669+
670+
consoleWarnSpy.mockRestore()
616671
})
617672

618673
it("should handle image blocks with placeholder", async () => {

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,36 @@ describe("extractTextCountFromMessage", () => {
434434
const result = extractTextCountFromMessage(message)
435435
expect(result).toBe("result-id")
436436
})
437+
438+
it("should log Zoo Code branded warning when tool call input stringify fails", () => {
439+
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {})
440+
441+
// Create an object with a circular reference that will throw on JSON.stringify
442+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
443+
const circularInput: any = { name: "circular" }
444+
circularInput.self = circularInput
445+
446+
const mockToolCallPart = new (vitest.mocked(vscode).LanguageModelToolCallPart)(
447+
"call-id",
448+
"broken-tool",
449+
circularInput,
450+
)
451+
452+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
453+
const message: any = {
454+
role: vscode.LanguageModelChatMessageRole.Assistant,
455+
content: [mockToolCallPart],
456+
}
457+
458+
const result = extractTextCountFromMessage(message)
459+
460+
// Should still return the tool name and callId even when input stringify fails
461+
expect(result).toBe("broken-toolcall-id")
462+
expect(consoleErrorSpy).toHaveBeenCalledWith(
463+
"Zoo Code <Language Model API>: Failed to stringify tool call input:",
464+
expect.any(Error),
465+
)
466+
467+
consoleErrorSpy.mockRestore()
468+
})
437469
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ describe("ClineProvider", () => {
544544
})
545545

546546
expect(mockWebviewView.webview.html).toContain("<!DOCTYPE html>")
547+
expect(mockWebviewView.webview.html).toContain("<title>Zoo Code</title>")
547548
})
548549

549550
describe("logWebviewHiddenDiagnostics", () => {

0 commit comments

Comments
 (0)