@@ -462,4 +462,153 @@ describe("claudecode.init", function()
462
462
assert .is_nil (call_args [2 ], " Second argument should be nil when no args provided" )
463
463
end )
464
464
end )
465
+
466
+ describe (" ClaudeCodeSelectModel command with arguments" , function ()
467
+ local mock_terminal
468
+ local mock_ui_select
469
+ local mock_vim_cmd
470
+
471
+ before_each (function ()
472
+ mock_terminal = {
473
+ toggle = spy .new (function () end ),
474
+ simple_toggle = spy .new (function () end ),
475
+ focus_toggle = spy .new (function () end ),
476
+ open = spy .new (function () end ),
477
+ close = spy .new (function () end ),
478
+ }
479
+
480
+ -- Mock vim.ui.select to automatically select the first model
481
+ mock_ui_select = spy .new (function (models , opts , callback )
482
+ -- Simulate user selecting the first model
483
+ callback (models [1 ])
484
+ end )
485
+
486
+ -- Mock vim.cmd to capture command execution
487
+ mock_vim_cmd = spy .new (function (cmd ) end )
488
+
489
+ vim .ui = vim .ui or {}
490
+ vim .ui .select = mock_ui_select
491
+ vim .cmd = mock_vim_cmd
492
+
493
+ local original_require = _G .require
494
+ _G .require = function (mod )
495
+ if mod == " claudecode.terminal" then
496
+ return mock_terminal
497
+ elseif mod == " claudecode.server.init" then
498
+ return mock_server
499
+ elseif mod == " claudecode.lockfile" then
500
+ return mock_lockfile
501
+ elseif mod == " claudecode.selection" then
502
+ return mock_selection
503
+ else
504
+ return original_require (mod )
505
+ end
506
+ end
507
+ end )
508
+
509
+ it (" should register ClaudeCodeSelectModel command with correct configuration" , function ()
510
+ local claudecode = require (" claudecode" )
511
+ claudecode .setup ({ auto_start = false })
512
+
513
+ local command_found = false
514
+ for _ , call in ipairs (vim .api .nvim_create_user_command .calls ) do
515
+ if call .vals [1 ] == " ClaudeCodeSelectModel" then
516
+ command_found = true
517
+ local config = call .vals [3 ]
518
+ assert .is_equal (" *" , config .nargs )
519
+ assert .is_true (
520
+ string.find (config .desc , " model.*arguments" ) ~= nil ,
521
+ " Description should mention model and arguments"
522
+ )
523
+ break
524
+ end
525
+ end
526
+ assert .is_true (command_found , " ClaudeCodeSelectModel command was not registered" )
527
+ end )
528
+
529
+ it (" should call ClaudeCode command with model arg when no additional args provided" , function ()
530
+ local claudecode = require (" claudecode" )
531
+ claudecode .setup ({ auto_start = false })
532
+
533
+ -- Find and call the ClaudeCodeSelectModel command handler
534
+ local command_handler
535
+ for _ , call in ipairs (vim .api .nvim_create_user_command .calls ) do
536
+ if call .vals [1 ] == " ClaudeCodeSelectModel" then
537
+ command_handler = call .vals [2 ]
538
+ break
539
+ end
540
+ end
541
+
542
+ assert .is_function (command_handler , " Command handler should be a function" )
543
+
544
+ command_handler ({ args = " " })
545
+
546
+ -- Verify vim.ui.select was called
547
+ assert (# mock_ui_select .calls > 0 , " vim.ui.select was not called" )
548
+
549
+ -- Verify vim.cmd was called with the correct ClaudeCode command
550
+ assert (# mock_vim_cmd .calls > 0 , " vim.cmd was not called" )
551
+ local cmd_arg = mock_vim_cmd .calls [1 ].vals [1 ]
552
+ assert .is_equal (" ClaudeCode --model opus" , cmd_arg , " Should call ClaudeCode with model arg" )
553
+ end )
554
+
555
+ it (" should call ClaudeCode command with model and additional args" , function ()
556
+ local claudecode = require (" claudecode" )
557
+ claudecode .setup ({ auto_start = false })
558
+
559
+ -- Find and call the ClaudeCodeSelectModel command handler
560
+ local command_handler
561
+ for _ , call in ipairs (vim .api .nvim_create_user_command .calls ) do
562
+ if call .vals [1 ] == " ClaudeCodeSelectModel" then
563
+ command_handler = call .vals [2 ]
564
+ break
565
+ end
566
+ end
567
+
568
+ assert .is_function (command_handler , " Command handler should be a function" )
569
+
570
+ command_handler ({ args = " --resume --verbose" })
571
+
572
+ -- Verify vim.ui.select was called
573
+ assert (# mock_ui_select .calls > 0 , " vim.ui.select was not called" )
574
+
575
+ -- Verify vim.cmd was called with the correct ClaudeCode command including additional args
576
+ assert (# mock_vim_cmd .calls > 0 , " vim.cmd was not called" )
577
+ local cmd_arg = mock_vim_cmd .calls [1 ].vals [1 ]
578
+ assert .is_equal (
579
+ " ClaudeCode --model opus --resume --verbose" ,
580
+ cmd_arg ,
581
+ " Should call ClaudeCode with model and additional args"
582
+ )
583
+ end )
584
+
585
+ it (" should handle user cancellation gracefully" , function ()
586
+ local claudecode = require (" claudecode" )
587
+ claudecode .setup ({ auto_start = false })
588
+
589
+ -- Mock vim.ui.select to simulate user cancellation
590
+ vim .ui .select = spy .new (function (models , opts , callback )
591
+ callback (nil ) -- User cancelled
592
+ end )
593
+
594
+ -- Find and call the ClaudeCodeSelectModel command handler
595
+ local command_handler
596
+ for _ , call in ipairs (vim .api .nvim_create_user_command .calls ) do
597
+ if call .vals [1 ] == " ClaudeCodeSelectModel" then
598
+ command_handler = call .vals [2 ]
599
+ break
600
+ end
601
+ end
602
+
603
+ assert .is_function (command_handler , " Command handler should be a function" )
604
+
605
+ command_handler ({ args = " --resume" })
606
+
607
+ -- Verify vim.ui.select was called
608
+ assert (# vim .ui .select .calls > 0 , " vim.ui.select was not called" )
609
+
610
+ -- Verify vim.cmd was NOT called due to user cancellation
611
+ assert .is_equal (0 , # mock_vim_cmd .calls , " vim.cmd should not be called when user cancels" )
612
+ end )
613
+ end )
465
614
end )
0 commit comments