You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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: 4
Check name
Status
Explanation
Title check
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
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
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
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.
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds unit tests for the API adapter's transport and usage modules.
TransportResponseDebugoutput shows status and body length, never the body.TransportErrormessages are fixed and carry no URL, key or body.usage_recordaccepts a reserved cost at the safe-integer limit and rejects one above it or an overflowing reported cost.Closes #634