import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { mkdtempSync, rmSync } from 'fs'; import { tmpdir } from 'os'; import { join } from 'path'; import { createHandoff, listHandoffs, getHandoff } from '../src/core/services/handoffService.js'; describe('handoffService', () => { let cwd: string; beforeEach(() => { cwd = mkdtempSync(join(tmpdir(), 'ah-hof-')); }); afterEach(() => { rmSync(cwd, { recursive: true, force: true }); }); it('creates and reads a handoff', () => { const h = createHandoff(cwd, { fromRole: 'architect', toRole: 'implementer', summary: 's', context: 'c' }); expect(h.id).toBe('HOF-0001'); expect(getHandoff(cwd, h.id).handoff.summary).toBe('s'); expect(listHandoffs(cwd)).toHaveLength(1); }); it('listHandoffs carries fromRole and toRole in the index entry', () => { createHandoff(cwd, { fromRole: 'architect', toRole: 'implementer', summary: 'Hand over design', context: 'done', }); const items = listHandoffs(cwd); expect(items).toHaveLength(1); expect(items[0].fromRole).toBe('architect'); expect(items[0].toRole).toBe('implementer'); // agent names default to undefined when not supplied expect(items[0].fromAgent == null).toBe(true); expect(items[0].toAgent == null).toBe(true); }); it('listHandoffs carries fromAgent and toAgent when supplied', () => { createHandoff(cwd, { fromRole: 'reviewer', toRole: 'implementer', fromAgent: 'claude', toAgent: 'codex', summary: 'Review complete', context: 'lgtm', }); const items = listHandoffs(cwd); expect(items[0].fromAgent).toBe('claude'); expect(items[0].toAgent).toBe('codex'); }); });