Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion src/activate/__tests__/registerCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Mock } from "vitest"
import * as vscode from "vscode"
import { ClineProvider } from "../../core/webview/ClineProvider"

import { getVisibleProviderOrLog, registerCommands, setPanel } from "../registerCommands"
import { getVisibleProviderOrLog, openClineInNewTab, registerCommands, setPanel } from "../registerCommands"

vi.mock("execa", () => ({
execa: vi.fn(),
Expand All @@ -13,8 +13,16 @@ vi.mock("vscode", () => ({
QuickFix: { value: "quickfix" },
RefactorRewrite: { value: "refactor.rewrite" },
},
Uri: {
joinPath: vi.fn((_base: unknown, ..._pathSegments: string[]) => ({ path: _pathSegments.join("/") })),
},
ViewColumn: {
Two: 2,
},
window: {
createTextEditorDecorationType: vi.fn().mockReturnValue({ dispose: vi.fn() }),
createWebviewPanel: vi.fn(),
visibleTextEditors: [],
},
workspace: {
workspaceFolders: [
Expand Down Expand Up @@ -349,3 +357,53 @@ describe("registerCommands handlers", () => {
)
})
})

describe("openClineInNewTab", () => {
let mockOutputChannel: vscode.OutputChannel
let mockContext: vscode.ExtensionContext

beforeEach(() => {
vi.clearAllMocks()

mockOutputChannel = {
appendLine: vi.fn(),
append: vi.fn(),
clear: vi.fn(),
hide: vi.fn(),
name: "mock",
replace: vi.fn(),
show: vi.fn(),
dispose: vi.fn(),
}

mockContext = {
subscriptions: [],
extensionUri: { path: "/mock/ext" },
} as unknown as vscode.ExtensionContext

const mockPanel = {
webview: { postMessage: vi.fn() },
onDidChangeViewState: vi.fn(),
onDidDispose: vi.fn(),
}
;(vscode.window.createWebviewPanel as Mock).mockReturnValue(mockPanel)

// Reset module-level panel state.
setPanel(undefined, "sidebar")
setPanel(undefined, "tab")
})

it("creates a webview panel with title 'Zoo Code'", async () => {
await openClineInNewTab({ context: mockContext, outputChannel: mockOutputChannel })

expect(vscode.window.createWebviewPanel).toHaveBeenCalledWith(
"zoo-code.TabPanelProvider",
"Zoo Code",
expect.any(Number),
expect.objectContaining({
enableScripts: true,
retainContextWhenHidden: true,
}),
)
})
})
2 changes: 1 addition & 1 deletion src/activate/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const openClineInNewTab = async ({ context, outputChannel }: Omit<Registe

const targetCol = hasVisibleEditors ? Math.max(lastCol + 1, 1) : vscode.ViewColumn.Two

const newPanel = vscode.window.createWebviewPanel(ClineProvider.tabPanelId, "Roo Code", targetCol, {
const newPanel = vscode.window.createWebviewPanel(ClineProvider.tabPanelId, "Zoo Code", targetCol, {
enableScripts: true,
retainContextWhenHidden: true,
localResourceRoots: [context.extensionUri],
Expand Down
6 changes: 4 additions & 2 deletions src/api/providers/__tests__/lmstudio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ describe("LmStudioHandler", () => {
for await (const _chunk of stream) {
// Should not reach here
}
}).rejects.toThrow("Please check the LM Studio developer logs to debug what went wrong")
}).rejects.toThrow(
"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.",
)
})
})

Expand All @@ -144,7 +146,7 @@ describe("LmStudioHandler", () => {
it("should handle API errors", async () => {
mockCreate.mockRejectedValueOnce(new Error("API Error"))
await expect(handler.completePrompt("Test prompt")).rejects.toThrow(
"Please check the LM Studio developer logs to debug what went wrong",
"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.",
)
})

Expand Down
46 changes: 46 additions & 0 deletions src/api/providers/__tests__/vscode-lm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,52 @@ describe("VsCodeLmHandler", () => {

await expect(handler.createMessage(systemPrompt, messages).next()).rejects.toThrow("API Error")
})

it("should brand the LM authorization justification as Zoo Code", async () => {
const systemPrompt = "You are a helpful assistant"
const messages: Anthropic.Messages.MessageParam[] = [
{
role: "user" as const,
content: "Hello",
},
]

mockLanguageModelChat.sendRequest.mockResolvedValueOnce({
stream: (async function* () {
yield new vscode.LanguageModelTextPart("Hi")
return
})(),
text: (async function* () {
yield "Hi"
return
})(),
})

const stream = handler.createMessage(systemPrompt, messages)
for await (const _chunk of stream) {
// drain
}

expect(mockLanguageModelChat.sendRequest).toHaveBeenCalledWith(
expect.any(Array),
expect.objectContaining({
justification:
"Zoo Code would like to use 'Test Model' from 'test-vendor', Click 'Allow' to proceed.",
}),
expect.anything(),
)
})
})

describe("initializeClient", () => {
it("should throw a Zoo Code branded error when client initialization fails", async () => {
;(vscode.lm.selectChatModels as Mock).mockRejectedValueOnce(new Error("select failed"))
handler["client"] = null

await expect(handler.initializeClient()).rejects.toThrow(
"Zoo Code <Language Model API>: Failed to initialize client: Zoo Code <Language Model API>: Failed to select model: select failed",
)
})
})

describe("getModel", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/providers/lm-studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
} as const
} catch (error) {
throw new Error(
"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 Roo Code's prompts.",
"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.",
)
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
return response.choices[0]?.message.content || ""
} catch (error) {
throw new Error(
"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 Roo Code's prompts.",
"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.",
)
}
}
Expand Down
Loading
Loading