113 lines
4.3 KiB
Go
113 lines
4.3 KiB
Go
package dto
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"browser.local/platform/domain"
|
|
)
|
|
|
|
func TestAIProviderResponseExposesOnlyKeyReference(t *testing.T) {
|
|
responseType := reflect.TypeOf(AIProviderResponse{})
|
|
if _, ok := responseType.FieldByName("APIKey"); ok {
|
|
t.Fatal("AI provider response must not expose raw API key")
|
|
}
|
|
if _, ok := responseType.FieldByName("RawAPIKey"); ok {
|
|
t.Fatal("AI provider response must not expose raw API key")
|
|
}
|
|
if _, ok := responseType.FieldByName("APIKeyRef"); !ok {
|
|
t.Fatal("AI provider response must expose API key reference")
|
|
}
|
|
}
|
|
|
|
func TestAIProviderFromDomainCopiesModels(t *testing.T) {
|
|
provider := domain.AIProvider{
|
|
ID: "ai.openai",
|
|
Name: "OpenAI",
|
|
Kind: domain.AIProviderKindOpenAI,
|
|
BaseURL: "https://api.openai.com/v1",
|
|
APIKeyRef: "secret://providers/openai",
|
|
Models: []string{"gpt-4.1"},
|
|
DefaultModel: "gpt-4.1",
|
|
RelayMode: domain.AIRelayModeDirect,
|
|
TimeoutMS: 30000,
|
|
Status: domain.AIProviderStatusActive,
|
|
RedactionPolicy: "default",
|
|
}
|
|
|
|
response := AIProviderFromDomain(provider)
|
|
response.Models[0] = "mutated"
|
|
|
|
if provider.Models[0] != "gpt-4.1" {
|
|
t.Fatalf("expected response models to be copied, got source models %+v", provider.Models)
|
|
}
|
|
if response.APIKeyRef != provider.APIKeyRef {
|
|
t.Fatalf("expected API key reference to be preserved, got %q", response.APIKeyRef)
|
|
}
|
|
}
|
|
|
|
func TestGamePluginManifestRegistrationToDomainCopiesSlices(t *testing.T) {
|
|
request := GamePluginManifestRegistrationRequest{
|
|
ManifestRef: "artifact://manifests/game.example/0.1.0",
|
|
Manifest: GamePluginManifestBody{
|
|
ID: "game.example",
|
|
Name: "Example Server",
|
|
Version: "0.1.0",
|
|
Kind: "game-plugin",
|
|
Tags: []string{"example"},
|
|
Capabilities: []string{"process.start"},
|
|
Permissions: []string{"server.lifecycle"},
|
|
Server: GamePluginManifestServerBody{
|
|
Type: "example",
|
|
DisplayName: "Example Server",
|
|
SupportedOS: []string{"linux"},
|
|
CreateFormSchema: "schemas/create-form.schema.json",
|
|
},
|
|
Actions: PluginLifecycleActionsBody{Install: "actions/install.json", Start: "actions/start.json", Stop: "actions/stop.json"},
|
|
Pages: []GamePluginPageBody{
|
|
{Key: "logs", Title: "Logs", Path: "/logs", Permissions: []string{"server.logs.read"}},
|
|
},
|
|
AI: GamePluginManifestAIBody{Purposes: []string{"logs.diagnose"}},
|
|
},
|
|
}
|
|
|
|
domainRegistration := request.ToDomain()
|
|
domainRegistration.Manifest.Tags[0] = "mutated"
|
|
domainRegistration.Manifest.Server.SupportedOS[0] = "darwin"
|
|
domainRegistration.Manifest.Pages[0].Permissions[0] = "ai.invoke"
|
|
domainRegistration.Manifest.AI.Purposes[0] = "config.suggest"
|
|
|
|
if request.Manifest.Tags[0] != "example" || request.Manifest.Server.SupportedOS[0] != "linux" || request.Manifest.Pages[0].Permissions[0] != "server.logs.read" || request.Manifest.AI.Purposes[0] != "logs.diagnose" {
|
|
t.Fatalf("expected manifest request slices to be copied, got %+v", request)
|
|
}
|
|
}
|
|
|
|
func TestGamePluginFromDomainCopiesRegistryMetadata(t *testing.T) {
|
|
plugin := domain.GamePlugin{
|
|
ID: "game.example",
|
|
Name: "Example Server",
|
|
Version: "0.1.0",
|
|
ServerType: "example",
|
|
RequiredRunCapabilities: []string{"process.start"},
|
|
DeclaredPermissions: []string{"server.lifecycle"},
|
|
SupportedOS: []string{"linux"},
|
|
Pages: []domain.GamePluginPage{
|
|
{Key: "logs", Title: "Logs", Path: "/logs", Permissions: []string{"server.logs.read"}},
|
|
},
|
|
Tags: []string{"example"},
|
|
AIPurposes: []string{"logs.diagnose"},
|
|
}
|
|
|
|
response := GamePluginFromDomain(plugin)
|
|
response.RequiredRunCapabilities[0] = "files.read"
|
|
response.DeclaredPermissions[0] = "ai.invoke"
|
|
response.SupportedOS[0] = "darwin"
|
|
response.Pages[0].Permissions[0] = "ai.invoke"
|
|
response.Tags[0] = "mutated"
|
|
response.AIPurposes[0] = "config.suggest"
|
|
|
|
if plugin.RequiredRunCapabilities[0] != "process.start" || plugin.DeclaredPermissions[0] != "server.lifecycle" || plugin.SupportedOS[0] != "linux" || plugin.Pages[0].Permissions[0] != "server.logs.read" || plugin.Tags[0] != "example" || plugin.AIPurposes[0] != "logs.diagnose" {
|
|
t.Fatalf("expected plugin response registry metadata to be copied, got %+v", plugin)
|
|
}
|
|
}
|