Skip to content

test(errors): add unit tests for EmptyResponseError and ToolIdMismatchError#555

Merged
giuliovv merged 1 commit intomainfrom
test/errors
Apr 28, 2026
Merged

test(errors): add unit tests for EmptyResponseError and ToolIdMismatchError#555
giuliovv merged 1 commit intomainfrom
test/errors

Conversation

@giuliovv
Copy link
Copy Markdown
Collaborator

Unit test ramp up exercise

…hError

Co-Authored-By: Giulio Vaccari <io@giuliovaccari.it>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

Walkthrough

A new test file is introduced with 105 lines of test code for two custom error classes. The test suite verifies that these errors behave like standard Error objects, store constructor inputs correctly, generate default messages containing attempt counts and tool ID lists, support custom message parameters, handle edge cases, maintain array references, and are catchable as both their specific types and generic Error instances.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding unit tests for two specific error classes (EmptyResponseError and ToolIdMismatchError).
Description check ✅ Passed The description is related to the changeset as a unit test exercise, though minimal in detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR adds a new errors.test.ts file with unit tests for EmptyResponseError and ToolIdMismatchError, covering construction, property storage, default/custom messages, instanceof checks, throw/catch behaviour, and edge cases. The tests are well-structured and align with the implementation in errors.ts.

Confidence Score: 4/5

Safe to merge; the only finding is a misleading test name that doesn't validate what it claims.

Only P2 findings are present. The test suite provides solid coverage of both error classes, and no logic or security issues were found.

src/plugin/errors.test.ts — one test description claims to verify singular language but the assertion does not.

Important Files Changed

Filename Overview
src/plugin/errors.test.ts New unit test file covering EmptyResponseError and ToolIdMismatchError; well-structured and mostly correct, with one misleading test name that doesn't actually verify the singular-language behaviour it claims to check.

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class Error {
        +message: string
        +name: string
    }
    class EmptyResponseError {
        +provider: string
        +model: string
        +attempts: number
        +constructor(provider, model, attempts, message?)
    }
    class ToolIdMismatchError {
        +expectedIds: string[]
        +foundIds: string[]
        +constructor(expectedIds, foundIds, message?)
    }
    Error <|-- EmptyResponseError
    Error <|-- ToolIdMismatchError
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/plugin/errors.test.ts
Line: 38-41

Comment:
**Misleading test name doesn't verify singular language**

The test is titled `"works with attempts = 1 (singular language check)"` but only asserts `toContain("1")`. It never checks that the message uses singular form. The current implementation always interpolates `"attempts"` — so with `attempts = 1` the message reads *"after 1 attempts"*, which is grammatically wrong, yet this test passes. If the intent is to document and verify singular handling, the assertion should match:

```suggestion
  it("works with attempts = 1 (singular language check)", () => {
    const err = new EmptyResponseError("p", "m", 1);
    expect(err.message).toContain("1");
    expect(err.message).toMatch(/\b1 attempt\b/);
  });
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "test(errors): add unit tests for EmptyRe..." | Re-trigger Greptile

Comment thread src/plugin/errors.test.ts
Comment on lines +38 to +41
});

it("can be thrown and caught as an Error", () => {
expect(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Misleading test name doesn't verify singular language

The test is titled "works with attempts = 1 (singular language check)" but only asserts toContain("1"). It never checks that the message uses singular form. The current implementation always interpolates "attempts" — so with attempts = 1 the message reads "after 1 attempts", which is grammatically wrong, yet this test passes. If the intent is to document and verify singular handling, the assertion should match:

Suggested change
});
it("can be thrown and caught as an Error", () => {
expect(() => {
it("works with attempts = 1 (singular language check)", () => {
const err = new EmptyResponseError("p", "m", 1);
expect(err.message).toContain("1");
expect(err.message).toMatch(/\b1 attempt\b/);
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugin/errors.test.ts
Line: 38-41

Comment:
**Misleading test name doesn't verify singular language**

The test is titled `"works with attempts = 1 (singular language check)"` but only asserts `toContain("1")`. It never checks that the message uses singular form. The current implementation always interpolates `"attempts"` — so with `attempts = 1` the message reads *"after 1 attempts"*, which is grammatically wrong, yet this test passes. If the intent is to document and verify singular handling, the assertion should match:

```suggestion
  it("works with attempts = 1 (singular language check)", () => {
    const err = new EmptyResponseError("p", "m", 1);
    expect(err.message).toContain("1");
    expect(err.message).toMatch(/\b1 attempt\b/);
  });
```

How can I resolve this? If you propose a fix, please make it concise.

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 (2)
src/plugin/errors.test.ts (2)

98-104: Avoid over-constraining internals via reference-identity assertions.

At Line 98, asserting toBe on arrays locks in reference preservation as part of the public contract, which can block safe future refactors (e.g., defensive copies). Prefer value-level contract unless identity is intentionally required API behavior.

Alternative assertion
-    expect(err.expectedIds).toBe(expected);
-    expect(err.foundIds).toBe(found);
+    expect(err.expectedIds).toEqual(expected);
+    expect(err.foundIds).toEqual(found);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/plugin/errors.test.ts` around lines 98 - 104, The test is asserting
reference identity for arrays which over-constrains ToolIdMismatchError
internals; change the two assertions in the "preserves array references exactly"
test to value-level equality checks (e.g., use deep equality assertions against
err.expectedIds and err.foundIds) so the spec verifies contents not object
identity while keeping the public contract for ToolIdMismatchError intact.

24-28: Strengthen default-message assertions to validate formatting, not just tokens.

At Line 24 and Line 74, toContain(...) checks are a bit permissive. Consider asserting the full expected default message for fixed inputs so regressions in phrasing/format are caught earlier.

Proposed tightening
-    expect(err.message).toContain("2");
-    expect(err.message).toContain("attempts");
+    expect(err.message).toBe(
+      "The model returned an empty response after 2 attempts. This may indicate a temporary service issue. Please try again.",
+    );
-    expect(err.message).toContain("x");
-    expect(err.message).toContain("y");
-    expect(err.message).toContain("z");
+    expect(err.message).toBe(
+      "Tool ID mismatch: expected [x, y] but found [z]",
+    );

Also applies to: 74-79

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

In `@src/plugin/errors.test.ts` around lines 24 - 28, The tests use loose
toContain assertions for EmptyResponseError messages; change them to assert the
exact expected default message string for given constructor inputs so
formatting/regression issues are caught. Update the first spec that constructs
new EmptyResponseError("gemini","model-x",2) to expect the full exact message
(including the attempt count and the word "attempts") rather than
toContain("2")/toContain("attempts"), and likewise tighten the second spec
around the other EmptyResponseError case (the block at lines ~74-79) to compare
against the full expected message text produced by EmptyResponseError instead of
partial contains checks.
🤖 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/plugin/errors.test.ts`:
- Around line 98-104: The test is asserting reference identity for arrays which
over-constrains ToolIdMismatchError internals; change the two assertions in the
"preserves array references exactly" test to value-level equality checks (e.g.,
use deep equality assertions against err.expectedIds and err.foundIds) so the
spec verifies contents not object identity while keeping the public contract for
ToolIdMismatchError intact.
- Around line 24-28: The tests use loose toContain assertions for
EmptyResponseError messages; change them to assert the exact expected default
message string for given constructor inputs so formatting/regression issues are
caught. Update the first spec that constructs new
EmptyResponseError("gemini","model-x",2) to expect the full exact message
(including the attempt count and the word "attempts") rather than
toContain("2")/toContain("attempts"), and likewise tighten the second spec
around the other EmptyResponseError case (the block at lines ~74-79) to compare
against the full expected message text produced by EmptyResponseError instead of
partial contains checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 631384db-49b1-4189-b43b-a0a18ce564a7

📥 Commits

Reviewing files that changed from the base of the PR and between 4f8989f and 7ea5c9b.

📒 Files selected for processing (1)
  • src/plugin/errors.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Greptile Review
  • GitHub Check: Test on Node.js
🔇 Additional comments (1)
src/plugin/errors.test.ts (1)

6-105: Solid coverage for both error classes.

Nice test ramp-up: inheritance, metadata fields, default/custom messages, and throw/catch behavior are all covered well.

@giuliovv giuliovv merged commit ae4ae82 into main Apr 28, 2026
4 checks passed
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.

1 participant