Skip to content

Add edge-case tests for the API adapter - #637

Open
n33miaz wants to merge 1 commit into
developfrom
feature/634-api-adapter-edge-tests
Open

n33miaz wants to merge 1 commit into
developfrom
feature/634-api-adapter-edge-tests

Conversation

@n33miaz

@n33miaz n33miaz commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Adds unit tests for the API adapter's transport and usage modules.

  • TransportResponse Debug output shows status and body length, never the body.
  • TransportError messages are fixed and carry no URL, key or body.
  • usage_record accepts a reserved cost at the safe-integer limit and rejects one above it or an overflowing reported cost.

Closes #634

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The pull request adds API adapter tests for transport debug output, transport error messages, and usage cost limits. The tests cover body-content redaction, distinct transport error messages, and safe-integer cost boundaries.

Changes: Transport output and errors

Layer / File(s) Summary
Transport debug and error assertions
crates/adapters/api/src/transport.rs
Tests check that debug output includes the response status and body length but excludes body contents. They also check that NotSent and MaybeSent have distinct, detail-free display messages.

Usage cost limits

Layer / File(s) Summary
Usage cost boundary tests
crates/adapters/api/src/usage.rs
Tests check that the maximum safe-integer reserved cost is accepted, while an out-of-range reserved cost and reported usage with maximum token counts are rejected.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

Suggested labels: area: adapters

Suggested reviewers: claude

Merge Risk: Low · up to 172e7

This change only adds tests, so runtime behavior is unaffected. The reported-cost overflow test does not exercise the check it claims to, and the debug-output test is weaker than it appears. Tighten both so they catch regressions.

Security architecture risk: Minimal · up to 172e7

The API adapter gains tests for what transport diagnostics disclose and which usage costs it accepts. The tests do not change runtime behavior or require action from callers or operators.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Add edge-case tests for the API adapter" matches the changeset, which adds unit tests to the API adapter's transport and usage modules. It names the change type and the area. It does not li…
Description check Passed The description states what changed: unit tests for the transport and usage modules of the API adapter. It lists the three behaviors covered (redacted Debug output, fixed TransportError messages, and …
Linked Issues check Passed Issue #634 asks for focused tests for (1) redacted transport debug output, (2) transport error messages, and (3) rejection of reserved usage costs outside the contract range. The diff adds these tests…
Out of Scope Changes check Passed The whole-PR diff against the merge base ca262314 touches only crates/adapters/api/src/transport.rs (+33 lines) and crates/adapters/api/src/usage.rs (+68 lines). Both changes add only `#[cfg(tes…
Full details: Title check

Explanation

The title "Add edge-case tests for the API adapter" matches the changeset, which adds unit tests to the API adapter's transport and usage modules. It names the change type and the area. It does not list every test, which is acceptable. It is 39 characters, within the 72-character limit in the repository template.

Full details: Description check

Explanation

The description states what changed: unit tests for the transport and usage modules of the API adapter. It lists the three behaviors covered (redacted Debug output, fixed TransportError messages, and usage_record cost boundaries) and links issue #634. It does not fill the template sections "Por que", "Como testar", or the checklist. The template is written in Portuguese, and the description is in English. Those gaps are minor for a test-only change, so the description is mostly complete.

Full details: Linked Issues check

Explanation

Issue #634 asks for focused tests for (1) redacted transport debug output, (2) transport error messages, and (3) rejection of reserved usage costs outside the contract range. The diff adds these tests:

  • Redacted debug output, in crates/adapters/api/src/transport.rs: transport_response_debug_redacts_body_contents builds a response with a 27-byte body. It asserts the debug output contains status: 200 and body_bytes: 27, and does not contain the body text. The head Debug impl uses debug_struct with status and body_bytes: self.body.len(), so the assertions match the code. The byte count is 27, which matches the test body.
  • Error messages, in transport.rs: transport_error_display_messages_are_distinct_and_carry_no_detail asserts the exact Display strings for NotSent and MaybeSent, and asserts that the two strings differ. The head Display impl returns these fixed strings with no URL, key, or body.
  • Reserved cost limits, in crates/adapters/api/src/usage.rs: usage_record_accepts_reserved_cost_at_safe_limit checks that a reserved cost of 2^53-1 succeeds. usage_record_rejects_reserved_cost_above_safe_integer checks that u64::MAX fails with the same error as RecordApiUsageV3SafeInteger::new(u64::MAX). usage_record_rejects_reported_cost_above_safe_integer checks that reported usage with u64::MAX tokens fails.

The tests were read from the diff and head source. They were not executed, so pass or fail status is based on static reading.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base ca262314 touches only crates/adapters/api/src/transport.rs (+33 lines) and crates/adapters/api/src/usage.rs (+68 lines). Both changes add only #[cfg(test)] mod tests blocks. No production code, public declarations, or other files change. Every added test maps to an objective in #634 (debug redaction, error message content, reserved cost range). No unrelated change was found.

@coderabbitai coderabbitai 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.

Actionable comments

Minor 2
  1. Reject byte-formatted body contents.
  2. Use valid token counts to test reported-cost rejection.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ca26231 and 172e7b0.

Files selected for processing: 2

  • crates/adapters/api/src/transport.rs
  • crates/adapters/api/src/usage.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

let formatted = format!("{response:?}");
assert!(formatted.contains("status: 200"));
assert!(formatted.contains("body_bytes: 27"));
assert!(!formatted.contains("sensitive-conversation-text"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Reject byte-formatted body contents.

If the formatter also adds .field("body", &self.body), Rust prints the bytes as numbers. All three assertions still pass, but the output exposes the body. Assert the complete expected debug output to catch this regression.

Comment on lines +94 to +95
tokens_in: u64::MAX,
tokens_out: u64::MAX,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Use valid token counts to test reported-cost rejection.

Both counts exceed the safe-integer limit. report_usage therefore returns at Line 45, before it computes or validates the reported cost. This test passes even if reported-cost validation is removed.

Keep both counts within the contract range. Choose counts and prices that produce a cost above the limit. Assert that usage_record rejects that cost.

The PR objectives explicitly require reported-cost overflow coverage.

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.

Cover API adapter redaction and usage cost limits

1 participant