sched: entry-level history cursor so tied occurrence entries paginate exactly once (B4)

This commit is contained in:
lda
2026-09-09 17:08:27 +07:00 Verified
parent c1c9500e1b
commit b3302eb197
5 changed files with 298 additions and 23 deletions
@@ -265,6 +265,58 @@ async def test_rpc_schedule_occurrences_pagination_and_pending(tmp_path) -> None
assert all(row["kind"] != "pending" for row in plain["occurrences"])
async def test_rpc_schedule_occurrences_tied_entries_traverse_once(tmp_path) -> None:
"""Tied admission/stopped entries each arrive exactly once over RPC (B4)."""
server = await _seed_server(tmp_path)
client, http_client = _client_for(server)
store = FileScheduleStore(tmp_path / "store")
base = datetime(2026, 9, 8, 12, 0, tzinfo=UTC)
async with http_client:
await client.create_schedule(
schedule_id="s",
deployment_id="dep.personal",
trigger=_cron(),
)
recorder = FileScheduleHistoryRecorder(store)
recorder.record(
HistoryEntry(
schedule_id="s",
kind="admitted",
resolved_at=base,
run_id="run-1",
revision=1,
reason="rev=1",
created_at=base,
)
)
recorder.record(
HistoryEntry(
schedule_id="s",
kind="interrupted",
resolved_at=base,
run_id="run-1",
revision=1,
reason="fresh-result",
checkpoint_id="run-1.000001",
created_at=base + timedelta(minutes=5),
)
)
seen: list[tuple[str, object]] = []
cursor: object = None
while True:
page = await client.list_schedule_occurrences(
schedule_id="s", cursor=cursor, limit=1 # type: ignore[arg-type]
)
assert page["total"] == 2
for row in page["occurrences"]:
seen.append((row["kind"], row["checkpoint_id"]))
cursor = page["next_cursor"]
if cursor is None:
break
assert seen == [("admitted", None), ("interrupted", "run-1.000001")]
async def test_rpc_schedule_error_mapping(tmp_path) -> None:
server = await _seed_server(tmp_path)
client, http_client = _client_for(server)