From 2c111bff297db27374639aa8c58a1cc3554b90c6 Mon Sep 17 00:00:00 2001 From: VANSH BAJPAI Date: Mon, 23 Nov 2026 22:51:54 +0530 Subject: [PATCH 1/2] Validate review pagination before yielding page records --- proofline/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proofline/client.py b/proofline/client.py index 1d8c1519..f98e0490 100644 --- a/proofline/client.py +++ b/proofline/client.py @@ -528,12 +528,12 @@ def iter_reviews( count = 0 for _ in range(max_pages): page = self.list_reviews(organization_id, **params) + cursor = _next_cursor(page, seen) for item in page.items: if count == max_items: raise _pagination_limit() yield item count += 1 - cursor = _next_cursor(page, seen) if cursor is None: return params["cursor"] = cursor @@ -923,12 +923,12 @@ async def iter_reviews( count = 0 for _ in range(max_pages): page = await self.list_reviews(organization_id, **params) + cursor = _next_cursor(page, seen) for item in page.items: if count == max_items: raise _pagination_limit() yield item count += 1 - cursor = _next_cursor(page, seen) if cursor is None: return params["cursor"] = cursor From b4a035c28582ff40c58d8b8f0512440c3034d1ca Mon Sep 17 00:00:00 2001 From: VANSH BAJPAI Date: Mon, 23 Nov 2026 22:52:37 +0530 Subject: [PATCH 2/2] Test review page validation before yielding --- tests/test_review_page_validation.py | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/test_review_page_validation.py diff --git a/tests/test_review_page_validation.py b/tests/test_review_page_validation.py new file mode 100644 index 00000000..5e0869cb --- /dev/null +++ b/tests/test_review_page_validation.py @@ -0,0 +1,57 @@ +from __future__ import annotations + +from typing import Any + +import pytest + +from proofline import ProoflineError + +from .fixtures import ORG +from .http_server import Reply, Server +from .test_http import MODES, page, session + + +async def next_review(client: Any) -> Any: + iterator = client.iter_reviews(ORG) + if hasattr(iterator, "__aiter__"): + return await anext(iterator) + return next(iterator) + + +@MODES +@pytest.mark.parametrize( + "cursor,truncated,error_type", + [ + (None, True, "invalid-pagination"), + ("", True, "invalid-pagination"), + ("unexpected", False, "invalid-response"), + ], +) +async def test_invalid_first_page_is_rejected_before_yield( + mode: str, cursor: str | None, truncated: bool, error_type: str +) -> None: + with Server( + lambda request, index: Reply(body=page(cursor=cursor, truncated=truncated)) + ) as server: + async with session(mode, server.url) as client: + with pytest.raises(ProoflineError) as caught: + await next_review(client) + assert caught.value.type == f"urn:proofline:sdk:{error_type}" + assert len(server.requests) == 1 + + +@MODES +async def test_repeated_cursor_page_is_rejected_before_yield(mode: str) -> None: + with Server(lambda request, index: Reply(body=page(cursor="same", truncated=True))) as server: + async with session(mode, server.url) as client: + iterator = client.iter_reviews(ORG) + if mode == "sync": + next(iterator) + with pytest.raises(ProoflineError) as caught: + next(iterator) + else: + await anext(iterator) + with pytest.raises(ProoflineError) as caught: + await anext(iterator) + assert caught.value.type == "urn:proofline:sdk:invalid-pagination" + assert len(server.requests) == 2