Files
openclaw/src/plugin-sdk/provider-auth-result.test.ts
Peter Steinberger 00d8d7ead0 refactor: extract normalization core package
Extract shared normalization/coercion helpers into private @openclaw/normalization-core workspace package while preserving existing plugin SDK helper subpaths.\n\nAlso keeps direct normalization-core imports internal, wires UI/build/loader resolution, and replaces the slow PR network CodeQL lane with a fast added-line boundary scan while retaining full CodeQL for scheduled/manual runs.\n\nVerification: local moved tests, plugin SDK boundary tests, extension loader tests, agents-support shard, UI build/test, build artifacts, lint, workflow guards, autoreview, and GitHub CI passed on PR head 963d893715.
2026-05-31 01:33:00 +01:00

112 lines
3.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { MAX_DATE_TIMESTAMP_MS } from "../../packages/normalization-core/src/number-coercion.js";
import { buildOauthProviderAuthResult } from "./provider-auth-result.js";
describe("buildOauthProviderAuthResult", () => {
it("normalizes retired Gemini defaults before emitting config patches", () => {
const result = buildOauthProviderAuthResult({
providerId: "google",
defaultModel: "google/gemini-3-pro-preview",
access: "access-token",
});
expect(result.defaultModel).toBe("google/gemini-3.1-pro-preview");
expect(result.configPatch).toEqual({
agents: {
defaults: {
models: {
"google/gemini-3.1-pro-preview": {},
},
},
},
});
});
it("normalizes retired Gemini refs inside explicit config patches", () => {
const result = buildOauthProviderAuthResult({
providerId: "google",
defaultModel: "google/gemini-3-pro-preview",
access: "access-token",
configPatch: {
agents: {
defaults: {
model: {
primary: "google/gemini-3-pro-preview",
fallbacks: ["google/gemini-3-pro-preview", "openai/gpt-5.5"],
},
models: {
"google/gemini-3-pro-preview": { alias: "gemini" },
},
},
},
models: {
providers: {
google: {
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
models: [
{
id: "google/gemini-3-pro-preview",
name: "Gemini 3 Pro",
contextWindow: 1_048_576,
maxTokens: 65_536,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
reasoning: true,
},
],
},
},
},
},
});
expect(result.defaultModel).toBe("google/gemini-3.1-pro-preview");
expect(result.configPatch).toEqual({
agents: {
defaults: {
model: {
primary: "google/gemini-3.1-pro-preview",
fallbacks: ["google/gemini-3.1-pro-preview", "openai/gpt-5.5"],
},
models: {
"google/gemini-3.1-pro-preview": { alias: "gemini" },
},
},
},
models: {
providers: {
google: {
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
models: [
{
id: "google/gemini-3.1-pro-preview",
name: "Gemini 3 Pro",
contextWindow: 1_048_576,
maxTokens: 65_536,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
reasoning: true,
},
],
},
},
},
});
});
it("omits OAuth expiry values outside the Date timestamp range", () => {
const result = buildOauthProviderAuthResult({
providerId: "google",
defaultModel: "google/gemini-3.1-pro-preview",
access: "access-token",
expires: MAX_DATE_TIMESTAMP_MS + 1,
});
expect(result.profiles[0]?.credential).toEqual({
type: "oauth",
provider: "google",
access: "access-token",
});
});
});