@@ -108,6 +108,15 @@ const claudeAdapter = {
108108 planSelectionTransition : ( ) => Effect . succeed ( { type : "apply_on_next_turn" as const } ) ,
109109 openSession : ( ) => Effect . die ( "provider execution is disabled in launch tests" ) ,
110110} as ProviderAdapter . ProviderAdapterV2 [ "Service" ] ;
111+ // A second account of the same provider, configured as its own instance.
112+ const otherCodexModelSelection = {
113+ instanceId : ProviderInstanceId . make ( "codex_work" ) ,
114+ model : modelSelection . model ,
115+ } as const ;
116+ const otherCodexAdapter = {
117+ ...adapter ,
118+ instanceId : otherCodexModelSelection . instanceId ,
119+ } as ProviderAdapter . ProviderAdapterV2 [ "Service" ] ;
111120
112121interface HarnessOptions {
113122 readonly managedFolders ?: Layer . Layer < ManagedProjectFolders . ManagedProjectFolders > ;
@@ -125,7 +134,11 @@ interface HarnessOptions {
125134
126135function makeHarness ( options : HarnessOptions = { } ) {
127136 const layerDatabase = SqlitePersistence . layerMemory ;
128- const layerRegistry = ProviderAdapterRegistry . layerFromAdapters ( [ adapter , claudeAdapter ] ) ;
137+ const layerRegistry = ProviderAdapterRegistry . layerFromAdapters ( [
138+ adapter ,
139+ claudeAdapter ,
140+ otherCodexAdapter ,
141+ ] ) ;
129142 const layerOrchestrator = ProviderReplayHarness . layerWithRegistry (
130143 { name : "thread-launch" } ,
131144 layerRegistry ,
@@ -378,8 +391,17 @@ it.effect.each(
378391 } ,
379392) ;
380393
381- it . effect ( "runs a thread-bound automation on the provider the thread uses now" , ( ) => {
382- const harness = makeHarness ( ) ;
394+ it . effect . each ( [
395+ { switchedTo : "another provider" , selection : claudeModelSelection } ,
396+ { switchedTo : "another account of the same provider" , selection : otherCodexModelSelection } ,
397+ ] ) ( "runs a thread-bound automation on $switchedTo the thread uses now" , ( { selection } ) => {
398+ const harness = makeHarness ( {
399+ serverSettings : {
400+ providerInstances : {
401+ [ otherCodexModelSelection . instanceId ] : { driver : adapter . driver , config : { } } ,
402+ } ,
403+ } ,
404+ } ) ;
383405 const layerScheduledTasks = ScheduledTasks . layer . pipe (
384406 Layer . provide (
385407 Layer . mergeAll (
@@ -413,21 +435,21 @@ it.effect("runs a thread-bound automation on the provider the thread uses now",
413435 createdBy : "agent" ,
414436 creationSource : "mcp" ,
415437 } ) ;
416- // ...and the user then switches the thread to Claude .
438+ // ...and the user then switches the thread away from that instance .
417439 yield * threads . dispatch ( {
418440 type : "thread.model-selection.set" ,
419- commandId : CommandId . make ( "command:switch-to-claude " ) ,
441+ commandId : CommandId . make ( "command:switch-selection " ) ,
420442 threadId : launched . threadId ,
421- modelSelection : claudeModelSelection ,
443+ modelSelection : selection ,
422444 } ) ;
423445
424446 const result = yield * tasks . runNow ( { id : task . id } ) ;
425447 assert . equal ( result . task . lastRunStatus , "succeeded" ) ;
426448 const projection = yield * threads . getThreadProjection ( launched . threadId ) ;
427449 const message = projection . messages . find ( ( item ) => item . scheduledTaskId === task . id ) ;
428450 const run = projection . runs . find ( ( item ) => item . id === message ?. runId ) ;
429- assert . deepStrictEqual ( run ?. modelSelection , claudeModelSelection ) ;
430- assert . deepStrictEqual ( projection . thread . modelSelection , claudeModelSelection ) ;
451+ assert . deepStrictEqual ( run ?. modelSelection , selection ) ;
452+ assert . deepStrictEqual ( projection . thread . modelSelection , selection ) ;
431453 } ) . pipe ( Effect . provide ( Layer . mergeAll ( harness . layer , layerScheduledTasks ) ) ) ;
432454} ) ;
433455
0 commit comments