test(virtual): add depth tests for vJoy, vXBox, axis output, FFB passthrough#53
test(virtual): add depth tests for vJoy, vXBox, axis output, FFB passthrough#53EffortlessSteven wants to merge 3 commits intomainfrom
Conversation
- VirtualController with axis/button/hat management and snapshots - VirtualOutput with smoothing and rate-limited frame generation - EmulatedDevice for HID device emulation in testing - 35+ tests covering all virtual device functionality Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Review Summary by QodoAdd virtual controller, output, and device emulator infrastructure
WalkthroughsDescription• Adds virtual controller with configurable axes, buttons, and hat switches • Implements virtual output frame generation with rate limiting and smoothing • Provides HID device emulator for testing without physical hardware • Includes 35+ comprehensive tests covering all virtual device functionality Diagramflowchart LR
VC["VirtualController<br/>axes/buttons/hats"] -- "snapshot()" --> CS["ControllerSnapshot"]
CS -- "compute_frame()" --> VO["VirtualOutput<br/>rate limiting/smoothing"]
VO -- "OutputFrame" --> ED["EmulatedDevice<br/>HID emulation"]
ED -- "inject_input()" --> ED
ED -- "enqueue_output()" --> ED
File Changes1. crates/flight-virtual/src/virtual_controller.rs
|
Code Review by Qodo
1.
|
| // Grow smoothed state to match snapshot. | ||
| if self.smoothed_axes.len() < snapshot.axes.len() { | ||
| self.smoothed_axes.resize(snapshot.axes.len(), 0.0); | ||
| } | ||
|
|
||
| let axes = if self.config.smoothing_enabled { | ||
| let alpha = self.config.smoothing_alpha.clamp(0.0, 1.0); | ||
| for (smoothed, &raw) in self.smoothed_axes.iter_mut().zip(snapshot.axes.iter()) { | ||
| *smoothed += alpha * (raw - *smoothed); | ||
| } | ||
| self.smoothed_axes.clone() | ||
| } else { | ||
| // Copy raw values into smoothed state so a later enable is seamless. | ||
| self.smoothed_axes.copy_from_slice(&snapshot.axes); | ||
| snapshot.axes.clone() | ||
| }; |
There was a problem hiding this comment.
1. Axis shrink panics/stales 🐞 Bug ✓ Correctness
VirtualOutput never shrinks smoothed_axes; if a later snapshot has fewer axes than a previous one, the non-smoothing path can panic (copy_from_slice length mismatch) and the smoothing path can emit extra stale axes beyond the snapshot length.
Agent Prompt
### Issue description
`VirtualOutput::compute_frame` maintains `smoothed_axes` that only grows. If `snapshot.axes.len()` decreases across calls, the non-smoothing path can panic (`copy_from_slice` requires equal lengths), and the smoothing path can return extra stale trailing axes.
### Issue Context
This is an API-facing function taking `&ControllerSnapshot` (a public struct with `Vec` fields), so callers can legally provide snapshots with varying axis counts.
### Fix Focus Areas
- crates/flight-virtual/src/virtual_output.rs[85-113]
- crates/flight-virtual/src/virtual_output.rs[131-288]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
- Resize smoothed_axes to match snapshot axis count each frame - Truncate on shrink, extend with 0.0 on grow - Add test for varying axis counts across frames Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…through Add 51 depth tests covering device creation, axis output, button modes, hat switches, FFB passthrough, error handling, and output pipeline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Add 51 depth tests for the virtual device subsystem in \crates/flight-virtual/tests/depth_tests.rs.
Test categories
Verification