import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { mkdtempSync, rmSync } from 'fs'; import { tmpdir } from 'os'; import { join } from 'path'; import { buildApp } from '../src/server/index.js'; import { init } from '../src/cli/commands/init.js'; describe('GET /team', () => { let cwd: string; let app: ReturnType; beforeEach(() => { cwd = mkdtempSync(join(tmpdir(), 'ah-team-')); init(cwd, { projectName: 'team-test', yes: true }); app = buildApp(cwd); }); afterEach(() => { rmSync(cwd, { recursive: true, force: true }); }); it('serves the team page as HTML', async () => { const res = await app.inject({ method: 'GET', url: '/team' }); expect(res.statusCode).toBe(200); expect(res.headers['content-type']).toContain('text/html'); const html = res.payload; expect(html).toContain('AgentHub Team'); expect(html).toContain('team-test'); expect(html).toContain('/board'); expect(html).toContain('/team'); }); it('renders configured agents by role', async () => { const res = await app.inject({ method: 'GET', url: '/team' }); const html = res.payload; expect(html).toContain('architect'); expect(html).toContain('implementer'); expect(html).toContain('claude'); expect(html).toContain('codex'); }); it('marks an agent as busy when they have an in-progress task', async () => { await app.inject({ method: 'POST', url: '/tasks', payload: { title: 'Busy work', role: 'implementer' }, }); await app.inject({ method: 'PATCH', url: '/tasks/TSK-0001', payload: { status: 'in_progress', assignedTo: 'codex' }, }); const res = await app.inject({ method: 'GET', url: '/team' }); const html = res.payload; expect(html).toContain('TSK-0001'); // The busy agent's card is tagged for the live client sync and rendered active. expect(html).toContain('data-agent="codex"'); expect(html).toContain('agent-card active'); expect(html).toContain('active'); }); });