Skip to content

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

Open
ashishvwl wants to merge 3 commits intomeilisearch:mainfrom
ashishvwl:main
Open

feat: add getTaskDocuments method for Meilisearch v1.13#956
ashishvwl wants to merge 3 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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

Adds a new Client.getTaskDocuments(int) API, a TasksHandler.getTaskDocuments(...) implementation, a documentation code sample entry, and multiple integration tests validating NDJSON task-document retrieval from GET /tasks/{taskUid}/documents.

Changes

Cohort / File(s) Summary
Documentation Sample
\.code-samples.meilisearch.yaml
Added get_task_documents_1 example showing client.getTaskDocuments(1) invocation.
Public API
src/main/java/com/meilisearch/sdk/Client.java
Added public String getTaskDocuments(int uid) throws MeilisearchException that delegates to TasksHandler.
Internal Handler
src/main/java/com/meilisearch/sdk/TasksHandler.java
Added String getTaskDocuments(int taskUid) throws MeilisearchException which builds /tasks/{taskUid}/documents route and returns raw NDJSON response.
Integration Tests
src/test/java/com/meilisearch/integration/TasksTest.java
Added numerous tests for getTaskDocuments(...): successful retrievals, NDJSON formatting checks, empty-task behavior, nested/multiple documents, invalid UID error handling, repeated-call consistency, and runtime-type assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Handler as TasksHandler
    participant Server as Meilisearch Server

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

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇
I nibbled code and found a stream,
NDJSON dancing like a dream.
A client call, a handler's tug,
Documents arrive — a crunchy hug. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a getTaskDocuments method for Meilisearch v1.13 support, which is the core purpose of this pull request.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #948: adds getTaskDocuments method to Client and TasksHandler, includes comprehensive test cases, and adds documentation sample entry.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the getTaskDocuments feature; no unrelated or out-of-scope modifications were introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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

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.

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

1 participant