功能修改

This commit is contained in:
npc0-hue
2026-07-20 16:42:33 +08:00
parent 48b8ad8d6c
commit a0e69417db
224 changed files with 22015 additions and 884 deletions
+45
View File
@@ -0,0 +1,45 @@
package dto
import (
"encoding/json"
"testing"
"browser.local/platform/domain"
)
func TestRuntimeLogEventDeclarationRoundTripUsesSafeProjection(t *testing.T) {
body := GamePluginRuntimeProfilesBody{
LogEvents: []RuntimeLogEventBody{{
Key: "chat-message", Title: "Chat message", SourceKey: "chat-log", EventType: "chat.message",
Permission: "server.logs.read", SchemaRef: "schemas/log-events/chat-message.schema.json", RetentionDays: 30, Severity: "info",
}},
}
profiles := body.ToDomain()
if len(profiles.LogEvents) != 1 || profiles.LogEvents[0].EventType != "chat.message" || profiles.LogEvents[0].Severity != "info" {
t.Fatalf("log event conversion lost declaration fields: %+v", profiles.LogEvents)
}
profiles.LogEvents[0].Title = "Mutated"
if body.LogEvents[0].Title != "Chat message" {
t.Fatal("log event domain conversion aliases request DTO data")
}
projection := runtimeProfilesFromDomain(domain.GamePluginRuntimeProfiles{LogEvents: profiles.LogEvents})
encoded, err := json.Marshal(projection.LogEvents[0])
if err != nil {
t.Fatalf("marshal log event projection: %v", err)
}
var fields map[string]any
if err := json.Unmarshal(encoded, &fields); err != nil {
t.Fatalf("decode log event projection: %v", err)
}
expected := []string{"key", "title", "sourceKey", "eventType", "permission", "schemaRef", "retentionDays", "severity"}
if len(fields) != len(expected) {
t.Fatalf("log event projection contains unexpected fields: %s", encoded)
}
for _, field := range expected {
if _, exists := fields[field]; !exists {
t.Fatalf("log event projection is missing %q: %s", field, encoded)
}
}
}