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

vi.mock('./config.js', () => ({
  config: { FEATURE_FLAGS_ENABLED: false },
}));

import { isFeatureEnabled, getAllFlags, setFlag } from './feature-flags.js';

describe('feature-flags', () => {
  it('has all 13 expected flag names', () => {
    const flags = getAllFlags();
    const expected = [
      'sandbox_enabled',
      'plugins_enabled',
      'mcp_connectors_enabled',
      'scheduling_enabled',
      'computer_use_enabled',
      'parallel_agents_enabled',
      'marketplace_enabled',
      'wasm_plugins_enabled',
      'llm_multi_model_enabled',
      'audit_logging_enabled',
      'platform_auth_required',
      'dispatch_api_enabled',
      'telemetry_enabled',
    ];
    for (const name of expected) {
      expect(flags).toHaveProperty(name);
    }
    expect(Object.keys(flags)).toHaveLength(expected.length);
  });

  it('defaults match seed.ts', () => {
    expect(isFeatureEnabled('sandbox_enabled')).toBe(true);
    expect(isFeatureEnabled('plugins_enabled')).toBe(true);
    expect(isFeatureEnabled('mcp_connectors_enabled')).toBe(true);
    expect(isFeatureEnabled('computer_use_enabled')).toBe(false);
    expect(isFeatureEnabled('wasm_plugins_enabled')).toBe(false);
    expect(isFeatureEnabled('llm_multi_model_enabled')).toBe(false);
    expect(isFeatureEnabled('platform_auth_required')).toBe(false);
    expect(isFeatureEnabled('marketplace_enabled')).toBe(true);
    expect(isFeatureEnabled('dispatch_api_enabled')).toBe(true);
    expect(isFeatureEnabled('audit_logging_enabled')).toBe(true);
    expect(isFeatureEnabled('telemetry_enabled')).toBe(false);
  });

  it('setFlag overrides a default', () => {
    setFlag('computer_use_enabled', true);
    expect(isFeatureEnabled('computer_use_enabled')).toBe(true);
    // Reset
    setFlag('computer_use_enabled', false);
  });
});
