Files
Enterprise-Knowledge-Base/internal/agent/think_stream_error_test.go
T
2026-07-16 00:17:16 +08:00

27 lines
997 B
Go

package agent
import (
"context"
"testing"
"github.com/Tencent/WeKnora/internal/models/chat"
"github.com/Tencent/WeKnora/internal/types"
)
func TestStreamLLMToEventBusRejectsPartialContentAfterStreamError(t *testing.T) {
model := &mockChat{responses: []mockResponse{{chunks: []types.StreamResponse{
{ResponseType: types.ResponseTypeAnswer, Content: "unverified partial"},
{ResponseType: types.ResponseTypeError, Content: "provider failed", Done: true},
{ResponseType: types.ResponseTypeAnswer, Content: "must be ignored", Done: true},
}}}}
engine := &AgentEngine{config: &types.AgentConfig{}, chatModel: model}
result, err := engine.streamLLMToEventBus(context.Background(), []chat.Message{{Role: "user", Content: "inspect image"}}, nil, nil)
if err == nil {
t.Fatal("expected stream error after partial content")
}
if result == nil || result.Content != "unverified partial" {
t.Fatalf("result = %#v; caller needs partial content identified for replacement", result)
}
}