The real proxy, with no daemon: it answers initialize and tools/list itself.
(clientInfo: object)
| 195 | describe('the proxy\'s local handshake says what the session says (#1267)', () => { |
| 196 | /** The real proxy, with no daemon: it answers initialize and tools/list itself. */ |
| 197 | async function proxyHandshake(clientInfo: object): Promise<{ init: any; list: any }> { |
| 198 | const proxyModule = path.resolve(__dirname, '../dist/mcp/proxy.js'); |
| 199 | const script = ` |
| 200 | const { runLocalHandshakeProxy } = require(${JSON.stringify(proxyModule)}); |
| 201 | runLocalHandshakeProxy({ |
| 202 | root: process.cwd(), |
| 203 | getDaemonSocket: async () => null, |
| 204 | makeEngine: () => { throw new Error('no tool call is made'); }, |
| 205 | }); |
| 206 | `; |
| 207 | const child = spawn(process.execPath, ['-e', script], { |
| 208 | cwd: indexedDir, |
| 209 | env: { |
| 210 | ...process.env, |
| 211 | CODEGRAPH_TELEMETRY: '0', DO_NOT_TRACK: '1', CODEGRAPH_NO_UPDATE_CHECK: '1', CODEGRAPH_NO_PROMPT_HOOK: '1', |
| 212 | CODEGRAPH_NO_WATCHDOG: '1', CODEGRAPH_PPID_POLL_MS: '0', |
| 213 | CODEGRAPH_STARTUP_HANDSHAKE_TIMEOUT_MS: '0', CODEGRAPH_DAEMON_RETRY_MS: '60000', |
| 214 | CODEGRAPH_MCP_TOOLS: ALL_TOOLS, |
| 215 | }, |
| 216 | stdio: ['pipe', 'pipe', 'pipe'], |
| 217 | }); |
| 218 | let out = ''; |
| 219 | let err = ''; |
| 220 | child.stdout!.on('data', (d) => { out += d; }); |
| 221 | child.stderr!.on('data', (d) => { err += d; }); |
| 222 | const exited = new Promise<void>((resolve) => child.once('exit', () => resolve())); |
| 223 | const send = (msg: object) => child.stdin!.write(JSON.stringify({ jsonrpc: '2.0', ...msg }) + '\n'); |
| 224 | const reply = (id: number) => |
| 225 | out.split('\n').filter((l) => l.startsWith('{')).map((l) => JSON.parse(l)).find((m) => m.id === id); |
| 226 | const until = async (check: () => boolean) => { |
| 227 | const deadline = Date.now() + 15_000; |
| 228 | while (!check()) { |
| 229 | if (Date.now() > deadline) throw new Error(`no reply: ${out}\n${err}`); |
| 230 | await new Promise((r) => setTimeout(r, 25)); |
| 231 | } |
| 232 | }; |
| 233 | try { |
| 234 | send({ id: 1, method: 'initialize', params: initializeParams(clientInfo, indexedDir) }); |
| 235 | send({ id: 2, method: 'tools/list', params: {} }); |
| 236 | await until(() => !!reply(1) && !!reply(2)); |
| 237 | return { init: reply(1).result, list: reply(2).result }; |
| 238 | } finally { |
| 239 | child.stdin!.end(); |
| 240 | child.kill('SIGKILL'); |
| 241 | await exited; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | it('gives an OpenCode client, and any other, the same initialize and tools/list answers as the session', async () => { |
| 246 | process.env.CODEGRAPH_MCP_TOOLS = ALL_TOOLS; |
no test coverage detected