UNPKG

claude-code-collective

Version:

Sub-agent collective framework for Claude Code with TDD validation, hub-spoke coordination, and automated handoffs

155 lines (132 loc) 4.44 kB
// handoff-test.template.js // Agent handoff validation tests // Project: {{PROJECT_NAME}} // Generated: {{INSTALL_DATE}} describe('Agent Handoff Validation', () => { describe('Hub-and-Spoke Routing', () => { test('should route all requests through @routing-agent', async () => { // Test that direct agent-to-agent communication is blocked const directHandoff = { from: 'test-agent', to: 'implementation-agent', bypassHub: true }; expect(() => validateHandoff(directHandoff)) .toThrow('Direct agent communication not allowed'); }); test('should validate routing agent capabilities', async () => { const routingRequest = { type: 'implementation', requirements: ['code-generation', 'file-operations'], context: 'Create new feature component' }; const selectedAgent = await selectAgent(routingRequest); expect(selectedAgent).toBeDefined(); expect(selectedAgent.capabilities).toContain('code-generation'); }); }); describe('Test-Driven Handoffs', () => { test('should require test contracts for handoffs', async () => { const handoffWithoutTest = { from: '@routing-agent', to: '@implementation-agent', context: 'Build feature', contract: null }; const validation = await validateHandoff(handoffWithoutTest); expect(validation.warnings).toContain('No test contract specified'); }); test('should validate preconditions before handoff', async () => { const handoff = { from: '@routing-agent', to: '@testing-agent', context: 'Run tests', contract: { preconditions: ['test-files-exist', 'dependencies-installed'], postconditions: ['tests-passed', 'coverage-report-generated'] } }; const validation = await validateHandoff(handoff); expect(validation.preconditionsValid).toBe(true); }); }); describe('Context Preservation', () => { test('should preserve context across handoffs', async () => { const originalContext = { userRequest: 'Create login component', requirements: ['authentication', 'validation'], constraints: ['mobile-responsive', 'accessible'] }; const handoff = await createHandoff('@routing-agent', '@component-agent', originalContext); expect(handoff.context).toEqual(originalContext); }); test('should track context degradation', async () => { const context = createLargeContext(1000); // 1000 tokens const handoff = await processHandoff(context); // Context should not degrade by more than 10% expect(handoff.contextRetention).toBeGreaterThan(0.9); }); }); }); // Test helper functions function validateHandoff(handoff) { if (handoff.bypassHub) { throw new Error('Direct agent communication not allowed'); } const warnings = []; if (!handoff.contract) { warnings.push('No test contract specified'); } return { valid: warnings.length === 0, warnings, preconditionsValid: handoff.contract ? checkPreconditions(handoff.contract.preconditions) : false }; } function selectAgent(request) { // Mock agent selection logic const agents = { '@implementation-agent': { capabilities: ['code-generation', 'file-operations', 'refactoring'] }, '@testing-agent': { capabilities: ['test-creation', 'validation', 'coverage'] } }; return agents['@implementation-agent']; } function createHandoff(from, to, context) { return { from, to, context, timestamp: new Date().toISOString() }; } function createLargeContext(tokens) { return { content: 'x'.repeat(tokens * 4), // Rough token estimation tokenCount: tokens }; } function processHandoff(context) { // Simulate context processing with some degradation const degradation = Math.random() * 0.05; // Max 5% degradation return { contextRetention: 1 - degradation }; } function checkPreconditions(preconditions) { // Mock precondition checking return preconditions.every(condition => { switch (condition) { case 'test-files-exist': return true; // Mock validation case 'dependencies-installed': return true; // Mock validation default: return false; } }); }