identity-auth-probe.py

import ast,json,sys
from pathlib import Path
from typing import Any,Dict,Optional
from fastapi import FastAPI,HTTPException
from fastapi.testclient import TestClient
from pydantic import BaseModel
root=Path(sys.argv[1]); path=root/'src/cells/identity_attribution/identity_cell/main.py'
names={'PIILookupRequest','PolicyUpdate','pii_lookup','update_policies'}
tree=ast.parse(path.read_text());nodes=[x for x in tree.body if isinstance(x,(ast.ClassDef,ast.FunctionDef)) and x.name in names]
class FixtureCell:
 def __init__(self):self.calls=[]
 def lookup_pii(self,ref,actor,reason):
  self.calls.append({'operation':'lookup','ref':ref,'actor':actor,'reason':reason});return {'email':'synthetic@example.invalid'}
 def update_policies(self,updates):self.calls.append({'operation':'policy_update','updates':updates});return updates
cell=FixtureCell();ns=dict(FastAPI=FastAPI,HTTPException=HTTPException,BaseModel=BaseModel,Optional=Optional,app=FastAPI(),cell=cell)
exec(compile(ast.Module(body=nodes,type_ignores=[]),str(path),'exec'),ns)
with TestClient(ns['app']) as c:
 r=c.post('/pii/lookup',json={'ref':'vault://fixture/users/another-record','actor':'claimed-admin','reason':'fixture'})
 p=c.put('/policies',json={'pii_access_role':'caller-selected-role','min_merge_confidence':0.0})
 print(json.dumps({'scope':'actual source route/model AST with fixture cell; no cloud/data calls','authorization_header':False,'pii_lookup_status':r.status_code,'pii_lookup_body':r.json(),'policy_update_status':p.status_code,'policy_update_body':p.json(),'calls':cell.calls},indent=2))
← All docsView source on GitHub →