Skip to content

Commit 0dd9cc6

Browse files
committed
test: bumping coverage
1 parent 843d235 commit 0dd9cc6

5 files changed

Lines changed: 84 additions & 11 deletions

File tree

src/api/providers/__tests__/native-ollama.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,54 @@ describe("NativeOllamaHandler", () => {
8181
expect(results[2]).toEqual({ type: "usage", inputTokens: 10, outputTokens: 2 })
8282
})
8383

84+
it("should map tool_result array content to a concatenated string (text kept, others dropped)", async () => {
85+
mockChat.mockImplementation(async function* () {
86+
yield { message: { content: "ok" } }
87+
})
88+
89+
const messages = [
90+
{
91+
role: "user" as const,
92+
content: [
93+
{
94+
type: "tool_result" as const,
95+
tool_use_id: "tool-1",
96+
content: [
97+
{ type: "text" as const, text: "line one" },
98+
// Non-text block (document) should be dropped to ""
99+
{
100+
type: "document" as const,
101+
source: {
102+
type: "base64" as const,
103+
media_type: "application/pdf",
104+
data: "abc",
105+
} as const,
106+
},
107+
{ type: "text" as const, text: "line two" },
108+
],
109+
},
110+
],
111+
},
112+
]
113+
114+
const stream = handler.createMessage("System", messages)
115+
for await (const _ of stream) {
116+
// consume stream
117+
}
118+
119+
// Text blocks are joined with "\n"; the non-text block contributes ""
120+
expect(mockChat).toHaveBeenCalledWith(
121+
expect.objectContaining({
122+
messages: expect.arrayContaining([
123+
expect.objectContaining({
124+
role: "user",
125+
content: "line one\n\nline two",
126+
}),
127+
]),
128+
}),
129+
)
130+
})
131+
84132
it("should not include num_ctx by default", async () => {
85133
// Mock the chat response
86134
mockChat.mockImplementation(async function* () {

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// npx vitest run api/transform/__tests__/openai-format.spec.ts
1+
// pnpm exec vitest run api/transform/__tests__/openai-format.spec.ts
22

33
import { Anthropic } from "@anthropic-ai/sdk"
44
import OpenAI from "openai"
@@ -143,7 +143,33 @@ describe("convertToOpenAiMessages", () => {
143143
expect((openAiMessages[0] as any).content).toBe("some text\n")
144144
})
145145

146-
it("should handle base64 image in tool result with placeholder and skip URL images", () => {
146+
it("should handle base64 image in tool result with placeholder", () => {
147+
const anthropicMessages: Anthropic.Messages.MessageParam[] = [
148+
{
149+
role: "user",
150+
content: [
151+
{
152+
type: "tool_result",
153+
tool_use_id: "tool-1",
154+
content: [
155+
{
156+
type: "image",
157+
source: { type: "base64", media_type: "image/png", data: "base64data" },
158+
},
159+
],
160+
},
161+
],
162+
},
163+
]
164+
165+
const openAiMessages = convertToOpenAiMessages(anthropicMessages)
166+
expect(openAiMessages[0].role).toBe("tool")
167+
// base64 images in tool results emit a placeholder; the image itself is
168+
// flushed in a separate user message (see comment block in openai-format.ts)
169+
expect((openAiMessages[0] as any).content).toBe("(see following user message for image)")
170+
})
171+
172+
it("should render [Image] placeholder for URL image in tool result", () => {
147173
const anthropicMessages: Anthropic.Messages.MessageParam[] = [
148174
{
149175
role: "user",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// npx vitest run src/api/transform/__tests__/vscode-lm-format.spec.ts
1+
// pnpm exec vitest run api/transform/__tests__/vscode-lm-format.spec.ts
22

33
import { Anthropic } from "@anthropic-ai/sdk"
44
import * as vscode from "vscode"

src/api/transform/__tests__/zai-format.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// npx vitest run api/transform/__tests__/zai-format.spec.ts
1+
// pnpm exec vitest run api/transform/__tests__/zai-format.spec.ts
22

33
import { Anthropic } from "@anthropic-ai/sdk"
44

src/integrations/misc/__tests__/export-markdown.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ describe("export-markdown", () => {
7676
it("should format document blocks", () => {
7777
const block = {
7878
type: "document",
79-
source: { type: "base64", media_type: "application/pdf", data: "abc" },
80-
} as any as ExtendedContentBlock
79+
source: { type: "base64", media_type: "application/pdf", data: "abc" } as const,
80+
} satisfies ExtendedContentBlock
8181
expect(formatContentBlockToMarkdown(block)).toBe("[Document]")
8282
})
8383

@@ -86,17 +86,16 @@ describe("export-markdown", () => {
8686
type: "search_result",
8787
source: "https://example.com",
8888
title: "Example",
89-
content: [],
90-
} as any as ExtendedContentBlock
89+
content: [{ type: "text", text: "result text" }],
90+
} satisfies ExtendedContentBlock
9191
expect(formatContentBlockToMarkdown(block)).toBe("[Search Result]")
9292
})
9393

9494
it("should format tool_reference blocks", () => {
9595
const block = {
9696
type: "tool_reference",
97-
id: "tool-1",
98-
name: "read_file",
99-
} as any as ExtendedContentBlock
97+
tool_name: "read_file",
98+
} satisfies ExtendedContentBlock
10099
expect(formatContentBlockToMarkdown(block)).toBe("[Tool Reference]")
101100
})
102101
})

0 commit comments

Comments
 (0)