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

Function startDaemon

__tests__/daemon-socket-shared-folder.test.ts:146–169  ·  view source on GitHub ↗

* The real daemon for `root`, from the built CLI, started the way a launcher * starts it but as a child of this test, which stops it. Resolves with the * socket it says it listens on.

(root: string)

Source from the content-addressed store, hash-verified

144 * socket it says it listens on.
145 */
146async function startDaemon(root: string): Promise<{ socketPath: string; stderr: () => string }> {
147 let stderr = '';
148 const child: ChildProcess = spawn(process.execPath, [...WASM_RUNTIME_FLAGS, BIN, 'serve', '--mcp', '--path', root], {
149 cwd: root,
150 stdio: ['ignore', 'ignore', 'pipe'],
151 env: { ...process.env, CODEGRAPH_DAEMON_INTERNAL: '1', CODEGRAPH_NO_DAEMON: '' },
152 });
153 child.stderr!.on('data', (chunk: Buffer) => { stderr += chunk.toString('utf8'); });
154 const exited = new Promise<void>((resolve) => child.once('exit', () => resolve()));
155 cleanups.push(async () => {
156 child.kill('SIGTERM');
157 const forced = setTimeout(() => child.kill('SIGKILL'), 10_000);
158 await exited;
159 clearTimeout(forced);
160 });
161 const deadline = Date.now() + 30_000;
162 for (;;) {
163 const listening = /Listening on (\S+) \(pid/.exec(stderr);
164 if (listening) return { socketPath: listening[1]!, stderr: () => stderr };
165 if (child.exitCode !== null) throw new Error(`the daemon exited before it listened:\n${stderr}`);
166 if (Date.now() > deadline) throw new Error(`the daemon did not listen within 30s:\n${stderr}`);
167 await new Promise((resolve) => setTimeout(resolve, 25));
168 }
169}
170
171/** Ask the daemon as the prompt hook does, until it answers: one still opening its index says it is busy. */
172async function askAsTheHook(root: string): Promise<DaemonExplore> {

Calls 5

spawnFunction · 0.85
pushMethod · 0.80
resolveFunction · 0.70
onMethod · 0.65
execMethod · 0.65

Tested by

no test coverage detected