|
| 1 | +import { scopeThreadRef } from "@t3tools/client-runtime/environment"; |
| 2 | +import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; |
| 3 | +import { |
| 4 | + EnvironmentId, |
| 5 | + ProviderDriverKind, |
| 6 | + ProviderInstanceId, |
| 7 | + ThreadId, |
| 8 | + type ServerProvider, |
| 9 | +} from "@t3tools/contracts"; |
| 10 | +import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings"; |
| 11 | +import { createModelSelection } from "@t3tools/shared/model"; |
| 12 | +import { expect, it } from "vite-plus/test"; |
| 13 | +import { page } from "vite-plus/test/browser"; |
| 14 | + |
| 15 | +import { render } from "../../../test/render"; |
| 16 | +import { useComposerDraftStore } from "../../composerDraftStore"; |
| 17 | +import { useComposerSelection } from "./useComposerSelection"; |
| 18 | + |
| 19 | +const environmentId = EnvironmentId.make("environment-local"); |
| 20 | +const threadRef = scopeThreadRef(environmentId, ThreadId.make("thread-cursor")); |
| 21 | +const cursor = ProviderInstanceId.make("cursor"); |
| 22 | +const stored = createModelSelection(cursor, "claude-opus-5-5", [{ id: "effort", value: "medium" }]); |
| 23 | + |
| 24 | +const providers: ReadonlyArray<ServerProvider> = [ |
| 25 | + { |
| 26 | + instanceId: cursor, |
| 27 | + driver: ProviderDriverKind.make("cursor"), |
| 28 | + enabled: true, |
| 29 | + installed: true, |
| 30 | + version: null, |
| 31 | + status: "ready", |
| 32 | + auth: { status: "authenticated" }, |
| 33 | + checkedAt: "2026-01-01T00:00:00.000Z", |
| 34 | + models: [{ slug: "auto-smart", name: "Auto", isCustom: false, capabilities: {} }], |
| 35 | + slashCommands: [], |
| 36 | + skills: [], |
| 37 | + }, |
| 38 | +]; |
| 39 | + |
| 40 | +// The hook reads only the thread's identity and stored selection. |
| 41 | +const activeThread = { |
| 42 | + environmentId, |
| 43 | + id: threadRef.threadId, |
| 44 | + modelSelection: stored, |
| 45 | +} as EnvironmentThreadShell; |
| 46 | + |
| 47 | +function Picker() { |
| 48 | + const { onProviderModelSelectStable } = useComposerSelection({ |
| 49 | + environmentId, |
| 50 | + composerDraftTarget: threadRef, |
| 51 | + draftThread: null, |
| 52 | + activeThread, |
| 53 | + activeRuntime: null, |
| 54 | + activeProjectSettings: { settings: { newWorktreesStartFromOrigin: false } }, |
| 55 | + settings: DEFAULT_UNIFIED_SETTINGS, |
| 56 | + providerStatuses: providers, |
| 57 | + lockedProvider: null, |
| 58 | + supportsProviderSwitchingViaHandoff: false, |
| 59 | + multipleModelSelections: null, |
| 60 | + runtimeMode: "full-access", |
| 61 | + interactionMode: "default", |
| 62 | + interactionModeEnabled: true, |
| 63 | + isLocalDraftThread: false, |
| 64 | + canOverrideServerThreadEnvMode: false, |
| 65 | + setPendingServerThreadEnvModeEntry: () => {}, |
| 66 | + setPendingServerThreadStartFromOriginByThreadId: () => {}, |
| 67 | + scheduleComposerFocus: () => {}, |
| 68 | + }); |
| 69 | + return ( |
| 70 | + <button type="button" onClick={() => onProviderModelSelectStable(cursor, stored.model)}> |
| 71 | + Pick the stored model |
| 72 | + </button> |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +it("keeps a Cursor thread's stored model when the user re-picks its unavailable row", async () => { |
| 77 | + await using _screen = await render(<Picker />); |
| 78 | + await page.getByRole("button", { name: "Pick the stored model" }).click(); |
| 79 | + |
| 80 | + expect( |
| 81 | + useComposerDraftStore.getState().getComposerDraft(threadRef)?.modelSelectionByProvider[cursor] |
| 82 | + ?.model, |
| 83 | + ).toBe("claude-opus-5-5"); |
| 84 | +}); |
0 commit comments