@@ -449,6 +449,129 @@ func TestStatusJSONOutput(t *testing.T) {
449449 }
450450}
451451
452+ func TestStatusRoutingModeInTable (t * testing.T ) {
453+ tests := []struct {
454+ name string
455+ routingMode string
456+ expected string
457+ }{
458+ {
459+ name : "retrieve_tools mode" ,
460+ routingMode : "retrieve_tools" ,
461+ expected : "retrieve_tools" ,
462+ },
463+ {
464+ name : "direct mode" ,
465+ routingMode : "direct" ,
466+ expected : "direct" ,
467+ },
468+ {
469+ name : "code_execution mode" ,
470+ routingMode : "code_execution" ,
471+ expected : "code_execution" ,
472+ },
473+ }
474+
475+ for _ , tt := range tests {
476+ t .Run (tt .name , func (t * testing.T ) {
477+ info := & StatusInfo {
478+ State : "Running" ,
479+ Edition : "personal" ,
480+ ListenAddr : "127.0.0.1:8080" ,
481+ APIKey : "a1b2****a1b2" ,
482+ WebUIURL : "http://127.0.0.1:8080/ui/?apikey=test" ,
483+ RoutingMode : tt .routingMode ,
484+ }
485+
486+ old := os .Stdout
487+ r , w , _ := os .Pipe ()
488+ os .Stdout = w
489+
490+ printStatusTable (info )
491+
492+ w .Close ()
493+ os .Stdout = old
494+
495+ buf := make ([]byte , 4096 )
496+ n , _ := r .Read (buf )
497+ output := string (buf [:n ])
498+
499+ if ! strings .Contains (output , "Routing:" ) {
500+ t .Errorf ("expected output to contain 'Routing:', output:\n %s" , output )
501+ }
502+ if ! strings .Contains (output , tt .expected ) {
503+ t .Errorf ("expected output to contain %q, output:\n %s" , tt .expected , output )
504+ }
505+ })
506+ }
507+ }
508+
509+ func TestStatusRoutingModeInJSON (t * testing.T ) {
510+ info := & StatusInfo {
511+ State : "Running" ,
512+ Edition : "personal" ,
513+ ListenAddr : "127.0.0.1:8080" ,
514+ APIKey : "testkey" ,
515+ WebUIURL : "http://127.0.0.1:8080/ui/" ,
516+ RoutingMode : "direct" ,
517+ }
518+
519+ old := os .Stdout
520+ r , w , _ := os .Pipe ()
521+ os .Stdout = w
522+
523+ err := printStatusJSON (info )
524+
525+ w .Close ()
526+ os .Stdout = old
527+
528+ if err != nil {
529+ t .Fatalf ("printStatusJSON failed: %v" , err )
530+ }
531+
532+ buf := make ([]byte , 8192 )
533+ n , _ := r .Read (buf )
534+ output := string (buf [:n ])
535+
536+ var result StatusInfo
537+ if jsonErr := json .Unmarshal ([]byte (output ), & result ); jsonErr != nil {
538+ t .Fatalf ("invalid JSON: %v\n Output: %s" , jsonErr , output )
539+ }
540+
541+ if result .RoutingMode != "direct" {
542+ t .Errorf ("expected routing_mode 'direct', got %q" , result .RoutingMode )
543+ }
544+ }
545+
546+ func TestCollectStatusFromConfigRoutingMode (t * testing.T ) {
547+ t .Run ("uses config routing mode" , func (t * testing.T ) {
548+ cfg := & config.Config {
549+ Listen : "127.0.0.1:8080" ,
550+ APIKey : "testkey" ,
551+ RoutingMode : "direct" ,
552+ }
553+
554+ info := collectStatusFromConfig (cfg , "/tmp/test.sock" , "/tmp/config.json" )
555+
556+ if info .RoutingMode != "direct" {
557+ t .Errorf ("expected routing mode 'direct', got %q" , info .RoutingMode )
558+ }
559+ })
560+
561+ t .Run ("defaults to retrieve_tools when empty" , func (t * testing.T ) {
562+ cfg := & config.Config {
563+ Listen : "127.0.0.1:8080" ,
564+ APIKey : "testkey" ,
565+ }
566+
567+ info := collectStatusFromConfig (cfg , "/tmp/test.sock" , "/tmp/config.json" )
568+
569+ if info .RoutingMode != config .RoutingModeRetrieveTools {
570+ t .Errorf ("expected routing mode %q, got %q" , config .RoutingModeRetrieveTools , info .RoutingMode )
571+ }
572+ })
573+ }
574+
452575// parseTestDuration is a helper to parse duration strings for tests.
453576func parseTestDuration (s string ) (time.Duration , error ) {
454577 return time .ParseDuration (s )
0 commit comments