feat(agents): shared runAgentTurn turn-runner

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-04 21:06:56 +10:00
parent 1a28742536
commit 01c6594bfb
2 changed files with 80 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
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');
});
});