Files
ttstd-infinite-canvas/backend/internal/service/channel_models_test.go

41 lines
1.5 KiB
Go

package service
import (
"testing"
"infinite-canvas/backend/internal/model"
)
func TestNormalizeChannelModelContract(t *testing.T) {
channel := &model.ModelChannel{APIKey: "test-key"}
modelKey, capability, protocol, err := normalizeChannelModelContract(channel, ChannelModelRequest{
ModelKey: "models/gpt-test", Capability: "text", Protocol: string(model.ChannelInterfaceChatCompletion),
})
if err != nil {
t.Fatalf("normalizeChannelModelContract() error = %v", err)
}
if modelKey != "gpt-test" || capability != "text" || protocol != model.ChannelInterfaceChatCompletion {
t.Fatalf("contract = %q, %q, %q", modelKey, capability, protocol)
}
}
func TestNormalizeChannelModelContractRejectsCapabilityMismatch(t *testing.T) {
channel := &model.ModelChannel{APIKey: "test-key"}
_, _, _, err := normalizeChannelModelContract(channel, ChannelModelRequest{
ModelKey: "image-test", Capability: "text", Protocol: string(model.ChannelInterfaceOpenAIImage),
})
if err == nil {
t.Fatal("normalizeChannelModelContract() should reject a mismatched capability")
}
}
func TestNormalizeChannelModelContractRequiresJiMengSecret(t *testing.T) {
channel := &model.ModelChannel{APIKey: "access-key"}
_, _, _, err := normalizeChannelModelContract(channel, ChannelModelRequest{
ModelKey: "jimeng-test", Capability: "image", Protocol: string(model.ChannelInterfaceVolcengineJiMengImage),
})
if err == nil {
t.Fatal("normalizeChannelModelContract() should require JiMeng credentials")
}
}