from pathlib import Path
import json
p=json.loads((Path(__file__).parent/'guard-policy.json').read_text(encoding='utf-8'))
attempts=[]; locked=False; results=[]
for e in p['events']:
 t=e['at']; kind=e['kind']
 if kind=='manual_reset':
  locked=False; attempts=[]; result='reset'
 elif kind=='maintenance_exit': result='maintenance_no_restart'
 elif locked: result='locked'
 else:
  attempts=[x for x in attempts if x>t-p['window_seconds']]
  if len(attempts)>=p['attempt_limit']:
   locked=True; result='locked'
  else:
   attempts.append(t); result='allow_attempt'
 results.append(result)
assert results==p['expected']
print(json.dumps({'decisions':results,'executed_process_actions':0},ensure_ascii=False))
