-
Notifications
You must be signed in to change notification settings - Fork 55
fix(loaders): accumulate all pages in CustomDocLoader (#376) #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
EnjoyBacon7
merged 5 commits into
refactor/hexagonal
from
fix/376-customdocloader-page-accumulation
May 21, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c934b22
fix(loaders): accumulate all pages in CustomDocLoader
EnjoyBacon7 b9608c1
ci: re-trigger api-tests (previous run hit infra timeout)
EnjoyBacon7 b6a24b5
test(loaders): regression test for CustomDocLoader page accumulation
EnjoyBacon7 4d40e96
test(loaders): use the project's absolute import convention
EnjoyBacon7 186fbcc
test(loaders): assert middle [PAGE_2] marker in page accumulation test
EnjoyBacon7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
openrag/components/indexer/loaders/test_customdocloader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """Regression test for CustomDocLoader page accumulation (#376). | ||
|
|
||
| The previous loop body used ``s = ...`` instead of ``s += ...``, so only | ||
| the final page survived. This test confirms every page's content is now | ||
| in the returned ``Document``. | ||
| """ | ||
|
|
||
| from unittest.mock import AsyncMock, MagicMock, patch | ||
|
|
||
| import pytest | ||
| from langchain_core.documents.base import Document as LCDocument | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_customdocloader_accumulates_all_pages(tmp_path): | ||
| from components.indexer.loaders.CustomDocLoader import CustomDocLoader | ||
|
|
||
| fake_pages = [ | ||
| LCDocument(page_content="page-one"), | ||
| LCDocument(page_content="page-two"), | ||
| LCDocument(page_content="page-three"), | ||
| ] | ||
| fake_loader_instance = MagicMock() | ||
| fake_loader_instance.aload = AsyncMock(return_value=fake_pages) | ||
| fake_loader_cls = MagicMock(return_value=fake_loader_instance) | ||
|
|
||
| file_path = tmp_path / "stub.docx" | ||
| file_path.write_text("ignored") | ||
|
|
||
| with patch.dict(CustomDocLoader.doc_loaders, {".docx": fake_loader_cls}, clear=True): | ||
| # BaseLoader.__init__ pulls a config; we bypass it with object.__new__ | ||
| loader = object.__new__(CustomDocLoader) | ||
| result = await loader.aload_document(str(file_path), metadata={"src": "x"}) | ||
|
|
||
| assert "page-one" in result.page_content | ||
| assert "page-two" in result.page_content | ||
| assert "page-three" in result.page_content | ||
| assert "[PAGE_1]" in result.page_content | ||
| assert "[PAGE_2]" in result.page_content | ||
| assert "[PAGE_3]" in result.page_content | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.