From 91188b553e96f19b17a54f7e267cd100111800cb Mon Sep 17 00:00:00 2001 From: Hadrien Blanc Date: Tue, 1 Dec 2026 10:39:04 +0100 Subject: [PATCH] Honor the limit filter in iter_reviews A ReviewFilters limit sets the page size when page_size is not passed, an agreeing pair is accepted, and a conflicting pair raises ValueError before any request. The honored limit keeps the 1..100 bound, in both the sync and async clients. --- README.md | 13 +++++++++++++ proofline/client.py | 14 ++++++++++++-- tests/test_http.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eaad94e2..6969aad1 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,19 @@ if outcome.status != "COMPLETED": `head_commit_sha` is a full SHA of 40 or 64 hexadecimal characters; any other value raises `ValueError` before a request. A review pinned to another head ends the wait on the read that names it. Its outcome is `INCOMPLETE` whatever the review's own status, its last gap has the reason code `HEAD_COMMIT_MISMATCH`, and `reason` says that the review is pinned to another head commit. A settled review that names no head has `HEAD_COMMIT_UNAVAILABLE` instead and is not `COMPLETED` either. `outcome.review.head_commit_sha` is the commit the review is pinned to. A patch review's head is a derived revision ID, so no commit matches it. In a GitHub Actions `pull_request` job, `GITHUB_SHA` is the merge commit; pass the pull request's head. +## Listing reviews + +`iter_reviews` follows page cursors and yields each review summary. `ReviewFilters` carries the same filters as `list_reviews`; a `limit` filter sets the page size exactly as `page_size` does, bounded from 1 to 100. Pass one of the two, or an agreeing pair; a conflicting pair raises `ValueError` before any request. A `cursor` filter resumes an iteration. Iteration stops only when the server omits the continuation cursor, and exhausting `max_pages` (1 to 1000) or `max_items` (1 to 100000) raises `urn:proofline:sdk:pagination-limit`, so a partial collection cannot silently appear complete. + +```python +with ProoflineClient() as client: + for review in client.iter_reviews( + organization_id, + filters={"status": "COMPLETED", "limit": 50}, + ): + print(review.id, review.status) +``` + ## Review exports `export_reviews` reads one CSV or NDJSON page over the bounded transport. Export tokens require `analytics:read`. diff --git a/proofline/client.py b/proofline/client.py index 1d8c1519..b94a7222 100644 --- a/proofline/client.py +++ b/proofline/client.py @@ -511,11 +511,16 @@ def iter_reviews( self, organization_id: UUID, *, - page_size: int = 100, + page_size: int | None = None, max_pages: int = 100, max_items: int = 10_000, filters: ReviewFilters | None = None, ) -> Iterator[ReviewSummary]: + requested = filters.get("limit") if filters else None + if page_size is None: + page_size = requested if requested is not None else 100 + elif requested is not None and requested != page_size: + raise ValueError("Pass page_size or a limit filter, not both.") _page_limits(page_size, max_pages, max_items) params: ReviewFilters = {} if filters: @@ -906,11 +911,16 @@ async def iter_reviews( self, organization_id: UUID, *, - page_size: int = 100, + page_size: int | None = None, max_pages: int = 100, max_items: int = 10_000, filters: ReviewFilters | None = None, ) -> AsyncIterator[ReviewSummary]: + requested = filters.get("limit") if filters else None + if page_size is None: + page_size = requested if requested is not None else 100 + elif requested is not None and requested != page_size: + raise ValueError("Pass page_size or a limit filter, not both.") _page_limits(page_size, max_pages, max_items) params: ReviewFilters = {} if filters: diff --git a/tests/test_http.py b/tests/test_http.py index c63899bf..8ded7409 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -1770,6 +1770,52 @@ def respond(request: Request, index: int) -> Reply: assert raised.value.type == "urn:proofline:sdk:pagination-limit" +@MODES +async def test_reviews_iterator_honors_the_limit_filter(mode: str) -> None: + def respond(request: Request, index: int) -> Reply: + query = parse_qs(urlsplit(request.path).query) + assert query["limit"] == ["2"] + return Reply(body=page()) + + with Server(respond) as server: + async with session(mode, server.url) as client: + items = await collect(client, filters={"limit": 2}) + assert [item.id for item in items] == [REVIEW] + assert len(server.requests) == 1 + + +@MODES +async def test_reviews_iterator_accepts_agreeing_page_size_and_limit_filter(mode: str) -> None: + def respond(request: Request, index: int) -> Reply: + query = parse_qs(urlsplit(request.path).query) + assert query["limit"] == ["2"] + return Reply(body=page()) + + with Server(respond) as server: + async with session(mode, server.url) as client: + items = await collect(client, page_size=2, filters={"limit": 2}) + assert [item.id for item in items] == [REVIEW] + assert len(server.requests) == 1 + + +@MODES +async def test_reviews_iterator_refuses_conflicting_page_size_and_limit_filter(mode: str) -> None: + with Server(lambda request, index: Reply(body=page())) as server: + async with session(mode, server.url) as client: + with pytest.raises(ValueError, match="not both"): + await collect(client, page_size=3, filters={"limit": 2}) + assert not server.requests + + +@MODES +async def test_reviews_iterator_bounds_the_honored_limit_filter(mode: str) -> None: + with Server(lambda request, index: Reply(body=page())) as server: + async with session(mode, server.url) as client: + with pytest.raises(ValueError, match="Pagination requires"): + await collect(client, filters={"limit": 101}) + assert not server.requests + + def test_token_environment_and_https_origin_rejection(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("PROOFLINE_TOKEN", TOKEN) with ProoflineClient() as client: