|
1 | 1 | import fs from "node:fs"; |
2 | 2 | import os from "node:os"; |
3 | 3 | import path from "node:path"; |
4 | | -import { afterEach, describe, expect, test } from "vitest"; |
| 4 | +import { afterEach, describe, expect, test, vi } from "vitest"; |
5 | 5 | import { resetConfigRuntimeState, setRuntimeConfigSnapshot } from "../config/config.js"; |
6 | 6 | import type { OpenClawConfig } from "../config/config.js"; |
7 | 7 | import type { SessionEntry } from "../config/sessions.js"; |
@@ -201,6 +201,93 @@ describe("gateway session utils", () => { |
201 | 201 | expect(row.thinkingDefault).toBe("medium"); |
202 | 202 | }); |
203 | 203 |
|
| 204 | + test("session list memoizes repeated thinking enrichment per provider model", async () => { |
| 205 | + const resolveThinkingProfile = vi.fn(() => ({ |
| 206 | + levels: [{ id: "off" as const }, { id: "medium" as const }], |
| 207 | + defaultLevel: "medium" as const, |
| 208 | + })); |
| 209 | + const registry = createEmptyPluginRegistry(); |
| 210 | + registry.providers.push({ |
| 211 | + pluginId: "test", |
| 212 | + source: "test", |
| 213 | + provider: { |
| 214 | + id: "openai-codex", |
| 215 | + label: "OpenAI Codex", |
| 216 | + auth: [], |
| 217 | + resolveThinkingProfile, |
| 218 | + }, |
| 219 | + }); |
| 220 | + setActivePluginRegistry(registry); |
| 221 | + |
| 222 | + const cfg = createModelDefaultsConfig({ primary: "openai-codex/gpt-5.5" }); |
| 223 | + const store = Object.fromEntries( |
| 224 | + Array.from({ length: 5 }, (_value, index) => [ |
| 225 | + `session-${index}`, |
| 226 | + { |
| 227 | + sessionId: `session-${index}`, |
| 228 | + modelProvider: "openai-codex", |
| 229 | + model: "gpt-5.5", |
| 230 | + updatedAt: Date.now() - index, |
| 231 | + } satisfies SessionEntry, |
| 232 | + ]), |
| 233 | + ); |
| 234 | + |
| 235 | + const result = await listSessionsFromStoreAsync({ |
| 236 | + cfg, |
| 237 | + storePath: "", |
| 238 | + store, |
| 239 | + opts: {}, |
| 240 | + }); |
| 241 | + |
| 242 | + expect(result.sessions).toHaveLength(5); |
| 243 | + expect(resolveThinkingProfile).toHaveBeenCalledTimes(3); |
| 244 | + }); |
| 245 | + |
| 246 | + test("session list thinking cache preserves case-distinct model catalog entries", async () => { |
| 247 | + const cfg = createModelDefaultsConfig({ primary: "custom/CaseModel" }); |
| 248 | + const modelCatalog = [ |
| 249 | + { |
| 250 | + provider: "custom", |
| 251 | + id: "CaseModel", |
| 252 | + name: "CaseModel", |
| 253 | + reasoning: true, |
| 254 | + compat: { supportedReasoningEfforts: ["low", "medium", "high", "xhigh"] }, |
| 255 | + }, |
| 256 | + { |
| 257 | + provider: "custom", |
| 258 | + id: "casemodel", |
| 259 | + name: "casemodel", |
| 260 | + reasoning: true, |
| 261 | + compat: { supportedReasoningEfforts: ["low", "medium", "high"] }, |
| 262 | + }, |
| 263 | + ]; |
| 264 | + const result = await listSessionsFromStoreAsync({ |
| 265 | + cfg, |
| 266 | + storePath: "", |
| 267 | + modelCatalog, |
| 268 | + store: { |
| 269 | + upper: { |
| 270 | + sessionId: "upper", |
| 271 | + modelProvider: "custom", |
| 272 | + model: "CaseModel", |
| 273 | + updatedAt: 2, |
| 274 | + } satisfies SessionEntry, |
| 275 | + lower: { |
| 276 | + sessionId: "lower", |
| 277 | + modelProvider: "custom", |
| 278 | + model: "casemodel", |
| 279 | + updatedAt: 1, |
| 280 | + } satisfies SessionEntry, |
| 281 | + }, |
| 282 | + opts: {}, |
| 283 | + }); |
| 284 | + |
| 285 | + const upper = result.sessions.find((session) => session.key === "upper"); |
| 286 | + const lower = result.sessions.find((session) => session.key === "lower"); |
| 287 | + expect(upper?.thinkingLevels?.map((level) => level.id)).toContain("xhigh"); |
| 288 | + expect(lower?.thinkingLevels?.map((level) => level.id)).not.toContain("xhigh"); |
| 289 | + }); |
| 290 | + |
204 | 291 | test("session defaults and rows expose xhigh from configured catalog compat", () => { |
205 | 292 | const cfg = createModelDefaultsConfig({ primary: "gmn/gpt-5.4" }); |
206 | 293 | const catalog = [ |
|
0 commit comments