import { describe, it, expect } from 'vitest';
import { RoutingPolicy } from './policy.js';

describe('RoutingPolicy', () => {
  it('uses default path when disabled', () => {
    const policy = new RoutingPolicy({
      enabled: false,
      fastPathThreshold: 0.8,
      llmThreshold: 0.4,
      defaultPath: 'llm',
    });

    expect(policy.decide({ confidence: 0.99 })).toEqual({ path: 'llm', reason: 'disabled' });
  });

  it('routes to fast at or above fast threshold', () => {
    const policy = new RoutingPolicy({
      enabled: true,
      fastPathThreshold: 0.8,
      llmThreshold: 0.4,
      defaultPath: 'llm',
    });

    expect(policy.decide({ confidence: 0.8 })).toEqual({ path: 'fast', reason: 'high_confidence' });
    expect(policy.decide({ confidence: 0.95 })).toEqual({ path: 'fast', reason: 'high_confidence' });
  });

  it('routes to llm at or below llm threshold', () => {
    const policy = new RoutingPolicy({
      enabled: true,
      fastPathThreshold: 0.8,
      llmThreshold: 0.4,
      defaultPath: 'fast',
    });

    expect(policy.decide({ confidence: 0.4 })).toEqual({ path: 'llm', reason: 'low_confidence' });
    expect(policy.decide({ confidence: 0.1 })).toEqual({ path: 'llm', reason: 'low_confidence' });
  });

  it('uses default path between thresholds', () => {
    const policy = new RoutingPolicy({
      enabled: true,
      fastPathThreshold: 0.8,
      llmThreshold: 0.4,
      defaultPath: 'llm',
    });

    expect(policy.decide({ confidence: 0.6 })).toEqual({ path: 'llm', reason: 'mid_confidence' });
  });
});
