Files
openclaw/ui/src/lib/chat/thinking.test.ts
T
Peter Steinberger 627e83d4f7 fix(ui): effort slider matches selected level after model switches (#122125)
* fix(ui): align effort picker after model switches

Publish ordered per-model effort profiles from the Gateway and reconcile new-session effort overrides so labels, slider positions, and create payloads stay consistent.

* fix(ci): align model profile contracts
2026-08-11 13:14:11 -07:00

133 lines
4.0 KiB
TypeScript

// Control UI tests cover canonical and legacy thinking-level normalization.
import { describe, expect, it } from "vitest";
import { normalizeThinkLevel } from "../../../../src/auto-reply/thinking.shared.js";
import {
formatThinkingOverrideLabel,
resolveChatThinkingSelectState,
resolveThinkingLevelInput,
} from "./thinking.ts";
describe("chat thinking helpers", () => {
it("keeps literal Ultra distinct from the legacy ultrathink alias", () => {
expect(normalizeThinkLevel("ultra")).toBe("ultra");
expect(normalizeThinkLevel("Ultra")).toBe("ultra");
expect(normalizeThinkLevel("ultrathink")).toBe("high");
expect(formatThinkingOverrideLabel("ultra")).toBe("Ultra");
});
it("accepts Ultra when the gateway advertises it for the session", () => {
expect(
resolveThinkingLevelInput(
"ultra",
{
key: "agent:main:main",
kind: "direct",
updatedAt: 1,
thinkingLevels: [{ id: "ultra", label: "Ultra" }],
},
undefined,
),
).toBe("ultra");
});
it("does not promote an unsupported persisted Ultra override into a slider stop", () => {
const state = resolveChatThinkingSelectState({
catalog: [],
sessionKey: "agent:main:main",
sessionsResult: {
ts: 1,
path: "",
count: 1,
defaults: { modelProvider: null, model: null, contextTokens: null },
sessions: [
{
key: "agent:main:main",
kind: "direct",
updatedAt: 1,
thinkingLevel: "ultra",
thinkingLevels: [{ id: "max", label: "max" }],
},
],
},
});
expect(state.selection).toEqual({
kind: "unanchored",
source: "override",
value: "ultra",
displayLabel: "Ultra",
});
expect(state.options.map((option) => option.value)).toEqual(["max"]);
});
it("does not inherit same-model thinking levels from a different runtime", () => {
const state = resolveChatThinkingSelectState({
catalog: [],
sessionKey: "agent:main:main",
sessionsResult: {
ts: 1,
path: "",
count: 1,
defaults: {
modelProvider: "openai",
model: "gpt-5.6-luna",
contextTokens: null,
agentRuntime: { id: "openclaw", source: "model" },
thinkingLevels: [
{ id: "max", label: "max" },
{ id: "ultra", label: "ultra" },
],
},
sessions: [
{
key: "agent:main:main",
kind: "direct",
updatedAt: 1,
modelProvider: "openai",
model: "gpt-5.6-luna",
agentRuntime: { id: "codex", source: "session-key" },
},
],
},
});
expect(state.options.map((option) => option.value)).not.toContain("ultra");
});
it("uses identical reasoning options for a canonical default and explicit selection", () => {
const thinkingLevels = ["off", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"].map(
(id) => ({ id, label: id }),
);
const defaults = {
modelProvider: "openai",
model: "gpt-5.6-sol",
contextTokens: null,
thinkingLevels,
thinkingOptions: thinkingLevels.map((level) => level.label),
thinkingDefault: "medium",
};
const inherited = resolveChatThinkingSelectState({
catalog: [{ provider: "openai", id: "gpt-5.6-sol", name: "GPT-5.6 Sol", reasoning: true }],
defaults,
sessionKey: "new-session:main",
session: { key: "new-session:main", kind: "direct", updatedAt: null },
sessionsResult: null,
});
const explicit = resolveChatThinkingSelectState({
catalog: [{ provider: "openai", id: "gpt-5.6-sol", name: "GPT-5.6 Sol", reasoning: true }],
defaults,
sessionKey: "new-session:main",
session: {
key: "new-session:main",
kind: "direct",
updatedAt: null,
modelProvider: "openai",
model: "gpt-5.6-sol",
},
sessionsResult: null,
});
expect(explicit).toEqual(inherited);
});
});