error reporting fixes
This commit is contained in:
@@ -2,6 +2,7 @@ package sidekick
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -148,3 +149,60 @@ func TestTempFileCleanup(t *testing.T) {
|
||||
t.Errorf("leak: before %d, after %d", bc, ac)
|
||||
}
|
||||
}
|
||||
|
||||
type errorLLMClient struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *errorLLMClient) Call(ctx context.Context, model ModelConfig, messages []Message,
|
||||
tools map[string]ToolDefinition, streamCallback, reasoningCallback func(string)) (Message, error) {
|
||||
return Message{}, e.err
|
||||
}
|
||||
|
||||
func TestLLMTimeoutError(t *testing.T) {
|
||||
SetLLMClient(&errorLLMClient{err: ErrLLMTimeout})
|
||||
a := NewSidekick(AgentConfig{MaxIterations: 1}, ModelConfig{}, nil)
|
||||
_, err := a.Run(context.Background(), nil, nil)
|
||||
if !errors.Is(err, ErrLLMTimeout) {
|
||||
t.Errorf("expected ErrLLMTimeout, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMalformedJSONAction(t *testing.T) {
|
||||
mc := &mockLLMClient{responses: []Message{
|
||||
{Content: `{"action": "TOOL_CALL", "params": { "missing_brace": `},
|
||||
}}
|
||||
SetLLMClient(mc)
|
||||
a := NewSidekick(AgentConfig{MaxIterations: 1}, ModelConfig{}, nil)
|
||||
_, err := a.Run(context.Background(), nil, nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "malformed JSON action") {
|
||||
t.Errorf("expected malformed JSON action error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingActionField(t *testing.T) {
|
||||
mc := &mockLLMClient{responses: []Message{
|
||||
{Content: `{"params": {"foo": "bar"}}`},
|
||||
}}
|
||||
SetLLMClient(mc)
|
||||
a := NewSidekick(AgentConfig{MaxIterations: 1}, ModelConfig{}, nil)
|
||||
_, err := a.Run(context.Background(), nil, nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "missing the 'action' field") {
|
||||
t.Errorf("expected missing action field error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlainTextResponse(t *testing.T) {
|
||||
mc := &mockLLMClient{responses: []Message{
|
||||
{Content: `This is a plain text response.`},
|
||||
}}
|
||||
SetLLMClient(mc)
|
||||
a := NewSidekick(AgentConfig{MaxIterations: 1}, ModelConfig{}, nil)
|
||||
res, err := a.Run(context.Background(), nil, nil)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
}
|
||||
if res != "This is a plain text response." {
|
||||
t.Errorf("expected plain text response, got %s", res)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user