147 lines
3.3 KiB
Go
147 lines
3.3 KiB
Go
package llm
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// --- ProviderManager tests ---
|
|
|
|
func TestNewProviderManager_Cov2(t *testing.T) {
|
|
m := NewProviderManager()
|
|
assert.NotNil(t, m)
|
|
}
|
|
|
|
func TestProviderManager_SetAccountModelResolver_Cov2(t *testing.T) {
|
|
m := NewProviderManager()
|
|
m.SetAccountModelResolver(nil)
|
|
// Should not panic
|
|
}
|
|
|
|
func TestProviderManager_Configure_Empty_Cov2(t *testing.T) {
|
|
m := NewProviderManager()
|
|
err := m.Configure(RuntimeProviderConfig{})
|
|
// May error due to no providers configured
|
|
_ = err
|
|
}
|
|
|
|
func TestWithAccountFeature_Cov2(t *testing.T) {
|
|
ctx := WithAccountFeature(context.Background(), 1, "copilot")
|
|
assert.NotNil(t, ctx)
|
|
}
|
|
|
|
func TestWithTemperatureOverride_Cov2(t *testing.T) {
|
|
ctx := WithTemperatureOverride(context.Background(), 0.7)
|
|
assert.NotNil(t, ctx)
|
|
}
|
|
|
|
// --- AnthropicProvider tests ---
|
|
|
|
func TestNewAnthropicProvider_Cov2(t *testing.T) {
|
|
p := NewAnthropicProvider(AnthropicProviderConfig{
|
|
APIKey: "test-key",
|
|
Model: "claude-3-opus",
|
|
})
|
|
assert.NotNil(t, p)
|
|
}
|
|
|
|
func TestNewAnthropicProvider_Defaults_Cov2(t *testing.T) {
|
|
p := NewAnthropicProvider(AnthropicProviderConfig{
|
|
APIKey: "test-key",
|
|
})
|
|
assert.NotNil(t, p)
|
|
}
|
|
|
|
// --- EinoProvider tests ---
|
|
|
|
func TestNewEinoProvider_Cov2(t *testing.T) {
|
|
p := NewEinoProvider(nil, nil)
|
|
assert.NotNil(t, p)
|
|
}
|
|
|
|
func TestEinoProvider_SetFallbackEmbedder_Cov2(t *testing.T) {
|
|
p := NewEinoProvider(nil, nil)
|
|
p.SetFallbackEmbedder(nil)
|
|
// Should not panic
|
|
}
|
|
|
|
// --- OpenAIProvider tests ---
|
|
|
|
func TestNewOpenAIProvider_Cov2(t *testing.T) {
|
|
p := NewOpenAIProvider(OpenAIProviderConfig{
|
|
APIKey: "test-key",
|
|
BaseURL: "http://localhost:8080",
|
|
Model: "gpt-4",
|
|
})
|
|
assert.NotNil(t, p)
|
|
}
|
|
|
|
func TestNewOpenAIProvider_Defaults_Cov2(t *testing.T) {
|
|
p := NewOpenAIProvider(OpenAIProviderConfig{
|
|
APIKey: "test-key",
|
|
})
|
|
assert.NotNil(t, p)
|
|
}
|
|
|
|
// --- ChatRequest / ChatResponse tests ---
|
|
|
|
func TestChatRequest_Struct_Cov2(t *testing.T) {
|
|
req := ChatRequest{
|
|
Messages: []ChatMessage{
|
|
{Role: "user", Content: "hello"},
|
|
},
|
|
Temperature: 0.7,
|
|
MaxTokens: 100,
|
|
}
|
|
assert.Len(t, req.Messages, 1)
|
|
assert.Equal(t, 0.7, req.Temperature)
|
|
}
|
|
|
|
func TestChatResponse_Struct_Cov2(t *testing.T) {
|
|
resp := &ChatResponse{
|
|
ID: "test-id",
|
|
Object: "chat.completion",
|
|
Model: "test-model",
|
|
}
|
|
assert.Equal(t, "test-id", resp.ID)
|
|
}
|
|
|
|
// --- normalizeRuntimeProviderConfig tests ---
|
|
|
|
func TestNormalizeRuntimeProviderConfig_Cov2(t *testing.T) {
|
|
cfg := normalizeRuntimeProviderConfig(RuntimeProviderConfig{})
|
|
// Should not panic and return normalized config
|
|
_ = cfg
|
|
}
|
|
|
|
// --- buildProviderSnapshot tests ---
|
|
|
|
func TestBuildProviderSnapshot_Empty_Cov2(t *testing.T) {
|
|
_, err := buildProviderSnapshot(RuntimeProviderConfig{})
|
|
// Will likely error due to no providers
|
|
_ = err
|
|
}
|
|
|
|
// --- FakeProvider additional tests ---
|
|
|
|
func TestFakeProvider_ChatCompletionStream_Cov2(t *testing.T) {
|
|
p := NewFakeLLMProvider()
|
|
err := p.ChatCompletionStream(context.Background(), ChatRequest{}, func(chunk StreamChunk) error {
|
|
require.NotNil(t, chunk)
|
|
return nil
|
|
})
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestFakeProvider_CreateEmbedding_Cov2(t *testing.T) {
|
|
p := NewFakeLLMProvider()
|
|
resp, err := p.CreateEmbedding(context.Background(), EmbeddingRequest{
|
|
Input: []string{"hello"},
|
|
})
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, resp)
|
|
}
|