1b98877d88
chat_sessions rows carry activity (turn_running, background_tasks, seq) from the hub's own state, and chat_activity is pushed to every connection when a session's turn starts or ends or its running background-task count changes. A room whose last viewer left stays observed while background tasks run, bounded by the unattended limits; a Claude Code process exit ends its tasks.
56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/coder/websocket/wsjson"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
// adoptingChat finds the session on another harness, as the chat manager does
|
|
// for a Claude Code or Codex session id.
|
|
type adoptingChat struct {
|
|
*fakeChat
|
|
backend string
|
|
asked []string
|
|
}
|
|
|
|
func (a *adoptingChat) AdoptSession(_ context.Context, id, backend string) (protocol.ChatSession, string, bool, error) {
|
|
a.asked = append(a.asked, backend)
|
|
return protocol.ChatSession{ID: id, Directory: "/work/claude"}, a.backend, true, nil
|
|
}
|
|
|
|
func TestChatAdoptRecordsTheOwningHarness(t *testing.T) {
|
|
ctx := context.Background()
|
|
store := newOperatorStore(t)
|
|
broker := &adoptingChat{fakeChat: scriptedChat(), backend: "claude"}
|
|
_, _, conn := dialChatOptions(t, Options{Chat: broker, OperatorRegistry: store})
|
|
const id = "27ca4504-744a-472b-938b-ab497c02aba7"
|
|
request := protocol.ChatAdoptRequest{SessionID: id, Title: "Flutter port"}
|
|
if err := wsjson.Write(ctx, conn, protocol.Message{Type: protocol.ChatAdopt, ID: "a1", ChatAdopt: &request}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var response protocol.Message
|
|
if err := readTestFrame(ctx, conn, &response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.Type != protocol.ChatAdopt || response.ChatSession == nil {
|
|
t.Fatalf("chat_adopt response = %+v", response)
|
|
}
|
|
if got := response.ChatSession; got.Backend != "claude" || got.Title != "Flutter port" || got.Directory != "/work/claude" {
|
|
t.Fatalf("adopted session = %+v", got)
|
|
}
|
|
if len(broker.asked) != 1 || broker.asked[0] != "" {
|
|
t.Fatalf("harness asked = %q, want one search across harnesses", broker.asked)
|
|
}
|
|
row, found, err := store.OperatorSession(ctx, id)
|
|
if err != nil || !found {
|
|
t.Fatalf("registry row = %v %v", found, err)
|
|
}
|
|
if row.Backend != "claude" || row.Title != "Flutter port" || row.Directory != "/work/claude" {
|
|
t.Fatalf("registry row = %+v", row)
|
|
}
|
|
}
|