From 4be5ad48f4e4b6084b663902ac4d88d74485412e Mon Sep 17 00:00:00 2001 From: Eason Liang Date: Tue, 1 Dec 2026 19:08:06 +0800 Subject: [PATCH] test(webview-ui): carry the validator rows in a unit of their own This file sat on a branch whose unit is the diff-view write wiring. The out-of-scope review row named it: that pull request held exactly one path under webview-ui/, this one, and the production file these rows assert against did not move. The removal there is answered here instead of the rows being dropped, so the file is carried byte for byte rather than rewritten. Carried, not rewritten. Blob 08b7f3f84fbb4ca27fd3484fca2808461cfa1bfd, 273 lines and 8908 bytes, written from the blob of the parent of the removal commit and re-hashed after writing. Row shape measured in this file: 3 describe blocks and 6 it constructs, of which 2 take their titles from a table of 16 entries and 4 carry fixed titles, so the file runs 36 cases; a count of nine is the construct total that counts a describe block alongside its rows, and it is not the number of cases the file runs. webview-ui/src/utils/validate.ts holds blob aa34fa4e8d39 both at this base commit and at the head the file was removed from, so nothing these rows call has moved. The commit adds one file and changes nothing else: no production file, no dependency, no configuration. What the rows pin. The provider configuration validator is called directly and the rows assert the decision it returns for a configuration: the credential a provider asks for, the provider an allow-list refused, the pair of regions a Bedrock ARN mismatch reports, and the model id a dynamic provider rejected or accepted. None of them drives an editor, a diff view or a write path, so they do not need the wiring that unit is about, and a reviewer reading that unit should not have to decide whether a validator regression is hidden in its diff. Not measured here, stated plainly. The suite was not run in the checkout that made this commit, because that checkout holds no installed dependencies. The first run of these rows in this location is the continuous integration run on this pull request, whose webview suite reports whether the carried file passes where it now lives. Answered here rather than there: review row 4568686689 asked that these rows exist somewhere that exercises them, and review id 6129507786 asked why a webview-ui path was inside that unit. Tags the inline row this commit answers; the review body that asked the scope question is named above in prose rather than tagged here. [cr 4568686689] --- .../validate.provider-validation.spec.ts | 273 ++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 webview-ui/src/utils/__tests__/validate.provider-validation.spec.ts diff --git a/webview-ui/src/utils/__tests__/validate.provider-validation.spec.ts b/webview-ui/src/utils/__tests__/validate.provider-validation.spec.ts new file mode 100644 index 00000000000..08b7f3f84fb --- /dev/null +++ b/webview-ui/src/utils/__tests__/validate.provider-validation.spec.ts @@ -0,0 +1,273 @@ +import { + providerIdentifiers, + type OrganizationAllowList, + type ProviderSettings, + type RouterModels, +} from "@roo-code/types" +import type { TFunction } from "i18next" + +import { getModelValidationError, validateApiConfigurationExcludingModelErrors, validateBedrockArn } from "../validate" + +// `TFunction` is branded; this double only answers a key plus its interpolation values, which is +// what these cases assert on: the key a provider earns and the values handed to the translator. +const t = ((key: string, options?: Record) => { + if (options) { + return Object.entries(options).reduce((acc, [k, v]) => `${acc} ${k}=${v}`, key) + } + return key +}) as unknown as TFunction + +const routerModels: RouterModels = { + openrouter: { + "valid-model": { + maxTokens: 8192, + contextWindow: 200000, + supportsImages: true, + supportsPromptCache: false, + inputPrice: 3, + outputPrice: 15, + }, + "another-valid-model": { + maxTokens: 4096, + contextWindow: 100000, + supportsImages: false, + supportsPromptCache: false, + inputPrice: 1, + outputPrice: 5, + }, + }, + requesty: {}, + unbound: {}, + litellm: {}, + ollama: {}, + lmstudio: {}, + "vercel-ai-gateway": {}, + poe: {}, + deepseek: {}, + "opencode-go": {}, + kenari: {}, + nanogpt: {}, + "zoo-gateway": {}, + "kimi-code": {}, + friendli: {}, + moonshot: {}, +} + +const restrictiveOrganization: OrganizationAllowList = { allowAll: false, providers: {} } + +describe("validateApiConfigurationExcludingModelErrors - the credential each provider asks for", () => { + // Each row of this matrix only proves a rejection: a provider branch that kept returning the + // same error after the value that branch asks for was supplied would still pass every row + // below. Each row therefore carries its pair - the same provider with that value present - + // asserted through the same entry point, so the accept path is pinned next to the reject path. + const cases: { + name: string + config: ProviderSettings + expected: string + pair: { name: string; config: ProviderSettings } + }[] = [ + { + name: "requesty without its key", + config: { apiProvider: providerIdentifiers.requesty }, + expected: "settings:validation.apiKey", + pair: { + name: "requesty with its key", + config: { apiProvider: providerIdentifiers.requesty, requestyApiKey: "mock-key" }, + }, + }, + { + name: "unbound without its key", + config: { apiProvider: providerIdentifiers.unbound }, + expected: "settings:validation.apiKey", + pair: { + name: "unbound with its key", + config: { apiProvider: providerIdentifiers.unbound, unboundApiKey: "mock-key" }, + }, + }, + { + name: "litellm without its key", + config: { apiProvider: providerIdentifiers.litellm }, + expected: "settings:validation.apiKey", + pair: { + name: "litellm with its key", + config: { apiProvider: providerIdentifiers.litellm, litellmApiKey: "mock-key" }, + }, + }, + { + name: "gemini without its key", + config: { apiProvider: providerIdentifiers.gemini }, + expected: "settings:validation.apiKey", + pair: { + name: "gemini with its key", + config: { apiProvider: providerIdentifiers.gemini, geminiApiKey: "mock-key" }, + }, + }, + { + name: "openai-native without its key", + config: { apiProvider: providerIdentifiers.openaiNative }, + expected: "settings:validation.apiKey", + pair: { + name: "openai-native with its key", + config: { apiProvider: providerIdentifiers.openaiNative, openAiNativeApiKey: "mock-key" }, + }, + }, + { + name: "mistral without its key", + config: { apiProvider: providerIdentifiers.mistral }, + expected: "settings:validation.apiKey", + pair: { + name: "mistral with its key", + config: { apiProvider: providerIdentifiers.mistral, mistralApiKey: "mock-key" }, + }, + }, + { + name: "fireworks without its key", + config: { apiProvider: providerIdentifiers.fireworks }, + expected: "settings:validation.apiKey", + pair: { + name: "fireworks with its key", + config: { apiProvider: providerIdentifiers.fireworks, fireworksApiKey: "mock-key" }, + }, + }, + { + name: "vercel-ai-gateway without its key", + config: { apiProvider: providerIdentifiers.vercelAiGateway }, + expected: "settings:validation.apiKey", + pair: { + name: "vercel-ai-gateway with its key", + config: { apiProvider: providerIdentifiers.vercelAiGateway, vercelAiGatewayApiKey: "mock-key" }, + }, + }, + { + name: "baseten without its key", + config: { apiProvider: providerIdentifiers.baseten }, + expected: "settings:validation.apiKey", + pair: { + name: "baseten with its key", + config: { apiProvider: providerIdentifiers.baseten, basetenApiKey: "mock-key" }, + }, + }, + { + name: "bedrock without a region", + config: { apiProvider: providerIdentifiers.bedrock }, + expected: "settings:validation.awsRegion", + pair: { + name: "bedrock with a region", + config: { apiProvider: providerIdentifiers.bedrock, awsRegion: "us-east-1" }, + }, + }, + { + name: "vertex with a project but no region", + config: { apiProvider: providerIdentifiers.vertex, vertexProjectId: "mock-project" }, + expected: "settings:validation.googleCloud", + pair: { + name: "vertex with its project and region", + config: { + apiProvider: providerIdentifiers.vertex, + vertexProjectId: "mock-project", + vertexRegion: "us-east1", + }, + }, + }, + { + name: "ollama without a model id", + config: { apiProvider: providerIdentifiers.ollama }, + expected: "settings:validation.modelId", + pair: { + name: "ollama with a model id", + config: { apiProvider: providerIdentifiers.ollama, ollamaModelId: "mock-model" }, + }, + }, + { + name: "lmstudio without a model id", + config: { apiProvider: providerIdentifiers.lmstudio }, + expected: "settings:validation.modelId", + pair: { + name: "lmstudio with a model id", + config: { apiProvider: providerIdentifiers.lmstudio, lmStudioModelId: "mock-model" }, + }, + }, + { + name: "vscode-lm without a model selector", + config: { apiProvider: providerIdentifiers.vscodeLm }, + expected: "settings:validation.modelSelector", + pair: { + name: "vscode-lm with a model selector", + config: { + apiProvider: providerIdentifiers.vscodeLm, + vsCodeLmModelSelector: { vendor: "mock-vendor", family: "mock-family" }, + }, + }, + }, + { + name: "qwen-code without an oauth path", + config: { apiProvider: providerIdentifiers.qwenCode }, + expected: "settings:validation.qwenCodeOauthPath", + pair: { + name: "qwen-code with an oauth path", + config: { apiProvider: providerIdentifiers.qwenCode, qwenCodeOauthPath: "mock-oauth-path" }, + }, + }, + ] + + cases.forEach(({ name, config, expected, pair }) => { + it(`returns ${expected} for ${name}`, () => { + expect(validateApiConfigurationExcludingModelErrors(config, t)).toBe(expected) + }) + + // The pair of the row above: the same provider once the value that branch asks for is in + // the configuration. This is the half the rejection matrix cannot show on its own - the + // successful return value, which is no error key at all. + it(`returns no error for ${pair.name}`, () => { + expect(validateApiConfigurationExcludingModelErrors(pair.config, t)).toBeUndefined() + }) + }) + + it("names the provider the organization allow-list refused", () => { + const config: ProviderSettings = { + apiProvider: providerIdentifiers.openrouter, + openRouterApiKey: "mock-key", + openRouterModelId: "valid-model", + } + + expect(validateApiConfigurationExcludingModelErrors(config, t, undefined, restrictiveOrganization)).toBe( + `settings:validation.providerNotAllowed provider=${providerIdentifiers.openrouter}`, + ) + }) +}) + +describe("validateBedrockArn - the pair a region mismatch reports", () => { + it("reports both the ARN region and the configured region", () => { + const arn = + "arn:aws:bedrock:eu-west-1:123456789012:inference-profile/eu.anthropic.claude-3-7-sonnet-20250219-v1:0" + + const result = validateBedrockArn(arn, t, "us-east-1") + + expect(result.isValid).toBe(true) + expect(result.arnRegion).toBe("eu-west-1") + expect(result.errorMessage).toBe("settings:validation.arn.regionMismatch arnRegion=eu-west-1 region=us-east-1") + }) +}) + +describe("getModelValidationError - the model a dynamic provider rejected", () => { + it("names the model id that is not in the fetched list", () => { + const config: ProviderSettings = { + apiProvider: providerIdentifiers.openrouter, + openRouterApiKey: "mock-key", + openRouterModelId: "not-in-the-list", + } + + expect(getModelValidationError(config, t, routerModels)).toBe( + "settings:validation.modelAvailability modelId=not-in-the-list", + ) + }) + it("accepts the model that is in the fetched list", () => { + const config: ProviderSettings = { + apiProvider: providerIdentifiers.openrouter, + openRouterApiKey: "mock-key", + openRouterModelId: "valid-model", + } + + expect(getModelValidationError(config, t, routerModels)).toBeUndefined() + }) +})