package server import ( "testing" "git.a-wan.net/alan/pipelines/internal/protocol" ) // A live agent report keeps its kind and sender across a resume snapshot, and // is never mistaken for the agent's final reply. func TestHubKeepsInjectedMessageKind(t *testing.T) { h := newChatHub() h.apply(protocol.ChatEventFrame{SessionID: "s", MessageID: "msg_1", Kind: protocol.ChatEventText, Delta: "The answer", Part: &protocol.ChatPart{ID: "msg_1#text#0"}}) h.apply(protocol.ChatEventFrame{ SessionID: "s", MessageID: "agent-report-x", MessageKind: protocol.ChatMessageKindAgentReport, Kind: protocol.ChatEventText, Delta: "## Report", Part: &protocol.ChatPart{ID: "agent-report-x#text#0", Name: "general-purpose"}, }) messages := h.snapshot("s") if len(messages) != 2 || messages[0].Kind != "" || messages[1].Kind != protocol.ChatMessageKindAgentReport || messages[1].Role != protocol.ChatRoleAssistant || messages[1].Parts[0].Name != "general-purpose" || messages[1].Parts[0].Text != "## Report" { t.Fatalf("snapshot: %+v", messages) } h.mu.Lock() reply := h.finalReplyTextLocked("s") h.mu.Unlock() if reply != "The answer" { t.Fatalf("final reply must skip the report, got %q", reply) } }