Skip to content

Commit 312318c

Browse files
committed
test(providers): use canonical identifiers
1 parent 523be43 commit 312318c

27 files changed

Lines changed: 350 additions & 284 deletions

‎src/__tests__/single-open-invariant.spec.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { TaskScheduler } from "../core/task/TaskScheduler"
88
import { type Task } from "../core/task/Task"
99
import { API } from "../extension/api"
1010
import * as ProfileValidatorMod from "../shared/ProfileValidator"
11+
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
1112

1213
type PrivateClineProviderMethods = {
1314
createTask: (
@@ -45,7 +46,7 @@ vi.mock("../core/task/Task", () => {
4546
}) {
4647
this.taskId = opts.historyItem?.id ?? `task-${Math.random().toString(36).slice(2, 8)}`
4748
this.parentTask = opts.parentTask
48-
this.apiConfiguration = opts.apiConfiguration ?? { apiProvider: "anthropic" }
49+
this.apiConfiguration = opts.apiConfiguration ?? { apiProvider: providerIdentifiers.anthropic }
4950
opts.onCreated?.(this)
5051
}
5152
start() {}
@@ -86,7 +87,7 @@ describe("Single-open-task invariant", () => {
8687
},
8788
setValues: vi.fn(),
8889
getState: vi.fn().mockResolvedValue({
89-
apiConfiguration: { apiProvider: "anthropic", consecutiveMistakeLimit: 0 },
90+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, consecutiveMistakeLimit: 0 },
9091
organizationAllowList: "*",
9192
enableCheckpoints: true,
9293
checkpointTimeout: 60,
@@ -130,7 +131,7 @@ describe("Single-open-task invariant", () => {
130131
taskScheduler: new TaskScheduler(),
131132
setValues: vi.fn(),
132133
getState: vi.fn().mockResolvedValue({
133-
apiConfiguration: { apiProvider: "anthropic", consecutiveMistakeLimit: 0 },
134+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, consecutiveMistakeLimit: 0 },
134135
organizationAllowList: "*",
135136
enableCheckpoints: true,
136137
checkpointTimeout: 60,
@@ -182,7 +183,7 @@ describe("Single-open-task invariant", () => {
182183
listConfig: vi.fn().mockResolvedValue([]),
183184
},
184185
getState: vi.fn().mockResolvedValue({
185-
apiConfiguration: { apiProvider: "anthropic", consecutiveMistakeLimit: 0 },
186+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, consecutiveMistakeLimit: 0 },
186187
enableCheckpoints: true,
187188
checkpointTimeout: 60,
188189
experiments: {},
@@ -256,7 +257,7 @@ describe("Single-open-task invariant", () => {
256257
listConfig: vi.fn().mockResolvedValue([]),
257258
},
258259
getState: vi.fn().mockResolvedValue({
259-
apiConfiguration: { apiProvider: "anthropic", consecutiveMistakeLimit: 0 },
260+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, consecutiveMistakeLimit: 0 },
260261
enableCheckpoints: true,
261262
checkpointTimeout: 60,
262263
experiments: {},
@@ -328,7 +329,7 @@ describe("Single-open-task invariant", () => {
328329
listConfig: vi.fn().mockResolvedValue([]),
329330
},
330331
getState: vi.fn().mockResolvedValue({
331-
apiConfiguration: { apiProvider: "anthropic", consecutiveMistakeLimit: 0 },
332+
apiConfiguration: { apiProvider: providerIdentifiers.anthropic, consecutiveMistakeLimit: 0 },
332333
enableCheckpoints: true,
333334
checkpointTimeout: 60,
334335
experiments: {},

‎src/api/providers/__tests__/bedrock-reasoning.spec.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BedrockRuntimeClient, ConverseStreamCommand } from "@aws-sdk/client-bed
55
import { logger } from "../../../utils/logging"
66

77
import { clearAllMocks } from "../../../test-utils/reset"
8+
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
89

910
// Mock the AWS SDK
1011
vi.mock("@aws-sdk/client-bedrock-runtime")
@@ -45,7 +46,7 @@ describe("AwsBedrockHandler - Extended Thinking", () => {
4546
describe("Extended Thinking Support", () => {
4647
it("should include thinking parameter for Claude Sonnet 4 when reasoning is enabled", async () => {
4748
handler = new AwsBedrockHandler({
48-
apiProvider: "bedrock",
49+
apiProvider: providerIdentifiers.bedrock,
4950
apiModelId: "anthropic.claude-sonnet-4-20250514-v1:0",
5051
awsRegion: "us-east-1",
5152
enableReasoningEffort: true,
@@ -113,7 +114,7 @@ describe("AwsBedrockHandler - Extended Thinking", () => {
113114

114115
it("should pass thinking parameters from metadata", async () => {
115116
handler = new AwsBedrockHandler({
116-
apiProvider: "bedrock",
117+
apiProvider: providerIdentifiers.bedrock,
117118
apiModelId: "anthropic.claude-3-7-sonnet-20250219-v1:0",
118119
awsRegion: "us-east-1",
119120
})
@@ -156,7 +157,7 @@ describe("AwsBedrockHandler - Extended Thinking", () => {
156157

157158
it("should log when extended thinking is enabled", async () => {
158159
handler = new AwsBedrockHandler({
159-
apiProvider: "bedrock",
160+
apiProvider: providerIdentifiers.bedrock,
160161
apiModelId: "anthropic.claude-opus-4-20250514-v1:0",
161162
awsRegion: "us-east-1",
162163
enableReasoningEffort: true,
@@ -188,7 +189,7 @@ describe("AwsBedrockHandler - Extended Thinking", () => {
188189

189190
it("should not include topP when thinking is disabled (global removal)", async () => {
190191
handler = new AwsBedrockHandler({
191-
apiProvider: "bedrock",
192+
apiProvider: providerIdentifiers.bedrock,
192193
apiModelId: "anthropic.claude-3-7-sonnet-20250219-v1:0",
193194
awsRegion: "us-east-1",
194195
// Note: no enableReasoningEffort = true, so thinking is disabled
@@ -234,7 +235,7 @@ describe("AwsBedrockHandler - Extended Thinking", () => {
234235

235236
it("should enable reasoning when enableReasoningEffort is true in settings", async () => {
236237
handler = new AwsBedrockHandler({
237-
apiProvider: "bedrock",
238+
apiProvider: providerIdentifiers.bedrock,
238239
apiModelId: "anthropic.claude-sonnet-4-20250514-v1:0",
239240
awsRegion: "us-east-1",
240241
enableReasoningEffort: true, // This should trigger reasoning
@@ -288,7 +289,7 @@ describe("AwsBedrockHandler - Extended Thinking", () => {
288289

289290
it("should support API key authentication", async () => {
290291
handler = new AwsBedrockHandler({
291-
apiProvider: "bedrock",
292+
apiProvider: providerIdentifiers.bedrock,
292293
apiModelId: "anthropic.claude-3-5-sonnet-20241022-v2:0",
293294
awsRegion: "us-east-1",
294295
awsUseApiKey: true,

‎src/api/providers/__tests__/friendli.spec.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getModelMaxOutputTokens } from "../../../shared/api"
1010
import { FriendliHandler } from "../friendli"
1111
import { asyncStreamFrom, collectStream } from "../../../test-utils/stream"
1212
import { clearAllMocks } from "../../../test-utils/reset"
13+
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
1314

1415
// Create mock functions
1516
const mockCreate = vi.fn()
@@ -324,7 +325,7 @@ describe("FriendliHandler", () => {
324325

325326
describe("buildApiHandler friendli wiring", () => {
326327
it("returns a FriendliHandler for apiProvider='friendli'", () => {
327-
const handler = buildApiHandler({ apiProvider: "friendli", friendliApiKey: "test-key" })
328+
const handler = buildApiHandler({ apiProvider: providerIdentifiers.friendli, friendliApiKey: "test-key" })
328329
expect(handler).toBeInstanceOf(FriendliHandler)
329330
})
330331
})
@@ -335,7 +336,7 @@ describe("Friendli model max output tokens (clamping behavior)", () => {
335336
const result = getModelMaxOutputTokens({
336337
modelId: "zai-org/GLM-5.2",
337338
model,
338-
settings: { apiProvider: "friendli" },
339+
settings: { apiProvider: providerIdentifiers.friendli },
339340
format: "openai",
340341
})
341342
// 1_000_000 * 0.2 = 200_000 > 131_072 → no clamping
@@ -347,7 +348,7 @@ describe("Friendli model max output tokens (clamping behavior)", () => {
347348
const result = getModelMaxOutputTokens({
348349
modelId: "zai-org/GLM-5.1",
349350
model,
350-
settings: { apiProvider: "friendli" },
351+
settings: { apiProvider: providerIdentifiers.friendli },
351352
format: "openai",
352353
})
353354
// 200_000 * 0.2 = 40_000 < 131_072 → clamped to 40_000
@@ -359,7 +360,7 @@ describe("Friendli model max output tokens (clamping behavior)", () => {
359360
const result = getModelMaxOutputTokens({
360361
modelId: "zai-org/GLM-5.1",
361362
model,
362-
settings: { apiProvider: "friendli", modelMaxTokens: 80_000 },
363+
settings: { apiProvider: providerIdentifiers.friendli, modelMaxTokens: 80_000 },
363364
format: "openai",
364365
})
365366
// supportsMaxTokens=true, user set 80k, model ceiling 131072 → min(80000, 131072) = 80000

‎src/api/providers/__tests__/gemini-handler.spec.ts‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ vi.mock("@roo-code/telemetry", () => ({
1313

1414
import { GeminiHandler } from "../gemini"
1515
import type { ApiHandlerOptions } from "../../../shared/api"
16+
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
1617

1718
describe("GeminiHandler backend support", () => {
1819
beforeEach(() => {
@@ -24,7 +25,7 @@ describe("GeminiHandler backend support", () => {
2425
// in Gemini API, so createMessage only uses function declarations.
2526
// URL context/grounding are only added in completePrompt.
2627
const options = {
27-
apiProvider: "gemini",
28+
apiProvider: providerIdentifiers.gemini,
2829
enableUrlContext: true,
2930
enableGrounding: true,
3031
} as ApiHandlerOptions
@@ -41,7 +42,7 @@ describe("GeminiHandler backend support", () => {
4142

4243
it("completePrompt passes config overrides without tools when URL context and grounding disabled", async () => {
4344
const options = {
44-
apiProvider: "gemini",
45+
apiProvider: providerIdentifiers.gemini,
4546
enableUrlContext: false,
4647
enableGrounding: false,
4748
} as ApiHandlerOptions
@@ -58,7 +59,7 @@ describe("GeminiHandler backend support", () => {
5859
describe("error scenarios", () => {
5960
it("should handle grounding metadata extraction failure gracefully", async () => {
6061
const options = {
61-
apiProvider: "gemini",
62+
apiProvider: providerIdentifiers.gemini,
6263
enableGrounding: true,
6364
} as ApiHandlerOptions
6465
const handler = new GeminiHandler(options)
@@ -93,7 +94,7 @@ describe("GeminiHandler backend support", () => {
9394

9495
it("should handle malformed grounding metadata", async () => {
9596
const options = {
96-
apiProvider: "gemini",
97+
apiProvider: providerIdentifiers.gemini,
9798
enableGrounding: true,
9899
} as ApiHandlerOptions
99100
const handler = new GeminiHandler(options)
@@ -144,7 +145,7 @@ describe("GeminiHandler backend support", () => {
144145

145146
it("should handle API errors when tools are enabled", async () => {
146147
const options = {
147-
apiProvider: "gemini",
148+
apiProvider: providerIdentifiers.gemini,
148149
enableUrlContext: true,
149150
enableGrounding: true,
150151
} as ApiHandlerOptions
@@ -192,7 +193,7 @@ describe("GeminiHandler backend support", () => {
192193

193194
it("should ignore allowedFunctionNames because Gemini rejects larger restriction lists", async () => {
194195
const options = {
195-
apiProvider: "gemini",
196+
apiProvider: providerIdentifiers.gemini,
196197
} as ApiHandlerOptions
197198
const handler = new GeminiHandler(options)
198199
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -213,7 +214,7 @@ describe("GeminiHandler backend support", () => {
213214

214215
it("should include all tools when allowedFunctionNames is provided", async () => {
215216
const options = {
216-
apiProvider: "gemini",
217+
apiProvider: providerIdentifiers.gemini,
217218
} as ApiHandlerOptions
218219
const handler = new GeminiHandler(options)
219220
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -236,7 +237,7 @@ describe("GeminiHandler backend support", () => {
236237

237238
it("should not pass large allowedFunctionNames lists to Gemini", async () => {
238239
const options = {
239-
apiProvider: "gemini",
240+
apiProvider: providerIdentifiers.gemini,
240241
} as ApiHandlerOptions
241242
const handler = new GeminiHandler(options)
242243
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -267,7 +268,7 @@ describe("GeminiHandler backend support", () => {
267268

268269
it("should not pass allowedFunctionNames even when history includes tool calls", async () => {
269270
const options = {
270-
apiProvider: "gemini",
271+
apiProvider: providerIdentifiers.gemini,
271272
} as ApiHandlerOptions
272273
const handler = new GeminiHandler(options)
273274
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -304,7 +305,7 @@ describe("GeminiHandler backend support", () => {
304305

305306
it("should fall back to tool_choice when allowedFunctionNames is provided", async () => {
306307
const options = {
307-
apiProvider: "gemini",
308+
apiProvider: providerIdentifiers.gemini,
308309
} as ApiHandlerOptions
309310
const handler = new GeminiHandler(options)
310311
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -327,7 +328,7 @@ describe("GeminiHandler backend support", () => {
327328

328329
it("should fall back to tool_choice when allowedFunctionNames is empty", async () => {
329330
const options = {
330-
apiProvider: "gemini",
331+
apiProvider: providerIdentifiers.gemini,
331332
} as ApiHandlerOptions
332333
const handler = new GeminiHandler(options)
333334
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -351,7 +352,7 @@ describe("GeminiHandler backend support", () => {
351352

352353
it("should not set toolConfig when allowedFunctionNames is undefined and no tool_choice", async () => {
353354
const options = {
354-
apiProvider: "gemini",
355+
apiProvider: providerIdentifiers.gemini,
355356
} as ApiHandlerOptions
356357
const handler = new GeminiHandler(options)
357358
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -374,7 +375,7 @@ describe("GeminiHandler backend support", () => {
374375
describe("Gemini schema compatibility", () => {
375376
it("should strip broad JSON Schema metadata from function declarations", async () => {
376377
const options = {
377-
apiProvider: "gemini",
378+
apiProvider: providerIdentifiers.gemini,
378379
} as ApiHandlerOptions
379380
const handler = new GeminiHandler(options)
380381
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -435,7 +436,7 @@ describe("GeminiHandler backend support", () => {
435436

436437
it("should collapse composition and type arrays in function declaration schemas", async () => {
437438
const options = {
438-
apiProvider: "gemini",
439+
apiProvider: providerIdentifiers.gemini,
439440
} as ApiHandlerOptions
440441
const handler = new GeminiHandler(options)
441442
const stub = vi.fn().mockReturnValue((async function* () {})())
@@ -495,7 +496,7 @@ describe("GeminiHandler backend support", () => {
495496
})
496497

497498
it("should deep-merge allOf fragments instead of overwriting earlier properties", async () => {
498-
const options = { apiProvider: "gemini" } as ApiHandlerOptions
499+
const options = { apiProvider: providerIdentifiers.gemini } as ApiHandlerOptions
499500
const handler = new GeminiHandler(options)
500501
const stub = vi.fn().mockReturnValue((async function* () {})())
501502
// @ts-ignore access private client
@@ -540,7 +541,7 @@ describe("GeminiHandler backend support", () => {
540541
})
541542

542543
it("should resolve $ref entries before dropping $defs", async () => {
543-
const options = { apiProvider: "gemini" } as ApiHandlerOptions
544+
const options = { apiProvider: providerIdentifiers.gemini } as ApiHandlerOptions
544545
const handler = new GeminiHandler(options)
545546
const stub = vi.fn().mockReturnValue((async function* () {})())
546547
// @ts-ignore access private client
@@ -589,7 +590,7 @@ describe("GeminiHandler backend support", () => {
589590
})
590591

591592
it("should preserve top-level properties and required entries when allOf is also present", async () => {
592-
const options = { apiProvider: "gemini" } as ApiHandlerOptions
593+
const options = { apiProvider: providerIdentifiers.gemini } as ApiHandlerOptions
593594
const handler = new GeminiHandler(options)
594595
const stub = vi.fn().mockReturnValue((async function* () {})())
595596
// @ts-ignore access private client
@@ -631,7 +632,7 @@ describe("GeminiHandler backend support", () => {
631632
})
632633

633634
it("should stop recursive $ref expansion before the sanitized schema becomes cyclic", async () => {
634-
const options = { apiProvider: "gemini" } as ApiHandlerOptions
635+
const options = { apiProvider: providerIdentifiers.gemini } as ApiHandlerOptions
635636
const handler = new GeminiHandler(options)
636637
const stub = vi.fn().mockReturnValue((async function* () {})())
637638
// @ts-ignore access private client
@@ -683,7 +684,7 @@ describe("GeminiHandler backend support", () => {
683684
})
684685

685686
it("should preserve parameter names that collide with stripped schema keywords", async () => {
686-
const options = { apiProvider: "gemini" } as ApiHandlerOptions
687+
const options = { apiProvider: providerIdentifiers.gemini } as ApiHandlerOptions
687688
const handler = new GeminiHandler(options)
688689
const stub = vi.fn().mockReturnValue((async function* () {})())
689690
// @ts-ignore access private client

‎src/api/providers/__tests__/kimi-code.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { buildApiHandler } from "../../index"
22
import { KimiCodeHandler } from "../kimi-code"
33

44
import { clearAllMocks } from "../../../test-utils/reset"
5+
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
56

67
const { mockGetAccessToken, mockForceRefreshAccessToken, mockGetModels } = vi.hoisted(() => ({
78
mockGetAccessToken: vi.fn(),
@@ -28,7 +29,7 @@ describe("KimiCodeHandler", () => {
2829

2930
it("is dispatched separately from Moonshot and preserves an unknown selected model", () => {
3031
const handler = buildApiHandler({
31-
apiProvider: "kimi-code",
32+
apiProvider: providerIdentifiers.kimiCode,
3233
kimiCodeAuthMethod: "api-key",
3334
kimiCodeApiKey: "kimi-key",
3435
apiModelId: "future-kimi-model",

0 commit comments

Comments
 (0)