fix: expose server deployment trigger

This commit is contained in:
npc0-hue
2026-07-28 15:11:01 +08:00
parent e4ef4024a8
commit c5806cc6b7
10 changed files with 151 additions and 5 deletions
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import type { GamePluginResponse } from "../api/types";
import { defaultServerCreateForm, runtimeBindingFields } from "../contracts/serverManagement";
import { canDeployServer, defaultServerCreateForm, runtimeBindingFields } from "../contracts/serverManagement";
import { serverCreateRequestFromForm, serverInstanceIdFromName } from "./serverManagement";
const plugin: GamePluginResponse = {
@@ -42,6 +42,13 @@ const plugin: GamePluginResponse = {
};
describe("runtime profile server creation contracts", () => {
it("allows deployment only from draft or failed server states", () => {
expect(canDeployServer("draft")).toBe(true);
expect(canDeployServer("failed")).toBe(true);
expect(canDeployServer("installing")).toBe(false);
expect(canDeployServer("ready")).toBe(false);
});
it("derives logical binding fields from the selected profile", () => {
expect(runtimeBindingFields(plugin, "local")).toEqual([
{ key: "java-runtime", required: false, sensitive: false },
+2 -2
View File
@@ -52,7 +52,7 @@ export function serverInstanceIdFromName(name: string, sequence = Date.now()): s
return normalized ? `server-${normalized}-${suffix}` : `server-${suffix}`;
}
export function serverLifecycleCommandRequest(instance: ServerInstanceResponse, action: "start" | "stop" | "status", sequence = Date.now()): ServerLifecycleCommandRequest {
export function serverLifecycleCommandRequest(instance: ServerInstanceResponse, action: "deploy" | "start" | "stop" | "status", sequence = Date.now()): ServerLifecycleCommandRequest {
return {
expectedConfigVersion: instance.configVersion,
expectedChecksum: instance.configChecksum,
@@ -130,6 +130,6 @@ export function runtimeIdempotencyKey(action: string, serverInstanceId: string,
return `web:${action}:${serverInstanceId}:${sequence}`;
}
export function lifecycleIdempotencyKey(action: "create" | "start" | "stop" | "status", serverInstanceId: string, sequence: number): string {
export function lifecycleIdempotencyKey(action: "create" | "deploy" | "start" | "stop" | "status", serverInstanceId: string, sequence: number): string {
return `web:${action}:${serverInstanceId}:${sequence}`;
}