Chat tests: accept text deltas joined in a subscriber's queue
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -313,8 +313,9 @@ func TestChatFanoutToSeveralClients(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
conn *websocket.Conn
|
conn *websocket.Conn
|
||||||
}{{"phone", phone}, {"tablet", tablet}} {
|
}{{"phone", phone}, {"tablet", tablet}} {
|
||||||
|
// Deltas still queued for a client may arrive joined into one frame.
|
||||||
var text strings.Builder
|
var text strings.Builder
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; text.Len() < len("hello"); i++ {
|
||||||
frame := nextEvent(t, ctx, client.conn)
|
frame := nextEvent(t, ctx, client.conn)
|
||||||
if frame.Kind != protocol.ChatEventText {
|
if frame.Kind != protocol.ChatEventText {
|
||||||
t.Fatalf("%s frame %d = %+v, want text", client.name, i, frame)
|
t.Fatalf("%s frame %d = %+v, want text", client.name, i, frame)
|
||||||
|
|||||||
@@ -549,10 +549,12 @@ func TestChatPromptStreamsEvents(t *testing.T) {
|
|||||||
t.Fatalf("ack = %+v", ack)
|
t.Fatalf("ack = %+v", ack)
|
||||||
}
|
}
|
||||||
frames := readChatTurn(t, ctx, conn)
|
frames := readChatTurn(t, ctx, conn)
|
||||||
if len(frames) != 4 {
|
// The two text deltas may arrive joined into one frame.
|
||||||
t.Fatalf("got %d frames, want 4", len(frames))
|
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
|
sawText, sawStep := false, false
|
||||||
|
var text strings.Builder
|
||||||
for _, frame := range frames {
|
for _, frame := range frames {
|
||||||
if frame.SessionID != "ses_1" || frame.MessageID != "msg_1" {
|
if frame.SessionID != "ses_1" || frame.MessageID != "msg_1" {
|
||||||
t.Fatalf("frame missing stable ids: %+v", frame)
|
t.Fatalf("frame missing stable ids: %+v", frame)
|
||||||
@@ -560,6 +562,7 @@ func TestChatPromptStreamsEvents(t *testing.T) {
|
|||||||
switch frame.Kind {
|
switch frame.Kind {
|
||||||
case protocol.ChatEventText:
|
case protocol.ChatEventText:
|
||||||
sawText = true
|
sawText = true
|
||||||
|
text.WriteString(frame.Delta)
|
||||||
case protocol.ChatEventStep:
|
case protocol.ChatEventStep:
|
||||||
sawStep = true
|
sawStep = true
|
||||||
if frame.Step == nil || frame.Step.Status != protocol.ChatStepEnded {
|
if frame.Step == nil || frame.Step.Status != protocol.ChatStepEnded {
|
||||||
@@ -567,8 +570,8 @@ func TestChatPromptStreamsEvents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !sawText || !sawStep {
|
if !sawText || !sawStep || text.String() != "hello world" {
|
||||||
t.Fatalf("missing text or step frame: %+v", frames)
|
t.Fatalf("missing text or step frame (text %q): %+v", text.String(), frames)
|
||||||
}
|
}
|
||||||
if prompts, _, _ := broker.counts(); prompts != 1 {
|
if prompts, _, _ := broker.counts(); prompts != 1 {
|
||||||
t.Fatalf("prompt forwarded %d times, want 1", prompts)
|
t.Fatalf("prompt forwarded %d times, want 1", prompts)
|
||||||
|
|||||||
Reference in New Issue
Block a user