"""Guarded same-binary file-logged 8/12/8ms render-allowance diagnostic.""" import hashlib,json,os,re,stat,subprocess,sys,time from pathlib import Path sys.path.insert(0,str(Path(__file__).parent)) from cadence_audit import identity,ipc root=Path(__file__).parent out=Path('/run/k230-source3-quiet-cadence-20261021');out.mkdir(mode=0o700) m=json.loads((root/'descriptor.json').read_text());before=identity() assert before['system']==m['system'] and before['profile']==m['system'] assert before['sway_sha256']==m['normal_sha256'] and before['apps']==['k230-terminal'] assert before['wallpaper']['state']=='still' and len(before['outputs'])==1 assert before['outputs'][0]['transform']=='270' and before['outputs'][0]['max_render_time']==8 keys=['StandardOutput','StandardError','LogLevelMax','LogRateLimitIntervalUSec','LogRateLimitBurst'] def properties():return {k:subprocess.check_output(['systemctl','show','shell.service','-p',k,'--value'],text=True).strip() for k in keys} original_properties=properties();assert original_properties['StandardOutput']=='journal' and original_properties['StandardError']=='inherit' override=Path('/run/systemd/system/shell.service.d/96-source3-quiet-cadence.conf');assert not override.exists() assert not Path('/run/systemd/system/shell.service.d/94-source3-cadence-timing.conf').exists() assert not Path('/run/systemd/system/shell.service.d/95-source3-log-destination.conf').exists() stable=root/'recovery';stable.mkdir(mode=0o700) start=subprocess.check_output(['systemctl','show','shell.service','-p','ExecStart','--value'],text=True) old=re.search(r'path=([^;]+);',start).group(1).strip();argv=re.search(r'argv\[\]=([^;]+);',start).group(1).strip() assert argv==old or argv.startswith(old+' ') args=argv[len(old):];assert re.fullmatch(r'[ /A-Za-z0-9_.+?=:-]*',args) assert re.fullmatch(r'/nix/store/[0-9a-z]{32}-k230-card-shell-hdmi-trial',m['candidate']) assert hashlib.sha256(Path(m['candidate_exe']).read_bytes()).hexdigest()==m['candidate_sha256'] gc=Path('/nix/var/nix/gcroots/source3-cadence-elapsed-20261021');assert gc.is_symlink() and str(gc.resolve())==m['candidate'] restore=stable/'restore.sh';restore.write_text('#!/bin/sh\nset -eu\nrm -f '+str(override)+'\nsystemctl daemon-reload\nsystemctl restart shell.service shell-ui.service theme-helper.service\n');restore.chmod(0o700) unit='k230-source3-quiet-cadence-20261021' subprocess.run(['systemd-run','--quiet','--unit='+unit,'--on-active=480s',str(restore)],check=True) assert subprocess.run(['systemctl','is-active','--quiet',unit+'.timer']).returncode==0 meta={'source_revision':m['source_revision'],'descriptor':m,'before':before,'original_properties':original_properties,'started_utc':time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime()),'runs':[],'restore_unit':unit} (stable/'before.private.json').write_text(json.dumps({**meta,'normal_exec_start':start},indent=2)+'\n') def ready(sha,timeout=60): end=time.monotonic()+timeout while time.monotonic()