import { describe, it, expect, vi, beforeEach } from 'vitest';

// ─── Judge runner tests (mock sql + real functions) ─────────────────────────

describe('judge runner', () => {
  beforeEach(() => {
    vi.restoreAllMocks();
  });

  it('runJudgeError', async () => {
    // Test that the judge runner imports correctly and has the expected interface.
    const mod = await import('../judge-runner.js');
    expect(typeof mod.runJudgeEval).toBe('function');
  });

  it('generateResponse rejects on bad URL', async () => {
    // The generateResponse function is internal, but we can test the public API.
    const { runJudgeEval } = await import('../judge-runner.js');

    // Mock sql operations.
    const mockSql = vi.fn().mockResolvedValue([]);
    mockSql.tag = vi.fn().mockReturnValue({ SQL: '' });

    const mockEmitter = {
      publish: vi.fn(),
    };

    const mockLogger = {
      info: vi.fn(),
      warn: vi.fn(),
      error: vi.fn(),
    };

    const progressHandler = vi.fn();

    // This will fail because resolveProviderBaseUrl returns null for unknown provider.
    const result = await runJudgeEval(
      {
        runId: 'test_run',
        providerId: 'nonexistent-provider',
        model: 'test-model',
        quant: null,
        tasks: [],
        judgeModel: null,
      },
      mockSql as unknown as import('../../db.js').Sql,
      mockEmitter as unknown as import('../../index.js').DeltaEmitter,
      0,
      mockLogger as unknown as import('fastify').FastifyBaseLogger,
      progressHandler,
    );

    expect(result.error).toContain('no base URL');
  });
});
