phoebus_os/installer/tests/vm/postinstall-build-reviews.py
2026-10-09 05:24:39 -07:00

75 lines
3.3 KiB
Bash
Executable file

#!/usr/bin/env python3
"""Exercise every installed build choice through the real assistant bridge.
Run as the desktop user inside a disposable Phoebus VM. Preparation must
produce approval-bound source plans without changing the package database.
Compilation/boot and the visible welcome journey are separate acceptance runs.
"""
import hashlib
import json
import pathlib
import subprocess
import sys
def installed_state():
records = sorted(str(p) for p in pathlib.Path('/var/db/pkg').glob('*/*'))
return hashlib.sha256('\n'.join(records).encode()).hexdigest()
def main():
before = installed_state()
bridge = subprocess.Popen(['/usr/local/bin/sys', '--assistant-bridge'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
text=True)
choices = [(app, {'action': 'convert_to_source', 'app': app}, atom)
for app, atom in [('firefox', 'www-client/firefox'),
('libreoffice', 'app-office/libreoffice'),
('thunderbird', 'mail-client/thunderbird'),
('calibre', 'app-text/calibre'),
('gimp', 'media-gfx/gimp')]]
choices += [(kind, {'action': f'build_{kind}_kernel', 'make_default': False},
'sys-kernel/gentoo-kernel') for kind in ['balanced', 'tuned']]
failures = 0
reviews = {}
try:
for request_id, (name, action, atom) in enumerate(choices, 1):
bridge.stdin.write(json.dumps({'id': request_id, 'op': 'prepare_build',
'action': action}) + '\n')
bridge.stdin.flush()
for line in bridge.stdout:
reply = json.loads(line)
if reply.get('id') == request_id and 'event' not in reply:
break
else:
raise RuntimeError('assistant bridge exited before returning a review')
result = reply.get('result') or {}
effects = result.get('effects') or []
source = any(e.get('source') == 'source'
and e.get('target', '').startswith(atom + '-')
and e.get('target', '')[len(atom) + 1:][:1].isdigit()
for e in effects)
ok = (reply.get('ok') and result.get('state') == 'prepared'
and result.get('plan_id') and result.get('digest')
and result.get('actions') == [action] and source)
if ok:
reviews[name] = result
print(f'CASE build-review-{name} PASS', flush=True)
else:
failures += 1
print(f'CASE build-review-{name} FAIL: '
+ str(reply.get('error') or 'missing bound source plan'), flush=True)
unchanged = before == installed_state()
print('CASE build-reviews-no-mutation ' + ('PASS' if unchanged else 'FAIL'), flush=True)
failures += int(not unchanged)
path = pathlib.Path('/tmp/phoebus-build-reviews.json')
path.touch(mode=0o600, exist_ok=True)
path.write_text(json.dumps(reviews, indent=2) + '\n')
finally:
bridge.stdin.close()
bridge.wait(timeout=30)
return int(failures != 0)
if __name__ == '__main__':
sys.exit(main())