@@ -439,6 +439,59 @@ func TestProcessMessage_UsesRouteSessionKey(t *testing.T) {
439439 }
440440}
441441
442+ func TestProcessDirectWithChannel_PreservesExplicitSessionKey (t * testing.T ) {
443+ tmpDir , err := os .MkdirTemp ("" , "agent-test-*" )
444+ if err != nil {
445+ t .Fatalf ("Failed to create temp dir: %v" , err )
446+ }
447+ defer os .RemoveAll (tmpDir )
448+
449+ cfg := & config.Config {
450+ Agents : config.AgentsConfig {
451+ Defaults : config.AgentDefaults {
452+ Workspace : tmpDir ,
453+ Model : "test-model" ,
454+ MaxTokens : 4096 ,
455+ MaxToolIterations : 10 ,
456+ },
457+ },
458+ }
459+
460+ msgBus := bus .NewMessageBus ()
461+ provider := & simpleMockProvider {response : "ok" }
462+ al := NewAgentLoop (cfg , msgBus , provider )
463+
464+ const sessionKey = "custom-session"
465+ response , err := al .ProcessDirectWithChannel (
466+ context .Background (),
467+ "hello" ,
468+ sessionKey ,
469+ "cli" ,
470+ "direct" ,
471+ )
472+ if err != nil {
473+ t .Fatalf ("ProcessDirectWithChannel() error = %v" , err )
474+ }
475+ if response != "ok" {
476+ t .Fatalf ("response = %q, want %q" , response , "ok" )
477+ }
478+
479+ defaultAgent := al .registry .GetDefaultAgent ()
480+ if defaultAgent == nil {
481+ t .Fatal ("No default agent found" )
482+ }
483+ history := defaultAgent .Sessions .GetHistory (sessionKey )
484+ if len (history ) != 2 {
485+ t .Fatalf ("history len = %d, want 2" , len (history ))
486+ }
487+ if history [0 ].Role != "user" || history [0 ].Content != "hello" {
488+ t .Fatalf ("unexpected user message: %+v" , history [0 ])
489+ }
490+ if history [1 ].Role != "assistant" || history [1 ].Content != "ok" {
491+ t .Fatalf ("unexpected assistant message: %+v" , history [1 ])
492+ }
493+ }
494+
442495func TestProcessMessage_CommandOutcomes (t * testing.T ) {
443496 tmpDir , err := os .MkdirTemp ("" , "agent-test-*" )
444497 if err != nil {
0 commit comments