diff --git a/docs/extensions/server-certification.md b/docs/extensions/server-certification.md new file mode 100644 index 0000000..f734000 --- /dev/null +++ b/docs/extensions/server-certification.md @@ -0,0 +1,57 @@ +# Server driver certification + +Bundled means that a driver implements the OpenHosting lifecycle contract; it +does not mean every vendor/version combination has been exercised with live +credentials. A driver is certified only after `create → suspend → unsuspend → +terminate` succeeds against a disposable staging resource. + +## Live lifecycle harness + +Create a fixture outside the repository so credentials are not committed: + +```json +{ + "config": { + "panel_url": "https://staging-panel.example.com", + "api_key": "replace-with-a-staging-key" + }, + "productConfig": { + "location_id": "1", + "nest_id": "1", + "egg_id": "1", + "docker_image": "ghcr.io/example/image:latest", + "startup": "./start.sh", + "memory": "512", + "disk": "1024", + "cpu": "100" + }, + "user": { + "email": "certification@example.test", + "firstName": "Driver", + "lastName": "Test" + } +} +``` + +Run the harness only against a sandbox or staging tenant: + +```bash +npm run certify:server -- \ + --driver pterodactyl \ + --fixture /secure/path/pterodactyl-certification.json \ + --confirm-live-lifecycle +``` + +The confirmation flag is mandatory because the command creates and deletes a +real resource. The fixture is validated against the driver's required fields, +credentials are never printed, each stage is timed, and cleanup termination is +attempted if an intermediate stage fails. Keep the staging account isolated and +verify in the provider console that no resource remains after the run. + +## Current status + +All 27 drivers pass static registry checks for unique slugs, complete lifecycle +hooks, and valid configuration metadata. Live certification requires operator +credentials and is intentionally not claimed by the repository itself. Record a +successful run with provider product/version, date, and any required permission +scope in the tracking issue before changing a driver to field-tested status. diff --git a/docs/extensions/server-modules.md b/docs/extensions/server-modules.md index 009eb7f..80580e3 100644 --- a/docs/extensions/server-modules.md +++ b/docs/extensions/server-modules.md @@ -6,6 +6,11 @@ OpenHosting includes 27 server-provisioning integrations. Enable one under module creates the server; the billing lifecycle then suspends, unsuspends and terminates it automatically. +The registry is contract-tested, but vendor APIs and deployed versions vary. +Before production use, run the disposable-resource lifecycle described in +[Server driver certification](server-certification.md) against your staging +tenant. + Config options with env keys (e.g. `MEMORY`, `CORES`, `DISK`, `DOMAIN`) let customers pick sizes at checkout — see [Products → config options](../guides/products.md#config-options). @@ -115,4 +120,5 @@ see [Writing an extension](writing-extensions.md). > **Note:** the driver implementations follow each vendor's documented API. As > with any provisioning integration, validate against your actual panel version -> in staging before relying on it in production. +> in staging before relying on it in production. A bundled driver is not a claim +> of live certification. diff --git a/package.json b/package.json index 46f53bc..5b41816 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "test": "vitest run --config vitest.config.mts", "test:watch": "vitest --config vitest.config.mts", "test:coverage": "vitest run --config vitest.config.mts --coverage", - "test:integration": "vitest run --config vitest.integration.config.mts" + "test:integration": "vitest run --config vitest.integration.config.mts", + "certify:server": "node --conditions=react-server --import tsx scripts/certify-server-driver.ts" }, "dependencies": { "@anthropic-ai/sdk": "^0.115.0", diff --git a/scripts/certify-server-driver.ts b/scripts/certify-server-driver.ts new file mode 100644 index 0000000..d8bccc2 --- /dev/null +++ b/scripts/certify-server-driver.ts @@ -0,0 +1,193 @@ +import { readFile } from "node:fs/promises"; +import { resolve } from "node:path"; +import type { Service, User } from "@/generated/prisma/client"; +import { getServerDriver } from "@/lib/extensions/registry"; +import type { ConfigField, ServerDriver } from "@/lib/extensions/types"; + +type CertificationFixture = { + config: Record; + productConfig: Record; + user?: Partial>; + service?: { + config?: Array<{ option?: string; envKey?: string; value: string }>; + cycle?: Service["cycle"]; + price?: number; + currency?: string; + quantity?: number; + }; +}; + +function argument(name: string): string | null { + const index = process.argv.indexOf(name); + return index >= 0 ? process.argv[index + 1] ?? null : null; +} + +function requiredFields( + fields: ConfigField[], + values: Record, +): string[] { + return fields + .filter((field) => field.required && !values[field.key]?.trim()) + .map((field) => field.key); +} + +function assertFixture(value: unknown): asserts value is CertificationFixture { + if (!value || typeof value !== "object") { + throw new Error("The fixture must be a JSON object."); + } + const fixture = value as Partial; + if (!fixture.config || typeof fixture.config !== "object") { + throw new Error("The fixture must contain a config object."); + } + if (!fixture.productConfig || typeof fixture.productConfig !== "object") { + throw new Error("The fixture must contain a productConfig object."); + } +} + +function certificationService( + fixture: CertificationFixture, +): Service & { user: User } { + const createdAt = new Date(); + const userId = fixture.user?.id ?? `cert-user-${createdAt.getTime()}`; + return { + id: `cert-service-${createdAt.getTime()}`, + userId, + productId: "certification-product", + orderId: null, + status: "ACTIVE", + cycle: fixture.service?.cycle ?? "MONTHLY", + price: fixture.service?.price ?? 1, + currency: fixture.service?.currency ?? "USD", + quantity: fixture.service?.quantity ?? 1, + config: fixture.service?.config ?? [], + externalId: null, + expiresAt: null, + suspendedAt: null, + cancelledAt: null, + cancelAtPeriodEnd: false, + resaleData: null, + createdAt, + updatedAt: createdAt, + user: { + id: userId, + email: fixture.user?.email ?? "driver-certification@example.test", + password: "not-used", + firstName: fixture.user?.firstName ?? "Driver", + lastName: fixture.user?.lastName ?? "Certification", + companyName: null, + address: null, + city: null, + state: null, + zip: null, + country: null, + phone: null, + credits: 0, + currency: null, + vatId: null, + vatValidatedAt: null, + referredByAffiliateId: null, + emailVerifiedAt: createdAt, + totpSecret: null, + totpEnabledAt: null, + roleId: null, + createdAt, + updatedAt: createdAt, + }, + } as unknown as Service & { user: User }; +} + +async function stage(name: string, operation: () => Promise) { + const startedAt = Date.now(); + await operation(); + return { name, durationMs: Date.now() - startedAt, status: "passed" }; +} + +async function certify( + driver: ServerDriver, + fixture: CertificationFixture, +): Promise { + const missingConfig = requiredFields(driver.configFields, fixture.config); + const missingProductConfig = requiredFields( + driver.productConfigFields, + fixture.productConfig, + ); + if (missingConfig.length || missingProductConfig.length) { + throw new Error( + [ + missingConfig.length + ? `Missing config fields: ${missingConfig.join(", ")}` + : "", + missingProductConfig.length + ? `Missing productConfig fields: ${missingProductConfig.join(", ")}` + : "", + ] + .filter(Boolean) + .join("\n"), + ); + } + + const service = certificationService(fixture); + const results: Array<{ name: string; durationMs: number; status: string }> = []; + let created = false; + let terminated = false; + try { + let externalId: string | null = null; + results.push( + await stage("create", async () => { + externalId = await driver.create( + service, + fixture.config, + fixture.productConfig, + ); + if (!externalId) throw new Error("create returned no external id"); + service.externalId = externalId; + created = true; + }), + ); + results.push( + await stage("suspend", () => driver.suspend(service, fixture.config)), + ); + results.push( + await stage("unsuspend", () => driver.unsuspend(service, fixture.config)), + ); + results.push( + await stage("terminate", () => driver.terminate(service, fixture.config)), + ); + terminated = true; + } finally { + if (created && !terminated) { + await driver.terminate(service, fixture.config).catch((error) => { + const detail = error instanceof Error ? error.message : String(error); + process.stderr.write(`Cleanup failed: ${detail}\n`); + }); + } + } + + process.stdout.write( + `${JSON.stringify({ driver: driver.slug, status: "passed", results }, null, 2)}\n`, + ); +} + +async function main(): Promise { + const slug = argument("--driver"); + const fixturePath = argument("--fixture"); + if (!slug || !fixturePath || !process.argv.includes("--confirm-live-lifecycle")) { + throw new Error( + "Usage: npm run certify:server -- --driver --fixture --confirm-live-lifecycle", + ); + } + const driver = getServerDriver(slug); + if (!driver) throw new Error(`Unknown server driver: ${slug}`); + + const fixture = JSON.parse( + await readFile(resolve(fixturePath), "utf8"), + ) as unknown; + assertFixture(fixture); + await certify(driver, fixture); +} + +main().catch((error) => { + const detail = error instanceof Error ? error.message : String(error); + process.stderr.write(`Certification failed: ${detail}\n`); + process.exitCode = 1; +}); diff --git a/src/lib/extensions/server-drivers.test.ts b/src/lib/extensions/server-drivers.test.ts new file mode 100644 index 0000000..5983475 --- /dev/null +++ b/src/lib/extensions/server-drivers.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, test } from "vitest"; +import { SERVER_DRIVERS } from "@/lib/extensions/registry"; + +describe("server driver registry", () => { + test("registers 27 uniquely named drivers", () => { + expect(SERVER_DRIVERS).toHaveLength(27); + expect(new Set(SERVER_DRIVERS.map((driver) => driver.slug)).size).toBe(27); + expect(new Set(SERVER_DRIVERS.map((driver) => driver.name)).size).toBe(27); + }); + + test.each(SERVER_DRIVERS)("$slug exposes a complete lifecycle", (driver) => { + expect(driver.slug).toMatch(/^[a-z0-9-]+$/); + expect(driver.name.trim()).not.toBe(""); + expect(driver.create).toBeTypeOf("function"); + expect(driver.suspend).toBeTypeOf("function"); + expect(driver.unsuspend).toBeTypeOf("function"); + expect(driver.terminate).toBeTypeOf("function"); + }); + + test.each(SERVER_DRIVERS)("$slug has valid configuration fields", (driver) => { + for (const fields of [driver.configFields, driver.productConfigFields]) { + expect(new Set(fields.map((field) => field.key)).size).toBe(fields.length); + for (const field of fields) { + expect(field.key).toMatch(/^[a-z0-9_]+$/); + expect(field.label.trim()).not.toBe(""); + if (field.type === "select") { + expect(field.options?.length).toBeGreaterThan(0); + } + } + } + }); +});