(os: VmOs)
| 48 | }; |
| 49 | |
| 50 | export async function setupCliTarget(os: VmOs): Promise<(() => Promise<void>) | void> { |
| 51 | process.env.E2E_VM_OS = os; // so the worker-side target resolves the same OS |
| 52 | |
| 53 | const arch: VmArch = os === "windows" ? "x64" : "arm64"; |
| 54 | const binDir = await buildGuestBinary(os, arch); |
| 55 | const vm: VmHandle = |
| 56 | os === "windows" ? await ec2Vm(os, arch).provision() : await tartVm(os, arch).provision(); |
| 57 | const plan = guestPlan(os); |
| 58 | |
| 59 | let tunnelClose: (() => void) | undefined; |
| 60 | try { |
| 61 | await vm.ssh(plan.prep); |
| 62 | await vm.push(`${binDir}/.`, os === "windows" ? plan.dir : `${plan.dir}/`); |
| 63 | await vm.ssh(plan.postPush); |
| 64 | |
| 65 | const install = await vm.ssh(plan.install); |
| 66 | if (install.code !== 0) { |
| 67 | throw new Error(`service install failed: ${install.stderr.trim() || install.stdout.trim()}`); |
| 68 | } |
| 69 | |
| 70 | // The supervised daemon mints/loads its bearer into auth.json on first boot. |
| 71 | const tokenRaw = (await vm.ssh(plan.readToken)).stdout.trim(); |
| 72 | const token = (JSON.parse(tokenRaw) as { token: string }).token; |
| 73 | |
| 74 | const tunnel = await vm.tunnel(PORT); |
| 75 | tunnelClose = tunnel.close; |
| 76 | const baseUrl = `http://127.0.0.1:${tunnel.localPort}`; |
| 77 | await waitForHttp(`${baseUrl}/`, { timeoutMs: 60_000 }); |
| 78 | |
| 79 | process.env.E2E_CLI_BASE_URL = baseUrl; |
| 80 | process.env.E2E_CLI_AUTH_TOKEN = token; |
| 81 | process.env.E2E_CLI_VM_HOST = vm.host; |
| 82 | if (vm.sshKeyPath) process.env.E2E_CLI_SSH_KEY = vm.sshKeyPath; |
| 83 | process.env.E2E_CLI_TUNNEL_PORT = String(tunnel.localPort); |
| 84 | process.env.E2E_CLI_BIN_DIR = plan.dir; |
| 85 | } catch (error) { |
| 86 | tunnelClose?.(); |
| 87 | await vm.ssh(plan.uninstall).catch(() => undefined); |
| 88 | await vm.discard(); |
| 89 | throw error; |
| 90 | } |
| 91 | |
| 92 | return async () => { |
| 93 | tunnelClose?.(); |
| 94 | await vm.ssh(plan.uninstall).catch(() => undefined); |
| 95 | await vm.discard(); |
| 96 | }; |
| 97 | } |
no test coverage detected