@@ -28,6 +28,7 @@ import {
2828 buildThreadTurnInterruptInput ,
2929 createLocalDispatchSnapshot ,
3030 deriveComposerSendState ,
31+ deriveLockedProvider ,
3132 dismissBranchMismatchForSession ,
3233 ENVIRONMENT_RECONNECT_WARNING_GRACE_MS ,
3334 getAntigravitySendBlockReason ,
@@ -792,6 +793,113 @@ describe("resolveComposerProviderSelection", () => {
792793 ] ) [ 0 ] ! ;
793794 }
794795
796+ function importedThread ( instanceId : ProviderInstanceId ) {
797+ return makeThread ( {
798+ modelSelection : { instanceId, model : "default" } ,
799+ messages : [
800+ {
801+ id : MessageId . make ( `import:${ instanceId } :session:000000` ) ,
802+ role : "user" ,
803+ text : "Continue the imported conversation" ,
804+ turnId : null ,
805+ createdAt : now ,
806+ updatedAt : now ,
807+ streaming : false ,
808+ } ,
809+ ] ,
810+ } ) ;
811+ }
812+
813+ it . each ( [
814+ [ "claudeAgent" , "claude_work" ] ,
815+ [ "codex" , "codex_work" ] ,
816+ [ "ollama" , "local_models" ] ,
817+ ] ) ( "keeps imported %s history selectable through its custom instance" , ( driver , instanceId ) => {
818+ const importedEntry = entry ( driver , instanceId ) ;
819+ const entries = [ entry ( driver === "codex" ? "claudeAgent" : "codex" ) , importedEntry ] ;
820+ const thread = importedThread ( importedEntry . instanceId ) ;
821+ const lockedProvider = deriveLockedProvider ( {
822+ thread,
823+ selectedProvider : entries [ 0 ] ! . instanceId ,
824+ threadProvider : thread . modelSelection . instanceId ,
825+ providers : entries . map ( ( entry ) => entry . snapshot ) ,
826+ } ) ;
827+
828+ expect ( thread . session ) . toBeNull ( ) ;
829+ expect ( lockedProvider ) . toBe ( driver ) ;
830+ expect (
831+ resolveComposerProviderSelection ( {
832+ entries,
833+ candidateInstanceIds : [ thread . modelSelection . instanceId ] ,
834+ lockedProvider,
835+ lockedInstanceId : thread . modelSelection . instanceId ,
836+ } ) . selectedProviderEntry ?. instanceId ,
837+ ) . toBe ( importedEntry . instanceId ) ;
838+ } ) ;
839+
840+ it ( "keeps the session driver authoritative over instance and draft selections" , ( ) => {
841+ const selected = entry ( "claudeAgent" , "claude_work" ) ;
842+ const sessionEntry = entry ( "ollama" , "local_models" ) ;
843+ const thread = importedThread ( selected . instanceId ) ;
844+
845+ expect (
846+ deriveLockedProvider ( {
847+ thread : {
848+ ...thread ,
849+ session : {
850+ ...readySession ,
851+ providerName : sessionEntry . driverKind ,
852+ providerInstanceId : sessionEntry . instanceId ,
853+ } ,
854+ } ,
855+ selectedProvider : selected . instanceId ,
856+ threadProvider : thread . modelSelection . instanceId ,
857+ providers : [ selected . snapshot , sessionEntry . snapshot ] ,
858+ } ) ,
859+ ) . toBe ( sessionEntry . driverKind ) ;
860+ } ) ;
861+
862+ it . each ( [ "missing" , "disabled" ] as const ) (
863+ "does not move imported history to another driver when its instance is %s" ,
864+ ( state ) => {
865+ const imported = entry ( "claudeAgent" , "claude_work" , { enabled : false } ) ;
866+ const other = entry ( "codex" ) ;
867+ const entries = state === "missing" ? [ other ] : [ other , imported ] ;
868+ const thread = importedThread ( imported . instanceId ) ;
869+ const lockedProvider = deriveLockedProvider ( {
870+ thread,
871+ selectedProvider : other . instanceId ,
872+ threadProvider : thread . modelSelection . instanceId ,
873+ providers : entries . map ( ( entry ) => entry . snapshot ) ,
874+ } ) ;
875+
876+ expect ( lockedProvider ) . not . toBeNull ( ) ;
877+ expect (
878+ resolveComposerProviderSelection ( {
879+ entries,
880+ candidateInstanceIds : [ other . instanceId , imported . instanceId ] ,
881+ lockedProvider,
882+ lockedInstanceId : imported . instanceId ,
883+ } ) . selectedProviderEntry ,
884+ ) . toBeUndefined ( ) ;
885+ } ,
886+ ) ;
887+
888+ it ( "leaves a new draft free to select a different driver" , ( ) => {
889+ const original = entry ( "claudeAgent" , "claude_work" ) ;
890+ const selected = entry ( "codex" , "codex_work" ) ;
891+ expect (
892+ deriveLockedProvider ( {
893+ thread : makeThread ( {
894+ modelSelection : { instanceId : original . instanceId , model : "default" } ,
895+ } ) ,
896+ selectedProvider : selected . instanceId ,
897+ threadProvider : original . instanceId ,
898+ providers : [ original . snapshot , selected . snapshot ] ,
899+ } ) ,
900+ ) . toBeNull ( ) ;
901+ } ) ;
902+
795903 it ( "uses the custom instance's capability instead of the default instance" , ( ) => {
796904 const defaultEntry = entry ( "antigravity" , "antigravity" , {
797905 showInteractionModeToggle : true ,
0 commit comments