@@ -337,4 +337,68 @@ describe('opencode.core', function()
337337 assert .is_true (core .opencode_ok ())
338338 end )
339339 end )
340+
341+ describe (' switch_to_mode' , function ()
342+ it (' sets current model from config file when mode has a model configured' , function ()
343+ stub (config_file , ' get_opencode_agents' ).returns ({ ' plan' , ' build' , ' custom' })
344+ stub (config_file , ' get_opencode_config' ).returns ({
345+ agent = {
346+ custom = {
347+ model = ' anthropic/claude-3-opus' ,
348+ },
349+ },
350+ })
351+
352+ state .current_mode = nil
353+ state .current_model = nil
354+
355+ local success = core .switch_to_mode (' custom' )
356+
357+ assert .is_true (success )
358+ assert .equal (' custom' , state .current_mode )
359+ assert .equal (' anthropic/claude-3-opus' , state .current_model )
360+
361+ config_file .get_opencode_agents :revert ()
362+ config_file .get_opencode_config :revert ()
363+ end )
364+
365+ it (' does not change current model when mode has no model configured' , function ()
366+ stub (config_file , ' get_opencode_agents' ).returns ({ ' plan' , ' build' })
367+ stub (config_file , ' get_opencode_config' ).returns ({
368+ agent = {
369+ plan = {},
370+ },
371+ })
372+
373+ state .current_mode = nil
374+ state .current_model = ' existing/model'
375+
376+ local success = core .switch_to_mode (' plan' )
377+
378+ assert .is_true (success )
379+ assert .equal (' plan' , state .current_mode )
380+ assert .equal (' existing/model' , state .current_model )
381+
382+ config_file .get_opencode_agents :revert ()
383+ config_file .get_opencode_config :revert ()
384+ end )
385+
386+ it (' returns false when mode is invalid' , function ()
387+ stub (config_file , ' get_opencode_agents' ).returns ({ ' plan' , ' build' })
388+
389+ local success = core .switch_to_mode (' nonexistent' )
390+
391+ assert .is_false (success )
392+
393+ config_file .get_opencode_agents :revert ()
394+ end )
395+
396+ it (' returns false when mode is empty' , function ()
397+ local success = core .switch_to_mode (' ' )
398+ assert .is_false (success )
399+
400+ success = core .switch_to_mode (nil )
401+ assert .is_false (success )
402+ end )
403+ end )
340404end )
0 commit comments