Skip to content

refactor(body_cap): share non-iteration logic between sync/async#102

Merged
lesnik512 merged 3 commits into
mainfrom
worktree-body-cap-shared-non-iteration-logic
Jul 13, 2026
Merged

refactor(body_cap): share non-iteration logic between sync/async#102
lesnik512 merged 3 commits into
mainfrom
worktree-body-cap-shared-non-iteration-logic

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

  • Extracts two byte-identical blocks from _read_capped/_read_capped_async in _internal/body_cap.py into shared functions: _reject_if_declared_length_exceeds_cap (declared-Content-Length early-reject) and _build_buffered_response (final Response reconstruction).
  • The byte-accumulation loop stays duplicated — sync/async genuinely differ there, same judgment applied to every other sync/async split this session.
  • Closes out the deepening of the body_cap module that this session's first refactor extracted out of client.py but didn't fully share at the time.

Fix folded in from final review: no test anywhere asserted content_length on the reason="streamed" path when a declared length is actually present (the gzip-bomb scenario) — every existing "streamed" test used a chunked body with no declared length. A dropped return value across the new function boundary would have shipped green at 100% coverage. Added the missing assertion plus a new async mirror test (also closing a pre-existing sync/async parity gap — there was no async gzip-bomb test at all before this).

Change file (Lightweight lane): planning/changes/2026-07-13.06-body-cap-shared-non-iteration-logic.md

Test plan

  • just test — 780 passed, 100% coverage
  • just lint-ci — ruff format/check, ty check, planning validator all clean
  • Task-scoped review (spec + quality): Approved, zero findings
  • Final whole-branch review: Ready to merge = Yes after one fix cycle (test-gap finding empirically verified as closed)

lesnik512 and others added 3 commits July 13, 2026 19:58
Extract declared-length validation and response reconstruction into
_reject_if_declared_length_exceeds_cap and _build_buffered_response,
eliminating duplication between _read_capped and _read_capped_async.
The byte-accumulation loops remain separate (sync vs async).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 60f7072 into main Jul 13, 2026
6 checks passed
@lesnik512 lesnik512 deleted the worktree-body-cap-shared-non-iteration-logic branch July 13, 2026 17:18
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.

1 participant