Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions apps/mcp-server/src/agent/agent.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,4 +804,183 @@ describe('AgentService', () => {
expect(result.executionHint).toContain('/taskmaestro stop all');
});
});

describe('dispatchAgents with taskmaestro+teams composable strategy', () => {
it('should return both taskmaestro and teams fields', async () => {
vi.mocked(mockRulesService.getAgent!)
.mockResolvedValueOnce(mockSecurityAgent)
.mockResolvedValueOnce(mockPerformanceAgent);

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist', 'performance-specialist'],
executionStrategy: 'taskmaestro+teams',
});

expect(result.taskmaestro).toBeDefined();
expect(result.teams).toBeDefined();
expect(result.executionStrategy).toBe('taskmaestro+teams');
});

it('should set executionPlan with nested layers', async () => {
vi.mocked(mockRulesService.getAgent!)
.mockResolvedValueOnce(mockSecurityAgent)
.mockResolvedValueOnce(mockPerformanceAgent);

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist', 'performance-specialist'],
executionStrategy: 'taskmaestro+teams',
});

expect(result.executionPlan).toBeDefined();
expect(result.executionPlan!.outerExecution.type).toBe('taskmaestro');
expect(result.executionPlan!.innerCoordination).toBeDefined();
expect(result.executionPlan!.innerCoordination!.type).toBe('teams');
});

it('should match pane count to specialists', async () => {
vi.mocked(mockRulesService.getAgent!)
.mockResolvedValueOnce(mockSecurityAgent)
.mockResolvedValueOnce(mockPerformanceAgent);

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist', 'performance-specialist'],
executionStrategy: 'taskmaestro+teams',
});

expect(result.taskmaestro!.paneCount).toBe(2);
expect(result.teams!.teammates).toHaveLength(2);
});

it('should use mode-based session/team name', async () => {
vi.mocked(mockRulesService.getAgent!).mockResolvedValueOnce(mockSecurityAgent);

const result = await service.dispatchAgents({
mode: 'PLAN',
specialists: ['security-specialist'],
executionStrategy: 'taskmaestro+teams',
});

expect(result.taskmaestro!.sessionName).toBe('plan-specialists');
expect(result.teams!.team_name).toBe('plan-specialists');
});

it('should include composable execution hint', async () => {
vi.mocked(mockRulesService.getAgent!)
.mockResolvedValueOnce(mockSecurityAgent)
.mockResolvedValueOnce(mockPerformanceAgent);

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist', 'performance-specialist'],
executionStrategy: 'taskmaestro+teams',
});

expect(result.executionHint).toContain('Composable execution');
expect(result.executionHint).toContain('TaskMaestro');
expect(result.executionHint).toContain('Teams');
});

it('should include primary agent when provided', async () => {
vi.mocked(mockRulesService.getAgent!)
.mockResolvedValueOnce(mockSecurityAgent) // primary
.mockResolvedValueOnce(mockPerformanceAgent); // specialist

const result = await service.dispatchAgents({
mode: 'EVAL',
primaryAgent: 'security-specialist',
specialists: ['performance-specialist'],
executionStrategy: 'taskmaestro+teams',
});

expect(result.primaryAgent).toBeDefined();
expect(result.primaryAgent!.name).toBe('security-specialist');
expect(result.taskmaestro).toBeDefined();
expect(result.teams).toBeDefined();
});

it('should handle failed agents in composable strategy', async () => {
vi.mocked(mockRulesService.getAgent!)
.mockResolvedValueOnce(mockSecurityAgent)
.mockRejectedValueOnce(new Error('Agent not found'));

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist', 'invalid-agent'],
executionStrategy: 'taskmaestro+teams',
});

expect(result.taskmaestro!.paneCount).toBe(1);
expect(result.teams!.teammates).toHaveLength(1);
expect(result.failedAgents).toHaveLength(1);
});
});

describe('executionPlan in all strategies', () => {
it('subagent strategy populates executionPlan', async () => {
vi.mocked(mockRulesService.getAgent!).mockResolvedValueOnce(mockSecurityAgent);

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist'],
includeParallel: true,
});

expect(result.executionPlan).toBeDefined();
expect(result.executionPlan!.outerExecution.type).toBe('subagent');
expect(result.executionPlan!.innerCoordination).toBeUndefined();
});

it('taskmaestro strategy populates executionPlan', async () => {
vi.mocked(mockRulesService.getAgent!).mockResolvedValueOnce(mockSecurityAgent);

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist'],
executionStrategy: 'taskmaestro',
});

expect(result.executionPlan).toBeDefined();
expect(result.executionPlan!.outerExecution.type).toBe('taskmaestro');
expect(result.executionPlan!.innerCoordination).toBeUndefined();
});

it('teams strategy populates executionPlan', async () => {
vi.mocked(mockRulesService.getAgent!).mockResolvedValueOnce(mockSecurityAgent);

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist'],
executionStrategy: 'teams',
});

expect(result.executionPlan).toBeDefined();
expect(result.executionPlan!.outerExecution.type).toBe('teams');
expect(result.executionPlan!.innerCoordination).toBeUndefined();
});

it('no specialists results in no executionPlan', async () => {
const result = await service.dispatchAgents({
mode: 'EVAL',
});

expect(result.executionPlan).toBeUndefined();
});

it('backward compat: no executionStrategy still defaults to subagent', async () => {
vi.mocked(mockRulesService.getAgent!).mockResolvedValueOnce(mockSecurityAgent);

const result = await service.dispatchAgents({
mode: 'EVAL',
specialists: ['security-specialist'],
includeParallel: true,
});

expect(result.executionStrategy).toBe('subagent');
expect(result.executionPlan).toBeDefined();
expect(result.executionPlan!.outerExecution.type).toBe('subagent');
});
});
});
Loading
Loading