|
| 1 | +import { describe, it, expect } from 'vitest' |
| 2 | +import path from 'path' |
| 3 | +import { AgentManager } from './AgentManager.js' |
| 4 | +import { PromptTemplateManager } from './PromptTemplateManager.js' |
| 5 | + |
| 6 | +/** |
| 7 | + * Integration test for AgentManager + PromptTemplateManager + real agent templates. |
| 8 | + * |
| 9 | + * These tests read the actual agent markdown files from templates/agents/, |
| 10 | + * run real Handlebars substitution, and verify the end-to-end result of |
| 11 | + * frontmatter parsing with template variables. |
| 12 | + */ |
| 13 | + |
| 14 | +// Resolve the real templates/agents/ directory relative to the project root |
| 15 | +const PROJECT_ROOT = path.resolve(import.meta.dirname, '..', '..') |
| 16 | +const AGENTS_DIR = path.join(PROJECT_ROOT, 'templates', 'agents') |
| 17 | +const PROMPTS_DIR = path.join(PROJECT_ROOT, 'templates', 'prompts') |
| 18 | + |
| 19 | +// All agent names expected in the templates/agents/ directory |
| 20 | +const ALL_AGENT_NAMES = [ |
| 21 | + 'iloom-artifact-reviewer', |
| 22 | + 'iloom-code-reviewer', |
| 23 | + 'iloom-framework-detector', |
| 24 | + 'iloom-issue-analyze-and-plan', |
| 25 | + 'iloom-issue-analyzer', |
| 26 | + 'iloom-issue-complexity-evaluator', |
| 27 | + 'iloom-issue-enhancer', |
| 28 | + 'iloom-issue-implementer', |
| 29 | + 'iloom-issue-planner', |
| 30 | + 'iloom-wave-verifier', |
| 31 | +] |
| 32 | + |
| 33 | +describe('AgentManager integration (real templates)', () => { |
| 34 | + // Use real PromptTemplateManager and real agent files |
| 35 | + const templateManager = new PromptTemplateManager(PROMPTS_DIR) |
| 36 | + |
| 37 | + describe('loadAgents with SWARM_MODE=true', () => { |
| 38 | + it('should load all agents successfully', async () => { |
| 39 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 40 | + const agents = await manager.loadAgents(undefined, { SWARM_MODE: true }) |
| 41 | + |
| 42 | + const loadedNames = Object.keys(agents).sort() |
| 43 | + expect(loadedNames).toEqual(ALL_AGENT_NAMES) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should resolve swarm-mode model overrides from Handlebars conditionals', async () => { |
| 47 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 48 | + const agents = await manager.loadAgents(undefined, { SWARM_MODE: true }) |
| 49 | + |
| 50 | + // Agents with conditional model: sonnet in swarm mode |
| 51 | + expect(agents['iloom-issue-implementer'].model).toBe('sonnet') |
| 52 | + expect(agents['iloom-issue-planner'].model).toBe('sonnet') |
| 53 | + expect(agents['iloom-issue-enhancer'].model).toBe('sonnet') |
| 54 | + expect(agents['iloom-code-reviewer'].model).toBe('sonnet') |
| 55 | + |
| 56 | + // Agents with unconditional model (always opus regardless of mode) |
| 57 | + expect(agents['iloom-issue-analyzer'].model).toBe('opus') |
| 58 | + expect(agents['iloom-issue-analyze-and-plan'].model).toBe('opus') |
| 59 | + expect(agents['iloom-wave-verifier'].model).toBe('opus') |
| 60 | + expect(agents['iloom-framework-detector'].model).toBe('opus') |
| 61 | + expect(agents['iloom-artifact-reviewer'].model).toBe('opus') |
| 62 | + expect(agents['iloom-issue-complexity-evaluator'].model).toBe('haiku') |
| 63 | + }) |
| 64 | + |
| 65 | + it('should resolve swarm-mode effort defaults from Handlebars conditionals', async () => { |
| 66 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 67 | + const agents = await manager.loadAgents(undefined, { SWARM_MODE: true }) |
| 68 | + |
| 69 | + // Agents with conditional effort: {{#if SWARM_MODE}}effort: <level>{{/if}} |
| 70 | + expect(agents['iloom-issue-analyzer'].effort).toBe('high') |
| 71 | + expect(agents['iloom-issue-planner'].effort).toBe('high') |
| 72 | + expect(agents['iloom-issue-implementer'].effort).toBe('medium') |
| 73 | + expect(agents['iloom-issue-enhancer'].effort).toBe('medium') |
| 74 | + expect(agents['iloom-code-reviewer'].effort).toBe('medium') |
| 75 | + expect(agents['iloom-issue-complexity-evaluator'].effort).toBe('high') |
| 76 | + expect(agents['iloom-issue-analyze-and-plan'].effort).toBe('high') |
| 77 | + |
| 78 | + // Agents with unconditional effort (always set regardless of SWARM_MODE) |
| 79 | + expect(agents['iloom-wave-verifier'].effort).toBe('high') |
| 80 | + expect(agents['iloom-framework-detector'].effort).toBe('high') |
| 81 | + |
| 82 | + // Agents with no effort field at all |
| 83 | + expect(agents['iloom-artifact-reviewer'].effort).toBeUndefined() |
| 84 | + }) |
| 85 | + |
| 86 | + it('should have non-empty prompts for all agents', async () => { |
| 87 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 88 | + const agents = await manager.loadAgents(undefined, { SWARM_MODE: true }) |
| 89 | + |
| 90 | + for (const [name, config] of Object.entries(agents)) { |
| 91 | + expect(config.prompt.length, `${name} should have a non-empty prompt`).toBeGreaterThan(0) |
| 92 | + } |
| 93 | + }) |
| 94 | + |
| 95 | + it('should have non-empty descriptions for all agents', async () => { |
| 96 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 97 | + const agents = await manager.loadAgents(undefined, { SWARM_MODE: true }) |
| 98 | + |
| 99 | + for (const [name, config] of Object.entries(agents)) { |
| 100 | + expect(config.description.length, `${name} should have a non-empty description`).toBeGreaterThan(0) |
| 101 | + } |
| 102 | + }) |
| 103 | + }) |
| 104 | + |
| 105 | + describe('loadAgents with SWARM_MODE=false (non-swarm)', () => { |
| 106 | + it('should load all agents successfully', async () => { |
| 107 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 108 | + const agents = await manager.loadAgents(undefined, { SWARM_MODE: false }) |
| 109 | + |
| 110 | + const loadedNames = Object.keys(agents).sort() |
| 111 | + expect(loadedNames).toEqual(ALL_AGENT_NAMES) |
| 112 | + }) |
| 113 | + |
| 114 | + it('should resolve non-swarm model defaults', async () => { |
| 115 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 116 | + const agents = await manager.loadAgents(undefined, { SWARM_MODE: false }) |
| 117 | + |
| 118 | + // Agents with conditional model resolve to opus in non-swarm mode |
| 119 | + expect(agents['iloom-issue-implementer'].model).toBe('opus') |
| 120 | + expect(agents['iloom-issue-planner'].model).toBe('opus') |
| 121 | + expect(agents['iloom-issue-enhancer'].model).toBe('opus') |
| 122 | + expect(agents['iloom-code-reviewer'].model).toBe('opus') |
| 123 | + |
| 124 | + // Agents with unconditional model are the same regardless of mode |
| 125 | + expect(agents['iloom-issue-analyzer'].model).toBe('opus') |
| 126 | + expect(agents['iloom-issue-analyze-and-plan'].model).toBe('opus') |
| 127 | + expect(agents['iloom-wave-verifier'].model).toBe('opus') |
| 128 | + expect(agents['iloom-framework-detector'].model).toBe('opus') |
| 129 | + expect(agents['iloom-artifact-reviewer'].model).toBe('opus') |
| 130 | + expect(agents['iloom-issue-complexity-evaluator'].model).toBe('haiku') |
| 131 | + }) |
| 132 | + |
| 133 | + it('should have undefined effort for agents that only set effort in swarm mode', async () => { |
| 134 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 135 | + const agents = await manager.loadAgents(undefined, { SWARM_MODE: false }) |
| 136 | + |
| 137 | + // These agents use {{#if SWARM_MODE}}effort: <level>{{/if}} - resolves to empty/undefined |
| 138 | + expect(agents['iloom-issue-analyzer'].effort).toBeUndefined() |
| 139 | + expect(agents['iloom-issue-planner'].effort).toBeUndefined() |
| 140 | + expect(agents['iloom-issue-implementer'].effort).toBeUndefined() |
| 141 | + expect(agents['iloom-issue-enhancer'].effort).toBeUndefined() |
| 142 | + expect(agents['iloom-code-reviewer'].effort).toBeUndefined() |
| 143 | + expect(agents['iloom-issue-complexity-evaluator'].effort).toBeUndefined() |
| 144 | + expect(agents['iloom-issue-analyze-and-plan'].effort).toBeUndefined() |
| 145 | + |
| 146 | + // These agents have unconditional effort - always present |
| 147 | + expect(agents['iloom-wave-verifier'].effort).toBe('high') |
| 148 | + expect(agents['iloom-framework-detector'].effort).toBe('high') |
| 149 | + |
| 150 | + // No effort field at all |
| 151 | + expect(agents['iloom-artifact-reviewer'].effort).toBeUndefined() |
| 152 | + }) |
| 153 | + }) |
| 154 | + |
| 155 | + describe('loadAgents without templateVariables (no substitution)', () => { |
| 156 | + it('should load all agents successfully even without template variables', async () => { |
| 157 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 158 | + const agents = await manager.loadAgents() |
| 159 | + |
| 160 | + const loadedNames = Object.keys(agents).sort() |
| 161 | + expect(loadedNames).toEqual(ALL_AGENT_NAMES) |
| 162 | + }) |
| 163 | + }) |
| 164 | + |
| 165 | + describe('swarm vs non-swarm model differences', () => { |
| 166 | + it('should produce different models for swarm-conditional agents', async () => { |
| 167 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 168 | + |
| 169 | + const swarmAgents = await manager.loadAgents(undefined, { SWARM_MODE: true }) |
| 170 | + const nonSwarmAgents = await manager.loadAgents(undefined, { SWARM_MODE: false }) |
| 171 | + |
| 172 | + // Agents that change model between swarm and non-swarm |
| 173 | + const conditionalModelAgents = [ |
| 174 | + 'iloom-issue-implementer', |
| 175 | + 'iloom-issue-planner', |
| 176 | + 'iloom-issue-enhancer', |
| 177 | + 'iloom-code-reviewer', |
| 178 | + ] |
| 179 | + |
| 180 | + for (const name of conditionalModelAgents) { |
| 181 | + expect( |
| 182 | + swarmAgents[name].model, |
| 183 | + `${name} swarm model should be sonnet`, |
| 184 | + ).toBe('sonnet') |
| 185 | + expect( |
| 186 | + nonSwarmAgents[name].model, |
| 187 | + `${name} non-swarm model should be opus`, |
| 188 | + ).toBe('opus') |
| 189 | + } |
| 190 | + }) |
| 191 | + |
| 192 | + it('should produce different effort levels for swarm-conditional agents', async () => { |
| 193 | + const manager = new AgentManager(AGENTS_DIR, templateManager) |
| 194 | + |
| 195 | + const swarmAgents = await manager.loadAgents(undefined, { SWARM_MODE: true }) |
| 196 | + const nonSwarmAgents = await manager.loadAgents(undefined, { SWARM_MODE: false }) |
| 197 | + |
| 198 | + // Agents that only have effort in swarm mode |
| 199 | + const conditionalEffortAgents = [ |
| 200 | + 'iloom-issue-analyzer', |
| 201 | + 'iloom-issue-planner', |
| 202 | + 'iloom-issue-implementer', |
| 203 | + 'iloom-issue-enhancer', |
| 204 | + 'iloom-code-reviewer', |
| 205 | + 'iloom-issue-complexity-evaluator', |
| 206 | + 'iloom-issue-analyze-and-plan', |
| 207 | + ] |
| 208 | + |
| 209 | + for (const name of conditionalEffortAgents) { |
| 210 | + expect( |
| 211 | + swarmAgents[name].effort, |
| 212 | + `${name} should have effort in swarm mode`, |
| 213 | + ).toBeDefined() |
| 214 | + expect( |
| 215 | + nonSwarmAgents[name].effort, |
| 216 | + `${name} should NOT have effort in non-swarm mode`, |
| 217 | + ).toBeUndefined() |
| 218 | + } |
| 219 | + }) |
| 220 | + }) |
| 221 | +}) |
0 commit comments