first commit

This commit is contained in:
npc0-hue
2026-07-11 14:56:10 +08:00
commit 7e05d0a4e7
660 changed files with 78119 additions and 0 deletions
+100
View File
@@ -0,0 +1,100 @@
package model
import (
"testing"
"browser.local/platform/domain"
)
func TestTableNames(t *testing.T) {
tests := map[string]string{
User{}.TableName(): "users",
AIProvider{}.TableName(): "ai_providers",
GamePlugin{}.TableName(): "game_plugins",
ServerInstance{}.TableName(): "server_instances",
RunEndpoint{}.TableName(): "run_endpoints",
Job{}.TableName(): "jobs",
Artifact{}.TableName(): "artifacts",
LogStream{}.TableName(): "log_streams",
AuditEvent{}.TableName(): "audit_events",
}
for got, want := range tests {
if got != want {
t.Fatalf("expected table name %q, got %q", want, got)
}
}
}
func TestGamePluginModelRoundTripCopiesSlices(t *testing.T) {
source := domain.GamePlugin{
ID: "server.scum",
Name: "SCUM",
Version: "1.0.0",
ServerType: "scum",
ManifestRef: "artifact://manifest",
CreateFormSchemaRef: "artifact://schema",
RequiredRunCapabilities: []string{"process.start", "logs.read"},
DeclaredPermissions: []string{"server.logs.read"},
SupportedOS: []string{"linux"},
Pages: []domain.GamePluginPage{
{Key: "logs", Title: "Logs", Path: "/logs", Permissions: []string{"server.logs.read"}},
},
Tags: []string{"survival"},
AIPurposes: []string{"logs.diagnose"},
Permissions: domain.PluginPermissions{
Jobs: true,
Logs: true,
},
Status: domain.GamePluginStatusInstalled,
}
row := GamePluginFromDomain(source)
roundTrip := row.ToDomain()
roundTrip.RequiredRunCapabilities[0] = "files.read"
roundTrip.DeclaredPermissions[0] = "ai.invoke"
roundTrip.SupportedOS[0] = "darwin"
roundTrip.Pages[0].Permissions[0] = "ai.invoke"
roundTrip.Tags[0] = "mutated"
roundTrip.AIPurposes[0] = "config.suggest"
if source.RequiredRunCapabilities[0] != "process.start" {
t.Fatalf("expected source plugin capabilities to remain unchanged, got %+v", source.RequiredRunCapabilities)
}
if row.RequiredRunCapabilities[0] != "process.start" {
t.Fatalf("expected model plugin capabilities to remain unchanged, got %+v", row.RequiredRunCapabilities)
}
if source.DeclaredPermissions[0] != "server.logs.read" || source.Pages[0].Permissions[0] != "server.logs.read" || source.Tags[0] != "survival" || source.AIPurposes[0] != "logs.diagnose" {
t.Fatalf("expected source plugin registry metadata to remain unchanged, got %+v", source)
}
if row.DeclaredPermissions[0] != "server.logs.read" || row.Pages[0].Permissions[0] != "server.logs.read" || row.Tags[0] != "survival" || row.AIPurposes[0] != "logs.diagnose" {
t.Fatalf("expected model plugin registry metadata to remain unchanged, got %+v", row)
}
}
func TestAIProviderModelUsesKeyReference(t *testing.T) {
source := 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",
}
row := AIProviderFromDomain(source)
if row.APIKeyRef != source.APIKeyRef {
t.Fatalf("expected API key reference %q, got %q", source.APIKeyRef, row.APIKeyRef)
}
roundTrip := row.ToDomain()
roundTrip.Models[0] = "mutated"
if row.Models[0] != "gpt-4.1" {
t.Fatalf("expected model provider models to remain unchanged, got %+v", row.Models)
}
}