()
| 31 | * Reuses an existing handle if already started. |
| 32 | */ |
| 33 | export async function startTestProxy(): Promise<ProxyHandle> { |
| 34 | if (proxyHandle) return proxyHandle; |
| 35 | |
| 36 | const wallet = await resolveOrGenerateWalletKey(); |
| 37 | const testPort = getTestPort(); |
| 38 | |
| 39 | proxyHandle = await startProxy({ |
| 40 | wallet, |
| 41 | port: testPort, |
| 42 | skipBalanceCheck: true, |
| 43 | }); |
| 44 | |
| 45 | // Wait for /health to return 200 |
| 46 | const deadline = Date.now() + HEALTH_TIMEOUT_MS; |
| 47 | while (Date.now() < deadline) { |
| 48 | try { |
| 49 | const res = await fetch(`${proxyHandle.baseUrl}/health`); |
| 50 | if (res.ok) return proxyHandle; |
| 51 | } catch { |
| 52 | // proxy not ready yet |
| 53 | } |
| 54 | await new Promise((r) => setTimeout(r, HEALTH_POLL_INTERVAL_MS)); |
| 55 | } |
| 56 | |
| 57 | throw new Error(`Test proxy did not become healthy within ${HEALTH_TIMEOUT_MS}ms`); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Stop the test proxy and clear the cached handle. |
no test coverage detected