62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
|
|
package runtime
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"code.tczkiot.com/wlw/ai-agent/contract"
|
||
|
|
"code.tczkiot.com/wlw/ai-agent/internal/ai"
|
||
|
|
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/dto/request"
|
||
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
|
||
|
|
|
||
|
|
"github.com/glebarez/sqlite"
|
||
|
|
"github.com/mlogclub/simple/sqls"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
type evaluationPlatformAIProvider struct{}
|
||
|
|
|
||
|
|
func (evaluationPlatformAIProvider) ModelSource(context.Context) (string, error) {
|
||
|
|
return contract.ModelSourcePlatform, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (evaluationPlatformAIProvider) Config(context.Context) (*contract.PlatformAIConfig, error) {
|
||
|
|
return &contract.PlatformAIConfig{
|
||
|
|
APIKey: "license-signed",
|
||
|
|
BaseURL: "https://platform.example/v1",
|
||
|
|
ModelName: "platform-default",
|
||
|
|
}, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (evaluationPlatformAIProvider) Status(context.Context) (*contract.PlatformAIStatus, error) {
|
||
|
|
return &contract.PlatformAIStatus{Enabled: true}, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestRunAgentEvaluationResolvesPlatformWithoutCustomConfig(t *testing.T) {
|
||
|
|
db, err := gorm.Open(sqlite.Open("file:"+strings.ReplaceAll(t.Name(), "/", "_")+"?mode=memory&cache=shared"), &gorm.Config{})
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("open sqlite: %v", err)
|
||
|
|
}
|
||
|
|
if err := db.AutoMigrate(&models.AIAgent{}); err != nil {
|
||
|
|
t.Fatalf("auto migrate: %v", err)
|
||
|
|
}
|
||
|
|
sqls.SetDB(db)
|
||
|
|
agent := &models.AIAgent{Name: "platform-agent", Status: enums.StatusOk, AIConfigID: 0}
|
||
|
|
if err := db.Create(agent).Error; err != nil {
|
||
|
|
t.Fatalf("create agent: %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
ai.SetPlatformAIProvider(evaluationPlatformAIProvider{})
|
||
|
|
t.Cleanup(func() { ai.SetPlatformAIProvider(nil) })
|
||
|
|
|
||
|
|
report, err := RunAgentEvaluation(context.Background(), request.RunAgentEvaluationRequest{AIAgentID: agent.ID})
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("RunAgentEvaluation() error = %v", err)
|
||
|
|
}
|
||
|
|
if report.Total != 0 || !strings.Contains(report.CSV, "case_id") {
|
||
|
|
t.Fatalf("RunAgentEvaluation() = %+v", report)
|
||
|
|
}
|
||
|
|
}
|