Files
ai-agent/internal/handlers/dashboard/ai_agent_handler_test.go
T
mlogclub 847f688398 Refactor AI Agent configuration and workflow handling
- Removed runtime mode handling from AIAgentConfigWorkbench and related components.
- Updated tests to reflect changes in AI Agent policy copy and configuration.
- Changed terminology from "workflow" to "revision" in various components and API responses.
- Simplified agent binding logic in channel editing.
- Cleaned up unused variables and types related to runtime modes.
- Updated localization files for consistency with new terminology.
2026-07-27 23:29:02 +08:00

52 lines
1.3 KiB
Go

package dashboard
import (
"testing"
"agent-desk/internal/models"
"github.com/glebarez/sqlite"
"github.com/mlogclub/simple/sqls"
"gorm.io/gorm"
)
func TestBuildAIAgentResponseExposesPublishedRevision(t *testing.T) {
setupAIAgentHandlerTestDB(t)
published := buildAIAgentResponse(&models.AIAgent{PublishedRevisionID: 12})
if published.PublishedRevisionID != 12 {
t.Fatalf("published revision = %d, want 12", published.PublishedRevisionID)
}
rollout := buildAIAgentResponse(&models.AIAgent{RolloutPercent: 20, PreviousRolloutPercent: 100})
if rollout.RolloutPercent != 20 || rollout.PreviousRolloutPercent != 100 {
t.Fatalf("unexpected rollout response: %#v", rollout)
}
}
func setupAIAgentHandlerTestDB(t *testing.T) {
t.Helper()
db, err := gorm.Open(sqlite.Open("file:"+t.Name()+"?mode=memory&cache=shared"), &gorm.Config{})
if err != nil {
t.Fatalf("open sqlite db: %v", err)
}
sqlDB, err := db.DB()
if err != nil {
t.Fatalf("get sqlite db: %v", err)
}
t.Cleanup(func() {
if err := sqlDB.Close(); err != nil {
t.Fatalf("close sqlite db: %v", err)
}
})
if err := db.AutoMigrate(
&models.AIConfig{},
&models.AgentTeam{},
&models.KnowledgeBase{},
&models.SkillDefinition{},
); err != nil {
t.Fatalf("auto migrate: %v", err)
}
sqls.SetDB(db)
}