|
| 1 | +import { describe, test, expect } from 'bun:test'; |
| 2 | +import { detectPlatform, detectArch, getPlatformInfo } from '../../src/utils/platform.js'; |
| 3 | +import { generateUserAgent } from '../../src/utils/user-agent.js'; |
| 4 | + |
| 5 | +describe('Platform Detection', () => { |
| 6 | + test('should detect current platform', () => { |
| 7 | + const platform = detectPlatform(); |
| 8 | + expect(platform).toBeTruthy(); |
| 9 | + expect(typeof platform).toBe('string'); |
| 10 | + expect(platform.length).toBeGreaterThan(0); |
| 11 | + }); |
| 12 | + |
| 13 | + test('should detect current architecture', () => { |
| 14 | + const arch = detectArch(); |
| 15 | + expect(arch).toBeTruthy(); |
| 16 | + expect(typeof arch).toBe('string'); |
| 17 | + expect(arch.length).toBeGreaterThan(0); |
| 18 | + }); |
| 19 | + |
| 20 | + test('should return valid platform info format', () => { |
| 21 | + const platformInfo = getPlatformInfo(); |
| 22 | + expect(platformInfo).toContain('; '); |
| 23 | + const [platform, arch] = platformInfo.split('; '); |
| 24 | + expect(platform).toBeTruthy(); |
| 25 | + expect(arch).toBeTruthy(); |
| 26 | + }); |
| 27 | +}); |
| 28 | + |
| 29 | +describe('User-Agent Generation', () => { |
| 30 | + test('should generate valid User-Agent format', () => { |
| 31 | + const userAgent = generateUserAgent(); |
| 32 | + expect(userAgent).toMatch(/^QwenCode\/\d+\.\d+\.\d+ \(.+; .+\)$/); |
| 33 | + }); |
| 34 | + |
| 35 | + test('should include version 0.12.0', () => { |
| 36 | + const userAgent = generateUserAgent(); |
| 37 | + expect(userAgent).toContain('QwenCode/0.12.0'); |
| 38 | + }); |
| 39 | + |
| 40 | + test('should include detected platform', () => { |
| 41 | + const userAgent = generateUserAgent(); |
| 42 | + const platform = detectPlatform(); |
| 43 | + expect(userAgent).toContain(platform); |
| 44 | + }); |
| 45 | + |
| 46 | + test('should include detected architecture', () => { |
| 47 | + const userAgent = generateUserAgent(); |
| 48 | + const arch = detectArch(); |
| 49 | + expect(userAgent).toContain(arch); |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
| 53 | +describe('Platform Mapping', () => { |
| 54 | + test('should map known platforms correctly', () => { |
| 55 | + // This test verifies the mapping logic works |
| 56 | + // Actual values depend on the runtime environment |
| 57 | + const platform = detectPlatform(); |
| 58 | + const knownPlatforms = ['Linux', 'macOS', 'Windows', 'FreeBSD', 'OpenBSD', 'Solaris', 'AIX', 'Unknown']; |
| 59 | + expect(knownPlatforms).toContain(platform); |
| 60 | + }); |
| 61 | + |
| 62 | + test('should map known architectures correctly', () => { |
| 63 | + const arch = detectArch(); |
| 64 | + const knownArches = ['x64', 'arm64', 'ia32', 'ppc64', 'arm', 'mips', 'unknown']; |
| 65 | + expect(knownArches).toContain(arch); |
| 66 | + }); |
| 67 | +}); |
0 commit comments