功能修改
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"browser.local/platform/domain"
|
||||
)
|
||||
|
||||
func TestAIProviderResponseExposesOnlyKeyPresence(t *testing.T) {
|
||||
func TestAIProviderResponseExposesOnlySecretPresence(t *testing.T) {
|
||||
responseType := reflect.TypeOf(AIProviderResponse{})
|
||||
if _, ok := responseType.FieldByName("BaseURL"); ok {
|
||||
t.Fatal("AI provider response must not expose the provider base URL")
|
||||
}
|
||||
if _, ok := responseType.FieldByName("APIKey"); ok {
|
||||
t.Fatal("AI provider response must not expose raw API key")
|
||||
}
|
||||
@@ -21,6 +25,9 @@ func TestAIProviderResponseExposesOnlyKeyPresence(t *testing.T) {
|
||||
if _, ok := responseType.FieldByName("APIKeyConfigured"); !ok {
|
||||
t.Fatal("AI provider response must expose API key presence")
|
||||
}
|
||||
if _, ok := responseType.FieldByName("BaseURLConfigured"); !ok {
|
||||
t.Fatal("AI provider response must expose base URL presence")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAIProviderFromDomainCopiesModels(t *testing.T) {
|
||||
@@ -47,6 +54,9 @@ func TestAIProviderFromDomainCopiesModels(t *testing.T) {
|
||||
if !response.APIKeyConfigured {
|
||||
t.Fatal("expected configured API key presence")
|
||||
}
|
||||
if !response.BaseURLConfigured {
|
||||
t.Fatal("expected configured base URL presence")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGamePluginManifestRegistrationToDomainCopiesSlices(t *testing.T) {
|
||||
@@ -113,3 +123,49 @@ func TestGamePluginFromDomainCopiesRegistryMetadata(t *testing.T) {
|
||||
t.Fatalf("expected plugin response registry metadata to be copied, got %+v", plugin)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGameClientBridgeQueryTemplateDeclarationRoundTripIsSafe(t *testing.T) {
|
||||
body := GameClientBridgeManifestBody{
|
||||
QueryTemplates: []GameClientBridgeQueryTemplateDeclarationBody{{
|
||||
Key: "player.lookup", Title: "Player lookup", Permission: "server.game-client.read", Engine: "sqlite", TransportKey: "sqlite-db", TargetKey: "db/sqlite",
|
||||
ParameterSchemaRef: "schemas/bridge/query/player-lookup.parameters.schema.json", ResultSchemaRef: "schemas/bridge/query/player-lookup.result.schema.json", MaxRows: 50, TimeoutSeconds: 10,
|
||||
}},
|
||||
CommandRetentionSeconds: 86400,
|
||||
MaxCommands: 1000,
|
||||
Pages: []GameClientBridgePageContractBody{{PageKey: "players", QueryTemplateKeys: []string{"player.lookup"}}},
|
||||
}
|
||||
|
||||
domainManifest := body.ToDomain()
|
||||
if len(domainManifest.QueryTemplates) != 1 || domainManifest.QueryTemplates[0].TransportKey != "sqlite-db" || domainManifest.QueryTemplates[0].MaxRows != 50 || domainManifest.Pages[0].QueryTemplateKeys[0] != "player.lookup" {
|
||||
t.Fatalf("query template conversion lost declaration fields: %#v", domainManifest)
|
||||
}
|
||||
domainManifest.Pages[0].QueryTemplateKeys[0] = "mutated"
|
||||
if body.Pages[0].QueryTemplateKeys[0] != "player.lookup" {
|
||||
t.Fatal("query template page keys alias request DTO data")
|
||||
}
|
||||
domainManifest.Pages[0].QueryTemplateKeys[0] = "player.lookup"
|
||||
|
||||
response := gameClientBridgeManifestFromDomain(domainManifest)
|
||||
response.Pages[0].QueryTemplateKeys[0] = "mutated"
|
||||
if domainManifest.Pages[0].QueryTemplateKeys[0] != "player.lookup" {
|
||||
t.Fatal("query template page keys alias domain data")
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(response.QueryTemplates[0])
|
||||
if err != nil {
|
||||
t.Fatalf("marshal safe query template projection: %v", err)
|
||||
}
|
||||
var projection map[string]any
|
||||
if err := json.Unmarshal(encoded, &projection); err != nil {
|
||||
t.Fatalf("decode safe query template projection: %v", err)
|
||||
}
|
||||
expectedFields := []string{"key", "title", "permission", "engine", "transportKey", "targetKey", "parameterSchemaRef", "resultSchemaRef", "maxRows", "timeoutSeconds"}
|
||||
if len(projection) != len(expectedFields) {
|
||||
t.Fatalf("query template projection contains unexpected fields: %s", encoded)
|
||||
}
|
||||
for _, field := range expectedFields {
|
||||
if _, exists := projection[field]; !exists {
|
||||
t.Fatalf("query template projection is missing %q: %s", field, encoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user