Skip to content

Add buffer-size cap and Python/Rust boundary property tests (#82, #90) - #229

Merged
leynos merged 8 commits into
mainfrom
rust-buffer-boundary-tests
Jul 27, 2026
Merged

Add buffer-size cap and Python/Rust boundary property tests (#82, #90)#229
leynos merged 8 commits into
mainfrom
rust-buffer-boundary-tests

Conversation

@leynos

@leynos leynos commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Summary

Hardens buffer_size validation with an explicit upper cap and adds property-based coverage on both sides of the Python/Rust boundary.

Changes

Rust (#82)

  • Extract a pure checked_buffer_size(i64) -> Result<usize, &'static str> from validate_buffer_size, and add an explicit 1 GiB cap (MAX_BUFFER_SIZE). An absurd buffer_size is now rejected before allocation instead of attempting a huge Vec. The PyO3 wrapper maps the stable message to PyValueError as before.
  • buffer_size_tests.rs: proptest that checked_buffer_size accepts exactly the positive, in-range, at-or-below-cap values and rejects non-positive, over-cap, and usize-overflowing inputs, with explicit boundary unit tests (1, cap, cap+1, i64::MAX, 0, i64::MIN) and a drift guard tying the test cap constant to MAX_BUFFER_SIZE.

Python (#90)

  • test_rust_streams_boundary_property.py: Hypothesis properties at the seam proving non-positive and over-cap buffer_size values and negative / out-of-i32-range descriptors raise ValueError, and that omitting buffer_size matches the explicit 65536 default. (Existing example tests already cover buffer_size=0 and the OSError I/O-failure path.)

Regenerated the maturin wheel-manifest snapshot for the new test module.

Verification

make check-fmt lint typecheck markdownlint green (clippy, whitaker, cargo doc -D warnings); cargo nextest 37/37. The new Python boundary tests were verified against a locally-built native extension (they, like the existing rust_streams suite, skip when the extension is not installed and run in CI). Two unrelated test_folded_summary.py Hypothesis-deadline tests flaked under concurrent machine load and pass in isolation.

Closes #82
Closes #90

🤖 Generated with Claude Code

Extract a pure `checked_buffer_size(i64) -> Result<usize, &str>` from
`validate_buffer_size` and introduce an explicit 1 GiB upper cap
(MAX_BUFFER_SIZE), so an absurd `buffer_size` is rejected before allocation
instead of attempting a huge `Vec`. The PyO3 wrapper maps the stable error
message to `PyValueError` as before.

Rust (`buffer_size_tests.rs`): proptest that `checked_buffer_size` accepts
exactly the positive, in-range, at-or-below-cap values and rejects
non-positive, over-cap, and usize-overflowing inputs, with explicit
boundary unit tests (1, cap, cap+1, i64::MAX, 0, i64::MIN).

Python (`test_rust_streams_boundary_property.py`): Hypothesis properties at
the Python/Rust seam proving non-positive and over-cap `buffer_size` values
and negative / out-of-i32-range descriptors raise `ValueError`, and that
omitting `buffer_size` matches the explicit 65536 default.

Regenerate the maturin wheel-manifest snapshot for the new test module.

Closes #82
Closes #90

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry @leynos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Add a 1 GiB maximum buffer size, centralize Rust validation, expand Rust and Python boundary tests, update stream documentation, record the new packaged test, and add CodeScene rule overrides.

Changes

Stream buffer validation

Layer / File(s) Summary
Add capped buffer validation
rust/cuprum-rust/src/lib.rs, rust/cuprum-rust/src/buffer_size_tests.rs
Define the 1 GiB maximum, centralize validation in checked_buffer_size, map failures to PyValueError, and cover numeric boundaries with unit and property tests.
Exercise Python stream boundaries
cuprum/unittests/test_rust_streams_boundary_property.py, cuprum/unittests/__snapshots__/test_maturin_build.ambr
Add Hypothesis coverage for invalid buffer sizes and descriptors, default-buffer equivalence, safe pipe consumption, and the updated wheel snapshot entry.
Update stream contracts and quality rules
cuprum/_streams_rs.py, docs/cuprum-design.md, docs/developers-guide.md, docs/users-guide.md, .codescene/code-health-rules.json
Document the 1 GiB constraint, validation contract, default size, and repository-scoped CodeScene rule overrides.

Sequence Diagram(s)

sequenceDiagram
  participant PythonTests
  participant RustStreams
  participant BufferValidator
  PythonTests->>RustStreams: Call stream helper with buffer_size
  RustStreams->>BufferValidator: Validate positive value within 1 GiB
  BufferValidator-->>RustStreams: Return usize or validation error
  RustStreams-->>PythonTests: Return output/count or ValueError
Loading

Suggested labels: Issue

Poem

Buffers meet their measured bounds,
Pipes carry bytes through testing grounds.
Rust checks values, Python agrees,
Hypothesis swirls on testing seas.
A capped stream now flows with ease.

🚥 Pre-merge checks | ✅ 19 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Developer Documentation ⚠️ Warning The developer guide and design doc are updated, but roadmap items 6.1.1 and 6.1.2 still show unchecked despite the implemented change. Mark roadmap 6.1.1 and 6.1.2 done, then refresh any related execplan or decision record so the docs match the code.
✅ Passed checks (19 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change and includes both linked issue references (#82, #90).
Description check ✅ Passed The description is on-topic and accurately summarises the buffer-size cap and boundary test work.
Linked Issues check ✅ Passed The Rust and Python boundary tests, plus the new cap and helper, satisfy the linked issue objectives.
Out of Scope Changes check ✅ Passed No clearly unrelated code changes stand out; the docs, snapshot, and CodeScene updates tie back to the test and validation work.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Testing (Overall) ✅ Passed The new Rust property tests and Python Hypothesis boundary tests exercise the cap, invalid FDs, and default-path behaviour against real helpers, without mocks or tautological oracles.
User-Facing Documentation ✅ Passed docs/users-guide.md now documents the Rust stream APIs, the 64 KiB default, the 1 GiB cap, and the ValueError boundary.
Module-Level Documentation ✅ Passed PASS: every touched source module has a top-level docstring/comment, and each explains its purpose plus its relation to the Rust/Python boundary.
Testing (Unit And Behavioural) ✅ Passed PASS: The Rust proptests target the pure checked_buffer_size invariant, and the Python Hypothesis tests hit the public Rust stream boundary with edge cases and error paths.
Testing (Property / Proof) ✅ Passed Treat this as PASS: Rust proptest and Python Hypothesis cover the new range invariants, overflow/cap bounds, descriptor validation, and default equivalence.
Testing (Compile-Time / Ui) ✅ Passed No new compile-time surface is added; the PR adds runtime boundary tests and a focused, normalised wheel-manifest snapshot with redaction.
Unit Architecture ✅ Passed Keep side-effects at the edge: buffer validation is now pure, fallible work is surfaced via PyResult/ValueError, and tests hit the seam without hiding I/O.
Domain Architecture ✅ Passed PASS: Keep the new validation inside the Rust/PyO3 stream adapter; the domain model remains untouched and boundary concerns are isolated.
Observability ✅ Passed PASS: the PR only hardens input validation and adds tests/docs; it adds no new production state, boundary, or telemetry sink, so logs, metrics, tracing, and alerts were not required.
Security And Privacy ✅ Passed PASS: The PR adds buffer-size validation/tests/docs only; no secrets, credentials, auth/permission changes, or unsafe sinks were introduced.
Performance And Resource Use ✅ Passed PASS: Keep validation O(1), cap allocations at 1 GiB, and bound the new property-test I/O with tiny payloads and 50 examples.
Concurrency And State ✅ Passed PASS: The PR only tightens buffer-size validation and adds isolated property tests; it introduces no shared mutable state, async work, locks, or ordering-sensitive code.
Architectural Complexity And Maintainability ✅ Passed The new helper is a narrow, pure seam for boundary tests, documented and test-gated; no generic layer, reuse trap, or cycle was introduced.
Rust Compiler Lint Integrity ✅ Passed No broad lint suppressions or artificial references were added, and the new Rust helper/test items are all directly used; no suspicious clone() calls appear in the touched Rust files.
📋 Issue Planner

Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).

View plan for ticket: #82

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rust-buffer-boundary-tests

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

codescene-access[bot]

This comment was marked as outdated.

@coderabbitai coderabbitai Bot added the Issue label Jul 26, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d34b3dada2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cuprum/unittests/test_rust_streams_boundary_property.py
Comment thread rust/cuprum-rust/src/lib.rs

@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 posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cuprum/unittests/test_rust_streams_boundary_property.py`:
- Around line 148-149: Add concise assertion messages to both assertions in the
boundary property test, clearly identifying the explicit-versus-default
comparison and the default-versus-decoded-payload comparison; preserve the
existing assertion conditions and decoding behavior.
- Line 28: The packaged test must not import the unavailable
tests.helpers.stream_pipes module. In
cuprum/unittests/test_rust_streams_boundary_property.py at lines 28-28, move
_safe_close into shipped test support or define the small cleanup helper
locally; in cuprum/unittests/__snapshots__/test_maturin_build.ambr at lines
105-105, regenerate the packaging manifest to include that support module, or
omit test_rust_streams_boundary_property.py from the wheel.
- Around line 38-40: Update the _UNUSED_FD test fixture in
test_rust_streams_boundary_property.py from 0 to -1 so it is deterministically
invalid and cannot refer to stdin; preserve the existing buffer_size validation
assertion and all other test behavior.

In `@rust/cuprum-rust/src/buffer_size_tests.rs`:
- Around line 43-60: Update the matches_bounds property to assert each rejected
result against its exact documented Err message instead of only checking
is_err(). Extract the three-way expected-result logic into a predicate or
helper, then keep the property body focused on comparing
checked_buffer_size(value) with that expected result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2a83724c-7376-4d73-a280-b520a07cf8ac

📥 Commits

Reviewing files that changed from the base of the PR and between aa1fd32 and d34b3da.

📒 Files selected for processing (4)
  • cuprum/unittests/__snapshots__/test_maturin_build.ambr
  • cuprum/unittests/test_rust_streams_boundary_property.py
  • rust/cuprum-rust/src/buffer_size_tests.rs
  • rust/cuprum-rust/src/lib.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • leynos/shared-actions (auto-detected)
  • leynos/pylint-pypy-shim (auto-detected)
  • leynos/whitaker (auto-detected)

Comment thread cuprum/unittests/test_rust_streams_boundary_property.py Outdated
Comment thread cuprum/unittests/test_rust_streams_boundary_property.py Outdated
Comment thread cuprum/unittests/test_rust_streams_boundary_property.py Outdated
Comment thread rust/cuprum-rust/src/buffer_size_tests.rs
codescene-access[bot]

This comment was marked as outdated.

Suppress two module-level Code Health findings where refactoring would be
deleterious, each scoped narrowly and documented in the config:

- `rust/cuprum-rust/src/lib.rs` — Primitive Obsession. The raw `i64`
  file-descriptor and buffer-size arguments are the untyped inputs PyO3
  hands over from Python; these functions exist to validate them INTO the
  crate's domain newtypes (BufferSize, ReaderFd, WriterFd, PlatformFd).
  Wrapping the raw inputs in further domain types before validation would
  add ceremony without value.

- `**/*tests.rs` — Code Duplication. The EINTR-retry tests for the read
  seam (`read_raw_fd_with`) and the write seam (`write_all_unix_with`) are
  deliberately parallel to document that both seams honour the identical
  retry contract; extracting a shared representation would couple
  independent module boundaries and obscure which seam each test exercises.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

Respond to Codex and CodeRabbit feedback on the buffer-size / boundary PR:

- Make the packaged boundary test self-contained: define `_safe_close`
  locally instead of importing it from `tests/helpers/stream_pipes.py`,
  which the wheel does not ship, so the module now collects from a clean
  installed wheel (CodeRabbit).
- Use `-1` as the throwaway descriptor instead of `0` (stdin), so a
  validation-order regression fails loudly rather than blocking on a real
  fd (CodeRabbit).
- Skip the two descriptor properties on Windows: they assert the Unix i32
  file-descriptor conversion contract, which does not hold on the Windows
  handle path (Codex).
- Add failure messages to the round-trip assertions (CodeRabbit / path
  instructions).
- Document the new 1 GiB buffer-size ceiling and its `ValueError` in the
  `cuprum/_streams_rs.py` wrapper docstrings and `docs/cuprum-design.md`,
  which previously stated only that `buffer_size` must be positive (Codex).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@buzzybee-df12

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot removed the Issue label Jul 26, 2026

@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 posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.codescene/code-health-rules.json:
- Around line 12-15: The Code Duplication override currently applies to every
Rust test file via matching_content_path. Update the rule configuration around
matching_content_path to target only the specific documented EINTR and seam test
module paths, using separate exact entries where needed, while preserving the
zero weight and rationale for those modules.

In `@cuprum/unittests/test_rust_streams_boundary_property.py`:
- Around line 160-176: Extend test_default_buffer_matches_explicit to exercise
rust_pump_stream with both omitted and explicit _DEFAULT_BUFFER_SIZE (65536)
buffer_size values, and assert their outputs match. Retain the existing
rust_consume_stream assertions while adding substantive property coverage for
the pump default-equivalence contract.
- Around line 136-157: Refactor _consume_via_pipe to use contextlib.ExitStack
for cleanup, registering both read_fd and write_fd immediately after creating
the pipe. Preserve the explicit write_fd close before calling
rust_consume_stream, and avoid the current write_fd sentinel and try/finally
cleanup logic.

In `@docs/cuprum-design.md`:
- Line 1721: Update the buffer_size validation documentation to state that
ValueError is raised when the value is not a positive integer, in addition to
values below 1 or above the 1 GiB maximum. Ensure the documented behavior
matches the wrapper contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d9d171f8-f59e-4dfe-bab9-5b0d8069ec20

📥 Commits

Reviewing files that changed from the base of the PR and between aa1fd32 and b171861.

📒 Files selected for processing (7)
  • .codescene/code-health-rules.json
  • cuprum/_streams_rs.py
  • cuprum/unittests/__snapshots__/test_maturin_build.ambr
  • cuprum/unittests/test_rust_streams_boundary_property.py
  • docs/cuprum-design.md
  • rust/cuprum-rust/src/buffer_size_tests.rs
  • rust/cuprum-rust/src/lib.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • leynos/shared-actions (auto-detected)
  • leynos/pylint-pypy-shim (auto-detected)
  • leynos/whitaker (auto-detected)

Comment thread .codescene/code-health-rules.json Outdated
Comment thread cuprum/unittests/test_rust_streams_boundary_property.py Outdated
Comment thread cuprum/unittests/test_rust_streams_boundary_property.py
Comment thread docs/cuprum-design.md Outdated
- Narrow the Code Duplication CodeScene override from the `**/*tests.rs`
  wildcard to the exact file that needs it
  (`rust/cuprum-rust/src/io_utils/tests.rs`), so the exception cannot
  silently cover unrelated future test modules (CodeRabbit).
- Refactor `_consume_via_pipe` to manage descriptors with
  `contextlib.ExitStack` and add a shared `_feed_pipe` helper, replacing the
  manual `try`/`finally` sentinel cleanup (CodeRabbit).
- Add `test_pump_default_buffer_matches_explicit` so the default-equivalence
  property covers `rust_pump_stream`, not just `rust_consume_stream`
  (CodeRabbit).
- Align the `docs/cuprum-design.md` pump `ValueError` wording with the
  wrapper contract ("not a positive integer or exceeds the 1 GiB maximum")
  (CodeRabbit).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@leynos leynos changed the title Add buffer-size cap and Python/Rust boundary property tests Add buffer-size cap and Python/Rust boundary property tests (#82, #90) Jul 26, 2026
@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai On the "Out of Scope Changes" pre-merge check for .codescene/code-health-rules.json:

This override is not unrelated to #82 — it is required because of the #82 change. Adding checked_buffer_size(i64) to rust/cuprum-rust/src/lib.rs pushed that module's primitive-argument ratio to 35.5% (> the 30% threshold), tripping CodeScene's Primitive Obsession rule and failing this PR's own "CodeScene Code Health Review" CI gate. The override documents why those raw i64 FFI inputs are the untyped values the boundary exists to validate into domain newtypes, and is scoped to lib.rs only. Without it, this PR cannot go green, so it belongs with the change that caused the finding rather than in a separate PR. The Code Duplication rule_set has been narrowed to the exact file (io_utils/tests.rs) per the inline review.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- CodeScene override configuration ---'
cat .codescene/code-health-rules.json

printf '%s\n' '--- Relevant Rust declarations ---'
ast-grep outline rust/cuprum-rust/src/lib.rs --items all --type function,constant --match 'checked_buffer_size|validate_buffer_size|MAX_BUFFER_SIZE'

Length of output: 2275


@pandalump Treat the .codescene/code-health-rules.json changes as in scope for this PR.

The verified configuration scopes Primitive Obsession solely to rust/cuprum-rust/src/lib.rs, where checked_buffer_size(i64) and the PyO3 conversion boundary live, and documents why raw FFI i64 values must remain unwrapped until validated into domain types. The Code Duplication exception is also now confined to rust/cuprum-rust/src/io_utils/tests.rs.

Withdraw the “Out of Scope Changes” finding. 🐇


✏️ Learnings added
Learnt from: pandalump
URL: https://github.com/leynos/cuprum/pull/229

Timestamp: 2026-07-26T21:31:16.476Z
Learning: In `leynos/cuprum`, `.codescene/code-health-rules.json` may contain a narrowly scoped Primitive Obsession override for `rust/cuprum-rust/src/lib.rs`: PyO3 boundary functions intentionally receive raw `i64` Python inputs and validate them into `BufferSize`, `ReaderFd`, `WriterFd`, and `PlatformFd`; introducing pre-validation domain wrappers would not add value.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai On the "User-Facing Documentation" and "Developer Documentation" pre-merge checks for the buffer-size cap:

The new 1 GiB buffer_size ceiling and its ValueError are already documented where this contract lives: the cuprum/_streams_rs.py wrapper docstrings (rust_pump_stream / rust_consume_stream) and docs/cuprum-design.md (both the pump and consume signatures), updated in this PR. The rust_*_stream helpers are an internal optimization boundary — rust_consume_stream is not even wired into production (ADR-002, Phase 2) — so they are deliberately not surfaced in docs/users-guide.md, which covers end-user command behaviour. No user-facing behaviour changed. If a dedicated developers-guide section for the Rust stream boundary is wanted as a follow-up, I'm happy to open an issue for it, but it's disproportionate to this test/cap PR.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@pandalump Treat the wrapper docstrings and docs/cuprum-design.md as the authoritative documentation for this internal Rust stream boundary.

The 1 GiB limit and its ValueError are documented at both relevant API signatures. Keep docs/users-guide.md focused on end-user command behaviour, since that behaviour has not changed and these helpers remain an internal optimisation boundary. Withdraw the “User-Facing Documentation” and “Developer Documentation” pre-merge findings.

🐇🔎


✏️ Learnings added
Learnt from: pandalump
URL: https://github.com/leynos/cuprum/pull/229

Timestamp: 2026-07-26T21:31:54.516Z
Learning: In `leynos/cuprum`, document contracts for the internal Rust stream boundary (`rust_pump_stream` and `rust_consume_stream`) in the `cuprum/_streams_rs.py` wrapper docstrings and `docs/cuprum-design.md`; do not require entries in `docs/users-guide.md` unless end-user command behaviour changes. `rust_consume_stream` is not production-wired under ADR-002 Phase 2.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

The invalid-reader pump property now passes a genuinely valid writer
descriptor (os.devnull) so the ValueError can only originate from the
invalid reader, not a coincidentally invalid writer (CodeRabbit pre-merge
Testing check).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@buzzybee-df12

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the Issue label Jul 27, 2026

@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 posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cuprum/unittests/test_rust_streams_boundary_property.py`:
- Around line 136-141: Replace the manual try/finally around writer_fd in the
rust_pump_stream test with contextlib.ExitStack, registering writer_fd for
cleanup immediately after os.open succeeds. Preserve the existing pytest.raises
assertion and bad_fd behavior while ensuring the descriptor is closed when the
stack exits.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b87676f9-ec0f-4228-bc16-812191f30e27

📥 Commits

Reviewing files that changed from the base of the PR and between b171861 and 12e62d3.

📒 Files selected for processing (3)
  • .codescene/code-health-rules.json
  • cuprum/unittests/test_rust_streams_boundary_property.py
  • docs/cuprum-design.md
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • leynos/shared-actions (auto-detected)
  • leynos/pylint-pypy-shim (auto-detected)
  • leynos/whitaker (auto-detected)

Comment thread cuprum/unittests/test_rust_streams_boundary_property.py Outdated
Manage the valid writer descriptor with contextlib.ExitStack instead of
try/finally, matching the repo convention for resource management
(CodeRabbit).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@buzzybee-df12

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Address the round-4 documentation pre-merge checks:

- users-guide: note under the Rust stream sections that buffer_size must
  be a positive integer no larger than 1 GiB, and that out-of-range values
  raise ValueError.
- developers-guide: add a "Rust stream buffer-size validation" section
  describing checked_buffer_size / MAX_BUFFER_SIZE, the pure-helper seam,
  and where the contract is property tested.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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 posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/users-guide.md`:
- Around line 1204-1207: Update the buffer_size documentation for
rust_pump_stream and rust_consume_stream to qualify that ValueError is raised
only after PyO3 converts the argument to i64; document that non-integer values
and Python integers outside the i64 range may raise a different exception
earlier, while preserving the existing positive and 1 GiB validation details.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fd16065b-41c9-44a0-9b9b-e409f3a5fe10

📥 Commits

Reviewing files that changed from the base of the PR and between f8dc751 and 9aac6b9.

📒 Files selected for processing (2)
  • docs/developers-guide.md
  • docs/users-guide.md
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • leynos/shared-actions (auto-detected)
  • leynos/pylint-pypy-shim (auto-detected)
  • leynos/whitaker (auto-detected)

Comment thread docs/users-guide.md
@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai Both documentation checks are already satisfied on the current branch head (commit 9aac6b9) — the walkthrough appears to be evaluating a superseded commit:

  • User-Facing Documentation: docs/users-guide.md, under "Rust stream pump (internal)", now states: "Both rust_pump_stream and rust_consume_stream accept an optional buffer_size (bytes, default 64 KiB). It must be a positive integer no larger than 1 GiB (1 << 30); a value below 1 or above the cap raises ValueError."
  • Developer Documentation: docs/developers-guide.md has a new "Rust stream buffer-size validation" section documenting checked_buffer_size / MAX_BUFFER_SIZE (1 GiB), the pure-helper seam, and where the contract is property tested.

Could you re-review against head 9aac6b9? Both docs were added in the "Document the 1 GiB buffer_size cap in the user and dev guides" commit.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- Current HEAD and requested commit ---'
git rev-parse --short HEAD
git show -s --format='%H%n%s' 9aac6b9
git merge-base --is-ancestor 9aac6b9 HEAD && echo '9aac6b9 is an ancestor of HEAD'

printf '%s\n' '--- User guide: Rust stream pump section and buffer_size contract ---'
rg -n -A12 -B4 'Rust stream pump \(internal\)|rust_pump_stream|rust_consume_stream|buffer_size' docs/users-guide.md

printf '%s\n' '--- Developer guide: buffer-size validation section ---'
rg -n -A24 -B3 'Rust stream buffer-size validation|checked_buffer_size|MAX_BUFFER_SIZE|buffer_size' docs/developers-guide.md

Length of output: 5345


@pandalump Treat both documentation checks as satisfied at HEAD 9aac6b9.

docs/users-guide.md documents the internal stream helpers’ 64 KiB default, positive-value requirement, 1 GiB (1 << 30) ceiling, and ValueError behaviour. docs/developers-guide.md documents the checked_buffer_size pure-validation seam, validate_buffer_sizePyValueError mapping, overflow/cap rules, and Rust/Python property-test coverage.

Withdraw the superseded user-facing and developer-documentation findings.

@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai The pre-merge "Developer Documentation" warning recommends marking roadmap items 6.1.1 and 6.1.2 as done. Please reconsider: this PR intentionally implements only a bounded slice of those items, so leaving them unchecked is correct.

Scope of this PR (head 9aac6b9):

  • Adds a buffer-size cap: checked_buffer_size(i64) -> Result<usize, &'static str> plus MAX_BUFFER_SIZE = 1 << 30, wired through validate_buffer_size so an invalid buffer_size raises ValueError.
  • Adds boundary property tests for that cap.

Roadmap 6.1.1 requires more than this slice: "Introduce a RustStreamError enum in rust/cuprum-rust/src/lib.rs and convert it to PyO3 errors at a single boundary point", with the success criterion that both invalid buffer_sizeValueError and I/O failures → OSError are produced through one centralized conversion. This PR does not introduce a RustStreamError enum and does not centralize the OSError side — you can confirm via git grep RustStreamError origin/rust-buffer-boundary-tests returns nothing. 6.1.2 likewise requires the full boundary error-mapping proptest parity, not only the buffer-size cap.

Checking 6.1.1/6.1.2 would therefore overstate completion and make the roadmap inaccurate. The enum-based centralized error mapping is tracked as future work. Could you confirm this reasoning and dismiss the warning?

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- HEAD ---'
git rev-parse --short HEAD
git show -s --format='%H%n%s' HEAD

printf '%s\n' '--- Roadmap items 6.1.1 / 6.1.2 ---'
rg -n -A20 -B4 '6\.1\.1|6\.1\.2|RustStreamError|centralized|centralised|error.mapping|error mapping' \
  README.md docs rust .github 2>/dev/null || true

printf '%s\n' '--- Rust error-related declarations and conversions ---'
ast-grep outline rust/cuprum-rust/src/lib.rs --items all --type enum,function,constant \
  --match 'RustStreamError|checked_buffer_size|validate_buffer_size|PyValueError|PyErr|OSError|io_error'

printf '%s\n' '--- Relevant implementation excerpts ---'
rg -n -A18 -B8 'RustStreamError|checked_buffer_size|validate_buffer_size|PyValueError|PyOSError|PyErr|OSError' \
  rust/cuprum-rust/src/lib.rs rust/cuprum-rust/src 2>/dev/null || true

printf '%s\n' '--- Changed paths at PR HEAD relative to merge-base ---'
base="$(git merge-base HEAD origin/main 2>/dev/null || git merge-base HEAD main)"
git diff --name-status "$base"...HEAD

Length of output: 47747


@pandalump Leave roadmap items 6.1.1 and 6.1.2 unchecked.

At HEAD 9aac6b9, checked_buffer_size and MAX_BUFFER_SIZE correctly deliver the bounded validation slice, but rust/cuprum-rust/src/lib.rs still maps validation errors through PyValueError separately from I/O errors through PyErr::from. rust/cuprum-rust/src/errors.rs centralizes PumpError → Python conversion for I/O-path failures only; it does not provide the required unified RustStreamError boundary covering both ValueError and OSError.

Item 6.1.2 also explicitly depends on 6.1.1 and requires the broader generated consume-parity domain, shrinking, and committed regression seeds. The new cap-focused property tests do not satisfy that full completion criterion.

Withdraw the “Developer Documentation” warning that recommends marking either roadmap item done. 🐇


✏️ Learnings added
Learnt from: pandalump
URL: https://github.com/leynos/cuprum/pull/229

Timestamp: 2026-07-27T13:47:33.036Z
Learning: In `leynos/cuprum`, leave `docs/roadmap.md` items 6.1.1 and 6.1.2 unchecked until the full milestones are delivered: 6.1.1 requires a unified `RustStreamError` conversion boundary for both validation `ValueError` and I/O `OSError`, while 6.1.2 depends on it and requires broader generated Rust-versus-Python consume-parity coverage with shrinking and committed regression seeds. Buffer-size-cap validation tests alone are only a bounded slice of this work.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Address two review findings on #229.

docs/users-guide.md: the buffer_size paragraph claimed invalid values
"raise ValueError" without distinguishing the two failure points. Clarify
that ValueError is raised after PyO3 converts the argument to a signed
64-bit integer and Rust validation runs, whereas a non-integer or a Python
integer outside the i64 range can fail earlier during PyO3 argument
conversion with a different exception. No specific conversion exception
type is claimed, since that is not verified for the pinned PyO3 version.

buffer_size_tests.rs: replace the branchy matches_bounds body with a
reference-oracle helper, expected_buffer_size_result, that re-encodes the
checked_buffer_size contract independently, and compare the two directly
with prop_assert_eq!. Existing boundary tests are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
codescene-access[bot]

This comment was marked as outdated.

@codescene-access codescene-access 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.

No quality gates enabled for this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

3 participants