@@ -320,19 +320,103 @@ describe("scheduled task model options", () => {
320320 } ;
321321
322322 it ( "uses the same saved reasoning and speed options for display and saving" , ( ) => {
323- expect ( resolveScheduledTaskModelSelection ( { instanceId, model : "model-a" } , saved ) ) . toBe ( saved ) ;
323+ expect (
324+ resolveScheduledTaskModelSelection (
325+ { instanceId, model : "model-a" } ,
326+ saved ,
327+ DEFAULT_SERVER_SETTINGS ,
328+ null ,
329+ ) ,
330+ ) . toBe ( saved ) ;
324331 } ) ;
325332
326333 it ( "does not carry options into a different model or provider" , ( ) => {
327334 const differentModel = { instanceId, model : "model-b" } ;
328335 const differentProvider = { instanceId : ProviderInstanceId . make ( "other" ) , model : "model-a" } ;
329- expect ( resolveScheduledTaskModelSelection ( differentModel , saved ) ) . toBe ( differentModel ) ;
330- expect ( resolveScheduledTaskModelSelection ( differentProvider , saved ) ) . toBe ( differentProvider ) ;
336+ const settings = { ...DEFAULT_SERVER_SETTINGS , defaultModelSelection : saved } ;
337+ expect ( resolveScheduledTaskModelSelection ( differentModel , saved , settings , null ) ) . toBe (
338+ differentModel ,
339+ ) ;
340+ expect ( resolveScheduledTaskModelSelection ( differentProvider , saved , settings , null ) ) . toBe (
341+ differentProvider ,
342+ ) ;
343+ } ) ;
344+
345+ it ( "retains selected default options and cannot revive an unavailable selection" , ( ) => {
346+ const settings = { ...DEFAULT_SERVER_SETTINGS , defaultModelSelection : saved } ;
347+ expect ( resolveScheduledTaskModelSelection ( saved , null , settings , null ) ) . toBe ( saved ) ;
348+ expect ( resolveScheduledTaskModelSelection ( null , saved , settings , null ) ) . toBeNull ( ) ;
331349 } ) ;
332350
333- it ( "retains project default options and cannot revive an unavailable selection" , ( ) => {
334- expect ( resolveScheduledTaskModelSelection ( saved , null ) ) . toBe ( saved ) ;
335- expect ( resolveScheduledTaskModelSelection ( null , saved ) ) . toBeNull ( ) ;
351+ it . each ( [ "environment" , "project override" , "legacy project" ] as const ) (
352+ "restores configured reasoning and speed when switching to the %s default" ,
353+ ( scope ) => {
354+ const projectId = ProjectId . make ( "project" ) ;
355+ const destination = { instanceId, model : "model-b" } ;
356+ const configured = {
357+ ...destination ,
358+ options : [
359+ { id : "reasoningEffort" , value : "high" } ,
360+ { id : "serviceTier" , value : "priority" } ,
361+ ] ,
362+ } ;
363+ const settings = {
364+ ...DEFAULT_SERVER_SETTINGS ,
365+ defaultModelSelection : scope === "environment" ? configured : saved ,
366+ projectSettingsOverrides :
367+ scope === "project override"
368+ ? { [ projectId ] : { defaultModelSelection : configured } }
369+ : { } ,
370+ } ;
371+ const project =
372+ scope === "legacy project"
373+ ? { id : projectId , defaultModelSelection : configured }
374+ : { id : projectId } ;
375+
376+ expect ( resolveScheduledTaskModelSelection ( destination , null , settings , project ) ) . toEqual (
377+ configured ,
378+ ) ;
379+ } ,
380+ ) ;
381+
382+ it ( "prefers project options while preserving explicitly cleared task options" , ( ) => {
383+ const projectId = ProjectId . make ( "project" ) ;
384+ const projectDefault = {
385+ ...saved ,
386+ options : [ { id : "reasoningEffort" , value : "low" } ] ,
387+ } ;
388+ const settings = {
389+ ...DEFAULT_SERVER_SETTINGS ,
390+ defaultModelSelection : saved ,
391+ projectSettingsOverrides : { [ projectId ] : { defaultModelSelection : projectDefault } } ,
392+ } ;
393+ const selection = { instanceId, model : saved . model } ;
394+ const cleared = { ...selection , options : [ ] } ;
395+ expect (
396+ resolveScheduledTaskModelSelection ( selection , null , settings , { id : projectId } ) ,
397+ ) . toEqual ( projectDefault ) ;
398+ expect (
399+ resolveScheduledTaskModelSelection ( selection , cleared , settings , { id : projectId } ) ,
400+ ) . toEqual ( cleared ) ;
401+ expect (
402+ resolveScheduledTaskModelSelection ( selection , saved , settings , { id : projectId } ) ,
403+ ) . toEqual ( saved ) ;
404+ } ) ;
405+
406+ it ( "uses matching environment options when the project defaults to another model" , ( ) => {
407+ const settings = { ...DEFAULT_SERVER_SETTINGS , defaultModelSelection : saved } ;
408+ const project = {
409+ id : ProjectId . make ( "project" ) ,
410+ defaultModelSelection : { ...saved , model : "model-b" } ,
411+ } ;
412+ expect (
413+ resolveScheduledTaskModelSelection (
414+ { instanceId, model : saved . model } ,
415+ null ,
416+ settings ,
417+ project ,
418+ ) ,
419+ ) . toEqual ( saved ) ;
336420 } ) ;
337421} ) ;
338422
0 commit comments