Skip to content

Commit 4c8e899

Browse files
committed
test(browser): add compatibility helper and tests; include new files in build
1 parent 1f6bdd8 commit 4c8e899

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { describe, test, expect, vi } from "vitest"
2+
3+
// Module under test
4+
import { generateSystemPrompt } from "../generateSystemPrompt"
5+
6+
// Mock SYSTEM_PROMPT to capture its third argument (browser capability flag)
7+
vi.mock("../../prompts/system", () => ({
8+
SYSTEM_PROMPT: vi.fn(async (_ctx, _cwd, canUseBrowserTool: boolean) => {
9+
// return a simple string to satisfy return type
10+
return `SYSTEM_PROMPT:${canUseBrowserTool}`
11+
}),
12+
}))
13+
14+
// Mock API handler so we control model.info flags
15+
vi.mock("../../api", () => ({
16+
buildApiHandler: vi.fn((_config) => ({
17+
getModel: () => ({
18+
id: "mock-model",
19+
info: {
20+
// New world: supportsImages controls browser capability
21+
supportsImages: true,
22+
// Legacy flag explicitly false to validate backward-compat behavior
23+
supportsComputerUse: false,
24+
contextWindow: 200_000,
25+
maxTokens: 8192,
26+
supportsPromptCache: false,
27+
},
28+
}),
29+
})),
30+
}))
31+
32+
// Minimal mode utilities: provide a custom mode that includes the "browser" group
33+
const mockCustomModes = [
34+
{
35+
slug: "test-mode",
36+
label: "Test Mode",
37+
description: "",
38+
groups: [{ id: "browser" }], // critical: include browser group
39+
},
40+
]
41+
42+
// Minimal ClineProvider stub
43+
function makeProviderStub() {
44+
return {
45+
cwd: "/tmp",
46+
context: {} as any,
47+
customModesManager: {
48+
getCustomModes: async () => mockCustomModes,
49+
},
50+
getCurrentTask: () => ({
51+
rooIgnoreController: { getInstructions: () => undefined },
52+
}),
53+
getMcpHub: () => undefined,
54+
// State must enable browser tool and provide apiConfiguration
55+
getState: async () => ({
56+
apiConfiguration: {
57+
apiProvider: "openrouter", // not used by the test beyond handler creation
58+
},
59+
customModePrompts: undefined,
60+
customInstructions: undefined,
61+
browserViewportSize: "900x600",
62+
diffEnabled: false,
63+
mcpEnabled: false,
64+
fuzzyMatchThreshold: 1.0,
65+
experiments: {},
66+
enableMcpServerCreation: false,
67+
browserToolEnabled: true, // critical: enabled in settings
68+
language: "en",
69+
maxReadFileLine: -1,
70+
maxConcurrentFileReads: 5,
71+
}),
72+
} as any
73+
}
74+
75+
describe("generateSystemPrompt browser capability (supportsImages=true, supportsComputerUse=false)", () => {
76+
test("passes canUseBrowserTool=true when mode has browser group and setting enabled", async () => {
77+
const provider = makeProviderStub()
78+
const message = { mode: "test-mode" } as any
79+
80+
const result = await generateSystemPrompt(provider, message)
81+
82+
// SYSTEM_PROMPT mock encodes the boolean into the returned string
83+
expect(result).toBe("SYSTEM_PROMPT:true")
84+
})
85+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe, test, expect } from "vitest"
2+
import { modelSupportsBrowserCapability } from "../browserCapability"
3+
4+
describe("modelSupportsBrowserCapability", () => {
5+
test("enables when supportsImages=true and supportsComputerUse=false/absent", () => {
6+
expect(modelSupportsBrowserCapability({ supportsImages: true } as any)).toBe(true)
7+
expect(modelSupportsBrowserCapability({ supportsImages: true, supportsComputerUse: false } as any)).toBe(true)
8+
})
9+
10+
test("enables when supportsComputerUse=true even if supportsImages=false", () => {
11+
expect(modelSupportsBrowserCapability({ supportsImages: false, supportsComputerUse: true } as any)).toBe(true)
12+
})
13+
14+
test("disabled when both flags are false or missing", () => {
15+
expect(modelSupportsBrowserCapability({ supportsImages: false } as any)).toBe(false)
16+
expect(modelSupportsBrowserCapability({} as any)).toBe(false)
17+
})
18+
})

src/shared/browserCapability.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { ModelInfo } from "@roo-code/types"
2+
import type { ProviderSettings } from "@roo-code/types"
3+
4+
/**
5+
* Temporary compatibility helper for determining whether the browser tool
6+
* should be considered supported by a model.
7+
*
8+
* During the transition away from supportsComputerUse, we treat models as
9+
* browser-capable if either:
10+
* - supportsImages === true (new behavior), OR
11+
* - supportsComputerUse === true (legacy behavior present in some providers)
12+
*/
13+
export function modelSupportsBrowserCapability(model: ModelInfo, _settings?: ProviderSettings): boolean {
14+
const supportsImages = (model as any)?.supportsImages === true
15+
// Legacy flag may still exist in some model tables or be read from older code paths
16+
const legacyComputerUse = (model as any)?.supportsComputerUse === true
17+
return supportsImages || legacyComputerUse
18+
}

0 commit comments

Comments
 (0)