Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(rag): cover pagination offsets and envelope (#7601) (#7643)

Chanhyo Jung4a883677d59b
diff --git a/tests/web/test_pagination_clamping_census.py b/tests/web/test_pagination_clamping_census.py
index 3ab737ee07..d80bf93194 100644
--- a/tests/web/test_pagination_clamping_census.py
+++ b/tests/web/test_pagination_clamping_census.py
@@ -51,6 +51,13 @@ from local_deep_research.database.models import (
ChatSession,
ChatSessionStatus,
)
+from local_deep_research.database.models.library import (
+ Collection,
+ Document,
+ DocumentCollection,
+ SourceType,
+)
+from local_deep_research.database.session_context import get_user_db_session
from local_deep_research.research_library.services.library_service import (
LibraryService,
)
@@ -517,38 +524,86 @@ def sql_probe(monkeypatch):
class TestSqlLevelLimitCensus:
+ @pytest.fixture
+ def rag_collection(self, client):
+ """Eleven real rows exercise partial pages as well as exact divisors."""
+ username = client.get("/auth/check").json()["username"]
+ collection_id = str(uuid.uuid4())
+ source_type_id = str(uuid.uuid4())
+ with get_user_db_session(username) as db:
+ db.add(Collection(id=collection_id, name="Pagination census"))
+ db.add(
+ SourceType(
+ id=source_type_id,
+ name="pagination_census",
+ display_name="Pagination census",
+ )
+ )
+ db.flush()
+ for i in range(11):
+ document_id = str(uuid.uuid4())
+ db.add(
+ Document(
+ id=document_id,
+ source_type_id=source_type_id,
+ document_hash=f"{i:064x}",
+ title=f"Document {i}",
+ file_size=0,
+ file_type="txt",
+ )
+ )
+ db.flush()
+ db.add(
+ DocumentCollection(
+ document_id=document_id,
+ collection_id=collection_id,
+ )
+ )
+ db.commit()
+ return collection_id
+
+ @pytest.mark.parametrize("page", [2, 3])
@pytest.mark.parametrize(
- ("raw_per_page", "expected"),
+ ("raw_per_page", "expected", "expected_pages"),
[
- ("1", 1),
- ("2", 2),
- ("9", 9),
- ("10", 10),
- ("100", 100),
- ("101", 100),
- (str(OVER_INT64), 100),
- ("0", 1),
- ("-5", 1),
- ("abc", 50),
- ("", 50),
- (None, 50),
+ ("1", 1, 11),
+ ("2", 2, 6),
+ ("9", 9, 2),
+ ("10", 10, 2),
+ ("100", 100, 1),
+ ("101", 100, 1),
+ (str(OVER_INT64), 100, 1),
+ ("0", 1, 11),
+ ("-5", 1, 11),
+ ("abc", 50, 1),
+ ("", 50, 1),
+ (None, 50, 1),
],
)
def test_rag_page_size_controls_sql_limit_and_offset(
- self, client, sql_probe, raw_per_page, expected
+ self,
+ client,
+ rag_collection,
+ sql_probe,
+ raw_per_page,
+ expected,
+ expected_pages,
+ page,
):
- params = {"page": "2"}
+ params = {"page": str(page), "collection_id": rag_collection}
if raw_per_page is not None:
params["per_page"] = raw_per_page
response = client.get("/library/api/rag/documents", params=params)
assert response.status_code == 200, response.text
pagination = response.json()["pagination"]
- assert pagination["page"] == 2
+ assert pagination["page"] == page
assert pagination["per_page"] == expected
+ assert pagination["total"] == 11
+ assert pagination["pages"] == expected_pages
assert sql_probe["limit"], "The documents query must reach SQL"
assert max(sql_probe["limit"]) == expected
- assert expected in sql_probe["offset"], sql_probe
+ assert sql_probe["offset"] == [(page - 1) * expected], sql_probe
def test_probe_observes_a_known_limit(self, client, sql_probe):
"""Negative control for ``sql_probe``.