Connect breast follow-up to the configured cohort

This commit is contained in:
Angel Capetillo Zavala
2026-11-13 15:16:14 -06:00
parent 7bc214b50c
commit 8b47f1522d
9 changed files with 220 additions and 305 deletions
+50
View File
@@ -0,0 +1,50 @@
"""Serve an isolated synthetic database through a loopback-only test proxy."""
import argparse
import os
from pathlib import Path
import secrets
import sys
import types
parser = argparse.ArgumentParser()
parser.add_argument('--database', required=True, help='Existing disposable synthetic SQLite database')
parser.add_argument('--secret-file', required=True, help='Persistent local pseudonym secret file')
parser.add_argument('--port', type=int, default=5059)
args = parser.parse_args()
database = Path(args.database).resolve(strict=True)
if not database.is_file():
raise ValueError('The synthetic database must be an existing file')
secret_file = Path(args.secret_file).resolve()
if not secret_file.exists():
with secret_file.open('x', encoding='ascii') as output:
output.write(secrets.token_hex(32))
secret = secret_file.read_text(encoding='ascii').strip()
token = secrets.token_hex(32)
os.environ.update(CAMA_DATABASE_URL='sqlite:///' + database.as_posix(),
CAMA_COHORT_SYNTHETIC='1', CAMA_COHORT_SECRET=secret,
CAMA_COHORT_ACCESS_TOKEN=token, MLFLOW_DISABLE_AGENT_HINT='1',
MLFLOW_DISABLE_TELEMETRY='true')
for domain in ('CACU', 'TEA', 'GOVERNANCE'):
os.environ[domain + '_DATABASE_URL'] = 'sqlite:///:memory:'
if os.name == 'nt':
fcntl = types.ModuleType('fcntl')
fcntl.LOCK_EX, fcntl.LOCK_UN = 2, 8
def unavailable(*_args):
raise RuntimeError('POSIX locking is unavailable in this Windows test harness')
fcntl.flock = unavailable
sys.modules['fcntl'] = fcntl
from webapi import create_app
from werkzeug.serving import make_server
app = create_app()
application = app.wsgi_app
def test_proxy(environ, start_response):
# The harness is loopback-only and replaces any caller-supplied test token.
environ['HTTP_X_CAMA_COHORT_TOKEN'] = token
return application(environ, start_response)
print(f'Isolated synthetic test proxy: http://127.0.0.1:{args.port}', flush=True)
make_server('127.0.0.1', args.port, test_proxy, threaded=True).serve_forever()