import { describe, it, expect } from 'vitest';
import { renderClaudeCodeAgent } from '../../src/agent-definitions/render-claude-code';
import type { AgentDefinition } from '../../src/agent-definitions/generator';

const mockDef: AgentDefinition = {
  name: 'harness-code-reviewer',
  description: 'Perform code review and address findings.',
  tools: ['Bash', 'Read', 'Glob', 'Grep'],
  role: 'Perform AI-powered code review',
  skills: ['harness-code-review'],
  steps: [
    { command: 'validate', when: 'always' },
    { skill: 'harness-code-review', when: 'on_pr', output: 'auto' },
  ],
  methodology: '# Code Review\n\nFull methodology here.',
};

describe('renderClaudeCodeAgent', () => {
  it('produces markdown with YAML frontmatter', () => {
    const output = renderClaudeCodeAgent(mockDef);
    expect(output).toMatch(/^---\n/);
    expect(output).toContain('name: harness-code-reviewer');
    expect(output).toContain('description:');
    expect(output).toContain('tools: Bash, Read, Glob, Grep');
  });

  it('includes generated header', () => {
    const output = renderClaudeCodeAgent(mockDef);
    expect(output).toContain('Generated by harness generate-agent-definitions');
  });

  it('includes role section', () => {
    const output = renderClaudeCodeAgent(mockDef);
    expect(output).toContain('## Role');
    expect(output).toContain('AI-powered code review');
  });

  it('includes steps section with formatted steps', () => {
    const output = renderClaudeCodeAgent(mockDef);
    expect(output).toContain('## Steps');
    expect(output).toContain('1. Run `harness validate` (always)');
    expect(output).toContain('2. Execute harness-code-review skill (on_pr)');
  });

  it('includes methodology section with SKILL.md content', () => {
    const output = renderClaudeCodeAgent(mockDef);
    expect(output).toContain('## Methodology');
    expect(output).toContain('Full methodology here');
  });

  it('omits methodology section when empty', () => {
    const def = { ...mockDef, methodology: '' };
    const output = renderClaudeCodeAgent(def);
    expect(output).not.toContain('## Methodology');
  });
});
