@@ -779,4 +779,48 @@ describe('opencode.core', function()
779779 config_file .get_opencode_config :revert ()
780780 end )
781781 end )
782+
783+ describe (' initialize_current_model' , function ()
784+ it (' keeps the current user-selected model and mode by default' , function ()
785+ state .model .set_model (' openai/gpt-4.1' )
786+ state .model .set_mode (' plan' )
787+ state .renderer .set_messages ({
788+ {
789+ info = {
790+ id = ' m1' ,
791+ providerID = ' anthropic' ,
792+ modelID = ' claude-3-opus' ,
793+ mode = ' build' ,
794+ },
795+ },
796+ })
797+
798+ local model = core .initialize_current_model ():wait ()
799+
800+ assert .equal (' openai/gpt-4.1' , model )
801+ assert .equal (' openai/gpt-4.1' , state .current_model )
802+ assert .equal (' plan' , state .current_mode )
803+ end )
804+
805+ it (' restores the latest session model and mode when explicitly requested' , function ()
806+ state .model .set_model (' openai/gpt-4.1' )
807+ state .model .set_mode (' plan' )
808+ state .renderer .set_messages ({
809+ {
810+ info = {
811+ id = ' m1' ,
812+ providerID = ' anthropic' ,
813+ modelID = ' claude-3-opus' ,
814+ mode = ' build' ,
815+ },
816+ },
817+ })
818+
819+ local model = core .initialize_current_model ({ restore_from_messages = true }):wait ()
820+
821+ assert .equal (' anthropic/claude-3-opus' , model )
822+ assert .equal (' anthropic/claude-3-opus' , state .current_model )
823+ assert .equal (' build' , state .current_mode )
824+ end )
825+ end )
782826end )
0 commit comments