| 1135 | } |
| 1136 | |
| 1137 | async function waitForServer(url, timeoutMs = DEFAULT_WAIT_TIMEOUT_MS) { |
| 1138 | const startedAt = Date.now(); |
| 1139 | |
| 1140 | while (Date.now() - startedAt < timeoutMs) { |
| 1141 | try { |
| 1142 | const response = await fetch(url); |
| 1143 | if (response.ok) { |
| 1144 | return; |
| 1145 | } |
| 1146 | } catch { |
| 1147 | // Keep polling until timeout. |
| 1148 | } |
| 1149 | |
| 1150 | await delay(500); |
| 1151 | } |
| 1152 | |
| 1153 | throw new Error(`Timed out waiting for agent-server at ${url}`); |
| 1154 | } |
| 1155 | |
| 1156 | function spawnProcess(command, args, options = {}) { |
| 1157 | const child = spawn( |