From 4be5ad48f4e4b6084b663902ac4d88d74485412e Mon Sep 17 00:00:00 2001 From: Eason Liang Date: Tue, 1 Dec 2026 19:08:06 +0800 Subject: [PATCH 1/2] 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() + }) +}) From 2daf7797e9ab4939dca5f98b4a75c22a286de6d4 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 3 Dec 2026 02:43:47 +0800 Subject: [PATCH 2/2] test(core): arm the retry-ask cancel from the posted ask row The row that cancels while the manual retry ask is pending scheduled its cancel from a wall-clock poll. It started the request loop, then polled the message list every 50 ms for 1000 ms - the default vitest wait budget - until the last posted row was the api_req_failed ask, and armed the abort in the finally. That budget is real time racing real time: reaching that ask costs a say("api_req_started") save, the saved user turn, and two saveClineMessages passes, and each of them is a locked, fsynced, rename-committed write. Over twenty measured rounds here the ask row lands 24-41 ms after the request starts, so the probe held a margin of 24-41x on a lane that runs five test lanes at turbo concurrency two with two vitest workers per lane on four runner vCPUs, and that reaches this row - the last of the file's seventeen still gated on that budget - with the detached saves of the fourteen rows before it still in flight. The ubuntu lane never spends that long on those writes, which is why the row went red there alone and not here. The cancel is now armed from the event that makes it true. addToClineMessages pushes the ask row, ask() having cleared the previous response fields before it, and then emits RooCodeEventName.Message with action "created": that emit is the causal moment the row exists unanswered, and an answer delivered from there on cannot be wiped by the ask that follows. A helper in the file waits for that emit on the api_req_failed row, and if the request loop settles first it rejects with the settled run rather than waiting out a deadline, so a regression fails on its own error instead of on elapsed time. The shared webview-answer helper used the same probe for the same ask, so it waits on the event as well. No assertion was dropped or relaxed: the ask row is still required to be the last posted message, checked now at a point production has already established. Measured, not assumed. Waiting for the flake was no use here - six runs of the parent bytes passed seventeen of seventeen, the row landing 24-41 ms in - so the cost was injected instead: holding every safeWriteJson 300 ms longer reproduces the reported failure on the parent bytes, five failed and twelve passed for this file and the row alone one failed with "expected undefined to be 'api_req_failed'" on the probe line, while the same injection passes seventeen of seventeen on these bytes. Two mutants of the production seam this helper waits on - renaming the created action in the emit, and renaming the api_req_failed ask in the empty-assistant retry branch - each take down the five rows that read that ask. Production did not move: this commit changes one spec file and nothing else. --- .../__tests__/empty-response-history.spec.ts | 57 ++++++++++++++++++- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/src/core/task/__tests__/empty-response-history.spec.ts b/src/core/task/__tests__/empty-response-history.spec.ts index 6dd8061075c..869d3175831 100644 --- a/src/core/task/__tests__/empty-response-history.spec.ts +++ b/src/core/task/__tests__/empty-response-history.spec.ts @@ -16,7 +16,14 @@ import * as vscode from "vscode" import type { Anthropic } from "@anthropic-ai/sdk" import type OpenAI from "openai" -import { providerIdentifiers, type GlobalState, type ModelInfo, type ProviderSettings } from "@roo-code/types" +import { + providerIdentifiers, + RooCodeEventName, + type GlobalState, + type ModelInfo, + type ProviderSettings, + type TaskEvents, +} from "@roo-code/types" import { TelemetryService } from "@roo-code/telemetry" import { Task } from "../Task" @@ -338,6 +345,48 @@ describe("empty-response history persistence (issue 2691)", () => { } } + /** + * The point where the manual retry ask is pending: `addToClineMessages` pushes + * the ask row - after clearing the previous response fields - and then emits + * `RooCodeEventName.Message` with `action: "created"`, so that emit is the causal + * moment the row exists unanswered and an answer delivered from here on cannot be + * wiped by the ask that follows it. Waiting on it replaces the `vi.waitFor` probe + * of `clineMessages.at(-1)`, whose default budget is 1000 ms of wall clock in 50 + * ms polls, and reaching that ask costs real time: a `say("api_req_started")` + * save, the saved user turn, and two `saveClineMessages()` passes, each a locked, + * fsynced, rename-committed write. Measured over 20 rounds here the ask row lands + * 24-41 ms after the request starts, so the probe held only a 24-41x margin on a + * lane that runs five test lanes at turbo concurrency 2 with two vitest workers + * per lane on four runner vCPUs, and that reaches this row - the last of the + * file's seventeen still gated on that budget - with the detached saves of the + * fourteen before it in flight. Holding every `safeWriteJson` 300 ms longer, the + * shape of that slowdown, turns the row red on the bytes before this change and + * leaves it green here. The event carries no clock budget, and when the request + * loop ends before the ask is posted the promise rejects with the settled run, so + * a regression fails on its own error instead of on an elapsed-time gamble. + */ + function retryAskPending(task: Task, run: Promise): Promise { + return new Promise((resolve, reject) => { + const onMessage = ({ action, message }: TaskEvents[RooCodeEventName.Message][0]) => { + if (action !== "created" || message.ask !== "api_req_failed") { + return + } + task.off(RooCodeEventName.Message, onMessage) + resolve() + } + task.on(RooCodeEventName.Message, onMessage) + void run.then( + () => { + task.off(RooCodeEventName.Message, onMessage) + reject(new Error(`task ${task.taskId} ended before the retry ask was posted`)) + }, + (error: unknown) => { + task.off(RooCodeEventName.Message, onMessage) + reject(error) + }, + ) + }) + } /** Keep the real ask wait pending across a poll, then deliver the webview response. */ async function runWithRetryResponse( task: Task, @@ -349,7 +398,8 @@ describe("empty-response history persistence (issue 2691)", () => { settled = true }) try { - await vi.waitFor(() => expect(task.clineMessages.at(-1)?.ask).toBe("api_req_failed")) + await retryAskPending(task, run) + expect(task.clineMessages.at(-1)?.ask).toBe("api_req_failed") // ask() polls every 100 ms. It must stay pending without a response. await new Promise((resolve) => setTimeout(resolve, 150)) expect(settled).toBe(false) @@ -691,7 +741,8 @@ describe("empty-response history persistence (issue 2691)", () => { const attempt = vi.spyOn(task, "attemptApiRequest").mockImplementationOnce(() => firstAttempt.body) const run = task.recursivelyMakeClineRequests(toolResultUserContent()) try { - await vi.waitFor(() => expect(task.clineMessages.at(-1)?.ask).toBe("api_req_failed")) + await retryAskPending(task, run) + expect(task.clineMessages.at(-1)?.ask).toBe("api_req_failed") } finally { setAbortLatch(task, true) await run