Skip to content

test(provider): pin the 2 MB response cap - #32

Merged
M3gA-Mind merged 3 commits into
tinyhumansai:mainfrom
M3gA-Mind:test/response-size-cap
Oct 23, 2026
Merged

M3gA-Mind merged 3 commits into
tinyhumansai:mainfrom
M3gA-Mind:test/response-size-cap

Conversation

@M3gA-Mind

@M3gA-Mind M3gA-Mind commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Provider responses are capped at 2 MB (MAX_BODY_BYTES): read_json refuses a response whose Content-Length is over the cap before reading it, and stops a body with no Content-Length (chunked or read-to-close) as soon as the streamed bytes pass the cap. The code is correct, but nothing tested it, so a refactor could drop either check and a large or endless upstream response would be buffered in full. This adds tests only.

Related issue

None.

API or behavior changes

None (tests only).

Validation

  • rustfmt --edition 2024 --check on the touched files
  • N/A: cargo clippy --all-targets --all-features -- -D warnings: left to CI
  • N/A: cargo build --all-targets --all-features: left to CI
  • N/A: cargo test --all-features: only the new tests ran locally (below); CI runs the suite

CARGO_INCREMENTAL=0 cargo test -p tinysearch --lib provider::http::tests

  • As is: ok. 3 passed; 0 failed.
  • With both cap comparisons disabled on purpose (restored afterwards): FAILED. 1 passed; 2 failed. The two refusal tests fail and the at-the-cap test still passes.

Tests

New provider/http_tests.rs (sibling of http.rs), against a raw local TCP server:

  • a_streamed_body_past_the_cap_is_refused: a chunked 200 of 2,000,001 bytes with no Content-Length is refused with "provider response too large".
  • an_announced_length_past_the_cap_is_refused_before_reading: Content-Length: 2000001 is refused before any body is read.
  • a_body_at_the_cap_is_read: a 2,000,000-byte body is read and parsed.

Documentation

Not needed (tests only).

Checklist

  • The change is focused on one logical change
  • No new #[allow(...)], #[ignore], or relaxed lints
  • No secrets, tokens, or .env contents in the diff or the description

Inherited CI red

module-ci / supply-chain fails on this PR because of RustSec advisories against the existing dependency tree (cargo-deny reports RUSTSEC-2026-0346 through 0349, 0367 through 0369, 0381 and 0382), including RUSTSEC-2026-0346 (Debug impls for client session values expose TLS secrets) and RUSTSEC-2026-0347 (buffered application data sent to the outer server after ECH rejection) in rustls. Both were published after main's last CI run, and this PR does not change dependencies. Fixing it needs a rustls bump on main.

read_json refuses a body over MAX_BODY_BYTES, either from an announced
Content-Length or while streaming a body that has none, but nothing
tested it. Add tests for both refusals and for a body exactly at the cap.
@tinysweeper

tinysweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Reviewed head: 510b64213ff359c85b4afe483db62fe162047569

Verdict: Ready for maintainer review · Priority: low
Coverage: Reviewed 2 of 2 files.
Pull request purpose (title): test(provider): pin…

Diagnostics and supporting details

Full summary

Pull request purpose (title): test(provider): pin the 2 MB response cap. Tiny Sweeper completed its review; deterministic results follow.

Review snapshot

Change surface Files Review signal Count
Production 1 Active findings 0
Tests 1 Noted findings 0
Documentation 0 Resolved findings 0
Configuration 0 Pending checks/questions 0

Completeness: Complete
Test assessment: No supported feature-to-test mapping was available; this does not mean tests are absent or passed.

What changed

No production behavior changes. The diff appends `#[cfg(test)] #[path = "http_tests.rs"] mod tests;` to `crates/tinysearch/src/provider/http.rs` and adds `crates/tinysearch/src/provider/http_tests.rs` (74 lines). The test file defines a `TestResult<T>` alias, a `cap()` helper that converts `MAX_BODY_BYTES` to `usize`, and helpers (`serve`, `read`) returning `TestResult` rather than unwrapping; `serve` binds a local `TcpListener` and writes one HTTP 200 reply. Three `#[tokio::test]` cases target the cap: a chunked body of `cap()? + 1` bytes with no `Content-Length` asserted to be refused with the exact `ProviderUnavailable("provider response too large")` error; a reply with a hard-coded `Content-Length: 2000001` and empty body asserted to be refused; and a body of exactly `MAX_BODY_BYTES` bytes, built as `{}` followed by spaces, asserted to parse to `serde_json::json!({})`. The description reports local runs as-is and with both cap comparisons deliberately disabled, but that is author-reported and not trusted check evidence.

Features

None identified with supported citations.

Tests

No supported feature-to-test mapping was produced. Test execution is not inferred.

Findings

No active actionable findings.

Before merge

None.

Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: Critique lane answered that the tests exercise the existing body-size cap and are otherwise sound, with the hard-coded `Content-Length: 2000001` the one defect worth reporting, at low severity.
  • Lane summary: The test file exercises the existing body-size cap in `read_json`. Two problems stand out: the "at the cap" test's chunked-less reply with no `Content-Length` depends on how reqwest frames a 200 with neither header, but more concretely the cap test asserts only that it errors — which it does via the loop — while the announced-length test relies on a hard-coded 2000001 that will silently stop testing the boundary if `MAX_BODY_BYTES` changes. The one defect worth fixing is `a_body_at_the_cap_is_read`: `rsplit`/`splice` puts the body at exactly `cap()` bytes, but the server writes the header block without a `Connection: close` terminator issue — actually the reply is wellformed. Net: the tests are sound apart from the hard-coded length; report that as low severity.

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: Security lane answered with no findings: no production code changed, and the tests use a local listener and fixed inputs, introducing no attacker-controlled path.
  • Lane summary: New test-only module for http.rs reading a streamed body cap; no production code changed. Tests use a local listener and fixed inputs, so there is no attacker-controlled path introduced. I found nothing reportable.

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: Tests lane answered with no findings: the tests exercise real cap boundaries (one byte over, over cap with no body, exactly at cap) against a live socket and follow the repository's sibling `*_tests.rs` layout, `use super::*;`, and absence of an inline test module.
  • Lane summary: The pull request adds only a test module declaration and a new sibling test file; no production behaviour changes. The tests exercise real cap boundaries against a live socket: a chunked body one byte over `MAX_BODY_BYTES`, a Content-Length over the cap with no body, and a body exactly at the cap, each asserting the specific outcome, so a regression in `read_json`'s bound or the `>` vs `>=` comparison would fail them. The file naming, `use super::*;`, sibling `_tests.rs` layout and absence of an inline `#[cfg(test)] mod tests` block all follow the repository's test rules.

commits

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: Commits lane answered with no findings: no sensitive content in committed files.
  • Lane summary: No sensitive content in committed files.

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: Description lane answered that the description accurately describes a tests-only diff adding `provider/http_tests.rs` with three tests pinning the cap, while reporting the at-cap test as likely failing.
  • Lane summary: Tests-only change adding `provider/http_tests.rs` with three tests pinning the 2 MB response cap; the description accurately describes the diff. One test is likely wrong: `a_body_at_the_cap_is_read` sends a 2,000,000-byte body that is whitespace after the leading `{}`, which `serde_json::from_slice` rejects with "trailing characters", so the at-the-cap assertion would fail in CI — which the description explicitly leaves to CI.
Evidence and run details
  • Models: ladder/vectors-oai3, deepseek-v4.1-flash
  • Spend: $0.000485
  • Tokens: 189757 input · 4571 output · 32256 cached · 185 embedding
  • Updated: 2026-10-23T12:31:32Z
Head State Pass summary
cb9cc865183b ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-10-22T23:04:36Z)
0ca63b68db83 ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-10-23T00:24:51Z)
510b64213ff3 ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-10-23T12:31:32Z)

tinysweeper 0.1.2

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 52e9d513-dd09-468d-844f-39c858c7d83f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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

tinysweeper found nothing blocking. Approving.

Diagnostics

Total spend: $0.0006

M3gA-Mind and others added 2 commits October 23, 2026 05:30
Return TestResult and use ? instead of unwrap, and convert the cap with
usize::try_from instead of an as cast.
@M3gA-Mind
M3gA-Mind merged commit c0352d2 into tinyhumansai:main Oct 23, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant