E2E — "Conectar datos" scripted and browser checks
Scripted end-to-end checks against a live WebApi/WebApp, driving the same endpoints and UI flows a real user would, instead of mocks. A failure here is a failure in the product.
Contents
| File | What it does |
|---|---|
make_fixtures.py |
Generates the CSV/Excel/JSON/PDF fixtures in fixtures/ and the legacy MySQL source tables (pacientes_his, citologias_his), deterministically. |
api_e2e.py |
Drives /imports/* and /data/* over HTTP: discovery, per-source validation, one multi-source commit, read-back through both the API and the models package. |
ingesta_hospital.py |
Ingests every table of a real (or simulated) hospital MySQL source through /imports/sources/sql/* and /imports/commit, using the API's own suggested column mappings. |
make_merge_demo_fixtures.py |
Generates the two-source "same paciente, two systems" fixture pair (merge_padron.csv + merge_ficha.pdf) used by merge_demo_gui.js. |
merge_demo_gui.js |
Drives the real /conectar Angular workspace over the Chrome DevTools Protocol: uploads both sources, commits with "Combinar duplicados", verifies the merged row. |
reset_target_dbs.py |
Drops, recreates and migrates the three target databases in the e2e MySQL container. |
fixtures/ |
Generated/static input files for the above. |
Scripted run (no browser)
# 0) MySQL up (OrbStack or equivalent)
docker start isssteleon-mysql-test
# 1) clean target DBs + migrate to head (+ alembic check)
../e2e/reset_target_dbs.py
# 2) fixtures (files + legacy MySQL tables)
cd WebApi && uv sync --extra sql-drivers
uv run python ../e2e/make_fixtures.py --legacy-url "mysql+pymysql://root:test_root_pw@127.0.0.1:3307/hospital_legacy"
# 3) API against MySQL (macOS needs the fork-safety env var for gunicorn)
export CACU_DATABASE_URL="mysql+pymysql://isss_app:isss_app_pw@127.0.0.1:3307/isss_cacu" \
CAMA_DATABASE_URL="mysql+pymysql://isss_app:isss_app_pw@127.0.0.1:3307/isss_cama" \
TEA_DATABASE_URL="mysql+pymysql://isss_app:isss_app_pw@127.0.0.1:3307/isss_tea"
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES uv run gunicorn -b 127.0.0.1:5051 -w 2 --timeout 300 "webapi:create_app()" &
# 4) the E2E (same env vars, so the `models` read-back sees the same DBs)
uv run python ../e2e/api_e2e.py --api http://127.0.0.1:5051 \
--legacy "mysql+pymysql://legacy_reader:legacy_pw@127.0.0.1:3307/hospital_legacy"
api_e2e.py checks: Excel sheets discovered, ;/BOM sniffed, which CSV
columns auto-map and which don't, writes refused on the SQL connector, PDF
table detected, scanned PDF has no text layer, OCR reads the ids,
per-source validation errors land exactly on the bad rows, one batch / one
transaction, conflicts itemized row by row, leading zeros kept (01000),
INT ZIP 1000 → '01000', a default value applied, a catalog alias
normalized, invalid rows not written, every child row linked to its patient
(pac_id), and models.CaCuModel().dataset("paciente") sees exactly what
the API wrote.
Fixtures
Each source in make_fixtures.py uses its own column names (none match
Core's field names exactly) and carries a few deliberately bad rows:
| Source | Kind | Destination | What it exercises |
|---|---|---|---|
cacu_pacientes.csv |
CSV (UTF-8 BOM, ;, dd/mm/yyyy) |
Paciente | "Clave única" does not auto-map (manual mapping); no parentesco column (a default value); 4 bad rows (sex out of catalog, impossible date, missing id, 4-digit ZIP) |
cacu_ordenes_y_notas.xlsx sheet Órdenes |
Excel | OrdenesEstudio | sheet picking; 2 bad rows (study type out of catalog, missing folio) |
| same workbook, sheet Notas médicas | Excel | NotaMedica | one file, two tables |
cacu_biometrias.json |
nested JSON | BiometriaHematica | dotted paths (resultados.hemoglobina); bad date and non-numeric value |
hospital_legacy.pacientes_his |
MySQL table | Paciente | INT ZIP codes (leading zero lost upstream); overlaps the CSV on EXP-0025…0030, producing conflicts |
custom SQL over citologias_his |
MySQL query | CitologiaCervical | UPPER(...) AS VPH projection; 1 value out of catalog |
cacu_biopsias_reporte.pdf |
PDF with a text layer | BiopsiaCervical | table auto-detected; 1 grade out of catalog |
pacientes_escaneados.pdf |
image-only PDF (2 pages) | Paciente | region drawing → OCR; a misread letter is caught by validation, not silently stored |
merge_padron.csv + merge_ficha.pdf |
CSV + scanned document | Paciente | neither source alone is valid (the CSV lacks the required birth date); merge_duplicates combines them into one row |
A GIF of the browser walkthrough is kept locally at
e2e/isssteleon_conectar_datos_e2e.gif (git-ignored — regenerable, and too
large to keep in version control).
Browser run: the "two sources, one paciente" merge
cd Extraction && uv run python ../e2e/make_merge_demo_fixtures.py # fixtures, once
# a headless Chrome with remote debugging:
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
--headless=new --disable-gpu --no-sandbox \
--remote-debugging-port=9333 --user-data-dir=/tmp/merge-demo-profile &
# WebApi and WebApp already running, pointed at a scratch database:
node e2e/merge_demo_gui.js --webapp http://localhost:4200 --api http://localhost:5050 --chrome-port 9333
Drives the real /conectar page over the Chrome DevTools Protocol: uploads
a CSV missing cacu.Paciente's required birth date, uploads a scanned
"ficha de identificación" through the document (NLP) connector supplying
it, commits both with "Combinar duplicados" checked, and verifies the
merged row directly against GET /data/cacu.Paciente — one row, with the
birth date from the document and the postal code from the CSV. This is a
standing regression check for the merge-eligibility gap ConnectWorkspaceStore.submittableFlows/LoadDialog
used to have (a flow missing a required field never reached the batch,
even when mergeDuplicates was on): if either of its two merge-specific
assertions ever fails again, that gap is back.
Writes a real patient (pac_id_hospital = DEMO-1001) through whatever
database WebApi is pointed at — use a scratch database, not one you care
about.
Chrome DevTools Protocol notes
- A new CDP session attaching to an already-open headless tab resets the
viewport to a tiny default, even after an earlier session on that same
tab called
Emulation.setDeviceMetricsOverride— reapply it on every reconnect, not just once. - A button whose only visible text is an icon ligature carries its real
label in
aria-label, nottextContent— match both when scripting a click by text. - Material
mat-selectneeds a trusted CDP mouse click on the trigger (a synthetic.click()doesn't open it); its option panel lives outside.cdk-overlay-container's expected order — query[role=option]. DOM.setFileInputFilesfireschangeitself.- A top-level
constinRuntime.evaluateleaks across evaluations on the same page — wrap eval snippets in IIFEs.
Known limits
- SQL credentials for the legacy/hospital source transit the browser
(stateless by design; narrowed by
SqlSourcePolicy's read-only, allowlisted, single-SELECT enforcement, not a substitute for auth). - TEA's staging tables had no natural key as of the last E2E pass, so re-importing TEA always inserts rather than upserting.
- Cross-field validation (
@model_validator) across the import schemas is not exercised here.