Skip to content

Add unit test for InputStream layout processing#8

Merged
sparkeh9 merged 1 commit into
mainfrom
test/stream-layout-parsing
Mar 23, 2026
Merged

Add unit test for InputStream layout processing#8
sparkeh9 merged 1 commit into
mainfrom
test/stream-layout-parsing

Conversation

@sparkeh9
Copy link
Copy Markdown
Owner

This PR adds a test verifying that DoclingPdfConversionRunner properly uses LoadDocumentFromBytes when an InputStream is provided, preventing regressions on the logic introduced in PR #7.

Copilot AI review requested due to automatic review settings March 23, 2026 08:47
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new unit test to validate the behavior of DoclingPdfConversionRunner when processing PDF documents from an InputStream. The test specifically ensures that the LoadDocumentFromBytes method is invoked with the correct byte array, thereby preventing regressions related to InputStream handling and maintaining the integrity of document loading from memory.

Highlights

  • New Unit Test: Added a new unit test ExecuteAsync_WhenInputStreamProvided_UsesLoadDocumentFromBytesAndSucceeds to DoclingPdfConversionRunnerSemanticsTests.cs.
  • InputStream Processing Verification: The new test verifies that DoclingPdfConversionRunner correctly utilizes LoadDocumentFromBytes when an InputStream is provided, ensuring proper handling of byte array inputs.
  • Test Infrastructure Update: Modified the FakeParseSession class to track calls to LoadDocumentFromBytes and store the last loaded byte array, enabling robust assertions in the new test case.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a regression unit test to ensure DoclingPdfConversionRunner loads PDFs from an InputStream via LoadDocumentFromBytes, protecting the stream-based execution path introduced in PR #7.

Changes:

  • Add a new semantics test covering PdfConversionRequest.InputStream usage and verifying LoadDocumentFromBytes is called with the expected bytes.
  • Extend the FakeParseSession test double to record LoadDocumentFromBytes invocations and the last provided byte payload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a2c63dd67

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +793 to +797
var result = await runner.ExecuteAsync(new PdfConversionRequest
{
InputStream = memoryStream,
RunId = "run-stream",
Timeout = TimeSpan.FromSeconds(2)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exercise the layout stage in this InputStream regression test

For stream-backed requests with layout inference enabled, this test will not catch the regression it claims to cover because the request never sets EnableLayoutInference. DoclingPdfConversionRunner.ExecuteAsync only builds the LayoutProcessRequest in the apply_layout_inference stage (dotnet/src/DoclingDotNet/Pipeline/DoclingPdfConversionRunner.cs:660-679), so a future break where layout providers stop receiving PdfBytes for InputStream inputs would still pass this test unchanged.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new unit test to verify the correct processing of InputStream by DoclingPdfConversionRunner. The test ensures that when an InputStream is provided, the LoadDocumentFromBytes method is called and the byte content is correctly passed to the parsing session. The FakeParseSession was updated to track these calls and the last loaded bytes, enabling proper assertion in the test. This is a valuable addition to prevent regressions related to InputStream handling.


Assert.Equal(PipelineRunStatus.Succeeded, result.Pipeline.Status);
Assert.Equal(1, fake.LoadDocumentFromBytesCalls);
Assert.Equal(expectedBytes, fake.LastLoadedBytes);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The assertion Assert.Equal(expectedBytes, fake.LastLoadedBytes); for byte arrays in C# checks for reference equality by default. To verify that the content of the byte arrays is identical, you should use SequenceEqual.

        Assert.True(expectedBytes.SequenceEqual(fake.LastLoadedBytes!));

@sparkeh9 sparkeh9 merged commit fdf5434 into main Mar 23, 2026
10 checks passed
@sparkeh9 sparkeh9 deleted the test/stream-layout-parsing branch March 23, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants