discovery-probe.py
import os,socket,sys,tempfile,json,asyncio
from pathlib import Path
from unittest.mock import patch
from datetime import datetime,timezone
attempts=[]
def deny(*a,**kw):attempts.append('network');raise AssertionError('offline fixture')
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 patch.object(google.auth,'default',side_effect=DefaultCredentialsError('offline fixture')):
import Cell2
from fastapi.testclient import TestClient
results=[]
with tempfile.TemporaryDirectory(prefix='fr45-owned-',dir='/tmp') as owned:
root=Path(owned).resolve()
with TestClient(Cell2.app,raise_server_exceptions=False) as client:
service=Cell2.app.state.extraction_service
for fail in [False,True]:
target=root/('failure-sentinel.json' if fail else 'success-sentinel.json')
original=b'OWNED_SENTINEL_BEFORE';uploaded=b'[{"value":7}]';target.write_bytes(original)
# Construct traversal only to this newly created, task-owned sentinel.
filename='../tmp/'+Path(owned).name+'/'+target.name
assert (Path('/tmp')/filename).resolve()==target
seen=[]
async def extraction(request):
observed=Path(request.source).resolve()
assert observed==target and root in observed.parents
seen.append({'same_owned_sentinel':observed==target,'bytes_replaced':observed.read_bytes()==uploaded})
if fail:raise RuntimeError('isolated fixture extraction failure')
return Cell2.ExtractionResult(extraction_id='fixture',status='validation_failed',schema=Cell2.DataSchema(fields=[]),record_count=1,validation_errors=['fixture only'],processing_time_seconds=0.0)
with patch.object(service.dlp_service,'dlp_client',object()),patch.object(service,'extract_and_process',new=extraction):
response=client.post('/api/v1/extract/file',data={'ontology_id':'fixture','format':'json'},files={'file':(filename,uploaded,'application/json')})
results.append({'exception_branch':fail,'status_code':response.status_code,'during_extraction':seen,'owned_sentinel_deleted':not target.exists()})
assert seen==[{'same_owned_sentinel':True,'bytes_replaced':True}]
assert not target.exists()
assert not attempts
Path('/tmp/fr45-upload-probe.json').write_text(json.dumps({'observed_at':datetime.now(timezone.utc).isoformat(),'source_checkout':sys.argv[1],'scope':'actual Cell2 ASGI multipart route; only newly created task-owned TemporaryDirectory sentinels; extraction substituted, no SDK calls','results':results,'network_attempts':attempts},indent=2)+'\n')
print('FR45 reproduced overwrite then deletion of owned sentinel on success and extraction-error paths; zero network/SDK calls')