import { describe, expect, it, vi } from 'vitest';
import { ProvidersController } from './providers.controller.js';

describe('ProvidersController operational status', (): void => {
  it('reports provider latency and effective policy without exposing provider error details', (): void => {
    const providerService = {
      getProvidersHealth: vi.fn(() => [
        {
          name: 'fleet',
          status: 'down',
          latencyMs: 42,
          lastChecked: '2026-07-12T00:00:00.000Z',
          modelCount: 0,
          error: 'credential-canary=secret-value',
        },
      ]),
      getEffectivePolicyStatus: vi.fn(() => ({
        healthCheckIntervalSecs: 60,
        configuredProviders: ['fleet'],
        availableModelCount: 0,
      })),
    };
    const controller = new ProvidersController(providerService as never, {} as never, {} as never);

    const status = controller.status();

    expect(status).toEqual({
      providers: [
        {
          name: 'fleet',
          status: 'down',
          latencyMs: 42,
          lastChecked: '2026-07-12T00:00:00.000Z',
          modelCount: 0,
          errorCode: 'provider_unavailable',
        },
      ],
      effectivePolicy: {
        healthCheckIntervalSecs: 60,
        configuredProviders: ['fleet'],
        availableModelCount: 0,
      },
    });
    expect(JSON.stringify(status)).not.toContain('secret-value');
  });
});
