Skip to content

Commit 555b572

Browse files
roomoterrewll
authored andcommitted
test: bump coverage for Roo-to-Zoo user-facing string changes (#971)
1 parent b9d8ac0 commit 555b572

3 files changed

Lines changed: 96 additions & 2 deletions

File tree

src/api/providers/__tests__/lmstudio.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ describe("LmStudioHandler", () => {
125125
for await (const _chunk of stream) {
126126
// Should not reach here
127127
}
128-
}).rejects.toThrow("Please check the LM Studio developer logs to debug what went wrong")
128+
}).rejects.toThrow(
129+
"Please check the LM Studio developer logs to debug what went wrong. You may need to load the model with a larger context length to work with Zoo Code's prompts.",
130+
)
129131
})
130132
})
131133

@@ -144,7 +146,7 @@ describe("LmStudioHandler", () => {
144146
it("should handle API errors", async () => {
145147
mockCreate.mockRejectedValueOnce(new Error("API Error"))
146148
await expect(handler.completePrompt("Test prompt")).rejects.toThrow(
147-
"Please check the LM Studio developer logs to debug what went wrong",
149+
"Please check the LM Studio developer logs to debug what went wrong. You may need to load the model with a larger context length to work with Zoo Code's prompts.",
148150
)
149151
})
150152

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,52 @@ describe("VsCodeLmHandler", () => {
397397

398398
await expect(handler.createMessage(systemPrompt, messages).next()).rejects.toThrow("API Error")
399399
})
400+
401+
it("should brand the LM authorization justification as Zoo Code", async () => {
402+
const systemPrompt = "You are a helpful assistant"
403+
const messages: Anthropic.Messages.MessageParam[] = [
404+
{
405+
role: "user" as const,
406+
content: "Hello",
407+
},
408+
]
409+
410+
mockLanguageModelChat.sendRequest.mockResolvedValueOnce({
411+
stream: (async function* () {
412+
yield new vscode.LanguageModelTextPart("Hi")
413+
return
414+
})(),
415+
text: (async function* () {
416+
yield "Hi"
417+
return
418+
})(),
419+
})
420+
421+
const stream = handler.createMessage(systemPrompt, messages)
422+
for await (const _chunk of stream) {
423+
// drain
424+
}
425+
426+
expect(mockLanguageModelChat.sendRequest).toHaveBeenCalledWith(
427+
expect.any(Array),
428+
expect.objectContaining({
429+
justification:
430+
"Zoo Code would like to use 'Test Model' from 'test-vendor', Click 'Allow' to proceed.",
431+
}),
432+
expect.anything(),
433+
)
434+
})
435+
})
436+
437+
describe("initializeClient", () => {
438+
it("should throw a Zoo Code branded error when client initialization fails", async () => {
439+
;(vscode.lm.selectChatModels as Mock).mockRejectedValueOnce(new Error("select failed"))
440+
handler["client"] = null
441+
442+
await expect(handler.initializeClient()).rejects.toThrow(
443+
"Zoo Code <Language Model API>: Failed to initialize client: Zoo Code <Language Model API>: Failed to select model: select failed",
444+
)
445+
})
400446
})
401447

402448
describe("getModel", () => {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import fs from "fs"
2+
import path from "path"
3+
4+
const localesDir = path.join(__dirname, "..", "locales")
5+
6+
const languages = fs
7+
.readdirSync(localesDir, { withFileTypes: true })
8+
.filter((dirent) => dirent.isDirectory() && !dirent.name.startsWith("."))
9+
.map((dirent) => dirent.name)
10+
11+
function loadTools(language: string): Record<string, string> {
12+
return JSON.parse(fs.readFileSync(path.join(localesDir, language, "tools.json"), "utf8"))
13+
}
14+
15+
describe("tools:missingToolParameter locales", () => {
16+
it("covers every shipped locale", () => {
17+
expect(languages.length).toBeGreaterThan(0)
18+
for (const language of languages) {
19+
const tools = loadTools(language)
20+
expect(tools.missingToolParameter, `missingToolParameter missing in ${language}`).toBeTruthy()
21+
expect(
22+
tools.missingToolParameterWithPath,
23+
`missingToolParameterWithPath missing in ${language}`,
24+
).toBeTruthy()
25+
}
26+
})
27+
28+
it("keeps all interpolation placeholders in every locale", () => {
29+
for (const language of languages) {
30+
const tools = loadTools(language)
31+
expect(tools.missingToolParameter, `placeholders missing in ${language}`).toContain("{{toolName}}")
32+
expect(tools.missingToolParameter, `placeholders missing in ${language}`).toContain("{{paramName}}")
33+
expect(tools.missingToolParameterWithPath, `placeholders missing in ${language}`).toContain("{{toolName}}")
34+
expect(tools.missingToolParameterWithPath, `placeholders missing in ${language}`).toContain("{{relPath}}")
35+
expect(tools.missingToolParameterWithPath, `placeholders missing in ${language}`).toContain("{{paramName}}")
36+
}
37+
})
38+
39+
it("brands the English messages as Zoo, not Roo", () => {
40+
const tools = loadTools("en")
41+
expect(tools.missingToolParameter).toContain("Zoo")
42+
expect(tools.missingToolParameter).not.toContain("Roo")
43+
expect(tools.missingToolParameterWithPath).toContain("Zoo")
44+
expect(tools.missingToolParameterWithPath).not.toContain("Roo")
45+
})
46+
})

0 commit comments

Comments
 (0)