← Files Job Outreach CopilotARCHIVED FILE

scripts/validate_tracker.py

2.11 KB · Nov 21, 2026 · 12:50 UTC

↓ Download file

See the change to this file →

#!/usr/bin/env python3
"""Validate candidate-specific tracker JSON without network access or profile persistence."""
import json,sys
from pathlib import Path
ALLOWED={
 'opportunity':{'identified','researching','qualified','skipped','closed'},
 'outreach':{'not_started','drafted','sent','replied','declined'},
 'application':{'not_started','prepared','submitted','reviewing','interviewing','offer','rejected','withdrawn'},
 'interview':{'not_scheduled','scheduled','completed','cancelled'},
}
PROOF={
 'outreach':{'sent','replied','declined'},
 'application':{'submitted','reviewing','interviewing','offer','rejected','withdrawn'},
 'interview':{'scheduled','completed','cancelled'},
}

def validate(records):
 errors=[]
 if not isinstance(records,list):return ['root must be an array of events']
 seen=set()
 for index,e in enumerate(records):
  loc=f'event[{index}]'
  if not isinstance(e,dict): errors.append(f'{loc}: must be object');continue
  for key in ['candidate_id','opportunity_id','dimension','status']:
   if not isinstance(e.get(key),str) or not e[key].strip():errors.append(f'{loc}: missing {key}')
  d=e.get('dimension');s=e.get('status')
  if d not in ALLOWED:errors.append(f'{loc}: invalid dimension');continue
  if s not in ALLOWED[d]:errors.append(f'{loc}: invalid {d} status');continue
  if s in PROOF.get(d,set()) and not (isinstance(e.get('evidence'),str) and e['evidence'].strip()):
   errors.append(f'{loc}: {d}.{s} requires actual evidence')
  if not e.get('candidate_id') or not e.get('opportunity_id'):continue
  event_id=e.get('event_id')
  if event_id:
   if event_id in seen:errors.append(f'{loc}: duplicate event_id')
   seen.add(event_id)
  if 'recipient' in e and e['recipient'] is not None and d=='outreach' and s=='not_started':errors.append(f'{loc}: recipient attached to not_started without action context')
 return errors

if __name__=='__main__':
 if len(sys.argv)!=2:print('Usage: python scripts/validate_tracker.py records.json');sys.exit(2)
 data=json.loads(Path(sys.argv[1]).read_text())
 errors=validate(data)
 print(json.dumps({'valid':not errors,'errors':errors},indent=2))
 sys.exit(0 if not errors else 1)

SHA-256: 18e5d8f79d6cec187f146fa0b8d7e667cb1193f2f405b9b981490ecb19f454fb