Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions disaster_report/store/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,11 @@ def read_news(self, incident_id: str) -> list[NewsItem]:
if self._news_incident.get(nuuid) == incident_id
]

def _pending_news_max_dates(self) -> dict[str, datetime]:
def _recent_news_max_dates(self) -> dict[str, datetime]:
max_pub: dict[str, datetime] = {}
for nuuid, n in self._news.items():
inc = self._news_incident.get(nuuid)
if inc is None or self._news_log.get(nuuid) is not None:
if inc is None:
continue
try:
dt = _as_utc(datetime.fromisoformat(n.get("published_date", "")))
Expand All @@ -530,7 +530,7 @@ def _pending_news_max_dates(self) -> dict[str, datetime]:
def active_incidents(self, window_days: int) -> list[Incident]:
now = _as_utc(self._clock())
cutoff = now - timedelta(days=window_days)
max_pub = self._pending_news_max_dates()
max_pub = self._recent_news_max_dates()
active_ids = [inc for inc, dt in max_pub.items() if cutoff <= dt <= now]
if not active_ids:
return []
Expand Down
20 changes: 19 additions & 1 deletion tests/integration/content_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ def test_active_ignores_old_pending_news(self, tmp_path: Path) -> None:
store.assign_news_to_incident(nid, inc)
assert store.active_incidents(WINDOW) == []

def test_active_ignores_summarized_news(self, tmp_path: Path) -> None:
def test_active_keeps_incident_with_recent_summarized_news(
self, tmp_path: Path
) -> None:
store = ContentStore(tmp_path, clock=_clock)
rid = store.ingest_source_report(_build_report())
nid = store.ingest_news_item(_build_news(published_date="2026-06-30T10:00:00Z"))
Expand All @@ -424,6 +426,22 @@ def test_active_ignores_summarized_news(self, tmp_path: Path) -> None:
store.append_timeline_with_provenance(
_build_log(incident_id=inc), {nid}
)
active = store.active_incidents(WINDOW)
assert len(active) == 1
assert active[0].incident_id == inc

def test_active_drops_incident_when_summarized_news_outside_window(
self, tmp_path: Path
) -> None:
store = ContentStore(tmp_path, clock=_clock)
rid = store.ingest_source_report(_build_report())
nid = store.ingest_news_item(_build_news(published_date="2025-01-01T00:00:00Z"))
inc = _new_incident_id()
store.add_report_incident(rid, inc)
store.assign_news_to_incident(nid, inc)
store.append_timeline_with_provenance(
_build_log(incident_id=inc), {nid}
)
assert store.active_incidents(WINDOW) == []


Expand Down
8 changes: 7 additions & 1 deletion tests/integration/content_store_test.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ class TestReadIncidents:
class TestActiveIncidents:
def test_active_fires_on_pending_news_in_window(self, tmp_path) -> None: ...
def test_active_ignores_old_pending_news(self, tmp_path) -> None: ...
def test_active_ignores_summarized_news(self, tmp_path) -> None: ...
def test_active_keeps_incident_with_recent_summarized_news(
self, tmp_path
) -> None: ...

def test_active_drops_incident_when_summarized_news_outside_window(
self, tmp_path
) -> None: ...

class TestMergeIncidents:
def test_merge_moves_reports(self, tmp_path) -> None: ...
Expand Down
Loading