MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / startProxy

Function startProxy

__tests__/proxy-shutdown.test.ts:65–96  ·  view source on GitHub ↗
(script: string, env: Record<string, string> = {})

Source from the content-addressed store, hash-verified

63}
64
65function 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
98describe('local proxy shutdown (#2311)', () => {
99 it('waits for an engine being retired before it exits', async () => {

Callers 1

Calls 6

spawnFunction · 0.85
exitedFunction · 0.70
untilFunction · 0.70
onMethod · 0.65
writeMethod · 0.65
destroyMethod · 0.45

Tested by

no test coverage detected