import { describe, expect, it } from "vitest"; import type { GamePluginResponse } from "../api/types"; import { defaultServerCreateForm, runtimeBindingFields } from "../contracts/serverManagement"; import { serverCreateRequestFromForm } from "./serverManagement"; const plugin: GamePluginResponse = { id: "game.runtime", name: "Runtime Game", version: "1.0.0", serverType: "runtime", manifestRef: "artifact://runtime-manifest", createFormSchemaRef: "schemas/create.json", requiredRunCapabilities: ["process.install"], declaredPermissions: ["server.create"], permissions: { ai: false, logs: true, files: false, jobs: true, artifacts: false }, lifecycleActions: { install: "actions/install.json", start: "actions/start.json", stop: "actions/stop.json" }, bridgeActions: [], pages: [], tags: [], aiPurposes: [], status: "installed", runtimeProfiles: { discovery: [{ key: "root-check", kind: "file.exists", targetKey: "server-root", required: true }], dependencyProbes: [{ key: "java", kind: "java.version", targetKey: "java-runtime", required: false }], installPlans: [{ key: "java-install", title: "Java", steps: [{ type: "package", targetKey: "package-source" }] }], logSources: [{ key: "main-log", kind: "file.tail", targetKey: "log-source", streamKey: "main" }], transportProfiles: [ { key: "rcon", kind: "rcon", targetKey: "rcon.password", capabilities: ["remote.run.rcon.command"] }, { key: "ftp", kind: "ftp", targetKey: "ftp.profile", capabilities: ["remote.ftp.read"] } ], lifecycleProfiles: [ { key: "local", mode: "local-process", capabilities: ["process.install", "process.start", "process.stop"], transportKeys: ["rcon"] }, { key: "hosted", mode: "hosted-ftp-rcon", capabilities: ["remote.ftp.read"], transportKeys: ["ftp"] } ] } }; describe("runtime profile server creation contracts", () => { it("derives logical binding fields from the selected profile", () => { expect(runtimeBindingFields(plugin, "local")).toEqual([ { key: "java-runtime", required: false, sensitive: false }, { key: "log-source", required: true, sensitive: false }, { key: "package-source", required: false, sensitive: false }, { key: "rcon.password", required: true, sensitive: true }, { key: "server-root", required: true, sensitive: false } ]); expect(runtimeBindingFields(plugin, "local").some((field) => field.key === "ftp.profile")).toBe(false); }); it("selects the plugin profile and submits real profile bindings", () => { const form = defaultServerCreateForm([plugin], []); expect(form.profileKey).toBe("local"); expect( serverCreateRequestFromForm( { ...form, id: " server-1 ", name: " Runtime Server ", bindings: { "server-root": " runtime.server-root ", "rcon.password": " secret://runtime/server-1/rcon ", "java-runtime": " " } }, 17 ) ).toEqual({ id: "server-1", pluginId: "game.runtime", runEndpointId: "", name: "Runtime Server", idempotencyKey: "web:create:server-1:17", profileKey: "local", bindings: { "server-root": "runtime.server-root", "rcon.password": "secret://runtime/server-1/rcon" } }); }); });