cache-probe.py

import os,socket,sys,asyncio,json,tempfile
from pathlib import Path
from unittest.mock import patch
attempts=[]
def deny(*a,**k):attempts.append('network');raise AssertionError('offline')
socket.socket.connect=deny;socket.create_connection=deny;socket.getaddrinfo=deny
os.environ['GCP_PROJECT_ID']='';os.environ['MIZOKI_SRPVDAL_ENABLED']='false';os.environ['SRPVDAL_ENABLED']='false'
sys.path[:0]=[sys.argv[1]+'/src/cells/cell02',sys.argv[1]+'/src']
import google.auth
from google.auth.exceptions import DefaultCredentialsError
with tempfile.TemporaryDirectory(prefix="fr41-fixture-") as fixture_dir, patch.object(google.auth,'default',side_effect=DefaultCredentialsError('offline fixture')):
 import Cell2,httpx
 async def run():
  outcomes=[]
  for enabled in [True,False]:
   calls=[]
   def transport(request):
    if request.method=='GET':return httpx.Response(200,json={'services':[]})
    body=json.loads(request.content);calls.append({'body':body,'api_key_header_present':'x-api-key' in request.headers,'authorization_header_present':'authorization' in request.headers})
    return httpx.Response(200,json={'status':'error','error':'Unknown message type: '+body['message_type']})
   config=Cell2.Cell2Config(gcp_project_id='',enable_cell4_cache=enabled,circuit_breaker_persistence_path=str(Path(fixture_dir) / f'breaker-{enabled}.json'))
   async with httpx.AsyncClient(transport=httpx.MockTransport(transport)) as client:
    service=Cell2.SchemaService(config,client)
    schema=Cell2.DataSchema(fields=[Cell2.SchemaField(name='email',type='string',nullable=False)])
    result=await service.validate_with_ontology(schema,'fixture-ontology','1.0.0')
    outcomes.append({'cache_enabled':enabled,'result':result,'outbound_requests':calls})
  return outcomes
 result=asyncio.run(run())
assert attempts==[]
print(json.dumps({'scope':'actual Cell02 schema service, mocked denial matching Cell4 source handler; no positive validation/provider evidence','default_cache':Cell2.Cell2Config.model_fields['enable_cell4_cache'].default,'network_attempts':attempts,'results':result}))
← All docsView source on GitHub →