quantum-cli-core
Version:
Quantum CLI Core - Multi-LLM Collaboration System
71 lines • 3.12 kB
JavaScript
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Tests for feature flags
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { isFeatureEnabled, FEATURE_FLAGS, isCollaborationEnabled, isDualVerificationEnabled, isSmartRoutingEnabled, isCostTrackingEnabled, } from './feature-flags.js';
describe('Feature Flags', () => {
beforeEach(() => {
// Clear all environment variables before each test
vi.unstubAllEnvs();
});
afterEach(() => {
vi.unstubAllEnvs();
});
describe('isFeatureEnabled', () => {
it('should return true when env var is "true"', () => {
vi.stubEnv('TEST_FLAG', 'true');
expect(isFeatureEnabled('TEST_FLAG')).toBe(true);
});
it('should return false when env var is "false"', () => {
vi.stubEnv('TEST_FLAG', 'false');
expect(isFeatureEnabled('TEST_FLAG')).toBe(false);
});
it('should return false when env var is not set', () => {
expect(isFeatureEnabled('UNSET_FLAG')).toBe(false);
});
it('should return false for any non-"true" value', () => {
vi.stubEnv('TEST_FLAG', 'TRUE');
expect(isFeatureEnabled('TEST_FLAG')).toBe(false);
vi.stubEnv('TEST_FLAG', '1');
expect(isFeatureEnabled('TEST_FLAG')).toBe(false);
vi.stubEnv('TEST_FLAG', 'yes');
expect(isFeatureEnabled('TEST_FLAG')).toBe(false);
});
});
describe('specific feature flags', () => {
it('should check collaboration flag', () => {
expect(isCollaborationEnabled()).toBe(false);
vi.stubEnv(FEATURE_FLAGS.ENABLE_COLLABORATION, 'true');
expect(isCollaborationEnabled()).toBe(true);
});
it('should check dual verification flag', () => {
expect(isDualVerificationEnabled()).toBe(false);
vi.stubEnv(FEATURE_FLAGS.ENABLE_DUAL_VERIFICATION, 'true');
expect(isDualVerificationEnabled()).toBe(true);
});
it('should check smart routing flag', () => {
expect(isSmartRoutingEnabled()).toBe(false);
vi.stubEnv(FEATURE_FLAGS.ENABLE_SMART_ROUTING, 'true');
expect(isSmartRoutingEnabled()).toBe(true);
});
it('should check cost tracking flag', () => {
expect(isCostTrackingEnabled()).toBe(false);
vi.stubEnv(FEATURE_FLAGS.ENABLE_COST_TRACKING, 'true');
expect(isCostTrackingEnabled()).toBe(true);
});
});
describe('FEATURE_FLAGS constant', () => {
it('should have all expected flags', () => {
expect(FEATURE_FLAGS.ENABLE_COLLABORATION).toBe('ENABLE_COLLABORATION');
expect(FEATURE_FLAGS.ENABLE_DUAL_VERIFICATION).toBe('ENABLE_DUAL_VERIFICATION');
expect(FEATURE_FLAGS.ENABLE_SMART_ROUTING).toBe('ENABLE_SMART_ROUTING');
expect(FEATURE_FLAGS.ENABLE_COST_TRACKING).toBe('ENABLE_COST_TRACKING');
});
});
});
//# sourceMappingURL=feature-flags.test.js.map