fix: preserve pending occurrence pagination bounds

This commit is contained in:
lda
2026-09-09 21:23:27 +07:00 Verified
parent d8a6795193
commit 384f610301
3 changed files with 104 additions and 9 deletions
+59
View File
@@ -787,6 +787,65 @@ async def test_occurrences_pending_synthesis_first_page_only(tmp_path: Path) ->
assert all(row["kind"] != "pending" for row in plain["occurrences"])
async def test_occurrences_pending_limit_one_traverses_every_row(
tmp_path: Path,
) -> None:
"""A synthesized pending row must not make the first stored row unreachable."""
api, sched_store, _, _, _ = _harness(tmp_path / "pending_limit_one")
await api.create_schedule(
schedule_id="s", deployment_id="dep.personal", trigger=_cron()
)
base = ts(2026, 9, 8, 12, 0)
recorder = FileScheduleHistoryRecorder(sched_store)
for index in range(3):
instant = base + timedelta(minutes=index)
recorder.record(
HistoryEntry(
schedule_id="s",
kind="admitted",
resolved_at=instant,
run_id=f"run-{index}",
revision=1,
reason="rev=1",
created_at=instant,
)
)
sched_store.save_candidate(
PendingCandidate(
schedule_id="s",
intended_at=base + timedelta(hours=1),
revision=1,
),
schedule_id="s",
)
rows: list[dict[str, Any]] = []
cursor: str | None = None
for _ in range(5):
page = await api.list_schedule_occurrences(
schedule_id="s", cursor=cursor, limit=1
)
assert len(page["occurrences"]) <= 1
rows.extend(page["occurrences"])
cursor = page["next_cursor"]
if cursor is None:
break
else:
pytest.fail("occurrence pagination did not terminate")
assert [row["kind"] for row in rows] == [
"pending",
"admitted",
"admitted",
"admitted",
]
assert [row["run_id"] for row in rows[1:]] == [
"run-0",
"run-1",
"run-2",
]
async def test_occurrences_pagination_visits_tied_entries_once(tmp_path: Path) -> None:
"""One occurrence's admission + stops each appear exactly once (B4).