| 1 | """Watchlist status remains accurate for multiple runs in one second.""" |
| 2 | |
| 3 | import store |
| 4 | |
| 5 | |
| 6 | def test_watchlist_reports_latest_status_when_timestamps_tie(tmp_path): |
| 7 | with store.scoped_db(tmp_path / "research.db"): |
| 8 | topic = store.add_topic("Rerunnable topic") |
| 9 | first = store.record_run(topic["id"], status="failed") |
| 10 | latest = store.record_run(topic["id"], status="completed") |
| 11 | conn = store._connect() |
| 12 | try: |
| 13 | with conn: |
| 14 | conn.execute( |
| 15 | "UPDATE research_runs SET created_at = ?, run_date = ? WHERE id IN (?, ?)", |
| 16 | ("2026-10-01 08:00:00", "2026-10-01 08:00:00", first, latest), |
| 17 | ) |
| 18 | finally: |
| 19 | conn.close() |
| 20 | |
| 21 | assert store.list_topics()[0]["last_status"] == "completed" |
| 22 |