MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / tartVm

Function tartVm

e2e/src/vm/tart.ts:98–240  ·  view source on GitHub ↗
(os: "macos" | "linux", arch: VmArch = "arm64")

Source from the content-addressed store, hash-verified

96};
97
98export 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++) {

Callers 4

provisionMacFunction · 0.90
setupCliTargetFunction · 0.90
provisionLinuxFunction · 0.90
mainFunction · 0.90

Calls 11

sleepFunction · 0.90
baseImageFunction · 0.85
fetchIpFunction · 0.85
waitSshFunction · 0.85
pushMethod · 0.80
discardMethod · 0.80
sshFunction · 0.70
freePortFunction · 0.70
spawnOnceFunction · 0.70
waitLocalPortFunction · 0.70
closeFunction · 0.70

Tested by

no test coverage detected