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

let capturedOptions: Record<string, unknown> | undefined;

vi.mock('openai', () => {
  class OpenAI {
    constructor(options: Record<string, unknown>) {
      capturedOptions = options;
    }
  }
  return { default: OpenAI };
});

describe('OpenAIClient', () => {
  it('passes baseURL through to the OpenAI SDK', async () => {
    const { OpenAIClient } = await import('./openai.js');

    capturedOptions = undefined;
    new OpenAIClient({
      model: 'gpt-4.1',
      apiKey: 'sk-test',
      baseURL: 'https://example.com/v1',
    });

    expect(capturedOptions).toBeDefined();
    if (!capturedOptions) {
      throw new Error('Expected OpenAI options to be captured');
    }
    expect((capturedOptions as Record<string, unknown>)['baseURL']).toBe('https://example.com/v1');
  });
});
