Fix SCUM generated run deployment flow
This commit is contained in:
@@ -303,6 +303,29 @@ func TestCoreServiceDedicatedRunRegistrationAutomaticallyDeploysGuidedDraftOnly(
|
||||
t.Fatalf("Run reconnect must not duplicate automatic install, jobs=%+v", jobs)
|
||||
}
|
||||
|
||||
generatedRunDraft := domain.ServerInstance{
|
||||
ID: "managed-generated",
|
||||
PluginID: plugin.ID,
|
||||
PluginVersion: plugin.Version,
|
||||
RunEndpointID: dedicatedRunEndpointID("managed-generated"),
|
||||
Name: "Managed Generated",
|
||||
State: domain.ServerInstanceStateDraft,
|
||||
ConfigVersion: 1,
|
||||
Deployment: domain.ServerDeploymentDefinition{Mode: domain.ServerDeploymentModeGuided, ServerRoot: "C:\\generated-scum", ProfileKey: "local", Revision: 1},
|
||||
}
|
||||
if err := svc.store.ServerInstances().Create(generatedRunDraft); err != nil {
|
||||
t.Fatalf("create generated Run draft: %v", err)
|
||||
}
|
||||
registerDedicatedRunForTest(t, svc, generatedRunDraft, plugin.ID)
|
||||
storedGenerated, err := svc.GetServerInstance(generatedRunDraft.ID)
|
||||
if err != nil || storedGenerated.State != domain.ServerInstanceStateInstalling {
|
||||
t.Fatalf("generated Run registration should queue install without deployment target, server=%+v err=%v", storedGenerated, err)
|
||||
}
|
||||
jobs, err = svc.store.Jobs().List(domain.JobFilter{ServerInstanceID: generatedRunDraft.ID})
|
||||
if err != nil || len(jobs) != 1 || jobs[0].Capability != domain.LifecycleCapabilityInstall {
|
||||
t.Fatalf("expected one automatic generated Run install job, jobs=%+v err=%v", jobs, err)
|
||||
}
|
||||
|
||||
existing, err := svc.CreateServerInstanceWorkflowForSession(owner, domain.ServerLifecycleCreate{ID: "managed-existing", PluginID: plugin.ID, DeploymentTargetID: "run-local", Name: "Managed Existing", IdempotencyKey: "managed-existing-create", ProfileKey: "local", Deployment: domain.ServerDeploymentDefinition{Mode: domain.ServerDeploymentModeExisting, ServerRoot: "C:\\existing-scum"}})
|
||||
if err != nil {
|
||||
t.Fatalf("create existing draft: %v", err)
|
||||
@@ -314,6 +337,114 @@ func TestCoreServiceDedicatedRunRegistrationAutomaticallyDeploysGuidedDraftOnly(
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoreServiceGeneratedSCUMRunRegistrationQueuesGuidedInstall(t *testing.T) {
|
||||
svc := newTestCoreService()
|
||||
plugin := scumDeploymentTestPlugin()
|
||||
plugin.Name = "SCUM"
|
||||
plugin.Version = "0.1.1"
|
||||
plugin.ServerType = "scum"
|
||||
plugin.Status = domain.GamePluginStatusInstalled
|
||||
plugin.SupportedOS = []string{"windows"}
|
||||
plugin.RequiredRunCapabilities = []string{
|
||||
domain.LifecycleCapabilityInstall,
|
||||
domain.LifecycleCapabilityStart,
|
||||
domain.LifecycleCapabilityStop,
|
||||
"process.restart",
|
||||
domain.LifecycleCapabilityStatus,
|
||||
domain.JobCapabilitySCUMDeploymentPlan,
|
||||
"files.list",
|
||||
domain.JobCapabilityFilesRead,
|
||||
"files.patch",
|
||||
"logs.read",
|
||||
domain.JobCapabilityClientManagerDeploy,
|
||||
domain.JobCapabilityClientManagerControl,
|
||||
domain.JobCapabilityClientManagerUpdate,
|
||||
domain.JobCapabilityClientManagerRollback,
|
||||
domain.JobCapabilityClientManagerUninstall,
|
||||
"artifacts.read",
|
||||
"artifacts.write",
|
||||
"ai.invoke",
|
||||
}
|
||||
plugin.DeclaredPermissions = []string{"server.run.distribution"}
|
||||
plugin.LifecycleActions = domain.PluginLifecycleActions{Install: "actions/install.json", Start: "actions/start.json", Stop: "actions/stop.json", Status: "actions/status.json"}
|
||||
plugin.RuntimeProfiles.LifecycleProfiles = []domain.RuntimeLifecycleProfile{{
|
||||
Key: "run-local", Mode: "local-process",
|
||||
Capabilities: []string{domain.LifecycleCapabilityInstall, domain.LifecycleCapabilityStart, domain.LifecycleCapabilityStop, domain.LifecycleCapabilityStatus},
|
||||
ActionRefs: domain.PluginLifecycleActions{Install: "actions/install.json", Start: "actions/start.json", Stop: "actions/stop.json", Status: "actions/status.json"},
|
||||
Platforms: []string{"windows"},
|
||||
}}
|
||||
requireManualSCUMRuntimeBindings(&plugin, "run-local")
|
||||
plugin.RuntimeProfiles.ServerDeployments[0].SupportedTargets = []domain.RuntimeTarget{{OS: "windows", Arch: "amd64"}}
|
||||
if err := svc.store.GamePlugins().Create(plugin); err != nil {
|
||||
t.Fatalf("create SCUM plugin fixture: %v", err)
|
||||
}
|
||||
|
||||
instance := domain.ServerInstance{
|
||||
ID: "scum-generated-guided",
|
||||
PluginID: plugin.ID,
|
||||
PluginVersion: plugin.Version,
|
||||
RunEndpointID: dedicatedRunEndpointID("scum-generated-guided"),
|
||||
Name: "SCUM Generated Guided",
|
||||
OwnerUserID: "owner-scum-generated",
|
||||
State: domain.ServerInstanceStateDraft,
|
||||
ConfigVersion: 1,
|
||||
Deployment: domain.ServerDeploymentDefinition{
|
||||
Mode: domain.ServerDeploymentModeGuided,
|
||||
ProfileKey: "run-local",
|
||||
ServerRoot: `D:\scum-e2e-guided`,
|
||||
CreateInputs: map[string]string{
|
||||
"serverName": "SCUM E2E",
|
||||
"gamePort": "27000",
|
||||
"queryPort": "27015",
|
||||
"maxPlayers": "128",
|
||||
},
|
||||
Revision: 1,
|
||||
},
|
||||
}
|
||||
if err := svc.store.ServerInstances().Create(instance); err != nil {
|
||||
t.Fatalf("create generated SCUM draft: %v", err)
|
||||
}
|
||||
|
||||
key, plainKey, err := svc.ensureActiveComponentKey(instance.ID, domain.DistributionComponentRun, "")
|
||||
if err != nil {
|
||||
t.Fatalf("get generated Run key: %v", err)
|
||||
}
|
||||
hello := validRunControlHello()
|
||||
hello.RunEndpointID = instance.RunEndpointID
|
||||
hello.RegistrationToken = plainKey
|
||||
hello.ServerInstanceID = instance.ID
|
||||
hello.PluginID = plugin.ID
|
||||
hello.ComponentKind = domain.DistributionComponentRun
|
||||
hello.KeyGeneration = key.Generation
|
||||
hello.Platform = "windows"
|
||||
hello.Architecture = "amd64"
|
||||
hello.CapabilityReport.Capabilities = []string{domain.LifecycleCapabilityInstall, domain.LifecycleCapabilityStart, domain.LifecycleCapabilityStop, domain.LifecycleCapabilityStatus, domain.JobCapabilityDeploymentPlan, domain.JobCapabilitySCUMDeploymentPlan}
|
||||
registered, err := svc.RegisterRunHello(hello)
|
||||
if err != nil || !registered.Accepted {
|
||||
t.Fatalf("register generated SCUM Run: result=%+v err=%v", registered, err)
|
||||
}
|
||||
|
||||
stored, err := svc.GetServerInstance(instance.ID)
|
||||
if err != nil || stored.State != domain.ServerInstanceStateInstalling {
|
||||
t.Fatalf("generated SCUM registration should queue install, server=%+v err=%v", stored, err)
|
||||
}
|
||||
jobs, err := svc.store.Jobs().List(domain.JobFilter{ServerInstanceID: instance.ID})
|
||||
if err != nil || len(jobs) != 1 {
|
||||
t.Fatalf("expected one SCUM install job, jobs=%+v err=%v", jobs, err)
|
||||
}
|
||||
job := jobs[0]
|
||||
if job.Capability != domain.LifecycleCapabilityInstall || job.ExecutionInput.Deployment == nil || job.ExecutionInput.ServerDeploymentPlan == nil {
|
||||
t.Fatalf("expected SCUM install job with protected deployment plan, job=%+v", job)
|
||||
}
|
||||
if job.ExecutionInput.Deployment.CreateInputs["gamePort"] != "27000" || job.ExecutionInput.Deployment.CreateInputs["maxPlayers"] != "128" {
|
||||
t.Fatalf("SCUM install job lost create inputs: %+v", job.ExecutionInput.Deployment.CreateInputs)
|
||||
}
|
||||
claim, err := svc.ClaimRunJob(domain.RunJobClaim{RunEndpointID: instance.RunEndpointID, SessionToken: registered.SessionToken, Capabilities: hello.CapabilityReport.Capabilities, Capacity: domain.RunCapacity{MaxJobs: 1}})
|
||||
if err != nil || !claim.HasJob || claim.Job.ExecutionInput.ServerDeploymentPlan == nil {
|
||||
t.Fatalf("generated SCUM Run should claim install job with frozen plan, claim=%+v err=%v", claim, err)
|
||||
}
|
||||
}
|
||||
|
||||
func registerDedicatedRunForTest(t *testing.T, svc *CoreService, instance domain.ServerInstance, pluginID string) {
|
||||
t.Helper()
|
||||
key, plainKey, err := svc.ensureActiveComponentKey(instance.ID, domain.DistributionComponentRun, "")
|
||||
|
||||
Reference in New Issue
Block a user