package agents import ( "slices" "testing" ) // TestOpenCodeACPRuntime_RequiresProcessKill is the regression test for GH // issue #1247: opencode acp keeps its HTTP server + MCP child tree alive // when stdin closes, so its RuntimeConfig must signal that the process // group has to be killed on shutdown. Without this flag the ACP adapter // returns RequiresProcessKill=false and the process manager only closes // stdin — opencode never exits and MCP children leak. func TestOpenCodeACPRuntime_RequiresProcessKill(t *testing.T) { rt := NewOpenCodeACP().Runtime() if rt == nil { t.Fatal("Runtime() returned nil") } if !rt.RequiresProcessKill { t.Error("RequiresProcessKill = false; opencode acp must opt into process-group kill") } } // TestACPAgents_DefaultProcessKill confirms the rest of the ACP agents // stick with the default (false). They communicate over plain stdin/stdout // and exit on EOF, so the process manager's graceful-stdin-close path is // the correct shutdown signal — flipping this true would force-kill agents // that are perfectly capable of cleanup. func TestACPAgents_DefaultProcessKill(t *testing.T) { cases := []struct { name string agent Agent }{ {"claude", NewClaudeACP()}, {"codex", NewCodexACP()}, {"cursor", NewCursorACP()}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { rt := tc.agent.Runtime() if rt == nil { t.Fatalf("%s Runtime() returned nil", tc.name) } if rt.RequiresProcessKill { t.Errorf("%s RequiresProcessKill = true; expected default false", tc.name) } }) } } func TestOpenCodeACPRemoteAuth(t *testing.T) { auth := NewOpenCodeACP().RemoteAuth() if auth == nil { t.Fatal("RemoteAuth() returned nil; expected files-based auth method") } if len(auth.Methods) != 1 { t.Fatalf("Methods len = %d, want 1", len(auth.Methods)) } m := auth.Methods[0] if m.Type != "files" { t.Errorf("Type = %q, want %q", m.Type, "files") } if m.TargetRelDir != ".local/share/opencode" { t.Errorf("TargetRelDir = %q, want %q", m.TargetRelDir, ".local/share/opencode") } want := []string{".local/share/opencode/auth.json"} for _, os := range []string{"darwin", "linux"} { got := m.SourceFiles[os] if !slices.Equal(got, want) { t.Errorf("SourceFiles[%q] = %v, want %v", os, got, want) } } }