import json,pathlib,sqlite3,subprocess root=pathlib.Path('/home/ps/huobao-video-cleanup') unit=pathlib.Path.home()/'.config/systemd/user/huobao-video-cleanup.service' # Avoid a target ordering cycle on the next server boot; no restart is needed. text=unit.read_text() if 'After=default.target\n' in text: unit.write_text(text.replace('After=default.target\n','')) subprocess.run(['systemctl','--user','daemon-reload'],check=True,capture_output=True) assert subprocess.check_output(['systemctl','--user','is-active','huobao-video-cleanup.service'],text=True).strip()=='active' assert subprocess.check_output(['systemctl','--user','is-enabled','huobao-video-cleanup.service'],text=True).strip()=='enabled' assert subprocess.check_output(['loginctl','show-user','ps','-p','Linger'],text=True).strip()=='Linger=yes' config=json.loads((root/'config.json').read_text());counts={} for b in config['bridges']: with sqlite3.connect('file:'+b['database']+'?mode=ro',uri=True) as db: counts[b['name']]=dict(db.execute('select status,count(*) from video_cleanup_acks group by status')) print(json.dumps({'active':True,'enabled':True,'bootPersistence':True,'cleanupCounts':counts})) code='''import app,asyncio,httpx,json async def main(): async with httpx.AsyncClient(timeout=10) as client: for p in app.providers().values(): response=await client.post(p.base_url+'/history',headers=app.provider_headers(p),json={'delete':[]});response.raise_for_status() print(json.dumps({'provider':p.id,'historyControlReady':True,'deleted':0})) asyncio.run(main())''' result=subprocess.run(['docker','exec','canvas-h3-prompt-normalizer-healthy-20261026','python','-c',code],capture_output=True,text=True) assert result.returncode==0,'Worker control test failed' print(result.stdout)