(os: "macos" | "linux", arch: VmArch = "arm64")
| 96 | }; |
| 97 | |
| 98 | export const tartVm = (os: "macos" | "linux", arch: VmArch = "arm64"): VmProvider => ({ |
| 99 | os, |
| 100 | provision: async () => { |
| 101 | const name = `executor-e2e-${os}-${process.pid}-${Math.floor(performance.now())}`; |
| 102 | await execFileP(TART, ["clone", baseImage(os), name]); |
| 103 | // `--no-graphics` opens NO host window (never steals focus) yet the guest |
| 104 | // still has a virtual display: with the base image's autologin it reaches a |
| 105 | // real Aqua session (WindowServer/Dock/Finder), so even the packaged GUI app |
| 106 | // renders and `screencapture` records it. No windowed/VNC mode is needed. |
| 107 | const runProc = spawn(TART, ["run", name, "--no-graphics"], { |
| 108 | stdio: "ignore", |
| 109 | detached: true, |
| 110 | }); |
| 111 | runProc.unref(); |
| 112 | |
| 113 | const tunnelClosers: Array<() => void> = []; |
| 114 | let ip = ""; |
| 115 | |
| 116 | const fetchIp = async (): Promise<boolean> => { |
| 117 | for (let i = 0; i < 90; i++) { |
| 118 | try { |
| 119 | const { stdout } = await execFileP(TART, ["ip", name]); |
| 120 | if (stdout.trim()) { |
| 121 | ip = stdout.trim(); |
| 122 | return true; |
| 123 | } |
| 124 | } catch { |
| 125 | /* not booted yet */ |
| 126 | } |
| 127 | await sleep(2000); |
| 128 | } |
| 129 | return false; |
| 130 | }; |
| 131 | |
| 132 | // Linux systemctl --user calls need XDG_RUNTIME_DIR; harmless elsewhere. |
| 133 | const wrap = (command: string): string => |
| 134 | os === "linux" ? `export XDG_RUNTIME_DIR=/run/user/$(id -u); ${command}` : command; |
| 135 | |
| 136 | const ssh = async (command: string): Promise<SshResult> => { |
| 137 | try { |
| 138 | const { stdout, stderr } = await execFileP( |
| 139 | SSHPASS, |
| 140 | ["-p", GUEST_PASS, "ssh", ...SSH_OPTS, `${GUEST_USER}@${ip}`, wrap(command)], |
| 141 | { maxBuffer: 32 * 1024 * 1024 }, |
| 142 | ); |
| 143 | return { stdout, stderr, code: 0 }; |
| 144 | } catch (err) { |
| 145 | const e = err as { stdout?: string; stderr?: string; code?: number }; |
| 146 | return { |
| 147 | stdout: e.stdout ?? "", |
| 148 | stderr: e.stderr ?? "", |
| 149 | code: typeof e.code === "number" ? e.code : 1, |
| 150 | }; |
| 151 | } |
| 152 | }; |
| 153 | |
| 154 | const waitSsh = async (attempts: number): Promise<boolean> => { |
| 155 | for (let i = 0; i < attempts; i++) { |
no test coverage detected