fr40-route-probe.py
import os, socket, sys
from unittest.mock import patch
import google.auth
from google.auth.exceptions import DefaultCredentialsError
attempts = []
def denied(*args, **kwargs):
attempts.append('network')
raise AssertionError('Cell02 fixture attempted external access')
socket.socket.connect = denied
socket.create_connection = denied
socket.getaddrinfo = denied
# Match Docker's src PYTHONPATH plus Cell02 working-directory import context.
sys.path[:0] = [sys.argv[1]+'/src/cells/cell02', sys.argv[1]+'/src']
# Explicitly absent fixture configuration, never workstation credentials.
os.environ['GCP_PROJECT_ID'] = ''
os.environ['MIZOKI_SRPVDAL_ENABLED'] = 'false'
os.environ['SRPVDAL_ENABLED'] = 'false'
with patch.object(google.auth, 'default', side_effect=DefaultCredentialsError('offline fixture')):
import Cell2
from fastapi.testclient import TestClient
assert Cell2.SRPVDAL_AVAILABLE
with TestClient(Cell2.app) as client:
# This legacy health route is liveness only; do not certify its claims.
health = client.get('/health')
assert health.status_code == 200
assert health.json()['service'] == Cell2.CONFIG.service_name
print('FR38_HEALTH', health.json())
print('FR38_READY', client.get('/ready').json())
print('FR38_CONFIG', repr(Cell2.CONFIG.gcp_project_id), 'fixture absent; SDK initialization refused')
from unittest.mock import AsyncMock
from types import SimpleNamespace
import pandas as pd
import httpx
captured = []
async def sink(url, **kwargs):
captured.append(kwargs['json'])
return httpx.Response(200, json={'status':'success','data':{'ingestion_id':'fixture-only'}})
service = Cell2.app.state.extraction_service
assert service.config.exclude_pii_fields is False
fixture = pd.DataFrame([{'email':'fixture@example.invalid','description':'synthetic only'}])
with patch.object(service, '_load_data', new=AsyncMock(return_value=fixture)), patch.object(service.http_client, 'post', new=sink):
for mode in ['absent', 'api_error']:
class BrokenDLP:
def deidentify_content(self, **kwargs):
raise Cell2.GoogleAPIError('synthetic provider failure')
with patch.object(service.dlp_service, 'dlp_client', None if mode == 'absent' else BrokenDLP()), patch.object(service.dlp_service, 'parent', 'projects/fixture/locations/global', create=True):
payload = {'source':'fixture-only','format':'json','ontology_id':'fixture-only'}
direct = client.post('/api/v1/extract', json=payload)
assert direct.status_code == 200, direct.text
assert direct.json()['status'] == 'completed', direct.text
assert direct.json()['pii_summary'] == {}
assert captured[-1]['payload']['data'][0]['email'] == 'fixture@example.invalid'
a2a = client.post('/tasks/send', json={'message_type':'cmd.extractor.extract.v1','payload':payload})
assert a2a.status_code == 200 and a2a.json()['status'] == 'success'
assert a2a.json()['data']['status'] == 'completed'
assert captured[-1]['payload']['data'][0]['email'] == 'fixture@example.invalid'
print('FR40_ROUTE', mode, 'extract200completed/A2A200success; raw synthetic email reached substituted Cell3 sink; no real transmission')
print('FR40_BOUNDARIES: source loading and HTTP sink substituted; actual masking/schema/cache/routing/results; captured',len(captured))
status = client.get('/srpvdal/status')
assert status.status_code == 200
assert status.json()['status'] == 'not_configured'
assert status.json()['cell3_connected'] is False
assert status.json()['cell3_status'] == 'unverified'
assert status.json()['supported_tasks'] == []
assert client.post('/srpvdal/execute', json={'task_type':'learn'}).status_code == 422
for task in ['extract', 'transform', 'analyze', 'learn', 'unknown']:
response = client.post('/srpvdal/execute', json={'task_type':task, 'input_data':{'text':'synthetic fixture'}, 'enable_learning':True})
assert response.status_code == 501, response.text
assert response.json()['detail']['status'] == 'not_configured'
assert 'result' not in response.json()
assert 'learned' not in response.json()
assert Cell2.app.state.identity_resolver is None
assert Cell2.app.state.journey_publisher is None
import asyncio
service = Cell2.DLPService(Cell2.CONFIG)
assert service.dlp_client is None
raw = 'Synthetic fixture: fixture@example.invalid'
masked, entities = asyncio.run(service.inspect_and_mask_text(raw))
assert masked == raw and entities == []
print('FR40: absent DLP client returns original synthetic text and empty findings')
assert not attempts, 'external attempt was swallowed'
print('actual Cell2 ASGI: liveness200; mounted SRPVDAL not_configured, invalid422, five task refusals501; no cloud calls')