import { describe, it, expect, vi } from 'vitest'; import { readFile } from 'fs/promises'; // Capture what runAgentTurn hands to runClaudeTurn (incl. the on-disk MCP config). const captured = {}; vi.mock('../../../lib/ai/claude_cli.js', () => ({ runClaudeTurn: vi.fn(async (opts) => { captured.opts = opts; captured.cfg = JSON.parse(await readFile(opts.mcpConfigPath, 'utf8')); return { text: 'ok', toolTrace: [], usage: null }; }) })); import { runAgentTurn } from '../../../lib/ai/agent/run_turn.js'; describe('runAgentTurn', () => { it('builds the MCP config (registry + tools + agent + space) and forwards to runClaudeTurn', async () => { const out = await runAgentTurn({ agent: { id: 'a1', slug: 'yerin', capabilities: { read: true }, scopes: {} }, persona: 'YERIN', registryName: 'security', toolNames: ['mcp__void__audit_log'], spaceId: null, sessionId: 'c1', userText: 'check', claudeExe: 'claude' }); expect(out.text).toBe('ok'); expect(captured.opts.systemPrompt).toBe('YERIN'); expect(captured.opts.tools).toEqual(['mcp__void__audit_log']); expect(captured.opts.allowedTools).toEqual(['mcp__void__audit_log']); const env = captured.cfg.mcpServers.void.env; expect(env.VOID_TOOL_REGISTRY).toBe('security'); expect(env.VOID_SPACE_ID).toBe(''); expect(JSON.parse(env.VOID_AGENT_JSON).id).toBe('a1'); }); });