/** * How mcpd opens a STDIO session: attach to PID 1, or exec a new process. * * Subtle and silent when wrong. With injected secret delivery the credentials * exist ONLY in PID 1's environment (a shell sourced /vault/secrets/ and * exec'd the server), so an `exec` starts a process with empty credentials — * the server comes up, answers tools/list, and fails every authenticated call. */ import { describe, it, expect } from 'vitest'; import { chooseStdioMode } from '../src/services/mcp-proxy-service.js'; const base = { name: 's', id: 'id1' }; describe('chooseStdioMode', () => { it('attaches for an injector server even though it has a packageName', () => { // The regression: packageName would otherwise select exec, and exec loses // the secrets entirely. expect(chooseStdioMode({ ...base, secretDelivery: 'injector', packageName: '@leval/mcp-grafana' })) .toEqual({ kind: 'attach' }); }); it('attaches for an injector server even though it has an explicit command', () => { expect(chooseStdioMode({ ...base, secretDelivery: 'injector', command: ['node', 'x.js'] })) .toEqual({ kind: 'attach' }); }); it('still execs a package server on the default env delivery', () => { const m = chooseStdioMode({ ...base, secretDelivery: 'env', packageName: '@leval/mcp-grafana', runtime: 'node' }); expect(m.kind).toBe('exec'); }); it('still prefers an explicit command over packageName on env delivery', () => { expect(chooseStdioMode({ ...base, secretDelivery: 'env', command: ['node', 'x.js'], packageName: 'p' })) .toEqual({ kind: 'exec', command: ['node', 'x.js'] }); }); it('attaches for an image-entrypoint server, as before', () => { expect(chooseStdioMode({ ...base, dockerImage: 'gitea/mcp:latest' })).toEqual({ kind: 'attach' }); }); it('rejects a server with no way to start', () => { expect(() => chooseStdioMode({ ...base })).toThrow(/packageName, command, or dockerImage/); }); });