Skip to content

feat: add getTaskDocuments method for Meilisearch v1.13#956

Closed
ashishvwl wants to merge 6 commits intomeilisearch:mainfrom
ashishvwl:main
Closed

feat: add getTaskDocuments method for Meilisearch v1.13#956
ashishvwl wants to merge 6 commits intomeilisearch:mainfrom
ashishvwl:main

Conversation

@ashishvwl
Copy link
Copy Markdown

@ashishvwl ashishvwl commented Mar 28, 2026

Pull Request

Related issue

Fixes #948

PR check List:

@Strift can you review this PR

Summary by CodeRabbit

  • New Features

    • Added ability to retrieve documents associated with a specific task, returning NDJSON for inspection.
  • Documentation

    • Added a code sample demonstrating how to retrieve task-related documents.
  • Tests

    • Added an integration test covering end-to-end document retrieval for a task.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new SDK method to fetch NDJSON documents for a specific async task: public Client.getTaskDocuments(int). Implementation delegates to TasksHandler which issues GET /tasks/{taskUid}/documents. Includes an integration test and a documentation code sample.

Changes

Cohort / File(s) Summary
Documentation Example
​.code-samples.meilisearch.yaml
Added get_task_documents_1 example calling client.getTaskDocuments(1);.
API Implementation
src/main/java/com/meilisearch/sdk/Client.java, src/main/java/com/meilisearch/sdk/TasksHandler.java
Added Client.getTaskDocuments(int) delegating to TasksHandler.getTaskDocuments(int); TasksHandler builds /tasks/{taskUid}/documents and performs HTTP GET returning NDJSON String. Minor Javadoc/whitespace tidy.
Integration Testing
src/test/java/com/meilisearch/integration/ClientTest.java
Added testGetTaskDocuments() which adds a document, waits for the add task, calls client.getTaskDocuments(taskUid), and asserts the NDJSON response contains the inserted document fields.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client\nrgba(52,152,219,0.5)
    participant Handler as TasksHandler\nrgba(46,204,113,0.5)
    participant Server as Meilisearch API\nrgba(231,76,60,0.5)

    Client->>Handler: getTaskDocuments(taskUid)
    Handler->>Server: GET /tasks/{taskUid}/documents
    Server-->>Handler: 200 OK (NDJSON body)
    Handler-->>Client: return NDJSON String
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped to fetch a task's tale,
NDJSON trails along the trail,
A client call, a handler's quest,
Documents returned — hop, we're blessed! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add getTaskDocuments method for Meilisearch v1.13' directly matches the main change: adding a new getTaskDocuments method for the Meilisearch v1.13 API.
Linked Issues check ✅ Passed All coding requirements from issue #948 are met: getTaskDocuments method added to Client and TasksHandler, integration test added, and code sample documentation added.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the issue requirements: new method implementation, integration test, and documentation example. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 94.74% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/test/java/com/meilisearch/integration/TasksTest.java (2)

417-419: Several tests are assertion-light and can miss wrong payloads.

The current checks (non-null/non-blank only) can still pass if the endpoint returns unexpected content. Please assert task-specific evidence (expected IDs/fields or expected empty result).

Example improvements for stronger assertions
@@
-        // Create index task should not have documents
-        assertThat(taskDocuments, is(notNullValue()));
+        // Create-index task should not have task documents
+        List<String> lines =
+                Arrays.stream(taskDocuments.split("\\R"))
+                        .filter(line -> !line.trim().isEmpty())
+                        .collect(Collectors.toList());
+        assertThat(lines.size(), is(equalTo(0)));
@@
-        assertThat(taskDocuments, is(notNullValue()));
-        assertThat(taskDocuments, not(blankOrNullString()));
+        assertThat(taskDocuments, is(notNullValue()));
+        assertThat(taskDocuments, not(blankOrNullString()));
+        assertThat(taskDocuments, containsString("\"id\": 1"));
+        assertThat(taskDocuments, containsString("\"id\": 2"));
+        assertThat(taskDocuments, containsString("\"id\": 3"));

Also applies to: 438-440, 455-457, 507-509, 537-539

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/meilisearch/integration/TasksTest.java` around lines 417 -
419, The tests in TasksTest use weak assertions like assertThat(taskDocuments,
is(notNullValue())) which can miss incorrect payloads; update the checks (e.g.,
in the blocks handling taskDocuments and similar variables) to assert
task-specific evidence such as expected task IDs, status fields, or that the
documents list is empty when appropriate (for example assert expected id equals
the created task id, assert status equals "succeeded"/"enqueued"/"failed" as
applicable, or assert that documents.size() == 0) so each test validates
concrete fields/values rather than just non-nullity; apply the same stronger
assertions to the other mentioned locations (around the checks at 438-440,
455-457, 507-509, 537-539).

395-405: NDJSON contract check is too permissive.

At Line 402 and Line 403, checking only for { and } can pass non-NDJSON payloads. Please assert non-empty line count and per-line object shape more strictly.

Proposed tightening for NDJSON assertions
-        // NDJSON format has each object on a separate line
-        String[] lines = taskDocuments.split("\n");
-        assertThat(lines.length, is(greaterThanOrEqualTo(1)));
-        
-        // Each line should be a valid JSON object
-        for (String line : lines) {
-            if (!line.trim().isEmpty()) {
-                assertThat(line, containsString("{"));
-                assertThat(line, containsString("}"));
-            }
-        }
+        // NDJSON format has one JSON object per non-empty line
+        List<String> lines =
+                Arrays.stream(taskDocuments.split("\\R"))
+                        .filter(line -> !line.trim().isEmpty())
+                        .collect(Collectors.toList());
+        assertThat(lines.size(), is(equalTo(2)));
+
+        for (String line : lines) {
+            String trimmed = line.trim();
+            assertTrue(trimmed.startsWith("{") && trimmed.endsWith("}"));
+            assertThat(trimmed, containsString("\"id\""));
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/meilisearch/integration/TasksTest.java` around lines 395 -
405, The current NDJSON check in TasksTest uses loose string checks on
taskDocuments lines; instead parse and validate each non-blank line as JSON and
assert it's an object. Update the loop that iterates over String[] lines (from
taskDocuments) to trim and skip empty lines, then use your JSON parser (e.g.,
Jackson's ObjectMapper.readTree) to parse each line and assert the resulting
JsonNode.isObject() (and optionally check for expected keys like "taskUid" or
"indexUid"); also ensure the top-level lines.length assertion verifies at least
one non-empty line. This replaces the containsString("{")/("}") checks with
strict JSON-object validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/test/java/com/meilisearch/integration/TasksTest.java`:
- Line 515: Replace the hardcoded 999999 with a deterministic impossible UID
constant to avoid flakiness: add a private static final long INVALID_TASK_UID =
Long.MAX_VALUE (or similarly impossible value) in TasksTest and change the
assertion to assertThrows(MeilisearchException.class, () ->
client.getTaskDocuments(INVALID_TASK_UID)); this keeps the failing UID stable
across environments and clearly identifies the intent in the test.

---

Nitpick comments:
In `@src/test/java/com/meilisearch/integration/TasksTest.java`:
- Around line 417-419: The tests in TasksTest use weak assertions like
assertThat(taskDocuments, is(notNullValue())) which can miss incorrect payloads;
update the checks (e.g., in the blocks handling taskDocuments and similar
variables) to assert task-specific evidence such as expected task IDs, status
fields, or that the documents list is empty when appropriate (for example assert
expected id equals the created task id, assert status equals
"succeeded"/"enqueued"/"failed" as applicable, or assert that documents.size()
== 0) so each test validates concrete fields/values rather than just
non-nullity; apply the same stronger assertions to the other mentioned locations
(around the checks at 438-440, 455-457, 507-509, 537-539).
- Around line 395-405: The current NDJSON check in TasksTest uses loose string
checks on taskDocuments lines; instead parse and validate each non-blank line as
JSON and assert it's an object. Update the loop that iterates over String[]
lines (from taskDocuments) to trim and skip empty lines, then use your JSON
parser (e.g., Jackson's ObjectMapper.readTree) to parse each line and assert the
resulting JsonNode.isObject() (and optionally check for expected keys like
"taskUid" or "indexUid"); also ensure the top-level lines.length assertion
verifies at least one non-empty line. This replaces the
containsString("{")/("}") checks with strict JSON-object validation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f88d4aa7-ec60-4ad3-9ce0-02ee531f5d6c

📥 Commits

Reviewing files that changed from the base of the PR and between d830b9a and 7520482.

📒 Files selected for processing (1)
  • src/test/java/com/meilisearch/integration/TasksTest.java

@Strift Strift added the enhancement New feature or request label Mar 30, 2026
Copy link
Copy Markdown
Contributor

@Strift Strift left a comment

Choose a reason for hiding this comment

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

Hi @ashishvwl, and thanks for your contribution!

Can you fix the failing CI? I recommend running tests and linter locally before submitting for review.

@ashishvwl
Copy link
Copy Markdown
Author

Hi @ashishvwl, and thanks for your contribution!

Can you fix the failing CI? I recommend running tests and linter locally before submitting for review.

how to run this integration local ? can you help

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/test/java/com/meilisearch/integration/ClientTest.java (1)

396-397: Strengthen assertions to validate actual NDJSON payload content.

On Line 396 and Line 397, checking only notNullValue and containsString("\"id\"") is permissive and can hide regressions. Parse the first NDJSON line and assert expected fields (id, title) explicitly.

Proposed test hardening
         String taskDocuments = client.getTaskDocuments(addTask.getTaskUid());

         assertThat(taskDocuments, is(notNullValue()));
-        assertThat(taskDocuments, containsString("\"id\""));
+        String[] ndjsonLines = taskDocuments.strip().split("\\R");
+        assertThat(ndjsonLines, is(arrayWithSize(1)));
+
+        JsonObject firstDoc = JsonParser.parseString(ndjsonLines[0]).getAsJsonObject();
+        assertThat(firstDoc.get("id").getAsInt(), is(equalTo(1)));
+        assertThat(firstDoc.get("title").getAsString(), is(equalTo("Document1")));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/com/meilisearch/integration/ClientTest.java` around lines 396 -
397, The assertions on taskDocuments in ClientTest are too weak; parse the first
NDJSON line from the taskDocuments string, deserialize it (e.g., into a Map or a
POJO) and assert the presence and expected values of the fields "id" and "title"
instead of only checking containsString and notNullValue. Locate the test block
around the taskDocuments variable in ClientTest, split the NDJSON by newline,
parse the first line, and replace the containsString assertion with explicit
assertions that the parsed object contains keys "id" and "title" and that their
values match the expected types/values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/test/java/com/meilisearch/integration/ClientTest.java`:
- Around line 396-397: The assertions on taskDocuments in ClientTest are too
weak; parse the first NDJSON line from the taskDocuments string, deserialize it
(e.g., into a Map or a POJO) and assert the presence and expected values of the
fields "id" and "title" instead of only checking containsString and
notNullValue. Locate the test block around the taskDocuments variable in
ClientTest, split the NDJSON by newline, parse the first line, and replace the
containsString assertion with explicit assertions that the parsed object
contains keys "id" and "title" and that their values match the expected
types/values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 95ee1e8d-0a1c-41cc-b9da-2cc8b25f677e

📥 Commits

Reviewing files that changed from the base of the PR and between ebc3439 and a1664fe.

📒 Files selected for processing (1)
  • src/test/java/com/meilisearch/integration/ClientTest.java

@Strift
Copy link
Copy Markdown
Contributor

Strift commented Mar 30, 2026

Please refer to the contributing guide

@ashishvwl ashishvwl closed this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Meilisearch v1.13.0] Add method to get tasks documents

2 participants