Skip to content

test(handbrake): pin calibration semantics and load-cell tolerance#514

Draft
EffortlessSteven wants to merge 1 commit into
mainfrom
claude/improve-code-coverage-xaNsj-handbrake
Draft

test(handbrake): pin calibration semantics and load-cell tolerance#514
EffortlessSteven wants to merge 1 commit into
mainfrom
claude/improve-code-coverage-xaNsj-handbrake

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Adds 13 new tests for openracing-handbrake covering paths the existing suite did not pin down. Pure additive — no production code changed.

What the new tests cover

  • HandbrakeCalibration::apply does not propagate center. The center field is currently a dangling public field; apply writes only min/max. The test pins that explicitly so a future change is intentional.
  • apply after zero samples uses constructor defaults [0, MAX_ANALOG_VALUE].
  • normalized with fully inverted full-range calibration (min=u16::MAX, max=0) at the midpoint returns ~0.5 — extreme bound stress for the internal reorder branch.
  • with_calibration(9000, 1000) stores the inverted pair verbatim (no reorder in the builder); normalized() still produces a value in [0, 1].
  • raw_value < min with inverted calibration returns 0.0 (saturating_sub clamp path).
  • HandbrakeCapabilities::load_cell permissive tolerance — negative, NaN, +∞, -∞ loads are all accepted verbatim. Pins the current contract (callers in vendor crates that want validation know to do it at the boundary).
  • HandbrakeCapabilities::Debug carries the type name and field names so dropping the derive is caught by CI.
  • HandbrakeError::Disconnected Display carries no digits — regression guard if someone accidentally adds a payload to that variant.
  • parse_gamepad header-byte isolation — bytes 0 and 1 do not affect output, even when both are 0xFF; all-0xFF payload engages.
  • HandbrakeCapabilities PartialEq inequality via differing max_load_kg.

Smells noticed but not fixed in this PR

  • HandbrakeError::InvalidPosition(u16) variant is never produced by any code path in the crate; only its Display is exercised in tests.
  • HandbrakeCalibration::center is a public field never read by apply.

Both are intentional left-overs documented by the new tests; happy to follow up with a cleanup PR if you want either removed.

Verification

cargo test -p openracing-handbrake
running 52/28/13/65/0 → 158 tests pass
cargo clippy -p openracing-handbrake --tests -- -D warnings    # clean

Test plan

  • cargo test -p openracing-handbrake
  • cargo clippy -p openracing-handbrake --tests -- -D warnings
  • Coverage CI confirms a bump for the crate

https://claude.ai/code/session_01NZ5jzdE2H3bbuPuYqbjCnh


Generated by Claude Code

Adds 13 tests for `openracing-handbrake` covering paths the
existing suite did not exercise:

- `HandbrakeCalibration::apply` reads only `min`/`max`; the public
  `center` field is currently a no-op for apply. Pin that contract
  explicitly so a future change is intentional.
- `apply` on a freshly-constructed calibration (zero samples) is
  equivalent to `[0, MAX_ANALOG_VALUE]`.
- `HandbrakeInput::normalized` with extreme inverted full-range
  calibration (`min=u16::MAX, max=0`) at the midpoint returns ~0.5.
- `HandbrakeInput::with_calibration(9000, 1000)` stores the
  inverted pair verbatim (no reorder in the builder); `normalized()`
  still produces a value in [0, 1].
- `normalized` with `raw_value < min` of an inverted calibration
  returns 0 (clamped via `saturating_sub`).
- `HandbrakeCapabilities::load_cell` is permissive about negative,
  NaN, and ±infinity loads. Pin the current contract.
- `HandbrakeCapabilities::Debug` carries the type name and field
  names so removing a derive is caught.
- `HandbrakeError::Disconnected` `Display` carries no digits.
- `parse_gamepad` ignores header bytes 0 and 1 even when they are
  0xFF; all-0xFF payload engages.
- `HandbrakeCapabilities` `PartialEq` inequality via differing
  `max_load_kg`.

Verified with `cargo test -p openracing-handbrake` (158 tests
pass) and `cargo clippy -p openracing-handbrake --tests
-- -D warnings`.
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 20 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 001aa476-e84a-49c0-9e43-c562bfda2e9b

📥 Commits

Reviewing files that changed from the base of the PR and between e6185be and 283fff0.

📒 Files selected for processing (1)
  • crates/openracing-handbrake/tests/coverage_gaps.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/improve-code-coverage-xaNsj-handbrake

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

Copy link
Copy Markdown

Compatibility Layer Usage Report

Current usage count: 193
Baseline usage count: 193
ℹ️ Usage unchanged

📈 Usage Trend (Last 30 Days)

  • Peak usage: 193
  • Current trend: insufficient_data (0%)
  • Projected removal: unknown

Usage Details

  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/compat_impl.rs:69 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/hid/linux.rs:1253 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/hid/linux.rs:1282 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/hid/mod.rs:230 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/protocol.rs:290 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/protocol.rs:742 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/protocol.rs:749 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/schemas/src/service_example.rs:189 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/schemas/src/service_example.rs:218 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/schemas/src/integration_test.rs:79 - temp_c

... and 183 more occurrences

Migration Guide

To migrate these usages, replace:

  • .temp_c().temperature_c
  • .faults().fault_flags
  • .wheel_angle_mdeg().wheel_angle_deg
  • .wheel_speed_mrad_s().wheel_speed_rad_s

See Migration Patterns for detailed examples.

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.

2 participants