Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package sse_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Tencent/WeKnora/cli/internal/sse"
|
|
sdk "github.com/Tencent/WeKnora/client"
|
|
)
|
|
|
|
func TestAgentAccumulator_FinalizesOnlyOnComplete(t *testing.T) {
|
|
a := &sse.AgentAccumulator{}
|
|
preTerminal := []*sdk.AgentStreamResponse{
|
|
{ResponseType: sdk.AgentResponseTypeThinking, Content: "think", Done: true},
|
|
{ResponseType: sdk.AgentResponseTypeToolCall, ID: "call_1", Content: "search"},
|
|
{ResponseType: sdk.AgentResponseTypeReflection, Content: "reflect", Done: true},
|
|
{ResponseType: sdk.AgentResponseTypeReferences, KnowledgeReferences: []*sdk.SearchResult{
|
|
{ID: "chunk_1", Content: "bulky passage"},
|
|
}},
|
|
{ResponseType: sdk.AgentResponseTypeAnswer, Content: "final answer", Done: true},
|
|
}
|
|
for _, event := range preTerminal {
|
|
a.Append(event)
|
|
if a.Done() {
|
|
t.Fatalf("%s Done=true terminated the whole stream", event.ResponseType)
|
|
}
|
|
}
|
|
|
|
a.Append(&sdk.AgentStreamResponse{ResponseType: sdk.AgentResponseTypeComplete, Done: true})
|
|
if !a.Done() {
|
|
t.Fatal("complete event did not terminate the stream")
|
|
}
|
|
if got := a.Answer(); got != "final answer" {
|
|
t.Errorf("answer=%q, want final answer", got)
|
|
}
|
|
if got := a.Thinking(); got != "thinkreflect" {
|
|
t.Errorf("thinking=%q, want thinkreflect", got)
|
|
}
|
|
if len(a.ToolEvents) != 1 {
|
|
t.Errorf("tool_events=%d, want 1", len(a.ToolEvents))
|
|
}
|
|
if len(a.References) != 1 || a.References[0].Content != "bulky passage" {
|
|
t.Errorf("references were not preserved: %+v", a.References)
|
|
}
|
|
|
|
a.Append(&sdk.AgentStreamResponse{ResponseType: sdk.AgentResponseTypeAnswer, Content: "late"})
|
|
if got := a.Answer(); got != "final answer" {
|
|
t.Errorf("post-complete event was appended: %q", got)
|
|
}
|
|
}
|