Skip to content

test(api): cover client endpoints + error paths (77.9% -> 96.3%)#269

Merged
saadqbal merged 2 commits into
developfrom
test/coverage-wave2-api
Jul 14, 2026
Merged

test(api): cover client endpoints + error paths (77.9% -> 96.3%)#269
saadqbal merged 2 commits into
developfrom
test/coverage-wave2-api

Conversation

@LukasWodka

@LukasWodka LukasWodka commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Wave-2 coverage for internal/api: 77.9% → 96.3% ✅. All via httptest stubs + a dead-transport client — no production changes.

  • APIError.Error(), RevokeClient, ListClientAdmins were 0% → now covered (2xx / non-2xx / bad-JSON arms).
  • Every endpoint's transport-error arm (post/get itself failing) via an errRoundTripper client.
  • Non-2xx APIError arms + 2xx-undecodable decode arms across RequestDeviceCode, PollToken, RevokeToken, CreateClient, PatchClientClusterID, ListClients, WhoAmI.
  • Edge cases: PollToken 2xx-missing-token + expired_tokenErrExpiredToken; RequestDeviceCode empty-fields; ListClients DRF next pagination (exercises nextPath + the follow loop).

Clears 95%. The few remaining branches are the central 426-upgrade detection, nextPath's bad-URL guard, and the maxListPages backstop — left per the "honest ceiling" policy.

Test plan

  • make ci green. Behavior-asserting httptest tests; no production changes.

🤖 Generated with Claude Code


Note

Low Risk
Test-only changes using httptest stubs; no runtime or API behavior is modified.

Overview
Adds test-only coverage for internal/api’s HTTP client, raising package coverage from ~78% to ~96% with no production code changes.

New httptest helpers (stubClient) and suites assert APIError.Error(), RevokeClient, and ListClientAdmins (success, HTTP errors, bad JSON). Bulk tests hit non-2xx APIError and 2xx decode failures across device auth, token revoke, client CRUD, WhoAmI, and ListClients.

errRoundTripper exercises transport failures on every exported endpoint. Edge cases cover RequestDeviceCode empty fields, PollToken missing token and expired_tokenErrExpiredToken, and ListClients DRF next pagination across two pages.

Reviewed by Cursor Bugbot for commit 2b07a1a. Bugbot is set up for automated code reviews on this repo. Configure here.

Wave-2 coverage for internal/api, all via httptest stubs + a dead transport:

- APIError.Error(), RevokeClient, ListClientAdmins — were 0%, now covered
  (2xx + non-2xx + bad-JSON arms).
- Every endpoint's transport-error arm (post/get returned an error) via an
  errRoundTripper client.
- Non-2xx APIError arms + 2xx-undecodable decode arms across RequestDeviceCode,
  PollToken, RevokeToken, CreateClient, PatchClientClusterID, ListClients, WhoAmI.
- PollToken edge cases (2xx-missing-token, expired_token -> ErrExpiredToken);
  RequestDeviceCode empty-fields; ListClients DRF `next` pagination + nextPath.

Package clears 95% (96.3%). The few remaining branches are the 426-upgrade
detection + nextPath's bad-URL guard + the maxListPages backstop.

make ci green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@LukasWodka LukasWodka self-assigned this Jul 14, 2026
@LukasWodka

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3bb6678. Configure here.

saadqbal
saadqbal previously approved these changes Jul 14, 2026

@saadqbal saadqbal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍 Good endpoint coverage — verified the expired_tokenErrExpiredToken mapping and the ListClients DRF next-pagination loop (with the maxListPages guard) against source. Batching the non-2xx/transport/decode arms across all endpoints keeps it tight. Clean.

@saadqbal
saadqbal self-requested a review July 14, 2026 10:45
@saadqbal

Copy link
Copy Markdown
Collaborator

Lint is red on errcheck, not a test failure:

internal/api/client_edges_coverage_test.go:97:15: fmt.Fprintf(w, `{"results":...`

The fmt.Fprintf(w, ...) in TestListClients_Pagination doesn't check its return, while every other write in the file uses _, _ = w.Write(...). Prefix it with _, _ = (_, _ = fmt.Fprintf(w, ...)) and Lint goes green — everything else (Test + all builds + schema + installer) is already passing.

The CI Lint job (errcheck) flagged the unchecked fmt.Fprintf in
TestListClients_Pagination's httptest handler. Assign to _,_ like the sibling
w.Write calls. No behavior change; unblocks #269's Lint check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@LukasWodka

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2b07a1a. Configure here.

@saadqbal
saadqbal merged commit fe4a494 into develop Jul 14, 2026
18 checks passed
@saadqbal
saadqbal deleted the test/coverage-wave2-api branch July 14, 2026 11:02
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.

2 participants