import pathlib,json,ast
ROOT=pathlib.Path(__file__).resolve().parents[1]
checks=[]
def c(n,x): checks.append((n,bool(x)))
req=json.loads((ROOT/'requirements.json').read_text()); policy=json.loads((ROOT/'fixture/golden-policy.json').read_text()); fixture=json.loads((ROOT/'fixture/baseline-ai-context.json').read_text())
for k in ['network','external_targets','real_credentials','external_llm','real_tools','irreversible_side_effects']: c(k+'_forbidden',req[k]=='forbidden')
c('synthetic_fixture',req['fixture']=='synthetic_local_only'); c('fixed_model_outputs',req['model_mode']=='fixed_outputs_only'); c('fixture_id',fixture['fixture_id']=='SEC008-SYNTHETIC-AI-CONTEXT-1'); c('policy_id',policy['fixture_id']==fixture['fixture_id']); c('action_count',len(policy['actions'])==3); c('guardrail_not_authority',policy['guardrail_is_authority'] is False); c('model_not_authority',policy['model_output_grants_authority'] is False); c('scope_no_expand',policy['external_context_may_expand_scope'] is False); c('approval_required','create_local_reminder' in policy['approval_gate_required_for'])
text=(ROOT/'src/ai_context_boundary.py').read_text(); tree=ast.parse(text); imports={n.names[0].name.split('.')[0] for n in ast.walk(tree) if isinstance(n,ast.Import)}|{(n.module or '').split('.')[0] for n in ast.walk(tree) if isinstance(n,ast.ImportFrom)}
for bad in ['requests','socket','httpx','aiohttp','openai','anthropic']: c('no_'+bad,bad not in imports)
c('no_eval','eval(' not in text and 'exec(' not in text); c('no_subprocess','subprocess' not in imports)
for n,ok in checks: print(('PASS' if ok else 'FAIL'),n)
print(f'SUMMARY {sum(x[1] for x in checks)}/{len(checks)} PASS'); raise SystemExit(0 if all(x[1] for x in checks) else 1)
