#!/usr/bin/env python3 """Check installer layout with mocked build/OS tools; not a native macOS build.""" import os from pathlib import Path import plistlib import shutil import subprocess import tempfile SOURCE = Path(__file__).resolve().parents[1] for platform in ('Linux', 'Darwin'): with tempfile.TemporaryDirectory(prefix='ducky-install-') as temporary: root = Path(temporary) checkout = root / 'checkout' checkout.mkdir() shutil.copy2(SOURCE / 'build.sh', checkout / 'build.sh') shutil.copytree(SOURCE / 'assets', checkout / 'assets') binary = checkout / 'target/release/ducky' binary.parent.mkdir(parents=True) binary.write_text('#!/bin/sh\nexit 0\n') binary.chmod(0o755) home = root / 'home with spaces' home.mkdir() stubs = root / 'stubs' stubs.mkdir() for name, body in {'uname': f'printf "{platform}\\n"', 'cargo': 'exit 0', 'codesign': 'exit 0'}.items(): path = stubs / name path.write_text('#!/bin/sh\n' + body + '\n') path.chmod(0o755) env = dict(os.environ, HOME=str(home), SHELL='/bin/zsh', PATH=f'{stubs}:{os.environ["PATH"]}') for key in ('XDG_CONFIG_HOME', 'XDG_DATA_HOME'): env.pop(key, None) config = home / ('Library/Application Support' if platform == 'Darwin' else '.config') / 'ducky' def install(): subprocess.run(['bash', str(checkout / 'build.sh')], env=env, check=True, stdout=subprocess.DEVNULL) install() assert (home / '.local/bin/ducky').read_bytes() == binary.read_bytes() assert (config / 'shell.bash').is_file() assert (config / 'config.lua').is_file() if platform == 'Darwin': app = home / 'Applications/Ducky.app/Contents' with (app / 'Info.plist').open('rb') as stream: info = plistlib.load(stream) assert info['CFBundleExecutable'] == 'ducky' assert info['CFBundleIdentifier'] == 'dev.ducky.shell' assert (app / 'MacOS/ducky').read_bytes() == binary.read_bytes() assert not (home / '.local/share/applications').exists() else: assert (home / '.local/share/applications/dev.ducky.shell.desktop').is_file() (config / 'config.lua').write_text('-- keep my config\nreturn {}\n') install() assert (config / 'config.lua').read_text().startswith('-- keep my config') assert (home / '.zshrc').read_text().count('# Ducky user-local binaries') == 1 print(f'{platform}: package layout, paths with spaces, config preservation, and repeat installation passed')