import { describe, it, expect, vi, beforeEach } from 'vitest';
import { loadEvalSuitesFromData } from '../../index.js';

// ─── loadEvalSuitesFromData tests ───────────────────────────────────────────

describe('loadEvalSuitesFromData', () => {
  it('loads suites from data/ YAML files', () => {
    const suites = loadEvalSuitesFromData();
    expect(suites.length).toBeGreaterThanOrEqual(4);

    const ids = suites.map((s) => s.id);
    expect(ids).toContain('agent-coding');
    expect(ids).toContain('chat-quality');
    expect(ids).toContain('long-context-retrieval');
    expect(ids).toContain('utility-calls');
  });

  it('loads code suite with correct structure', () => {
    const suites = loadEvalSuitesFromData();
    const codeSuite = suites.find((s) => s.id === 'agent-coding');
    expect(codeSuite).not.toBeUndefined();
    expect(codeSuite!.kind).toBe('code');
    expect(codeSuite!.tasks.length).toBeGreaterThan(0);

    const task = codeSuite!.tasks[0] as Record<string, unknown>;
    expect(task.id).toBeDefined();
    expect(task.prompt).toBeDefined();
    expect(task.test_code).toBeDefined();
    expect(task.expected_output).toBeDefined();
    expect(task.language).toBe('typescript');
  });

  it('loads chat suite with rubric structure', () => {
    const suites = loadEvalSuitesFromData();
    const chatSuite = suites.find((s) => s.id === 'chat-quality');
    expect(chatSuite).not.toBeUndefined();
    expect(chatSuite!.kind).toBe('chat');

    const task = chatSuite!.tasks[0] as Record<string, unknown>;
    expect(task.rubric).toBeDefined();
    expect((task.rubric as Record<string, unknown>).max_score).toBeGreaterThan(0);
  });

  it('handles missing data/ directory gracefully', () => {
    // The function catches errors and returns empty array.
    // We can't easily test this without mocking fs, but the try-catch is there.
    const suites = loadEvalSuitesFromData();
    expect(Array.isArray(suites)).toBe(true);
  });
});
