| 1 | import { afterEach, beforeEach, describe, expect, it } from "@effect/vitest"; |
| 2 | import { vi } from "vite-plus/test"; |
| 3 | |
| 4 | import { appAtomRegistry } from "./atom-registry"; |
| 5 | import { modelOptionMemoryAtom } from "./use-composer-drafts"; |
| 6 | import { |
| 7 | rememberModelOptions, |
| 8 | rememberedModelOptions, |
| 9 | withRememberedModelOptions, |
| 10 | } from "./use-model-option-memory"; |
| 11 | |
| 12 | const XHIGH = [{ id: "thinking", value: "xhigh" }] as const; |
| 13 | const HIGH = [{ id: "thinking", value: "high" }] as const; |
| 14 | |
| 15 | beforeEach(() => { |
| 16 | vi.useFakeTimers(); |
| 17 | }); |
| 18 | |
| 19 | afterEach(() => { |
| 20 | vi.clearAllTimers(); |
| 21 | vi.useRealTimers(); |
| 22 | appAtomRegistry.set(modelOptionMemoryAtom, {}); |
| 23 | }); |
| 24 | |
| 25 | describe("model option memory state", () => { |
| 26 | it("records and looks up options per instance and model", () => { |
| 27 | rememberModelOptions("codex", "gpt-5.3-codex", [...XHIGH]); |
| 28 | rememberModelOptions("codex", "gpt-5.4", [...HIGH]); |
| 29 | expect(rememberedModelOptions("codex", "gpt-5.3-codex")).toEqual(XHIGH); |
| 30 | expect(rememberedModelOptions("codex", "gpt-5.4")).toEqual(HIGH); |
| 31 | expect(rememberedModelOptions("pi", "gpt-5.3-codex")).toBeUndefined(); |
| 32 | }); |
| 33 | |
| 34 | it("ignores empty option sets when recording", () => { |
| 35 | rememberModelOptions("codex", "gpt-5.4", []); |
| 36 | expect(rememberedModelOptions("codex", "gpt-5.4")).toBeUndefined(); |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | describe("withRememberedModelOptions", () => { |
| 41 | it("restores the remembered options over descriptor defaults", () => { |
| 42 | rememberModelOptions("codex", "gpt-5.3-codex", [...XHIGH]); |
| 43 | expect( |
| 44 | withRememberedModelOptions({ |
| 45 | instanceId: "codex", |
| 46 | model: "gpt-5.3-codex", |
| 47 | options: [{ id: "reasoningEffort", value: "low" }], |
| 48 | }), |
| 49 | ).toEqual({ instanceId: "codex", model: "gpt-5.3-codex", options: XHIGH }); |
| 50 | }); |
| 51 | |
| 52 | it("keeps incoming selections that already match memory", () => { |
| 53 | rememberModelOptions("pi", "xai/grok-4.6", [...XHIGH]); |
| 54 | const selection = { instanceId: "pi", model: "xai/grok-4.6", options: [...XHIGH] }; |
| 55 | expect(withRememberedModelOptions(selection)).toBe(selection); |
| 56 | }); |
| 57 | |
| 58 | it("keeps incoming selections when nothing is remembered", () => { |
| 59 | const selection = { instanceId: "pi", model: "openai-codex/gpt-5.6-sol" }; |
| 60 | expect(withRememberedModelOptions(selection)).toBe(selection); |
| 61 | }); |
| 62 | }); |