import { describe, it, expect } from 'vitest';
import { parseBoolean, ensureEnabledTools } from './validation';
describe('parseBoolean', () => {
    describe('true values', () => {
        it('should return true for "true"', () => {
            expect(parseBoolean('true')).toBe(true);
        });
        it('should return true for "TRUE"', () => {
            expect(parseBoolean('TRUE')).toBe(true);
        });
        it('should return true for "1"', () => {
            expect(parseBoolean('1')).toBe(true);
        });
        it('should return true for "yes"', () => {
            expect(parseBoolean('yes')).toBe(true);
        });
        it('should return true for boolean true', () => {
            expect(parseBoolean(true)).toBe(true);
        });
    });
    describe('empty/null/undefined values', () => {
        it('should return default value (true) for empty string', () => {
            expect(parseBoolean('')).toBe(true); // 默认值是 true
        });
        it('should return default value (true) for null', () => {
            expect(parseBoolean(null)).toBe(true); // 默认值是 true
        });
        it('should return default value (true) for undefined', () => {
            expect(parseBoolean(undefined)).toBe(true); // 默认值是 true
        });
        it('should return false when defaultValue is false for empty string', () => {
            expect(parseBoolean('', false)).toBe(false);
        });
        it('should return false when defaultValue is false for null', () => {
            expect(parseBoolean(null, false)).toBe(false);
        });
        it('should return false when defaultValue is false for undefined', () => {
            expect(parseBoolean(undefined, false)).toBe(false);
        });
    });
    describe('default value', () => {
        it('should return default when value is null', () => {
            expect(parseBoolean(null, true)).toBe(true);
        });
        it('should return default when value is undefined', () => {
            expect(parseBoolean(undefined, true)).toBe(true);
        });
        it('should ignore default for valid values', () => {
            expect(parseBoolean('false', true)).toBe(false);
        });
    });
});
describe('ensureEnabledTools', () => {
    it('should return default tools for empty array', () => {
        const result = ensureEnabledTools([]);
        expect(result).toContain('claude');
        expect(result).toContain('opencode');
        expect(result).toContain('codex');
    });
    it('should return default tools for null', () => {
        const result = ensureEnabledTools(null);
        expect(result).toContain('claude');
        expect(result).toContain('opencode');
        expect(result).toContain('codex');
    });
    it('should return default tools for undefined', () => {
        const result = ensureEnabledTools(undefined);
        expect(result).toContain('claude');
        expect(result).toContain('opencode');
        expect(result).toContain('codex');
    });
    it('should return input array when not empty', () => {
        const result = ensureEnabledTools(['claude', 'gemini']);
        expect(result).toEqual(['claude', 'gemini']);
    });
    it('should handle single tool', () => {
        const result = ensureEnabledTools(['opencode']);
        expect(result).toEqual(['opencode']);
    });
    it('should deduplicate tools', () => {
        const result = ensureEnabledTools(['claude', 'claude', 'opencode']);
        expect(result).toEqual(['claude', 'opencode']);
    });
    it('should normalize tools to lowercase', () => {
        const result = ensureEnabledTools(['CLAUDE', 'OpenCode']);
        expect(result).toEqual(['claude', 'opencode']);
    });
});
