import { describe, test, expect } from 'vitest';
import { stealthLaunchOptions, resolveChannel, STEALTH_INIT_SCRIPT } from './stealth.js';

describe('stealthLaunchOptions', () => {
  test('suppresses the automation flag and hides AutomationControlled', () => {
    const o = stealthLaunchOptions();
    expect(o.ignoreDefaultArgs).toContain('--enable-automation');
    expect(o.args).toContain('--disable-blink-features=AutomationControlled');
  });
  test('does not pass a Windows-only or throwaway flag that would break bundled Chromium', () => {
    const o = stealthLaunchOptions();
    // every arg is a plain chromium switch
    expect(o.args.every((a) => a.startsWith('--'))).toBe(true);
  });
});

describe('resolveChannel', () => {
  test('auto -> chrome when host Chrome is available', () => {
    expect(resolveChannel('auto', true)).toBe('chrome');
  });
  test('auto -> chromium when host Chrome is absent (bundled fallback)', () => {
    expect(resolveChannel('auto', false)).toBe('chromium');
  });
  test('explicit chromium is honored even when Chrome exists', () => {
    expect(resolveChannel('chromium', true)).toBe('chromium');
  });
  test('explicit chrome is honored', () => {
    expect(resolveChannel('chrome', false)).toBe('chrome');
  });
});

describe('STEALTH_INIT_SCRIPT', () => {
  test('deletes navigator.webdriver', () => {
    expect(STEALTH_INIT_SCRIPT).toContain('webdriver');
  });
});
