diff --git a/src/providers/google-shared.ensures-function-call-comes-after-user-turn.test.ts b/src/providers/google-shared.ensures-function-call-comes-after-user-turn.test.ts index f3ecc5d34e7..e3b61c011e0 100644 --- a/src/providers/google-shared.ensures-function-call-comes-after-user-turn.test.ts +++ b/src/providers/google-shared.ensures-function-call-comes-after-user-turn.test.ts @@ -1,41 +1,7 @@ -import type { Context, Model } from "@mariozechner/pi-ai/dist/types.js"; +import type { Context } from "@mariozechner/pi-ai/dist/types.js"; import { convertMessages } from "@mariozechner/pi-ai/dist/providers/google-shared.js"; import { describe, expect, it } from "vitest"; - -const asRecord = (value: unknown): Record => { - expect(value).toBeTruthy(); - expect(typeof value).toBe("object"); - expect(Array.isArray(value)).toBe(false); - return value as Record; -}; - -const makeModel = (id: string): Model<"google-generative-ai"> => - ({ - id, - name: id, - api: "google-generative-ai", - provider: "google", - baseUrl: "https://example.invalid", - reasoning: false, - input: ["text"], - cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, - contextWindow: 1, - maxTokens: 1, - }) as Model<"google-generative-ai">; - -const makeGeminiCliModel = (id: string): Model<"google-gemini-cli"> => - ({ - id, - name: id, - api: "google-gemini-cli", - provider: "google-gemini-cli", - baseUrl: "https://example.invalid", - reasoning: false, - input: ["text"], - cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, - contextWindow: 1, - maxTokens: 1, - }) as Model<"google-gemini-cli">; +import { asRecord, makeGeminiCliModel, makeModel } from "./google-shared.test-helpers.js"; describe("google-shared convertTools", () => { it("ensures function call comes after user turn, not after model turn", () => { diff --git a/src/providers/google-shared.preserves-parameters-type-is-missing.test.ts b/src/providers/google-shared.preserves-parameters-type-is-missing.test.ts index a32053fd0e5..e125f8bbe2f 100644 --- a/src/providers/google-shared.preserves-parameters-type-is-missing.test.ts +++ b/src/providers/google-shared.preserves-parameters-type-is-missing.test.ts @@ -1,48 +1,7 @@ -import type { Context, Model, Tool } from "@mariozechner/pi-ai/dist/types.js"; +import type { Context, Tool } from "@mariozechner/pi-ai/dist/types.js"; import { convertMessages, convertTools } from "@mariozechner/pi-ai/dist/providers/google-shared.js"; import { describe, expect, it } from "vitest"; - -const asRecord = (value: unknown): Record => { - expect(value).toBeTruthy(); - expect(typeof value).toBe("object"); - expect(Array.isArray(value)).toBe(false); - return value as Record; -}; - -const getFirstToolParameters = ( - converted: ReturnType, -): Record => { - const functionDeclaration = asRecord(converted?.[0]?.functionDeclarations?.[0]); - return asRecord(functionDeclaration.parametersJsonSchema ?? functionDeclaration.parameters); -}; - -const makeModel = (id: string): Model<"google-generative-ai"> => - ({ - id, - name: id, - api: "google-generative-ai", - provider: "google", - baseUrl: "https://example.invalid", - reasoning: false, - input: ["text"], - cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, - contextWindow: 1, - maxTokens: 1, - }) as Model<"google-generative-ai">; - -const _makeGeminiCliModel = (id: string): Model<"google-gemini-cli"> => - ({ - id, - name: id, - api: "google-gemini-cli", - provider: "google-gemini-cli", - baseUrl: "https://example.invalid", - reasoning: false, - input: ["text"], - cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, - contextWindow: 1, - maxTokens: 1, - }) as Model<"google-gemini-cli">; +import { asRecord, getFirstToolParameters, makeModel } from "./google-shared.test-helpers.js"; describe("google-shared convertTools", () => { it("preserves parameters when type is missing", () => { diff --git a/src/providers/google-shared.test-helpers.ts b/src/providers/google-shared.test-helpers.ts new file mode 100644 index 00000000000..8d1e7f4e432 --- /dev/null +++ b/src/providers/google-shared.test-helpers.ts @@ -0,0 +1,49 @@ +import type { Model } from "@mariozechner/pi-ai/dist/types.js"; +import { expect } from "vitest"; + +export const asRecord = (value: unknown): Record => { + expect(value).toBeTruthy(); + expect(typeof value).toBe("object"); + expect(Array.isArray(value)).toBe(false); + return value as Record; +}; + +type ConvertedTools = ReadonlyArray<{ + functionDeclarations?: ReadonlyArray<{ + parametersJsonSchema?: unknown; + parameters?: unknown; + }>; +}>; + +export const getFirstToolParameters = (converted: ConvertedTools): Record => { + const functionDeclaration = asRecord(converted?.[0]?.functionDeclarations?.[0]); + return asRecord(functionDeclaration.parametersJsonSchema ?? functionDeclaration.parameters); +}; + +export const makeModel = (id: string): Model<"google-generative-ai"> => + ({ + id, + name: id, + api: "google-generative-ai", + provider: "google", + baseUrl: "https://example.invalid", + reasoning: false, + input: ["text"], + cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, + contextWindow: 1, + maxTokens: 1, + }) as Model<"google-generative-ai">; + +export const makeGeminiCliModel = (id: string): Model<"google-gemini-cli"> => + ({ + id, + name: id, + api: "google-gemini-cli", + provider: "google-gemini-cli", + baseUrl: "https://example.invalid", + reasoning: false, + input: ["text"], + cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, + contextWindow: 1, + maxTokens: 1, + }) as Model<"google-gemini-cli">;