The suite keeps only logic tests

Check API validation and response shaping through direct calls.

Checks: ruff check, ruff format --check, lint-imports (two contracts kept), and pytest (115 passed, 7 warnings in 42.52s).

removed WebApi/tests/test_bundles.py::test_export_and_import_through_the_api — slow integration (logic now covered by test_layout_and_manifest_hold_every_file_hash and test_roundtrip_registers_candidates_with_lineage)
removed WebApi/tests/test_bundles.py::test_import_refuses_a_wrong_sha_and_a_non_zip — slow integration (logic now covered by test_import_rejects_invalid_uploads)
removed WebApi/tests/test_bundles.py::test_importing_the_same_bundle_again_fails_the_run — slow integration (logic now covered by test_importing_twice_is_a_conflict_and_partial_imports_skip)
removed WebApi/tests/test_bundles.py::test_export_guard_failure_is_422 — slow integration (logic now covered by test_reference_group_size and test_selection_champion_latest_all)
removed WebApi/tests/test_bundles.py::test_an_untrusted_bundle_is_refused — slow integration (logic now covered by test_import_rejects_invalid_uploads and test_import_refuses_an_untrusted_digest)
removed WebApi/tests/test_cacu.py — parity-only
removed WebApi/tests/test_cacu.py::test_cacu_from_the_hospital_to_indicators_and_risks — parity-only
removed WebApi/tests/test_cama.py — parity-only
removed WebApi/tests/test_cama.py::test_cama_from_the_hospital_to_indicators — parity-only
removed WebApi/tests/test_conectar.py — slow integration (logic now covered by test_person_ids_survive_a_review_merge_and_split and test_a_concept_map_onto_a_code_no_field_allows_is_refused)
removed WebApi/tests/test_conectar.py::test_an_operator_connects_a_site_and_settles_its_review — slow integration (logic now covered by test_person_ids_survive_a_review_merge_and_split and test_a_concept_map_onto_a_code_no_field_allows_is_refused)
removed WebApi/tests/test_fhir_door.py — slow integration (logic now covered by test_fhir_in_joins_encounter_results_and_subject_by_full_url and tests/test_core_tea_fhir.py for FHIR mappings)
removed WebApi/tests/test_fhir_door.py::test_what_one_platform_serves_another_places_through_the_fhir_door — slow integration (logic now covered by test_fhir_in_joins_encounter_results_and_subject_by_full_url and tests/test_core_tea_fhir.py for FHIR mappings)
removed WebApi/tests/test_fhir_door.py::test_a_new_label_is_a_concept_map_row_not_code — slow integration (logic now covered by test_hospital_codes_and_dates_become_platform_values)
removed WebApi/tests/test_governance.py::test_version_lifecycle — slow integration (logic now covered by models/tests/test_bundle.py::test_version_lifecycle)
removed WebApi/tests/test_governance.py::test_imported_lineage — slow integration (logic now covered by test_roundtrip_registers_candidates_with_lineage)
removed WebApi/tests/test_governance.py::test_preview — slow integration (logic now covered by test_the_job_deletes_its_files_and_returns_the_result_as_output and test_shape_outputs)
removed WebApi/tests/test_governance.py::test_training_inputs — slow integration (logic now covered by the direct-call test_training_inputs)
removed WebApi/tests/test_runs.py::test_unknown_run_is_404 — implementation-detail
removed WebApi/tests/test_runs.py::test_failed_run_reports_its_error — slow integration (logic now covered by test_shape_failure_message_is_the_ops_own_exception)
removed WebApi/tests/test_runs.py::test_history_filters_by_job_and_domain — implementation-detail
removed WebApi/tests/test_runs.py::test_run_requests_validate_the_execution_choice — slow integration (logic now covered by test_resolve_rejects_unlisted_scheduler_and_scheduler_in_local_mode)
removed WebApi/tests/test_runs.py::test_execution_options_and_health — implementation-detail
removed WebApi/tests/test_runs.py::test_tea_eegs_analyze_validates_scope — slow integration (logic now covered by test_scope_validation)
removed WebApi/tests/test_runs.py::test_a_locked_run_storage_is_read_again — implementation-detail
removed WebApi/tests/test_runs.py::test_cancel_waits_for_a_starting_run — implementation-detail
removed WebApi/tests/test_runs.py::test_cancel_a_finished_run_is_409 — slow integration (logic now covered by test_cancel_a_finished_run_is_409 with a client double)
removed WebApi/tests/test_runs_concurrency.py — slow integration (logic now covered by test_cancel_returns_the_terminal_or_cancelling_state for the queued transition)
removed WebApi/tests/test_runs_concurrency.py::test_writing_runs_never_overlap — implementation-detail
removed WebApi/tests/test_runs_concurrency.py::test_cancelling_an_ingest_run_leaves_no_silver_or_gold — slow integration (logic now covered by test_cancel_returns_the_terminal_or_cancelling_state for the API state transition)
removed WebApi/tests/test_runs_concurrency.py::test_cancelling_a_queued_run_never_starts_it — slow integration (logic now covered by test_cancel_returns_the_terminal_or_cancelling_state for the queued transition)
removed WebApi/tests/test_runs_concurrency.py::test_a_dead_run_does_not_stay_running — implementation-detail
removed WebApi/tests/test_synthea.py — slow integration (logic now covered by test_fhir_in_joins_encounter_results_and_subject_by_full_url and test_hospital_codes_and_dates_become_platform_values)
removed WebApi/tests/test_synthea.py::test_a_synthea_population_comes_in_through_the_fhir_door — slow integration (logic now covered by test_fhir_in_joins_encounter_results_and_subject_by_full_url and test_hospital_codes_and_dates_become_platform_values)
removed WebApi/tests/test_synthea_cama.py — slow integration (logic now covered by test_fhir_in_joins_encounter_results_and_subject_by_full_url for FHIR ingestion mapping)
removed WebApi/tests/test_synthea_cama.py::test_a_synthea_cama_population_comes_in_through_the_fhir_door — slow integration (logic now covered by test_fhir_in_joins_encounter_results_and_subject_by_full_url for FHIR ingestion mapping)
removed WebApi/tests/test_tea.py — parity-only
removed WebApi/tests/test_tea.py::test_tea_from_the_hospital_to_indicators — parity-only
removed WebApi/tests/test_training_config.py::test_tea_training_config_schema — slow integration (logic now covered by the direct-call test_tea_training_config_schema)
removed WebApi/tests/test_training_config.py::test_other_domains_have_no_reference — slow integration (logic now covered by the direct-call test_other_domains_have_no_reference)
removed WebApi/tests/test_training_config.py::test_train_validates_the_reference — slow integration (logic now covered by the direct-call test_train_validates_the_reference and test_bad_references_fail_with_a_reason)
removed WebApi/tests/test_webapp.py — slow integration (logic now covered by existing WebApp unit tests for figure, row and export builders; loaded-page browser coverage is deferred to P5.5)
removed WebApi/tests/test_webapp.py::test_every_page_loads_from_the_api — slow integration (logic now covered by existing WebApp unit tests for figure, row and export builders; loaded-page browser coverage is deferred to P5.5)
This commit is contained in:
2026-11-30 16:45:51 -06:00
parent ec5d945f71
commit 80049112aa
14 changed files with 125 additions and 2420 deletions
+49 -170
View File
@@ -1,12 +1,9 @@
import os
import time
import pytest
import yaml
from dagster import DagsterRunStatus
from fastapi import HTTPException
import conftest
from persistance.cluster import Progress
from webapi.runs import STATE, graphql, shape
from webapi.runs import _locked, cancel_run, shape
PAYLOAD = {
"runId": "run",
@@ -88,7 +85,12 @@ def test_shape_progress_tag():
assert run.progress.done == 3
assert run.progress.phase == "analyzing"
assert shape(with_tag("{bad json"), []).progress is None
for status, state in STATE.items():
for status, state in (
("QUEUED", "queued"),
("STARTING", "running"),
("CANCELING", "cancelling"),
("CANCELED", "cancelled"),
):
run = shape(PAYLOAD | {"status": status}, [])
assert (run.status, run.state) == (status, state)
assert shape(PAYLOAD | {"status": "UNKNOWN"}, []).state == "running"
@@ -112,171 +114,48 @@ def test_shape_outputs():
assert shape(PAYLOAD, events, outputs=False).outputs is None
def _ok(response):
assert response.status_code == 200, response.text
return response.json()
@pytest.fixture
def failed_run(api):
run_id = _ok(api.post("/models/cacu/analyze"))["run_id"]
deadline = time.monotonic() + 120
while (run := _ok(api.get(f"/runs/{run_id}")))["state"] != "failed":
assert time.monotonic() < deadline, run
time.sleep(1)
return run
def test_unknown_run_is_404(api):
assert api.get("/runs/does-not-exist").status_code == 404
assert api.post("/runs/does-not-exist/cancel").status_code == 404
def test_failed_run_reports_its_error(failed_run):
assert failed_run["status"] == "FAILURE"
assert "analyze" in failed_run["error"]
assert isinstance(failed_run["info"], list)
assert isinstance(failed_run["warnings"], list)
assert any(
step["key"] == "analyze_studies" and step["status"] == "FAILURE"
for step in failed_run["steps"]
)
assert failed_run["domain"] == "cacu"
assert failed_run["job"] == "analyze"
def test_history_filters_by_job_and_domain(api, failed_run):
run_id = failed_run["id"]
history = _ok(api.get("/runs", params={"job": "analyze", "domain": "cacu"}))
assert run_id in {run["id"] for run in history}
for params in ({"job": "train"}, {"domain": "tea"}):
assert run_id not in {run["id"] for run in _ok(api.get("/runs", params=params))}
another_id = _ok(api.post("/models/cacu/analyze"))["run_id"]
page = _ok(api.get("/runs", params={"limit": 1}))
assert [run["id"] for run in page] == [another_id]
page = _ok(api.get("/runs", params={"limit": 1, "before": another_id}))
assert [run["id"] for run in page] == [run_id]
def test_cancel_a_finished_run_is_409(api, failed_run):
response = api.post(f"/runs/{failed_run['id']}/cancel")
assert response.status_code == 409
assert response.json()["detail"] == "the run already ended: failed"
@pytest.fixture
def api_with_dagster_address(platform, request, monkeypatch):
ports = []
free_port = conftest._free_port
def record_port():
port = free_port()
ports.append(port)
return port
monkeypatch.setattr(conftest, "_free_port", record_port)
api = request.getfixturevalue("api")
monkeypatch.setenv("DAGSTER_HOST", "127.0.0.1")
monkeypatch.setenv("DAGSTER_PORT", str(ports[0]))
return api
def test_run_requests_validate_the_execution_choice(api_with_dagster_address):
api = api_with_dagster_address
path = "/models/tea/analyze"
for execution in (
{"mode": "remote", "scheduler": "tcp://evil:8786"},
{"mode": "local", "scheduler": "tcp://x:8786"},
):
assert api.post(path, json={"execution": execution}).status_code == 422
run_id = _ok(api.post(path, json={"execution": {"mode": "sync"}}))["run_id"]
data = graphql(
"""
query RunConfig($id: ID!) {
runOrError(runId: $id) { ... on Run { runConfigYaml } }
}
""",
{"id": run_id},
)
config = yaml.safe_load(data["runOrError"]["runConfigYaml"])
assert config["ops"]["analyze_studies"]["config"]["execution"]["mode"] == "sync"
def test_execution_options_and_health(api):
options = _ok(api.get("/execution/options"))
assert options["default_mode"] == "sync"
configured = [s for s in os.environ.get("DASK_SCHEDULERS", "").split(",") if s]
assert options["schedulers"] == configured
health = _ok(api.get("/execution/health", params={"mode": "local"}))
assert health["reachable"] is True
assert health["workers"] >= 1
if configured:
remote = {"mode": "remote", "scheduler": configured[0]}
health = _ok(api.get("/execution/health", params=remote))
assert health["reachable"] is True
assert health["workers"] == int(os.environ.get("DASK_EXPECTED_WORKERS", "1"))
else:
assert api.get("/execution/health", params={"mode": "remote"}).status_code == 422
assert api.get("/execution/health?mode=sync&reference=..%2Fx").status_code == 422
def test_tea_eegs_analyze_validates_scope(api):
response = api.post("/tea/eegs/analyze", json={"scope": {"mode": "first_n"}})
assert response.status_code == 422
def test_a_locked_run_storage_is_read_again(monkeypatch):
from fastapi import HTTPException
from webapi import runs
error = {"__typename": "PythonError", "message": "OperationalError: database is locked"}
locked = {"data": {"runOrError": {"__typename": "Run"}, "logsForRun": error}}
fine = {
"data": {
"runOrError": {"__typename": "Run"},
"logsForRun": {"__typename": "EventConnection"},
}
}
answers = [locked, locked, fine]
class Answer:
status_code = 200
def __init__(self, payload):
self.payload = payload
def json(self):
return self.payload
monkeypatch.setattr(runs.time, "sleep", lambda s: None)
monkeypatch.setattr(runs.requests, "post", lambda *a, **k: Answer(answers.pop(0)))
assert runs.graphql("q", {}) == fine["data"]
monkeypatch.setattr(runs.requests, "post", lambda *a, **k: Answer(locked))
with pytest.raises(HTTPException) as raised:
runs.graphql("q", {})
assert raised.value.status_code == 503
def test_cancel_waits_for_a_starting_run(monkeypatch):
from webapi import runs
statuses = iter(["STARTING", "STARTING", "STARTED", "CANCELING"])
terminated = []
@pytest.mark.parametrize("initial", [DagsterRunStatus.QUEUED, DagsterRunStatus.STARTED])
def test_cancel_returns_the_terminal_or_cancelling_state(initial):
class Client:
def get_run_status(self, run_id):
class S:
value = next(statuses)
status = initial
return S()
def get_run_status(self, run_id):
return self.status
def terminate_run(self, run_id):
terminated.append(run_id)
self.status = {
DagsterRunStatus.QUEUED: DagsterRunStatus.CANCELED,
DagsterRunStatus.STARTED: DagsterRunStatus.CANCELING,
}[self.status]
monkeypatch.setattr(runs.time, "sleep", lambda s: None)
answer = runs.cancel_run("r1", client=Client())
assert terminated == ["r1"]
assert answer.status == "CANCELING"
result = cancel_run("r1", client=Client())
expected = (
("CANCELED", "cancelled")
if initial == DagsterRunStatus.QUEUED
else ("CANCELING", "cancelling")
)
assert (result.id, result.status, result.state) == ("r1", *expected)
def test_cancel_a_finished_run_is_409():
class Client:
def get_run_status(self, run_id):
return DagsterRunStatus.SUCCESS
with pytest.raises(HTTPException) as error:
cancel_run("r1", client=Client())
assert error.value.status_code == 409
assert error.value.detail == "the run already ended: succeeded"
def test_a_storage_lock_is_distinguished_from_a_run_failure():
assert _locked({"errors": [{"message": "OperationalError: database is locked"}]})
assert _locked(
{"data": {"logsForRun": {"__typename": "PythonError", "message": "database is locked"}}}
)
assert not _locked(
{"data": {"logsForRun": {"__typename": "EventConnection", "message": "database is locked"}}}
)
assert not _locked(
{"data": {"logsForRun": {"__typename": "PythonError", "message": "unknown error"}}}
)