diff --git a/internal/server/chat_multiclient_test.go b/internal/server/chat_multiclient_test.go index 53890952..3bf6fd6b 100644 --- a/internal/server/chat_multiclient_test.go +++ b/internal/server/chat_multiclient_test.go @@ -313,8 +313,9 @@ func TestChatFanoutToSeveralClients(t *testing.T) { name string conn *websocket.Conn }{{"phone", phone}, {"tablet", tablet}} { + // Deltas still queued for a client may arrive joined into one frame. var text strings.Builder - for i := 0; i < 2; i++ { + for i := 0; text.Len() < len("hello"); i++ { frame := nextEvent(t, ctx, client.conn) if frame.Kind != protocol.ChatEventText { t.Fatalf("%s frame %d = %+v, want text", client.name, i, frame) diff --git a/internal/server/chat_test.go b/internal/server/chat_test.go index 5b6513c4..3a03d262 100644 --- a/internal/server/chat_test.go +++ b/internal/server/chat_test.go @@ -549,10 +549,12 @@ func TestChatPromptStreamsEvents(t *testing.T) { t.Fatalf("ack = %+v", ack) } frames := readChatTurn(t, ctx, conn) - if len(frames) != 4 { - t.Fatalf("got %d frames, want 4", len(frames)) + // The two text deltas may arrive joined into one frame. + if len(frames) != 4 && len(frames) != 3 { + t.Fatalf("got %d frames, want 4 (or 3 with the deltas joined)", len(frames)) } sawText, sawStep := false, false + var text strings.Builder for _, frame := range frames { if frame.SessionID != "ses_1" || frame.MessageID != "msg_1" { t.Fatalf("frame missing stable ids: %+v", frame) @@ -560,6 +562,7 @@ func TestChatPromptStreamsEvents(t *testing.T) { switch frame.Kind { case protocol.ChatEventText: sawText = true + text.WriteString(frame.Delta) case protocol.ChatEventStep: sawStep = true if frame.Step == nil || frame.Step.Status != protocol.ChatStepEnded { @@ -567,8 +570,8 @@ func TestChatPromptStreamsEvents(t *testing.T) { } } } - if !sawText || !sawStep { - t.Fatalf("missing text or step frame: %+v", frames) + if !sawText || !sawStep || text.String() != "hello world" { + t.Fatalf("missing text or step frame (text %q): %+v", text.String(), frames) } if prompts, _, _ := broker.counts(); prompts != 1 { t.Fatalf("prompt forwarded %d times, want 1", prompts)