1- import { describe , expect , it } from "vite-plus/test" ;
1+ import { afterEach , beforeEach , describe , expect , it } from "@effect/vitest" ;
2+ import { vi } from "vite-plus/test" ;
23
34import { ProviderInstanceId , type ProviderOptionSelection } from "@t3tools/contracts" ;
5+ import { getProviderOptionDescriptors } from "@t3tools/shared/model" ;
46
57import type { ModelOption } from "../../lib/modelOptions" ;
8+ import { appAtomRegistry } from "../../state/atom-registry" ;
9+ import { modelOptionMemoryAtom } from "../../state/use-composer-drafts" ;
10+ import {
11+ rememberModelOptions ,
12+ withRememberedModelOptions ,
13+ } from "../../state/use-model-option-memory" ;
614import {
715 canCommitPendingModel ,
816 favoritesFirst ,
@@ -23,7 +31,30 @@ function modelOption(
2331 providerDriver : "codex" ,
2432 isDefault : false ,
2533 isLegacy : false ,
26- capabilities : null ,
34+ capabilities : {
35+ optionDescriptors : [
36+ {
37+ id : "effort" ,
38+ label : "Reasoning" ,
39+ type : "select" ,
40+ options : [
41+ { id : "medium" , label : "Medium" , isDefault : true } ,
42+ { id : "high" , label : "High" } ,
43+ ] ,
44+ currentValue : "medium" ,
45+ } ,
46+ {
47+ id : "serviceTier" ,
48+ label : "Service Tier" ,
49+ type : "select" ,
50+ options : [
51+ { id : "default" , label : "Standard" , isDefault : true } ,
52+ { id : "priority" , label : "Fast" } ,
53+ ] ,
54+ currentValue : "default" ,
55+ } ,
56+ ] ,
57+ } ,
2758 selection : {
2859 instanceId : ProviderInstanceId . make ( "codex" ) ,
2960 model,
@@ -32,6 +63,16 @@ function modelOption(
3263 } ;
3364}
3465
66+ beforeEach ( ( ) => {
67+ vi . useFakeTimers ( ) ;
68+ } ) ;
69+
70+ afterEach ( ( ) => {
71+ vi . clearAllTimers ( ) ;
72+ vi . useRealTimers ( ) ;
73+ appAtomRegistry . set ( modelOptionMemoryAtom , { } ) ;
74+ } ) ;
75+
3576describe ( "thread settings sheet state" , ( ) => {
3677 it ( "keeps favorites in catalog order ahead of other models" , ( ) => {
3778 const models = [
@@ -101,28 +142,68 @@ describe("thread settings sheet state", () => {
101142 ) . toBeNull ( ) ;
102143 } ) ;
103144
104- it ( "preserves staged options when the highlighted model is pressed again" , ( ) => {
145+ it ( "preserves in-progress edits when the staged model is pressed again" , ( ) => {
146+ rememberModelOptions ( "codex" , "gpt-next" , [ { id : "effort" , value : "medium" } ] ) ;
105147 const pending = modelOption ( "gpt-next" , [ { id : "effort" , value : "high" } ] ) ;
106148
107149 expect (
108150 pendingModelAfterPress ( {
109151 current : pending ,
110152 pressed : modelOption ( "gpt-next" ) ,
111153 pressedIsApplied : false ,
112- } ) ,
113- ) . toBe ( pending ) ;
154+ restoreSelection : withRememberedModelOptions ,
155+ } ) ?. selection . options ,
156+ ) . toEqual ( [ { id : "effort" , value : "high" } ] ) ;
157+ } ) ;
158+
159+ it ( "previews remembered options before Save when switching models" , ( ) => {
160+ const remembered = [
161+ { id : "effort" , value : "high" } ,
162+ { id : "serviceTier" , value : "priority" } ,
163+ ] ;
164+ rememberModelOptions ( "codex" , "gpt-other" , remembered ) ;
165+ const pressed = modelOption ( "gpt-other" ) ;
166+
167+ const pending = pendingModelAfterPress ( {
168+ current : modelOption ( "gpt-next" ) ,
169+ pressed,
170+ pressedIsApplied : false ,
171+ restoreSelection : withRememberedModelOptions ,
172+ } ) ;
173+
174+ expect ( pending ?. selection ) . toEqual ( { ...pressed . selection , options : remembered } ) ;
175+ const preview = getProviderOptionDescriptors ( {
176+ caps : pressed . capabilities ! ,
177+ selections : pending ?. selection . options ,
178+ } ) ;
179+ expect ( preview . map ( ( { id, currentValue } ) => ( { id, value : currentValue } ) ) ) . toEqual (
180+ remembered ,
181+ ) ;
182+ expect ( pending ?. selection ) . toEqual ( withRememberedModelOptions ( pressed . selection ) ) ;
114183 } ) ;
115184
116- it ( "stages a different model" , ( ) => {
185+ it ( "keeps catalog defaults for scheduled-task picks even when options are remembered" , ( ) => {
186+ rememberModelOptions ( "codex" , "gpt-other" , [
187+ { id : "effort" , value : "high" } ,
188+ { id : "serviceTier" , value : "priority" } ,
189+ ] ) ;
117190 const pressed = modelOption ( "gpt-other" ) ;
118191
119- expect (
120- pendingModelAfterPress ( {
121- current : modelOption ( "gpt-next" ) ,
122- pressed,
123- pressedIsApplied : false ,
124- } ) ,
125- ) . toBe ( pressed ) ;
192+ const pending = pendingModelAfterPress ( {
193+ current : modelOption ( "gpt-next" ) ,
194+ pressed,
195+ pressedIsApplied : false ,
196+ } ) ;
197+
198+ expect ( pending ?. selection ) . toEqual ( pressed . selection ) ;
199+ const preview = getProviderOptionDescriptors ( {
200+ caps : pressed . capabilities ! ,
201+ selections : pending ?. selection . options ,
202+ } ) ;
203+ expect ( preview . map ( ( { id, currentValue } ) => ( { id, value : currentValue } ) ) ) . toEqual ( [
204+ { id : "effort" , value : "medium" } ,
205+ { id : "serviceTier" , value : "default" } ,
206+ ] ) ;
126207 } ) ;
127208
128209 it ( "cannot select a hidden model exposed only for visibility management" , ( ) => {
0 commit comments