| 162 | } |
| 163 | |
| 164 | async function waitForHealth(port, child, deadlineMs = 5000) { |
| 165 | const started = Date.now(); |
| 166 | while (Date.now() - started < deadlineMs) { |
| 167 | if (child.exitCode !== null) { |
| 168 | throw new Error(`computerd exited early with code ${child.exitCode}`); |
| 169 | } |
| 170 | try { |
| 171 | const r = await httpGet(`http://127.0.0.1:${port}/health`); |
| 172 | if (r.statusCode === 200) return; |
| 173 | } catch {} |
| 174 | await sleep(50); |
| 175 | } |
| 176 | throw new Error("computerd never reported healthy"); |
| 177 | } |
| 178 | |
| 179 | async function targetSnapshot(port) { |
| 180 | const r = await httpGet(`http://127.0.0.1:${port}/__computerd/stubs`); |