Refactor run_app helpers into single entry point#255
Conversation
Reviewer's GuideThis PR refactors multiple specialized Class diagram for refactored run_app helpersclassDiagram
class helpers {
+processor() LengthPrefixedProcessor
+run_app(app, frames, capacity) io::Result<Vec<u8>>
+TestSerializer
}
class TestSerializer {
<<trait>>
}
class WireframeApp {
+handle_connection(server)
}
helpers --> TestSerializer : uses
helpers --> WireframeApp : uses
helpers : -run_app_with_frame
helpers : -run_app_with_frame_with_capacity
helpers : -run_app_with_frames
helpers : -run_app_with_frames_with_capacity
helpers : +run_app
Class diagram for updated wireframe_testing exportsclassDiagram
class wireframe_testing {
+TestSerializer
+drive_with_bincode
+drive_with_frame
+drive_with_frame_mut
+drive_with_frame_with_capacity
+drive_with_frames
+drive_with_frames_mut
+drive_with_frames_with_capacity
+processor
+run_app
+run_with_duplex_server
+LoggerHandle
+logger
}
wireframe_testing : -run_app_with_frame
wireframe_testing : -run_app_with_frame_with_capacity
wireframe_testing : -run_app_with_frames
wireframe_testing : -run_app_with_frames_with_capacity
wireframe_testing : +run_app
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Summary by CodeRabbit
WalkthroughUnify all references and implementations of test helper functions for the Wireframe app into a single Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Code
participant Helpers as run_app
participant App as WireframeApp
participant Duplex as DuplexStream
Test->>Helpers: Call run_app(app, frames, capacity)
Helpers->>Helpers: Validate capacity
Helpers->>Duplex: Create duplex stream with capacity
Helpers->>App: Spawn app task with duplex
loop For each frame
Helpers->>Duplex: Write frame
end
Helpers->>Duplex: Shutdown write
Helpers->>App: Await app task
Helpers->>Helpers: Collect output bytes
Helpers-->>Test: Return output or error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (1)**/*.rs📄 CodeRabbit Inference Engine (AGENTS.md)
Files:
⚙️ CodeRabbit Configuration File
Files:
🧬 Code Graph Analysis (1)wireframe_testing/src/lib.rs (1)
🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `wireframe_testing/src/helpers.rs:365` </location>
<code_context>
C: Send + 'static,
E: Packet,
{
+ let capacity = capacity.unwrap_or(DEFAULT_CAPACITY);
let (mut client, server) = duplex(capacity);
- let server_task = tokio::spawn(async move {
- app.handle_connection(server).await;
</code_context>
<issue_to_address>
No validation is performed on the provided capacity value.
Validating the `capacity` parameter can prevent issues from zero or excessively large values, reducing the risk of unexpected behavior or resource exhaustion.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
let capacity = capacity.unwrap_or(DEFAULT_CAPACITY);
let (mut client, server) = duplex(capacity);
let server_task = tokio::spawn(async move { app.handle_connection(server).await });
=======
const MAX_CAPACITY: usize = 1024 * 1024 * 10; // 10 MB, adjust as needed
let capacity = capacity.unwrap_or(DEFAULT_CAPACITY);
if capacity == 0 {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Capacity must be greater than zero",
));
}
if capacity > MAX_CAPACITY {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Capacity must not exceed {MAX_CAPACITY} bytes"),
));
}
let (mut client, server) = duplex(capacity);
let server_task = tokio::spawn(async move { app.handle_connection(server).await });
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `wireframe_testing/src/helpers.rs:367` </location>
<code_context>
- let server_task = tokio::spawn(async move {
- app.handle_connection(server).await;
- });
+ let server_task = tokio::spawn(async move { app.handle_connection(server).await });
for frame in &frames {
</code_context>
<issue_to_address>
The spawned task's result is not checked for panics or errors.
Consider matching on the JoinHandle's result to handle panics gracefully, rather than allowing them to propagate.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
run_app_with_*helpers with unifiedrun_appwireframe_testingTesting
make fmtmake markdownlintmake lintmake testmake nixie(fails: libasound.so.2: cannot open shared object file)https://chatgpt.com/codex/tasks/task_e_688fd4cfeec883228dd716e83449a668
Summary by Sourcery
Consolidate multiple test helper functions into a single run_app entry point and update code, documentation, and tests to use the unified API
Enhancements:
Documentation:
Tests: