@@ -13,7 +13,9 @@ import (
1313 "testing"
1414 "time"
1515
16+ "github.com/BackendStack21/kode/internal/config"
1617 "github.com/BackendStack21/kode/internal/loop"
18+ "github.com/BackendStack21/kode/internal/skills"
1719 "github.com/BackendStack21/kode/internal/telegram"
1820)
1921
@@ -468,6 +470,90 @@ func TestOnCommandStop_NoRunInfoWhenTaskCancelledEarly(t *testing.T) {
468470 }
469471}
470472
473+ // ── /new command handler test ──────────────────────────────────────
474+
475+ // TestOnCommandNew_SessionStartMessage verifies that /new returns a
476+ // rich session-start message with model, sandbox, verbose, and repo info.
477+ func TestOnCommandNew_SessionStartMessage (t * testing.T ) {
478+ chatID := int64 (99910 )
479+
480+ // Create a session store backed by a temp directory.
481+ store := newTestSessionStore (t )
482+ sm := telegram .NewSessionManager (store , 1 * time .Hour )
483+
484+ // Populate a session so there's something to delete.
485+ sm .GetOrCreate (chatID )
486+
487+ // Build a ResolvedConfig with known values.
488+ resolved := config.ResolvedConfig {
489+ Model : "deepseek-v4-flash" ,
490+ Sandbox : true ,
491+ GithubRepoDirectory : "/home/user/projects/odek" ,
492+ Skills : skills.SkillsConfig {Verbose : true },
493+ }
494+
495+ bot := newTestBot (t )
496+ h := newTestHandler (bot )
497+
498+ // Wire OnCommand with the same logic as telegram.go.
499+ h .OnCommand = func (cid int64 , mid int , cmdName string , argsStr string ) (string , error ) {
500+ if cmdName == "new" {
501+ sm .Delete (cid )
502+ // ResetApprover not needed for this test.
503+ var b strings.Builder
504+ b .WriteString ("🔄 *New session started*\n \n " )
505+ b .WriteString (fmt .Sprintf ("• Model: `%s`\n " , resolved .Model ))
506+ if resolved .Sandbox {
507+ b .WriteString ("• Sandbox: enabled\n " )
508+ }
509+ if resolved .Skills .Verbose {
510+ b .WriteString ("• Skills verbose: on\n " )
511+ }
512+ if resolved .GithubRepoDirectory != "" {
513+ repo := filepath .Base (resolved .GithubRepoDirectory )
514+ b .WriteString (fmt .Sprintf ("• Repo: `%s`\n " , repo ))
515+ }
516+ b .WriteString ("\n _Send a message to begin._" )
517+ return b .String (), nil
518+ }
519+ return "" , nil
520+ }
521+
522+ result , err := h .OnCommand (chatID , 0 , "new" , "" )
523+ if err != nil {
524+ t .Fatalf ("OnCommand /new returned error: %v" , err )
525+ }
526+
527+ // Verify the enhanced message contains all expected elements.
528+ if ! strings .Contains (result , "New session started" ) {
529+ t .Errorf ("expected 'New session started', got: %q" , result )
530+ }
531+ if ! strings .Contains (result , "deepseek-v4-flash" ) {
532+ t .Errorf ("expected model name, got: %q" , result )
533+ }
534+ if ! strings .Contains (result , "Sandbox: enabled" ) {
535+ t .Errorf ("expected sandbox status, got: %q" , result )
536+ }
537+ if ! strings .Contains (result , "Skills verbose: on" ) {
538+ t .Errorf ("expected skills verbose, got: %q" , result )
539+ }
540+ if ! strings .Contains (result , "odek" ) {
541+ t .Errorf ("expected repo name 'odek', got: %q" , result )
542+ }
543+ if ! strings .Contains (result , "Send a message to begin" ) {
544+ t .Errorf ("expected prompt to begin, got: %q" , result )
545+ }
546+
547+ // Verify the session was actually deleted.
548+ cs , err := sm .Load (chatID )
549+ if err != nil {
550+ t .Fatalf ("Load after delete: %v" , err )
551+ }
552+ if cs != nil {
553+ t .Errorf ("expected nil session after delete, got %+v" , cs )
554+ }
555+ }
556+
471557// ── Test helpers ───────────────────────────────────────────────────
472558
473559// newTestBot creates a telegram.Bot pointed at a mock server for testing.
0 commit comments