Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/hop/blob/main/Linux/tests/install_check.py # hop Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key. Brought by drakestapleton Sign in to star 1 stars 1 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `hop / Linux / tests / install_check.py` 209 lines ยท 10531 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Installer checks in disposable HOME and Git stores; never installs the real app. 3 Python and shell fixtures are independent measuring instruments only. 4 """ 5 import argparse 6 import hashlib 7 import json 8 import os 9 from pathlib import Path 10 import subprocess 11 import tempfile 12 13 14 def cmd(*args, **kw): 15 result = subprocess.run(list(args), capture_output=True, **kw) 16 assert result.returncode == 0, (args, result.returncode, result.stdout, result.stderr) 17 return result.stdout 18 19 20 def fixture(base): 21 source = base / 'source' 22 source.mkdir() 23 (source / '.gitignore').write_text('build/\n') 24 (source / 'LICENSE').write_text('Independent installer fixture.\n') 25 cmd('git', 'init', '-q', '-b', 'main', str(source)) 26 cmd('git', '-C', str(source), 'add', '.') 27 cmd('git', '-C', str(source), '-c', 'user.name=Installer test', 28 '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'fixture') 29 store = base / 'store.git' 30 cmd('git', 'clone', '--bare', '-q', str(source), str(store)) 31 build = source / 'build' / 'linux' 32 build.mkdir(parents=True) 33 for name in ('hop', 'hopcore'): 34 executable = build / name 35 executable.write_text('#!/bin/sh\nprintf "installer-fixture-ran\\n"\n') 36 executable.chmod(0o755) 37 (build / 'SOURCE_HEAD').write_bytes(cmd('git', '-C', str(source), 'rev-parse', 'HEAD')) 38 toolchain = source / 'build/linux-toolchain' 39 (toolchain / 'seed/out').mkdir(parents=True) 40 compiler = toolchain / 'seed/out/omc' 41 compiler.write_bytes(b'independent compiler fixture\n') 42 compiler_head = hashlib.sha1(compiler.read_bytes()).hexdigest() 43 (toolchain / 'source-commit').write_text(compiler_head + '\n') 44 record = ['HOPBUILD1', (build / 'SOURCE_HEAD').read_text().strip(), compiler_head] 45 record += [hashlib.sha256(p.read_bytes()).hexdigest() 46 for p in (compiler, build / 'hop', build / 'hopcore')] 47 (build / 'BUILD_RECORD').write_text('\n'.join(record) + '\n') 48 return source, store 49 50 51 def main(): 52 parser = argparse.ArgumentParser() 53 parser.add_argument('--compiler', required=True, type=Path) 54 parser.add_argument('--evidence', type=Path) 55 args = parser.parse_args() 56 root = Path(__file__).resolve().parents[2] 57 with tempfile.TemporaryDirectory(prefix='hop-install-check-') as raw: 58 base = Path(raw) 59 executable = base / 'installer' 60 build = subprocess.run([str(args.compiler.resolve())], 61 input=(root / 'Linux/install.om').read_bytes(), capture_output=True) 62 assert build.returncode == 0, build.stderr 63 executable.write_bytes(build.stdout) 64 executable.chmod(0o755) 65 source, store = fixture(base) 66 checks = [] 67 home = base / 'A home 50% "dollar$ back` slash\\' 68 home.mkdir() 69 data = base / 'custom data' 70 env = dict(os.environ, HOME=str(home), XDG_DATA_HOME=str(data), HOP_GIT_STORE=str(store)) 71 72 def install(**updates): 73 return subprocess.run([str(executable), str(source)], 74 env=dict(env, **updates), capture_output=True) 75 76 def refused(result, word): 77 assert result.returncode == 1 and word in result.stderr, result 78 79 (source / 'LICENSE').write_text('uncommitted\n') 80 refused(install(), b'clean checkout') 81 assert not (home / '.local').exists() and not data.exists() 82 cmd('git', '-C', str(source), 'checkout', '--', 'LICENSE') 83 checks.append('dirty source refused before installation') 84 (source / 'new-source').write_text('unpublished\n') 85 cmd('git', '-C', str(source), 'add', 'new-source') 86 cmd('git', '-C', str(source), '-c', 'user.name=Installer test', 87 '-c', 'user.email=fixture@example.invalid', 'commit', '-qm', 'unpublished') 88 refused(install(), b'clean checkout') 89 assert not (home / '.local').exists() and not data.exists() 90 cmd('git', '-C', str(source), 'reset', '--hard', 'HEAD~1') 91 checks.append('unpublished commit refused before installation') 92 stamp = source / 'build/linux/SOURCE_HEAD' 93 saved_stamp = stamp.read_bytes() 94 stamp.write_text('stale build\n') 95 refused(install(), b'Rebuild') 96 assert not (home / '.local').exists() 97 stamp.write_bytes(saved_stamp) 98 checks.append('stale build source stamp refused') 99 100 for name in ('hop', 'hopcore'): 101 artifact = source / 'build/linux' / name 102 saved = artifact.read_bytes() 103 artifact.write_bytes(b'#!/bin/sh\nprintf "UNBOUND-REPLACEMENT\\n"\n') 104 refused(install(), b'Rebuild') 105 assert not (home / '.local').exists() and not data.exists() 106 artifact.write_bytes(saved) 107 checks.append(f'replaced {name} refused with unchanged source stamp and build record') 108 record = source / 'build/linux/BUILD_RECORD' 109 saved_record = record.read_bytes() 110 for invalid in (b'', saved_record[:-1], saved_record + b'extra\n'): 111 record.write_bytes(invalid) 112 refused(install(), b'Rebuild') 113 assert not (home / '.local').exists() 114 record.write_bytes(saved_record) 115 checks.append('missing, incomplete and extended build proofs refused') 116 compiler = source / 'build/linux-toolchain/seed/out/omc' 117 compiler_saved = compiler.read_bytes() 118 compiler.write_bytes(b'changed compiler\n') 119 refused(install(), b'Rebuild') 120 assert not (home / '.local').exists() 121 compiler.write_bytes(compiler_saved) 122 checks.append('changed compiler refused against successful-build proof') 123 124 bindir = home / '.local/bin' 125 bindir.mkdir(parents=True) 126 collision = bindir / 'hop' 127 collision.write_text('another program\n') 128 refused(install(), b'belongs to something else') 129 assert collision.read_text() == 'another program\n' and not data.exists() 130 collision.unlink() 131 collision.symlink_to('/somewhere/else/hop') 132 refused(install(), b'belongs to something else') 133 assert os.readlink(collision) == '/somewhere/else/hop' 134 collision.unlink() 135 collision.symlink_to(str(home / '.local/lib/hop/../../else/hop')) 136 refused(install(), b'belongs to something else') 137 assert os.readlink(collision).endswith('/hop/../../else/hop') 138 collision.unlink() 139 checks.append('unrelated regular launcher, symlink and traversal target left untouched') 140 141 applications = data / 'applications' 142 applications.mkdir(parents=True) 143 desktop = applications / 'hop.desktop' 144 desktop.write_text('[Desktop Entry]\nName=Someone else\n') 145 refused(install(), b'belongs to something else') 146 assert desktop.read_text().endswith('Someone else\n') 147 desktop.unlink() 148 checks.append('unrelated desktop entry left untouched') 149 150 result = install() 151 assert result.returncode == 0, result.stderr 152 first_version = collision.resolve().parent 153 first_desktop = desktop.read_bytes() 154 assert cmd(str(collision)) == b'installer-fixture-ran\n' 155 assert (first_version / 'hopcore').read_bytes() == (source / 'build/linux/hopcore').read_bytes() 156 assert (first_version / 'LICENSE').read_bytes() == (source / 'LICENSE').read_bytes() 157 assert (first_version / 'SOURCE_HEAD').read_bytes() == saved_stamp 158 assert (first_version / 'BUILD_RECORD').read_bytes() == saved_record 159 assert not (home / '.local/share/applications/hop.desktop').exists() 160 cmd('desktop-file-validate', str(desktop)) 161 # GLib is an independent implementation of Desktop Entry parsing and Exec expansion. 162 assert cmd('gio', 'launch', str(desktop), env=env).endswith(b'installer-fixture-ran\n') 163 checks.append('main installs executable copies, license and a valid application entry in XDG_DATA_HOME') 164 checks.append('desktop launches correctly with spaces, percent, quotes, dollar, backtick and backslash in HOME') 165 166 result = install() 167 assert result.returncode == 0, result.stderr 168 second_version = collision.resolve().parent 169 assert second_version != first_version and first_version.exists() 170 links = list(bindir.glob('hop.backup.*')) 171 desktops = list(applications.glob('hop.desktop.backup.*')) 172 assert len(links) == 1 and links[0].resolve().parent == first_version 173 assert len(desktops) == 1 and desktops[0].read_bytes() == first_desktop 174 assert cmd(str(collision)) == b'installer-fixture-ran\n' 175 checks.append('repeat install preserves old executable version and exact launcher/desktop backups') 176 177 second_desktop = desktop.read_bytes() 178 for name in ('hop', 'hopcore'): 179 artifact = source / 'build/linux' / name 180 saved = artifact.read_bytes() 181 artifact.write_bytes(b'#!/bin/sh\nexit 0\n') 182 refused(install(), b'Rebuild') 183 assert collision.resolve().parent == second_version 184 assert desktop.read_bytes() == second_desktop 185 artifact.write_bytes(saved) 186 checks.append('tampered update preserves the previously published launcher and desktop') 187 188 # Default data path and canonical-store location are also exercised in another disposable HOME. 189 normal = base / 'default-home' 190 normal.mkdir() 191 (normal / 'git').mkdir() 192 cmd('git', 'clone', '--bare', '-q', str(store), str(normal / 'git/hop.git')) 193 default_env = {k: v for k, v in dict(env, HOME=str(normal)).items() 194 if k not in ('HOP_GIT_STORE', 'XDG_DATA_HOME')} 195 result = subprocess.run([str(executable), str(source)], env=default_env, capture_output=True) 196 assert result.returncode == 0, result.stderr 197 assert (normal / '.local/share/applications/hop.desktop').exists() 198 checks.append('default HOME/git/hop.git source check and HOME/.local/share application path work') 199 report = {'status': 'PASS', 'checks': checks, 200 'scope': 'disposable fixtures only; no real Hop installation performed'} 201 if args.evidence: 202 args.evidence.mkdir(parents=True, exist_ok=True) 203 (args.evidence / 'result.json').write_text(json.dumps(report, indent=2) + '\n') 204 (args.evidence / 'desktop-entry.txt').write_bytes(desktop.read_bytes()) 205 print(json.dumps(report)) 206 207 208 if __name__ == '__main__': 209 main()