test: remove impossible-scenario tests from DAG REST enrichment

Remove 6 tests that covered malformed data shapes (data=None,
data=string, data=list, non-dict event elements) that cannot
occur since our own code always writes well-formed dicts via
model_dump(mode="json").
This commit is contained in:
Igor Loskutov
2026-02-09 14:10:19 -05:00
parent 455cb3d099
commit 4d9f5fa4b4

View File

@@ -148,105 +148,6 @@ class TestFetchDagStatuses:
assert result == {}
class TestFetchDagStatusesMalformedData:
"""Test _fetch_dag_statuses with malformed event data."""
@pytest.mark.asyncio
async def test_event_missing_data_key(self):
"""DAG_STATUS event without 'data' key: ev.get('data', {}) returns {},
then {}.get('tasks') returns None, so transcript is skipped gracefully."""
events = [
{"event": "DAG_STATUS"},
]
mock_row = {"id": "t1", "events": events}
with patch("reflector.db.search.get_database") as mock_db:
mock_db.return_value.fetch_all = AsyncMock(return_value=[mock_row])
result = await _fetch_dag_statuses(["t1"])
assert result == {}
@pytest.mark.asyncio
async def test_event_data_is_string(self):
"""DAG_STATUS event where data is a string instead of dict.
ev.get('data', {}) returns the string, then .get('tasks') raises
AttributeError because str has no .get() method."""
events = [
{"event": "DAG_STATUS", "data": "not-a-dict"},
]
mock_row = {"id": "t1", "events": events}
with patch("reflector.db.search.get_database") as mock_db:
mock_db.return_value.fetch_all = AsyncMock(return_value=[mock_row])
with pytest.raises(AttributeError):
await _fetch_dag_statuses(["t1"])
@pytest.mark.asyncio
async def test_events_list_with_non_dict_elements_skipped(self):
"""Non-dict elements in events list are skipped by isinstance check."""
events = [
42,
"a string event",
None,
{
"event": "DAG_STATUS",
"data": {
"workflow_run_id": "r1",
"tasks": [{"name": "transcribe", "status": "running"}],
},
},
]
mock_row = {"id": "t1", "events": events}
with patch("reflector.db.search.get_database") as mock_db:
mock_db.return_value.fetch_all = AsyncMock(return_value=[mock_row])
result = await _fetch_dag_statuses(["t1"])
assert "t1" in result
assert result["t1"][0]["name"] == "transcribe"
@pytest.mark.asyncio
async def test_events_list_only_non_dict_elements(self):
"""Events list containing only non-dict elements produces no result."""
events = [42, "hello", None, True]
mock_row = {"id": "t1", "events": events}
with patch("reflector.db.search.get_database") as mock_db:
mock_db.return_value.fetch_all = AsyncMock(return_value=[mock_row])
result = await _fetch_dag_statuses(["t1"])
assert result == {}
@pytest.mark.asyncio
async def test_event_data_is_none(self):
"""DAG_STATUS event where data is explicitly None.
ev.get('data', {}) returns None, then None.get('tasks') raises
AttributeError."""
events = [
{"event": "DAG_STATUS", "data": None},
]
mock_row = {"id": "t1", "events": events}
with patch("reflector.db.search.get_database") as mock_db:
mock_db.return_value.fetch_all = AsyncMock(return_value=[mock_row])
with pytest.raises(AttributeError):
await _fetch_dag_statuses(["t1"])
@pytest.mark.asyncio
async def test_event_data_is_list(self):
"""DAG_STATUS event where data is a list instead of dict.
Lists don't have .get(), so raises AttributeError."""
events = [
{"event": "DAG_STATUS", "data": ["not", "a", "dict"]},
]
mock_row = {"id": "t1", "events": events}
with patch("reflector.db.search.get_database") as mock_db:
mock_db.return_value.fetch_all = AsyncMock(return_value=[mock_row])
with pytest.raises(AttributeError):
await _fetch_dag_statuses(["t1"])
def _extract_dag_status_from_transcript(transcript):
"""Replicate the dag_status extraction logic from transcript_get view.