"""Guarded complete still/video one/three-card diagnostic at quiet12ms.""" from pathlib import Path import hashlib,json,os,re,shlex,shutil,stat,subprocess,sys,time root=Path(__file__).parent;sys.path.insert(0,str(root));sys.path.insert(0,str(root/'tools')) from cadence_audit import identity,ipc from theme_background_metrics import measure out=Path('/run/k230-source3-paired12-20261021-attempt4');out.mkdir(mode=0o700) m=json.loads((root/'descriptor.json').read_text());before=identity();assert before['system']==before['profile']==m['system'] and before['sway_sha256']==m['normal_sha256'] assert before['apps']==['k230-terminal'] and before['wallpaper']['state']=='still' and before['outputs'][0]['max_render_time']==8 and before['outputs'][0]['transform']=='270' keys=['StandardOutput','StandardError','LogLevelMax','LogRateLimitIntervalUSec','LogRateLimitBurst'] def props():return {k:subprocess.check_output(['systemctl','show','shell.service','-p',k,'--value'],text=True).strip() for k in keys} original_props=props();assert original_props['StandardOutput']=='journal' and original_props['StandardError']=='inherit' override=Path('/run/systemd/system/shell.service.d/97-source3-paired12.conf');assert not override.exists() for n in ['94-source3-cadence-timing.conf','95-source3-log-destination.conf','96-source3-quiet-cadence.conf']:assert not (override.parent/n).exists() assert hashlib.sha256(Path(m['candidate_exe']).read_bytes()).hexdigest()==m['candidate_sha256'] recovery=root/'recovery';recovery.mkdir(mode=0o700) def theme(*args): r=subprocess.run([sys.executable,str(root/'theme.py'),*args],capture_output=True,text=True,timeout=125) (recovery/('theme-'+args[0]+'.private.log')).write_text(r.stdout+r.stderr) if r.returncode:raise RuntimeError('private theme adapter failed: '+args[0]) return json.loads(r.stdout) prepared=theme('prepare') restore=recovery/'restore.sh';restore.write_text('#!/bin/sh\nset -eu\n'+sys.executable+' '+str(root/'copy-private.py')+'\nrm -f '+str(override)+'\nsystemctl daemon-reload\nsystemctl restart shell.service shell-ui.service theme-helper.service\n'+sys.executable+' '+str(root/'restore-owned.py')+'\n');restore.chmod(0o700) unit='k230-source3-paired12-20261021-attempt4';subprocess.run(['systemd-run','--quiet','--unit='+unit,'--on-active=720s',str(restore)],check=True);assert subprocess.run(['systemctl','is-active','--quiet',unit+'.timer']).returncode==0 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) meta={'source_revision':m['source_revision'],'descriptor':m,'before':before,'original_properties':original_props,'theme_baseline':prepared,'started_utc':time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime()),'runs':[],'roles':[],'restore_unit':unit} def save(): p=root/'result.json';p.write_text(json.dumps(meta,indent=2)+'\n');p.chmod(0o600) def ready(sha): end=time.monotonic()+60 while time.monotonic()