Files
openclaw/extensions/xai/doctor-contract-api.test.ts
Peter Steinberger edecdbd05e refactor(config): config-surface reduction tranche 3 — product consolidations (review request) (#111527)
* refactor(config): consolidate media model lists

* refactor(config): unify memory configuration

* refactor(config): consolidate TTS ownership

* refactor(config): move typing policy to agents

* refactor(config): retire product-level config surfaces

* refactor(config): share scoped tool policy type

* chore(config): refresh generated baselines

* fix(config): honor agent typing overrides

* fix(config): migrate sibling config consumers

* refactor(infra): keep base64url decoder private

* fix(config): strip invalid legacy TTS values

* chore(config): refresh rebased baseline hash

* fix(doctor): route legacy messages.tts.realtime voice to talk during tts move

* refactor(config): polish final layout names

* refactor(config): freeze retired tuning defaults

* feat(config): add fast mode default symmetry

* refactor(config): key agent entries by id

* docs(config): update final layout reference

* test(config): cover final layout migrations

* chore(config): refresh final layout baselines

* fix(config): align final layout runtime readers

* fix(config): align remaining readers

* fix(config): stabilize final layout migrations

* fix(config): finalize config projection proof

* fix(config): address final layout review

* docs(release): preserve historical config names

* fix(config): complete keyed agent migration

* fix(config): close final migration gaps

* fix(config): finish full-branch review

* fix(config): complete runtime secret detection

* fix(config): close final review findings

* fix(config): finish canonical docs and heartbeat migration

* fix(config): integrate latest main after rebase

* refactor(env): isolate test-only controls

* refactor(env): isolate build and development controls

* refactor(env): collapse process identity indirection

* refactor(env): remove duplicate config and temp aliases

* docs(env): define the operator-facing allowlist

* ci(env): ratchet production variable count

* fix(env): remove stale provider helper import

* fix(env): make ratchet sorting explicit

* test(env): keep test seam in dead-code audit

* test(env): cover ratchet growth and boundary; document surface budgets

* docs(config): document tier-eval consolidations

* docs(config): clarify speech preference ownership

* test(memory): align retired tuning fixtures

* refactor(memory): freeze engine heuristics

* refactor(config): apply tier-eval tranche

* refactor(tts): move persona shaping to providers

* refactor(compaction): move prompt policy to providers

* test(config): align hookified prompt fixtures

* chore(deadcode): classify test-only exports

* chore(github): remove unused spawn helper

* chore(deadcode): classify queue diagnostics

* chore(deadcode): remove unused lane snapshot export

* chore(plugin-sdk): ratchet consolidated surface

* fix(config): integrate latest main after rebase
2026-07-21 20:28:43 -07:00

168 lines
5.8 KiB
TypeScript

// Xai tests cover plugin-owned doctor compatibility migrations.
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import { describe, expect, it } from "vitest";
import { legacyConfigRules, normalizeCompatibilityConfig } from "./doctor-contract-api.js";
describe("xAI doctor contract", () => {
it("detects and migrates retired server-tool defaults without changing other settings", () => {
const config = {
plugins: {
entries: {
xai: {
config: {
webSearch: { model: "grok-4-1-fast", timeoutSeconds: 60 },
xSearch: { model: "grok-4-1-fast-non-reasoning", inlineCitations: true },
codeExecution: { model: "grok-code-fast-1", maxTurns: 2 },
},
},
},
},
tools: {
web: {
search: { grok: { model: "grok-4-0709", baseUrl: "https://api.x.ai/v1" } },
x_search: { model: "grok-3", enabled: true },
},
},
models: {
providers: {
xai: {
baseUrl: "https://api.x.ai/v1",
api: "openai-responses",
models: [
{
id: "grok-4-1-fast",
name: "Grok 4.1 Fast",
reasoning: true,
input: ["text", "image"],
cost: { input: 0.2, output: 0.5, cacheRead: 0.05, cacheWrite: 0 },
contextWindow: 2_000_000,
maxTokens: 30_000,
},
{
id: "grok-3-mini",
name: "Custom Grok 3 Mini",
reasoning: true,
input: ["text"],
cost: { input: 0.3, output: 0.5, cacheRead: 0.075, cacheWrite: 0 },
contextWindow: 131_072,
maxTokens: 8_192,
},
{ id: "grok-4.20-beta-latest-reasoning", name: "moving alias" },
{ id: "custom-model", name: "custom" },
],
},
},
},
} as OpenClawConfig;
expect(
legacyConfigRules.filter((rule) => rule.match(readPathForTest(config, rule.path))),
).toHaveLength(4);
const result = normalizeCompatibilityConfig({ cfg: config });
expect(result.changes).toHaveLength(4);
expect(result.config).not.toBe(config);
expect(result.config.plugins?.entries?.xai?.config).toEqual({
webSearch: { model: "grok-4.3", timeoutSeconds: 60 },
xSearch: { model: "grok-4.3", inlineCitations: true },
codeExecution: { model: "grok-build-0.1", maxTurns: 2 },
});
expect(result.config.tools?.web).toEqual(config.tools?.web);
expect(result.config.models?.providers?.xai?.models).toEqual([
{
id: "grok-3-mini",
name: "Custom Grok 3 Mini",
reasoning: true,
input: ["text"],
cost: { input: 0.3, output: 0.5, cacheRead: 0.075, cacheWrite: 0 },
contextWindow: 131_072,
maxTokens: 8_192,
},
{ id: "grok-4.20-beta-latest-reasoning", name: "moving alias" },
{ id: "custom-model", name: "custom" },
]);
expect(config.plugins?.entries?.xai?.config).toMatchObject({
webSearch: { model: "grok-4-1-fast" },
});
expect(config.models?.providers?.xai?.models).toHaveLength(4);
expect(normalizeCompatibilityConfig({ cfg: result.config })).toEqual({
config: result.config,
changes: [],
});
});
it("leaves active aliases and intentional cross-mode choices unchanged", () => {
const config = {
plugins: {
entries: {
xai: {
config: {
webSearch: { model: "grok-4.20-beta-latest-reasoning" },
xSearch: { model: "grok-4-1-fast" },
codeExecution: { model: "grok-4-fast-non-reasoning" },
},
},
},
},
} as OpenClawConfig;
expect(normalizeCompatibilityConfig({ cfg: config })).toEqual({ config, changes: [] });
});
it("removes only the obsolete xAI STT model selector from media entries", () => {
const config = {
tools: {
media: {
models: [
{
provider: " xAI ",
model: " GROK-STT ",
language: "en",
timeoutSeconds: 30,
},
{ type: "provider", provider: "xai", model: "custom-stt" },
{ type: "provider", provider: "openai", model: "grok-stt" },
{ type: "cli", provider: "xai", model: "grok-stt", command: "whisper" },
{ provider: "x-ai", model: "grok-stt" },
{ provider: "xai" },
],
},
},
} as unknown as OpenClawConfig;
expect(
legacyConfigRules.filter((rule) => rule.match(readPathForTest(config, rule.path))),
).toHaveLength(1);
const result = normalizeCompatibilityConfig({ cfg: config });
expect(result.changes).toHaveLength(1);
expect(result.config).not.toBe(config);
expect(result.config.tools?.media?.models).toEqual([
{ provider: " xAI ", language: "en", timeoutSeconds: 30 },
{ type: "provider", provider: "xai", model: "custom-stt" },
{ type: "provider", provider: "openai", model: "grok-stt" },
{ type: "cli", provider: "xai", model: "grok-stt", command: "whisper" },
{ provider: "x-ai", model: "grok-stt" },
{ provider: "xai" },
]);
expect(config.tools?.media?.models?.[0]).toHaveProperty("model", " GROK-STT ");
expect(normalizeCompatibilityConfig({ cfg: result.config })).toEqual({
config: result.config,
changes: [],
});
});
});
function readPathForTest(root: unknown, path: readonly (string | number)[]): unknown {
let current = root;
for (const segment of path) {
if (!current || typeof current !== "object") {
return undefined;
}
current = (current as Record<string | number, unknown>)[segment];
}
return current;
}