Files
ai-use-outdoor-industry-res…/scripts/validate_run.py
T

67 lines
4.5 KiB
Python
Raw Normal View History

2026-09-14 12:34:28 -06:00
import json, sys
from pathlib import Path
from datetime import datetime, date, timedelta
CATEGORIES=['Strategy','Systems/infrastructure','Product development','Finance','Production','Logistics','Supply chain','Marketing','Sales/distribution','Other operations']
def validate(folder):
folder=Path(folder); errors=[]
def check(ok,msg):
if not ok: errors.append(msg)
for name in ['standard-web.md','exa.md','comparison.md','evidence.json','search-log.json']:
check((folder/name).is_file() and (folder/name).stat().st_size>0,'Missing '+name)
if errors:return errors
d=json.loads((folder/'evidence.json').read_text(encoding='utf-8'))
log=json.loads((folder/'search-log.json').read_text(encoding='utf-8'))
start=datetime.fromisoformat(d['window_start']); end=datetime.fromisoformat(d['window_end'])
check(end-start==timedelta(days=7),'Window must be exactly seven days')
check((start.tzinfo is not None and end.tzinfo is not None),'Timezone required')
check(log['window_start']==d['window_start'] and log['window_end']==d['window_end'],'Log window mismatch')
2026-11-09 13:34:35 -07:00
gaps=log.get('coverage_gaps',[])
partial=log.get('coverage_status')=='completed-with-gaps'
check(isinstance(gaps,list),'Coverage gaps must be an array')
check(log.get('coverage_status','complete') in ['complete','completed-with-gaps'],'Invalid coverage status')
check(not partial or bool(gaps),'Completed-with-gaps requires gaps')
check(partial or not gaps,'Coverage gaps require completed-with-gaps status')
gap_engines=set()
for gap in gaps if isinstance(gaps,list) else []:
valid=isinstance(gap,dict) and gap.get('engine') in ['standard-web','exa'] and isinstance(gap.get('reason'),str) and bool(gap['reason'].strip())
check(valid,'Invalid coverage gap')
if valid:
gap_engines.add(gap['engine'])
for name in ['standard-web.md','exa.md','comparison.md']:
txt=(folder/name).read_text(encoding='utf-8')
check('completed-with-gaps' in txt and gap['reason'] in txt,'Missing coverage disclosure: '+name)
2026-09-14 12:34:28 -06:00
for eng,key in [('standard-web','standard_web'),('exa','exa')]:
txt=(folder/(eng+'.md')).read_text(encoding='utf-8')
2026-11-09 13:34:35 -07:00
check(len(log.get(key,{}).get('queries',[]))>=6 or (partial and eng in gap_engines),'Missing search coverage: '+eng)
2026-09-14 12:34:28 -06:00
for cat in CATEGORIES:check('| '+cat+' |' in txt,'Missing coverage '+eng+' '+cat)
for h in ['Internal','Customer-facing','Both','Method and limitations']: check('## '+h in txt,'Missing group '+h)
ids=[]
for c in d['cases']:
for k in ['id','engine','organization','evidence_date','event_date','measurement_period','primary_function','secondary_functions','exposure','deployment_status','ai_mechanism','outcome','outcome_status','future_plans','source_url','source_type','source_opened','confidence','continuity','score']:
check(k in c,'Missing case field '+k)
if errors:continue
ids.append(c['id'])
check(c['engine'] in ['standard-web','exa'],'Invalid engine')
check(c['exposure'] in ['Internal','Customer-facing','Both'],'Invalid exposure')
check(c['primary_function'] in CATEGORIES and all(x in CATEGORIES for x in c['secondary_functions']),'Invalid function')
check(c['deployment_status'] in ['planned','pilot','live','scaled','withdrawn','unclear'],'Invalid status')
check(start.date()<=date.fromisoformat(c['evidence_date'])<=end.date(),'Out-of-window case')
check(c['source_url'].startswith('https://') and c['source_opened'] is True,'Missing opened citation')
if c['engine'] in ['standard-web','exa']:
txt=(folder/(c['engine']+'.md')).read_text(encoding='utf-8')
check(c['source_url'] in txt and c['id'] in txt,'Report missing case citation')
check(len(ids)==len(set(ids)),'Duplicate case ID')
return errors
2026-11-09 13:34:35 -07:00
def checkpoint_eligible(folder):
"""Full-success checkpoints exclude validated completed-with-gaps outputs."""
if validate(folder):
return False
log=json.loads((Path(folder)/'search-log.json').read_text(encoding='utf-8'))
return log.get('coverage_status','complete')=='complete' and not log.get('coverage_gaps')
2026-09-14 12:34:28 -06:00
if __name__=='__main__':
try: errors=validate(sys.argv[1])
except (KeyError,ValueError,OSError,IndexError) as e: errors=[str(e)]
print('\n'.join(errors) if errors else 'PASS: report structure, seven-day window, coverage and evidence fields')
sys.exit(bool(errors))