The "Attached to shared daemon" line is benign INFO, but it was written to stderr — and MCP hosts render all server stderr at error level (and append an `undefined` data field), so on every session start a healthy attach showed up as `[error] … undefined`. It is now gated behind CODEGRAPH_MCP_LOG_ATTACH=1: silent by default, opt-in for debugging daemon attach. Both attach sites (runProxy + connectWithHello) route through one helper. The daemon integration tests opt the harness into the log so their attach assertions still observe a successful attach. Re-applies the approach from #640 by @mturac. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
7fd8b4c185
commit
10defecc4b
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* #618 — the "attached to shared daemon" line is benign INFO, but MCP hosts
|
||||
* render server stderr at error level (and tack on an `undefined` data field),
|
||||
* so on every session start a healthy attach showed up as `[error] … undefined`.
|
||||
* It's now gated behind CODEGRAPH_MCP_LOG_ATTACH=1 — silent by default, opt-in
|
||||
* for debugging. Approach from #640 by @mturac.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { logAttachedDaemon } from '../src/mcp/proxy';
|
||||
|
||||
const hello = { pid: 4242, codegraph: '9.9.9' } as any;
|
||||
|
||||
describe('daemon attach log gating (#618)', () => {
|
||||
let spy: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
spy = vi.spyOn(process.stderr, 'write').mockImplementation((() => true) as any);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
spy.mockRestore();
|
||||
delete process.env.CODEGRAPH_MCP_LOG_ATTACH;
|
||||
});
|
||||
|
||||
it('is silent by default (no [error]/undefined noise in MCP hosts)', () => {
|
||||
delete process.env.CODEGRAPH_MCP_LOG_ATTACH;
|
||||
logAttachedDaemon('/tmp/cg.sock', hello);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('logs the attach line only when CODEGRAPH_MCP_LOG_ATTACH=1 (opt-in debug)', () => {
|
||||
process.env.CODEGRAPH_MCP_LOG_ATTACH = '1';
|
||||
logAttachedDaemon('/tmp/cg.sock', hello);
|
||||
const out = spy.mock.calls.map((c) => String(c[0])).join('');
|
||||
expect(out).toContain('Attached to shared daemon on /tmp/cg.sock');
|
||||
expect(out).toContain('pid 4242');
|
||||
});
|
||||
});
|
||||
@@ -52,7 +52,10 @@ function spawnServer(cwd: string, env: NodeJS.ProcessEnv = {}): SpawnedServer {
|
||||
const child = spawn(process.execPath, [BIN, 'serve', '--mcp'], {
|
||||
cwd,
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
env: { ...process.env, ...env },
|
||||
// #618: the daemon-attach log line is now off by default; opt the test
|
||||
// harness into it (CODEGRAPH_MCP_LOG_ATTACH=1) so the attach assertions
|
||||
// below can still observe a successful attach. A per-test env still wins.
|
||||
env: { CODEGRAPH_MCP_LOG_ATTACH: '1', ...process.env, ...env },
|
||||
}) as ChildProcessWithoutNullStreams;
|
||||
// Swallow spawn/EPIPE errors so killing a child mid-write can't surface as an
|
||||
// unhandled error that crashes the vitest worker.
|
||||
|
||||
Reference in New Issue
Block a user