Files
Peter Steinberger 153a6f59bf test: stop re-evaluating plugin module graphs for every test case (#131522)
The doctor contract registry suites called vi.resetModules() plus a dynamic
re-import in beforeEach, so all 54 cases re-evaluated the whole doctor owner
graph: setup policy, migration adapters, config normalization, loader state,
and native/SDK alias resolution. Load once in beforeAll instead and keep the
per-case mock resets, loader injection, cache clearing, and temp-dir cleanup
where they were. setup-registry.test.ts already used this shape.

doctor-contract-registry.test.ts: 29.7s -> 18.2s (-39%), import 508ms -> 136ms.

Also narrow imports that pulled broad graphs in for static work:
seven files reached createEmptyPluginRegistry through registry.js (the whole
registry construction graph) instead of its real owner registry-empty.js;
three provider tests imported api.js, paying for transport streaming,
provider auth, and image-generation SDK graphs to test string normalization;
and provider-utils.test.ts used importActual() to spread a runtime whose only
used export it immediately replaced.

Neither provider barrel suite actually asserted the narrowed exports, so add
explicit re-export assertions in extensions/{google,xai}/api.test.ts rather
than let that coverage lapse.

Unrelated flake fixed in passing: hooks.correlation.test.ts spawns a tsx
subprocess under a 3s deadline, which is killed under load and reports
status null. It failed 3/3 on unmodified code and passes 4/4 at 30s. No
assertion changed.

Test-only change: zero production LOC.
2026-08-27 21:45:58 -07:00

117 lines
3.9 KiB
TypeScript

// Google tests cover default model plugin behavior.
import type { OpenClawConfig } from "openclaw/plugin-sdk/provider-onboard";
import { describe, expect, it } from "vitest";
import { applyGoogleGeminiModelDefault, GOOGLE_GEMINI_DEFAULT_MODEL } from "./onboard.js";
describe("google default model", () => {
it("sets defaults when model is unset", () => {
const cfg: OpenClawConfig = { agents: { defaults: {} } };
const applied = applyGoogleGeminiModelDefault(cfg);
expect(applied.changed).toBe(true);
expect(applied.next.agents?.defaults?.model).toEqual({ primary: GOOGLE_GEMINI_DEFAULT_MODEL });
});
it("overrides existing models", () => {
const applied = applyGoogleGeminiModelDefault({
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
} as OpenClawConfig);
expect(applied.changed).toBe(true);
expect(applied.next.agents?.defaults?.model).toEqual({ primary: GOOGLE_GEMINI_DEFAULT_MODEL });
});
it("normalizes retired Gemini model map keys when applying the default", () => {
const applied = applyGoogleGeminiModelDefault({
agents: {
defaults: {
model: {
primary: "google/gemini-3-pro-preview",
fallbacks: ["google/gemini-3-pro-preview"],
},
models: {
"google/gemini-3-pro-preview": { alias: "gemini" },
},
},
},
} as OpenClawConfig);
expect(applied.changed).toBe(true);
expect(applied.next.agents?.defaults?.model).toEqual({
primary: "google/gemini-3.1-pro-preview",
fallbacks: ["google/gemini-3.1-pro-preview"],
});
expect(applied.next.agents?.defaults?.models).toEqual({
"google/gemini-3.1-pro-preview": { alias: "gemini" },
});
});
it("normalizes retired Gemini model maps even when the primary is already current", () => {
const applied = applyGoogleGeminiModelDefault({
agents: {
defaults: {
model: {
primary: GOOGLE_GEMINI_DEFAULT_MODEL,
fallbacks: ["google/gemini-3-pro-preview"],
},
models: {
"google/gemini-3-pro-preview": { alias: "gemini" },
},
},
},
} as OpenClawConfig);
expect(applied.changed).toBe(true);
expect(applied.next.agents?.defaults?.model).toEqual({
primary: GOOGLE_GEMINI_DEFAULT_MODEL,
fallbacks: [GOOGLE_GEMINI_DEFAULT_MODEL],
});
expect(applied.next.agents?.defaults?.models).toEqual({
[GOOGLE_GEMINI_DEFAULT_MODEL]: { alias: "gemini" },
});
});
it("normalizes retired Gemini provider catalog rows when the primary is already current", () => {
const applied = applyGoogleGeminiModelDefault({
agents: {
defaults: {
model: {
primary: GOOGLE_GEMINI_DEFAULT_MODEL,
},
},
},
models: {
providers: {
google: {
api: "google-generative-ai",
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
models: [
{
id: "google/gemini-3-pro-preview",
name: "Gemini 3 Pro",
contextWindow: 1_000_000,
maxTokens: 8192,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
reasoning: true,
},
],
},
},
},
} as OpenClawConfig);
expect(applied.changed).toBe(true);
expect(applied.next.models?.providers?.google?.models?.map((model) => model.id)).toEqual([
GOOGLE_GEMINI_DEFAULT_MODEL,
]);
});
it("no-ops when already on the target default", () => {
const cfg = {
agents: { defaults: { model: { primary: GOOGLE_GEMINI_DEFAULT_MODEL } } },
} as OpenClawConfig;
const applied = applyGoogleGeminiModelDefault(cfg);
expect(applied.changed).toBe(false);
expect(applied.next).toEqual(cfg);
});
});