| 63 | } |
| 64 | |
| 65 | function startProxy(script: string, env: Record<string, string> = {}): Proxy { |
| 66 | const child = spawn(process.execPath, ['-e', PRELUDE + script], { |
| 67 | env: { |
| 68 | ...process.env, |
| 69 | CODEGRAPH_TELEMETRY: '0', DO_NOT_TRACK: '1', CODEGRAPH_NO_PROMPT_HOOK: '1', |
| 70 | CODEGRAPH_NO_WATCHDOG: '1', CODEGRAPH_PPID_POLL_MS: '0', |
| 71 | CODEGRAPH_STARTUP_HANDSHAKE_TIMEOUT_MS: '0', |
| 72 | CODEGRAPH_DAEMON_RETRY_MS: '200', |
| 73 | ...env, |
| 74 | }, |
| 75 | stdio: ['pipe', 'pipe', 'pipe'], |
| 76 | }); |
| 77 | let stdout = '', stderr = ''; |
| 78 | child.stdout!.on('data', (d) => { stdout += d; }); |
| 79 | child.stderr!.on('data', (d) => { stderr += d; }); |
| 80 | // On a proxy that has already exited, a write fails with EPIPE; the |
| 81 | // assertions say what went wrong, not an unhandled stream error. |
| 82 | child.stdin!.on('error', () => { /* proxy gone */ }); |
| 83 | const exited = () => child.exitCode !== null || child.signalCode !== null; |
| 84 | return { |
| 85 | child, |
| 86 | out: () => stdout, |
| 87 | err: () => stderr, |
| 88 | exited, |
| 89 | write: (s) => { if (!exited()) child.stdin!.write(s); }, |
| 90 | dispose: async () => { |
| 91 | if (!exited()) child.kill('SIGKILL'); |
| 92 | await until(exited, 'the proxy to exit'); |
| 93 | child.stdin!.destroy(); |
| 94 | }, |
| 95 | }; |
| 96 | } |
| 97 | |
| 98 | describe('local proxy shutdown (#2311)', () => { |
| 99 | it('waits for an engine being retired before it exits', async () => { |