Skip to content

test: strengthen coverage for error handling, status codes, assertions, and metrics#351

Merged
curfew-marathon merged 2 commits into
mainfrom
test/improve-coverage-and-fix-stale-comments
Jun 28, 2026
Merged

test: strengthen coverage for error handling, status codes, assertions, and metrics#351
curfew-marathon merged 2 commits into
mainfrom
test/improve-coverage-and-fix-stale-comments

Conversation

@curfew-marathon

@curfew-marathon curfew-marathon commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR improves test coverage across several areas of the SDK, focusing on correctness guarantees for user-facing contracts and behavioral verification of internal routing logic.

FgaErrorTest (new)

FgaError.getMessage() produces the formatted message that SDK consumers see when catching errors — e.g. [write] HTTP 400 type not found (validation_error) [request-id: abc-123]. This method has several conditional paths (missing operation name, missing error code, missing request ID) that were previously unverified. The new tests cover:

  • Full message format with all fields present
  • Each optional field omitted in isolation
  • Minimal case (status code only, no metadata)
  • All helper predicates: isValidationError(), isUnknownError(), isRateLimitError(), isRetryable(), isClientError(), isServerError()

HttpStatusCodeTest (new)

HttpStatusCode drives retry decisions and error classification throughout the SDK. Boundary conditions at 200/300/500/600 and the deliberate 501 NOT_IMPLEMENTED exclusion from retries are now explicitly tested via parameterized tests, making off-by-one regressions immediately visible.

ClientAssertionTest (new)

ClientAssertion.asAssertion() and asAssertions() convert client-layer models to API models used in writeAssertions. Tests cover full field round-trip, false expectation, null input, empty list, and multi-item conversion with order preservation.

MetricsTest (updated)

The existing counter and histogram tests verified only that a non-null instrument was returned. They now additionally assert that:

  • The same instrument instance is returned on repeated calls (caching via ConcurrentHashMap is exercised)
  • Convenience methods (credentialsRequest(), requestDuration(), queryDuration()) delegate to the correct underlying metric, confirmed via instance identity

RetryStrategyTest (updated)

Removed three comments that incorrectly described the current implementation as failing its own tests. The tests themselves are correct and the code passes them — the comments were a readability hazard that could prompt unnecessary investigation or cause someone to revert correct behavior.

Test plan

  • All five affected test classes pass locally (./gradlew test)
  • No production code changed

Copilot AI review requested due to automatic review settings June 28, 2026 18:08
@curfew-marathon curfew-marathon requested a review from a team as a code owner June 28, 2026 18:08
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 28, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: curfew-marathon / name: curfew-marathon (5f541f8)

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@curfew-marathon, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 27 minutes and 49 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 252fa55c-7a28-433e-9c52-b590a68efe71

📥 Commits

Reviewing files that changed from the base of the PR and between fb6c59f and 0a8cd89.

📒 Files selected for processing (5)
  • src/test/java/dev/openfga/sdk/api/client/ClientAssertionTest.java
  • src/test/java/dev/openfga/sdk/errors/FgaErrorTest.java
  • src/test/java/dev/openfga/sdk/errors/HttpStatusCodeTest.java
  • src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java
  • src/test/java/dev/openfga/sdk/util/RetryStrategyTest.java
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/improve-coverage-and-fix-stale-comments

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.

Copilot AI left a comment

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.

Pull request overview

This PR expands and clarifies the SDK’s automated test coverage around user-facing error formatting/classification, HTTP status classification (including retry semantics), client assertion model conversion, and telemetry metric caching/delegation, while also removing misleading comments in an existing retry strategy test.

Changes:

  • Added new unit tests for FgaError message formatting and helper predicates, plus HttpStatusCode boundary/retry behavior.
  • Added new unit tests for ClientAssertion conversion helpers (asAssertion, asAssertions).
  • Strengthened MetricsTest assertions around instrument caching and convenience-method delegation; removed misleading comments from RetryStrategyTest.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/test/java/dev/openfga/sdk/util/RetryStrategyTest.java Removes misleading comments from retry-delay tests without altering behavior.
src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java Adds identity assertions to verify metric instrument caching and delegation behavior.
src/test/java/dev/openfga/sdk/errors/HttpStatusCodeTest.java Adds parameterized boundary and retryability tests for HTTP status classification.
src/test/java/dev/openfga/sdk/errors/FgaErrorTest.java Adds coverage for formatted error messages and error classification helpers.
src/test/java/dev/openfga/sdk/api/client/ClientAssertionTest.java Adds conversion/round-trip tests for client assertion helpers.

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

Comment thread src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java Outdated
Comment thread src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java Outdated
Comment thread src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java Outdated
Comment thread src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java Outdated
Comment thread src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java Outdated
Comment thread src/test/java/dev/openfga/sdk/errors/FgaErrorTest.java Outdated
@curfew-marathon curfew-marathon force-pushed the test/improve-coverage-and-fix-stale-comments branch from 1469ad0 to 0cca4f8 Compare June 28, 2026 18:15
- Add FgaErrorTest covering getMessage() format variants and all helper
  methods (isRetryable, isClientError, isServerError, etc.)
- Add HttpStatusCodeTest with boundary parameterized tests for
  isSuccessful, isServerError, and isRetryable including 501 exclusion
- Add ClientAssertionTest covering asAssertion() and asAssertions()
  including null and empty list cases
- Upgrade MetricsTest existence assertions to verify caching and
  delegation (credentialsRequest, requestDuration, queryDuration)
- Remove stale "Current code will FAIL" comments in RetryStrategyTest
@curfew-marathon curfew-marathon force-pushed the test/improve-coverage-and-fix-stale-comments branch from 0cca4f8 to 5f541f8 Compare June 28, 2026 18:16
@curfew-marathon

Copy link
Copy Markdown
Contributor Author

/easycla

@codecov-commenter

codecov-commenter commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.69%. Comparing base (fb6c59f) to head (0a8cd89).

❌ Your project status has failed because the head coverage (38.69%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #351      +/-   ##
============================================
+ Coverage     38.47%   38.69%   +0.22%     
- Complexity     1267     1289      +22     
============================================
  Files           198      198              
  Lines          7704     7704              
  Branches        900      900              
============================================
+ Hits           2964     2981      +17     
+ Misses         4591     4576      -15     
+ Partials        149      147       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@curfew-marathon curfew-marathon added this pull request to the merge queue Jun 28, 2026
Merged via the queue into main with commit 272a257 Jun 28, 2026
29 checks passed
@curfew-marathon curfew-marathon deleted the test/improve-coverage-and-fix-stale-comments branch June 28, 2026 19:30
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.

4 participants