const mockExistsSync = jest.fn() jest.mock('fs', () => ({ existsSync: (...args: unknown[]) => mockExistsSync(...args) })) import { buildYtdlpCommand } from '../ytdlp' function setPlatform(platform: NodeJS.Platform) { Object.defineProperty(process, 'platform', { value: platform }) } describe('buildYtdlpCommand', () => { const originalPlatform = process.platform afterEach(() => { setPlatform(originalPlatform) mockExistsSync.mockReset() }) it('runs the bundled binary directly on Linux', () => { setPlatform('linux') mockExistsSync.mockReturnValue(true) const { command, args } = buildYtdlpCommand(['-J', 'https://x.test']) expect(command).toContain('yt-dlp') expect(args).toEqual(['-J', 'https://x.test']) }) it('runs the bundled binary through python on Windows', () => { setPlatform('win32') mockExistsSync.mockReturnValue(true) const { command, args } = buildYtdlpCommand(['-J', 'https://x.test']) expect(command).toBe('python') expect(args[0]).toContain('yt-dlp') expect(args.slice(1)).toEqual(['-J', 'https://x.test']) }) it('runs a system-wide yt-dlp directly on Windows when no bundled binary exists', () => { setPlatform('win32') mockExistsSync.mockReturnValue(false) const { command, args } = buildYtdlpCommand(['-J', 'https://x.test']) expect(command).toBe('yt-dlp') expect(args).toEqual(['-J', 'https://x.test']) }) it('runs a system-wide yt-dlp directly on Linux when no bundled binary exists', () => { setPlatform('linux') mockExistsSync.mockReturnValue(false) const { command, args } = buildYtdlpCommand(['-J', 'https://x.test']) expect(command).toBe('yt-dlp') expect(args).toEqual(['-J', 'https://x.test']) }) })