Skip to content

✨ allow opening a LocalResponse from bytes - #352

Merged
ianardee merged 1 commit into
mainfrom
better-local-response
Sep 4, 2026
Merged

✨ allow opening a LocalResponse from bytes#352
ianardee merged 1 commit into
mainfrom
better-local-response

Conversation

@ianardee

@ianardee ianardee commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Add bytes[] constructor
  • rework and improve tests

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Requires a change to the official Guide documentation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The updated BaseLocalResponse file/path constructors can now throw UncheckedIOException despite declaring throws IOException, and the new HMAC normalization should avoid locale-dependent case-mapping while also documenting stream-closing behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR expands LocalResponse to be constructible from raw byte[] payloads (in both v1 and v2), refactors local-response payload loading/normalization in BaseLocalResponse, and updates the test suite/resource helpers accordingly. It also updates HMAC signature verification to use a constant-time comparison primitive.

Changes:

  • Add LocalResponse(byte[]) constructors for both v1 and v2 parsing.
  • Rework BaseLocalResponse payload ingestion to normalize JSON (remove line endings) across input types and update HMAC verification.
  • Rework tests to use a new getV2ProductPath(...) helper and add broader LocalResponse constructor coverage.
File summaries
File Description
src/test/java/com/mindee/v2/product/SplitTest.java Switches v2 product test fixtures to getV2ProductPath and simplifies fixture-relative paths.
src/test/java/com/mindee/v2/product/OcrTest.java Updates OCR product tests to use getV2ProductPath and new fixture paths.
src/test/java/com/mindee/v2/product/ExtractionTest.java Updates extraction product tests to use getV2ProductPath and new fixture paths.
src/test/java/com/mindee/v2/product/CropTest.java Updates crop product tests to use getV2ProductPath and new fixture paths.
src/test/java/com/mindee/v2/product/CropIT.java Updates integration test inputs to use getV2ProductPath.
src/test/java/com/mindee/v2/product/ClassificationTest.java Updates classification product tests to use getV2ProductPath and new fixture paths.
src/test/java/com/mindee/v2/parsing/LocalResponseTest.java Adds constructor coverage (String/byte[]/Path/stream), HMAC checks, and null/empty validation tests.
src/test/java/com/mindee/v2/MindeeClientTest.java Renames test methods (removes _async suffix).
src/test/java/com/mindee/v2/MindeeClientIT.java Updates v2 integration tests to use getV2ProductPath for fixtures and schema params.
src/test/java/com/mindee/v2/fileoperations/SplitTest.java Updates file-operation tests to use getV2ProductPath and new fixture paths.
src/test/java/com/mindee/v2/fileoperations/CropTest.java Updates file-operation tests to use getV2ProductPath and new fixture paths.
src/test/java/com/mindee/TestingUtilities.java Introduces getV2ProductPath helper and reorders resource-path helpers.
src/main/java/com/mindee/v2/parsing/LocalResponse.java Adds LocalResponse(byte[]) constructor (v2).
src/main/java/com/mindee/v1/parsing/LocalResponse.java Adds LocalResponse(byte[]) constructor (v1).
src/main/java/com/mindee/parsing/BaseLocalResponse.java Refactors payload ingestion, adds input validation, adds constant-time signature compare, and overrides toString().
Review details

Suppressed comments (1)

src/main/java/com/mindee/parsing/BaseLocalResponse.java:91

  • BaseLocalResponse(Path) declares throws IOException, but readToCleanUtf8Bytes(...) wraps read failures in UncheckedIOException, so callers catching IOException may miss real I/O errors. Consider unwrapping UncheckedIOException here and rethrowing its IOException cause to match the method signature.
  public BaseLocalResponse(Path input) throws IOException {
    if (input == null) {
      throw new IllegalArgumentException("Input path cannot be null.");
    }
    this.file = readToCleanUtf8Bytes(Files.newBufferedReader(input, StandardCharsets.UTF_8));
  • Files reviewed: 15/15 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/main/java/com/mindee/parsing/BaseLocalResponse.java Outdated
Comment thread src/main/java/com/mindee/parsing/BaseLocalResponse.java Outdated
Comment thread src/main/java/com/mindee/parsing/BaseLocalResponse.java
@ianardee
ianardee force-pushed the better-local-response branch from 83f8fcc to 60f14c1 Compare September 4, 2026 16:39
Copilot stopped work on behalf of ianardee due to an error September 4, 2026 16:42
@ianardee
ianardee force-pushed the better-local-response branch 6 times, most recently from 9a91d0c to d267daa Compare September 4, 2026 19:07
@ianardee
ianardee requested a lite review from Copilot September 4, 2026 19:10

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Only a minor Javadoc wording issue was found; the functional changes are straightforward and are backed by expanded constructor-path test coverage.

Review details

Suppressed comments (1)

src/main/java/com/mindee/parsing/BaseLocalResponse.java:32

  • The Javadoc for the String constructor says "Assumes UTF-8 encoding", but a Java String has no encoding; what matters is that it is encoded to UTF-8 bytes internally (and line separators are normalized away via lines()+joining). This wording is misleading for API consumers.
  /**
   * Load from a {@link String}.
   *
   * @param input Assumes UTF-8 encoding.
   */
  • Files reviewed: 15/15 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@ianardee
ianardee merged commit 8dbc280 into main Sep 4, 2026
15 checks passed
@ianardee
ianardee deleted the better-local-response branch September 4, 2026 19:48
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.

3 participants