import { describe, expect, it } from 'vitest';
import { classifyStreamError } from '../inference/stream-error-classifier.js';

describe('classifyStreamError', () => {
  it("classifies AbortError as 'stall'", () => {
    const err = new Error('aborted');
    err.name = 'AbortError';
    expect(classifyStreamError(err)).toBe('stall');
  });

  it("classifies a 503 HTTP error as 'transient'", () => {
    const err = Object.assign(new Error('Service Unavailable'), { status: 503 });
    expect(classifyStreamError(err)).toBe('transient');
  });

  it("classifies a 500 HTTP error as 'transient'", () => {
    const err = Object.assign(new Error('Internal Server Error'), { status: 500 });
    expect(classifyStreamError(err)).toBe('transient');
  });

  it("classifies a 4xx HTTP error as 'non-retryable'", () => {
    const err = Object.assign(new Error('Bad Request'), { status: 400 });
    expect(classifyStreamError(err)).toBe('non-retryable');
  });

  it("classifies a generic Error as 'non-retryable'", () => {
    expect(classifyStreamError(new Error('something went wrong'))).toBe('non-retryable');
  });
});
