/**
 * /v1/models conversion tests — small but it locks the OpenAI shape.
 */
import { describe, it, expect } from 'vitest';
import { buildModelsResponse } from './models-endpoint.js';

describe('buildModelsResponse', () => {
  it('returns the OpenAI list envelope even when empty', () => {
    const resp = buildModelsResponse([]);
    expect(resp.object).toBe('list');
    expect(resp.data).toEqual([]);
  });

  it('maps each backend id to a model entry (id-shaped, not role-shaped)', () => {
    // /v1/models stays backend-id-shaped: the Settings "physical backends"
    // panel (config-api /api/workers/:id/backends) reads it to list the GPUs
    // behind a proxy worker. Role-based routing lives in the router + worker,
    // not in this discovery endpoint (2026-06-09 decision).
    const resp = buildModelsResponse([
      { id: 'gpu-a', endpoint: 'http://a/v1', model: 'qwen3:8b', maxSlots: 4, roles: ['quality'] },
      { id: 'gpu-b', endpoint: 'http://b/v1', model: 'qwen3:14b', maxSlots: 4 },
    ]);
    expect(resp.data).toEqual([
      { id: 'gpu-a', object: 'model', owned_by: 'aao-gateway' },
      { id: 'gpu-b', object: 'model', owned_by: 'aao-gateway' },
    ]);
  });
});
