/** Interactive private Vite acceptance fixture. Always finish with cleanup. */ import { randomUUID } from "node:crypto"; import { readFile, writeFile } from "node:fs/promises"; import plugin from "../../packages/plugins/sandbox-providers/exe-dev/src/plugin.js"; import { ssh, quote } from "../../packages/plugins/sandbox-providers/exe-dev/src/transport.js"; import type { PluginEnvironmentLease } from "../../packages/plugins/sdk/src/protocol.js"; if (process.env.EXE_DEV_LIVE_SMOKE !== "1") throw new Error("EXE_DEV_LIVE_SMOKE=1 required"); const statePath = process.env.EXE_DEV_PREVIEW_STATE ?? "/tmp/paperclip-exe-preview.json"; const action = process.argv[2] ?? "create"; const hooks = plugin.definition; const sshConfig = { sshPrivateKey: process.env.EXE_DEV_SSH_PRIVATE_KEY, strictHostKeyChecking: "accept-new" as const, timeoutMs: 300000 }; type State = { companyId: string; environmentId: string; vmName: string; image: string; lease: PluginEnvironmentLease; createdAt: string }; let state: State; if (action === "create") { const image = process.env.PAPERCLIP_E2E_EXE_IMAGE; if (!image) throw new Error("PAPERCLIP_E2E_EXE_IMAGE required"); state = { companyId: randomUUID(), environmentId: randomUUID(), vmName: `paperclip-preview-${randomUUID().slice(0, 12)}`, image, lease: { providerLeaseId: null }, createdAt: new Date().toISOString() }; // Record the owned name before provisioning, including partial failures. await writeFile(statePath, JSON.stringify(state, null, 2), { mode: 0o600, flag: "wx" }); } else state = JSON.parse(await readFile(statePath, "utf8")); if (!/^paperclip-preview-[a-f0-9-]{12}$/.test(state.vmName)) throw new Error("Not an owned preview fixture"); const config = { ...sshConfig, mode: "create", vmName: state.vmName, image: state.image, reuseLease: true }; const scope = { companyId: state.companyId, environmentId: state.environmentId, driverKey: "exe-dev", config }; const host = `${state.vmName}.exe.xyz`; const run = (script: string) => ssh(sshConfig, host, script); try { if (action === "create") { state.lease = await hooks.onEnvironmentAcquireLease!({ ...scope, agentId: "vite-preview", runId: randomUUID() }); await writeFile(statePath, JSON.stringify(state, null, 2), { mode: 0o600 }); const cwd = String(state.lease.metadata?.remoteCwd); const files = { "package.json": JSON.stringify({ private: true, type: "module", dependencies: { vite: "8.2.2" } }), "index.html": '