Skip to content

Commit 926b46d

Browse files
committed
test(webview): add Ollama key help visual baseline and translations
1 parent 2ec4d68 commit 926b46d

25 files changed

Lines changed: 281 additions & 230 deletions

File tree

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

Lines changed: 113 additions & 208 deletions
Large diffs are not rendered by default.

‎src/api/providers/fetchers/__tests__/lmstudio.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ describe("LMStudio Fetcher", () => {
7979
)
8080
expect(hasLoadedFullDetails(modelId)).toBe(true)
8181
})
82+
83+
it("warns with only the origin when the connection is refused for a URL with credentials and a query", async () => {
84+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(function () {})
85+
try {
86+
const error = new Error("Connection refused")
87+
;(error as NodeJS.ErrnoException).code = "ECONNREFUSED"
88+
mockedAxios.get.mockRejectedValueOnce(error)
89+
const handler = { fetchModels: vi.fn() } as unknown as ApiHandler
90+
91+
await forceFullModelDetailsLoad(
92+
"http://user:pass@localhost:1234/path?token=secret",
93+
"any-model",
94+
handler,
95+
)
96+
97+
expect(warnSpy).toHaveBeenCalledWith("Error connecting to LMStudio at http://localhost:1234")
98+
} finally {
99+
warnSpy.mockRestore()
100+
}
101+
})
82102
})
83103

84104
describe("parseLMStudioModel", () => {

‎webview-ui/playwright/gallery/stories.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ export const stories: Record<string, Story> = {
164164
const { ModelInfoViewFixture } = await import("@/components/settings/__tests__/ModelInfoView.visual.fixture")
165165
return <ModelInfoViewFixture />
166166
},
167+
"ollama-api-key-help": async () => {
168+
const { OllamaApiKeyHelpFixture } =
169+
await import("@/components/settings/providers/__tests__/Ollama.visual.fixture")
170+
return <OllamaApiKeyHelpFixture />
171+
},
167172
"openai-codex": async () => {
168173
const { OpenAICodexFixture } =
169174
await import("@/components/settings/providers/__tests__/OpenAICodex.visual.fixture")

‎webview-ui/playwright/vite.config.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const rooCodeTypesShimImporters = [
1515
"/webview-ui/src/components/settings/UISettings.tsx",
1616
]
1717

18+
// Every story gets the Vitest toolkit mock, which draws a text field's label
19+
// below its input. These importers get the real toolkit so the story looks
20+
// like the extension. Add an importer here only with its own baseline.
21+
const realToolkitImporters = ["/settings/providers/Ollama.tsx"]
22+
const toolkitMock = path.resolve(webviewRoot, "src/__mocks__/@vscode/webview-ui-toolkit/react.tsx")
23+
1824
export default defineConfig({
1925
root: path.resolve(dirname, "gallery"),
2026
plugins: [
@@ -31,6 +37,15 @@ export default defineConfig({
3137
}
3238
},
3339
},
40+
{
41+
name: "playwright-gallery-toolkit-mock",
42+
enforce: "pre",
43+
resolveId(source, importer) {
44+
if (source !== "@vscode/webview-ui-toolkit/react") return
45+
if (importer && realToolkitImporters.some((suffix) => importer.endsWith(suffix))) return
46+
return toolkitMock
47+
},
48+
},
3449
react({
3550
babel: {
3651
plugins: [["babel-plugin-react-compiler", { target: "18" }]],
@@ -55,10 +70,6 @@ export default defineConfig({
5570
{ find: "@", replacement: path.resolve(webviewRoot, "src") },
5671
{ find: "@src", replacement: path.resolve(webviewRoot, "src") },
5772
{ find: "@roo", replacement: path.resolve(webviewRoot, "../src/shared") },
58-
{
59-
find: "@vscode/webview-ui-toolkit/react",
60-
replacement: path.resolve(webviewRoot, "src/__mocks__/@vscode/webview-ui-toolkit/react.tsx"),
61-
},
6273
{ find: "vscode", replacement: path.resolve(webviewRoot, "../src/__mocks__/vscode.js") },
6374
],
6475
},
@@ -71,6 +82,9 @@ export default defineConfig({
7182
"process.env.PKG_RELEASE_CHANNEL": JSON.stringify("stable"),
7283
},
7384
optimizeDeps: {
85+
// Pre-bundle the real toolkit (see realToolkitImporters). If Vite finds it
86+
// during the first page load, it re-optimizes and reloads mid-test.
87+
include: ["@vscode/webview-ui-toolkit/react"],
7488
exclude: ["@vscode/codicons"],
7589
},
7690
publicDir: path.resolve(webviewRoot, "../src/assets/images"),
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* v8 ignore file -- Playwright component fixture is covered by the visual test. */
2+
import React, { useState } from "react"
3+
import i18next from "i18next"
4+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
5+
6+
import { providerIdentifiers, type ProviderSettings } from "@roo-code/types"
7+
8+
import { TranslationContext as AppTranslationContext } from "@/i18n/TranslationContext"
9+
import { TranslationContext as PlaywrightTranslationContext } from "@src/i18n/TranslationContext"
10+
import { TooltipProvider } from "@src/components/ui/tooltip"
11+
import { Ollama } from "../Ollama"
12+
import enSettings from "@/i18n/locales/en/settings.json"
13+
14+
function flattenTranslations(obj: Record<string, unknown>, prefix = "settings:"): Record<string, string> {
15+
const result: Record<string, string> = {}
16+
for (const [key, value] of Object.entries(obj)) {
17+
const fullKey = `${prefix}${key}`
18+
if (typeof value === "string") {
19+
result[fullKey] = value
20+
} else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
21+
Object.assign(result, flattenTranslations(value as Record<string, unknown>, `${fullKey}.`))
22+
}
23+
}
24+
return result
25+
}
26+
27+
// An uninitialized instance is a valid `i18n` for the context. The stories read `t`.
28+
const i18n = i18next.createInstance()
29+
30+
const translations = flattenTranslations(enSettings as Record<string, unknown>)
31+
32+
const apiConfiguration: ProviderSettings = {
33+
apiProvider: providerIdentifiers.ollama,
34+
ollamaBaseUrl: "http://localhost:11434",
35+
ollamaApiKey: "",
36+
ollamaModelId: "",
37+
}
38+
39+
const Providers = ({ children }: React.PropsWithChildren) => {
40+
const [queryClient] = useState(
41+
() =>
42+
new QueryClient({
43+
defaultOptions: { queries: { retry: false } },
44+
}),
45+
)
46+
47+
return (
48+
<PlaywrightTranslationContext.Provider
49+
value={{
50+
t: (key) => translations[key] ?? key,
51+
i18n,
52+
}}>
53+
<AppTranslationContext.Provider
54+
value={{
55+
t: (key) => translations[key] ?? key,
56+
i18n,
57+
}}>
58+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
59+
</AppTranslationContext.Provider>
60+
</PlaywrightTranslationContext.Provider>
61+
)
62+
}
63+
64+
export const OllamaApiKeyHelpFixture = () => (
65+
<Providers>
66+
<TooltipProvider>
67+
<div className="w-[480px] max-w-full bg-vscode-editor-background p-4 text-vscode-foreground">
68+
<Ollama apiConfiguration={apiConfiguration} setApiConfigurationField={() => {}} />
69+
</div>
70+
</TooltipProvider>
71+
</Providers>
72+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expect, test } from "../../../../../playwright/coverage-fixture"
2+
import { mountedStory } from "../../../../../playwright/mounted-story"
3+
4+
test("renders the API key help text in the VS Code dark theme", async ({ mount, page }) => {
5+
// The full provider bundle leaves bare Zod references after gallery tree-shaking.
6+
await page.evaluate(() => Object.assign(globalThis, { z: undefined, z$1: undefined }))
7+
const component = mountedStory(await mount("ollama-api-key-help"))
8+
9+
await component.evaluate((element) => {
10+
const { document } = element.ownerDocument.defaultView!
11+
document.documentElement.className = "vscode-dark"
12+
document.body.className = "vscode-dark"
13+
document.body.dataset.vscodeThemeId = "Default Dark Modern"
14+
})
15+
16+
await expect
17+
.poll(() =>
18+
component.evaluate((element) => {
19+
return getComputedStyle(element.ownerDocument.body)
20+
.getPropertyValue("--vscode-editor-background")
21+
.trim()
22+
}),
23+
)
24+
.toBe("#1f1f1f")
25+
26+
// The real toolkit text field draws the label above the input once upgraded.
27+
await page.evaluate(() => customElements.whenDefined("vscode-text-field"))
28+
29+
await component.evaluate(async () => {
30+
await document.fonts.ready
31+
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))
32+
})
33+
34+
await expect(component).toHaveScreenshot("ollama-api-key-help-guidance-dark.png")
35+
})
50.2 KB
Loading

‎webview-ui/src/i18n/locales/ca/settings.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/src/i18n/locales/de/settings.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎webview-ui/src/i18n/locales/en/settings.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@
686686
"baseUrl": "Base URL (optional)",
687687
"modelId": "Model ID",
688688
"apiKey": "Ollama API Key",
689-
"apiKeyHelp": "Optional API key for authenticated Ollama instances or cloud services. The key is only sent to HTTPS or loopback endpoints; remote HTTP endpoints receive no credentials (the key would travel in cleartext), so use HTTPS for remote authenticated instances. Leave empty for local installations.",
689+
"apiKeyHelp": "Optional API key for Ollama instances that need authentication, or for cloud services. Zoo Code sends the key only to HTTPS or loopback endpoints. A remote HTTP endpoint gets no key, because the key would travel in plain text. Use HTTPS for a remote instance that needs a key. Leave this empty for a local installation.",
690690
"numCtx": "Context Window Size (num_ctx)",
691691
"numCtxHelp": "Override the model's default context window size. Leave empty to use the model's Modelfile configuration. Minimum value is 128.",
692692
"thinking": "Enable Thinking",

0 commit comments

Comments
 (0)