Skip to content

Conversation

leynos
Copy link
Owner

@leynos leynos commented Aug 1, 2025

Summary

  • move internal server helpers to src/server/worker.rs
  • expose worker task for tests and add helper accessors
  • migrate large mod tests from src/server.rs into tests/server_runtime*.rs
  • keep a small unit test for the worker task inside its module

Testing

  • make fmt
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_688bf634507c8322a842ee9c9bccda9a

Summary by Sourcery

Refactor the WireframeServer module by extracting worker logic into its own module and reorganize tests into integration suites

Enhancements:

  • Extract the worker task and connection processing helpers into src/server/worker.rs
  • Expose worker_task and add hidden has_preamble_success/has_preamble_failure methods on WireframeServer

Tests:

  • Migrate extensive inline server tests from src/server.rs into integration tests under tests/
  • Retain a minimal unit test for worker shutdown in the new worker module

Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 29 seconds before requesting another review.

⌛ 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 9f62d42 and 4e410c1.

📒 Files selected for processing (3)
  • src/server/worker.rs (1 hunks)
  • tests/server_helpers.rs (1 hunks)
  • tests/server_runtime.rs (1 hunks)

Summary by CodeRabbit

  • Refactor

    • Internal server logic for handling worker tasks and connection streams has been moved to a dedicated module, improving code organisation.
    • Server code now references worker handling via a new module, with associated code clean-up.
  • Tests

    • Comprehensive new runtime and behaviour tests for the server have been added, covering configuration, binding, callback invocation, shutdown, and error handling.
    • Additional test helpers and fixtures introduced for easier server testing and setup.
  • Chores

    • Test code and related callbacks have been reorganised and expanded for better coverage and maintainability.

Walkthrough

Relocate the worker task and connection processing logic from src/server.rs into a new src/server/worker.rs module. Remove all related tests from src/server.rs and introduce two new test modules, tests/server_runtime.rs and tests/server_runtime_more.rs, which provide comprehensive runtime and behavioural tests for the server.

Changes

Cohort / File(s) Change Summary
Server Logic Refactor
src/server.rs
Remove worker task, connection processing, and related imports. Add hidden methods for preamble callback presence. Remove all server tests from this file. Reference worker logic via new module.
Worker Module Introduction
src/server/worker.rs
Introduce new module containing worker_task and process_stream async functions for connection handling. Add test for shutdown behaviour.
Runtime Server Tests
tests/server_runtime.rs
Add new test module with fixtures and tests for server creation, worker configuration, preamble callbacks, binding, method chaining, and shutdown behaviour.
Advanced Server Tests
tests/server_runtime_more.rs
Add new test module with advanced and async tests for shutdown, worker concurrency, configuration persistence, preamble callback resetting, extreme worker counts, multi-address binding, debug assertions, and panic handling in connection tasks.
Test Utilities
tests/server_helpers.rs
Add helper module with fixtures for server factory, free port allocation, test preamble struct, and server binding helpers.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TcpListener
    participant WorkerTask
    participant WireframeApp

    Client->>TcpListener: Initiate TCP connection
    TcpListener->>WorkerTask: Accept connection
    WorkerTask->>WorkerTask: Decode preamble
    alt Preamble success
        WorkerTask->>WireframeApp: Create app instance with connection
        WorkerTask->>WorkerTask: Invoke success callback (if any)
    else Preamble failure
        WorkerTask->>WorkerTask: Invoke failure callback (if any)
        WorkerTask->>Client: Drop connection
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

Refactor winds sweep through the code,
Worker tasks pack up and hit the road.
Tests move out, new modules appear,
Server logic’s tidy, the purpose is clear.
Connections now handled with modular grace—
The server’s reborn, in a brand new place!
🚀

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/extract-tests-from-src/server.rs

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

sourcery-ai bot commented Aug 1, 2025

Reviewer's Guide

This PR refactors the server implementation by extracting connection-handling logic into a dedicated worker module, cleaning up imports and exposing testing hooks, and migrating the bulk of tests into standalone integration test files.

File-Level Changes

Change Details Files
Extract worker logic into a separate module
  • Created src/server/worker.rs with worker_task and process_stream
  • Replaced inline definitions in src/server.rs with references to worker::worker_task
  • Updated tracker.spawn calls to invoke the new module’s functions
src/server.rs
src/server/worker.rs
Expose testing hooks in the server API
  • Added has_preamble_success and has_preamble_failure accessor methods
  • Re-exported worker_task under #[cfg(test)] for external test use
src/server.rs
Relocate and restructure tests into integration files
  • Removed the large inline mod tests block from src/server.rs
  • Introduced tests/server_runtime.rs and tests/server_runtime_more.rs with migrated tests
src/server.rs
tests/server_runtime.rs
tests/server_runtime_more.rs
Clean up imports in server.rs
  • Removed unused tokio::time and other redundant imports
  • Streamlined crate imports to match the new worker module structure
src/server.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.

  • In worker_task and process_stream you still use eprintln! for errors; switch to tracing::error! (or another tracing macro) so logging is consistent with the rest of the server.
  • The two test files under tests/ largely duplicate types and fixtures (e.g. TestPreamble, EmptyPreamble, factory, free_port); consider extracting those into a shared test utility to DRY up the suite.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In worker_task and process_stream you still use eprintln! for errors; switch to tracing::error! (or another tracing macro) so logging is consistent with the rest of the server.
- The two test files under tests/ largely duplicate types and fixtures (e.g. TestPreamble, EmptyPreamble, factory, free_port); consider extracting those into a shared test utility to DRY up the suite.

## Individual Comments

### Comment 1
<location> `src/server/worker.rs:103` </location>
<code_context>
+/// // process_stream::<_, ()>(stream, factory, None, None).await;
+/// # }
+/// ```
+pub(crate) async fn process_stream<F, T>(
+    mut stream: tokio::net::TcpStream,
+    factory: F,
</code_context>

<issue_to_address>
Consider making process_stream private if not used outside this module.

If only used in this module, remove the visibility modifier. Use `pub(crate)` only if accessed from other modules or tests.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
+pub(crate) async fn process_stream<F, T>(
=======
+async fn process_stream<F, T>(
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Owner Author

leynos commented Aug 1, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

✅ Actions performed

Review triggered.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6583724 and c7a14f1.

📒 Files selected for processing (4)
  • src/server.rs (3 hunks)
  • src/server/worker.rs (1 hunks)
  • tests/server_runtime.rs (1 hunks)
  • tests/server_runtime_more.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • tests/server_runtime_more.rs
  • src/server/worker.rs
  • src/server.rs
  • tests/server_runtime.rs
🧬 Code Graph Analysis (3)
src/server/worker.rs (4)
src/extractor.rs (2)
  • std (270-270)
  • peer_addr (362-362)
tests/server_runtime_more.rs (1)
  • factory (32-34)
tests/server_runtime.rs (1)
  • factory (27-29)
src/server.rs (2)
  • new (91-107)
  • bind (268-274)
src/server.rs (2)
tests/preamble.rs (3)
  • tokio (131-131)
  • tokio (132-132)
  • oneshot (73-73)
src/server/worker.rs (2)
  • worker_task (24-76)
  • worker_task (161-161)
tests/server_runtime.rs (3)
tests/server_runtime_more.rs (3)
  • server (131-131)
  • factory (32-34)
  • free_port (37-41)
src/server/worker.rs (1)
  • factory (148-150)
src/server.rs (6)
  • new (91-107)
  • bind (268-274)
  • worker_count (227-227)
  • local_addr (231-233)
  • has_preamble_success (235-235)
  • has_preamble_failure (237-237)
🔇 Additional comments (8)
src/server/worker.rs (2)

1-18: Module structure looks good!

The module documentation clearly describes its purpose, and imports are well-organised.


19-76: Excellent implementation of worker task with robust error handling!

The panic catching mechanism with peer address logging and exponential backoff for accept errors demonstrates good defensive programming.

src/server.rs (3)

29-36: Clean module refactoring!

The worker module extraction and test-only export are well-structured.


234-237: Appropriate test helper methods.

The hidden accessor methods provide clean test interfaces without polluting the public API.


358-360: Seamless integration with extracted worker module.

The refactoring maintains the same functionality while improving code organisation.

tests/server_runtime.rs (2)

1-52: Well-structured test helpers and fixtures!

Good use of #[expect] with reason, and fixtures properly reduce test duplication.


140-256: Excellent callback and lifecycle tests!

Good use of atomic counters for callback verification and proper panic testing with expected messages.

tests/server_runtime_more.rs (1)

1-41: Consistent test setup across test modules.

Good reuse of patterns from server_runtime.rs.

Comment on lines 136 to 176
#[cfg(test)]
mod tests {
use rstest::{fixture, rstest};
use tokio::{
net::TcpListener,
time::{Duration, timeout},
};
use tokio_util::{sync::CancellationToken, task::TaskTracker};

use super::*;

#[fixture]
fn factory() -> impl Fn() -> WireframeApp + Send + Sync + Clone + 'static {
|| WireframeApp::default()
}

#[rstest]
#[tokio::test]
async fn test_worker_task_shutdown_signal(
factory: impl Fn() -> WireframeApp + Send + Sync + Clone + 'static,
) {
let token = CancellationToken::new();
let tracker = TaskTracker::new();
let listener = Arc::new(TcpListener::bind("127.0.0.1:0").await.unwrap());

tracker.spawn(worker_task::<_, ()>(
listener,
factory,
None,
None,
token.clone(),
tracker.clone(),
));

token.cancel();
tracker.close();

let result = timeout(Duration::from_millis(100), tracker.wait()).await;
assert!(result.is_ok());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Test implementation follows best practices.

Good use of rstest fixtures and focused test scope. Consider adding tests for accept error retry logic and panic handling scenarios.

Would you like me to generate additional test cases for error scenarios?

🤖 Prompt for AI Agents
In src/server/worker.rs around lines 136 to 176, the current test covers normal
shutdown signaling but lacks coverage for error retry logic and panic handling
in the worker task. Add new async tests that simulate accept errors on the
TcpListener to verify retry behavior, and tests that induce panics within the
worker task to ensure proper handling and recovery. Use similar patterns with
rstest and tokio::test to maintain consistency.

Comment on lines 71 to 103
#[rstest]
#[tokio::test]
async fn test_multiple_worker_creation(
factory: impl Fn() -> WireframeApp + Send + Sync + Clone + 'static,
free_port: SocketAddr,
) {
let _ = &factory;
let call_count = Arc::new(AtomicUsize::new(0));
let call_count_clone = call_count.clone();

let factory = move || {
call_count_clone.fetch_add(1, Ordering::SeqCst);
WireframeApp::default()
};

let server = WireframeServer::new(factory)
.workers(3)
.bind(free_port)
.expect("Failed to bind");

let shutdown_future = async {
tokio::time::sleep(Duration::from_millis(10)).await;
};

let result = timeout(
Duration::from_millis(1000),
server.run_with_shutdown(shutdown_future),
)
.await;

assert!(result.is_ok());
assert!(result.unwrap().is_ok());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add assertion for factory invocation count.

The test sets up call counting but doesn't verify the expected number of factory invocations.

     assert!(result.is_ok());
     assert!(result.unwrap().is_ok());
+    // Verify factory was called 3 times (once per worker)
+    assert_eq!(call_count.load(Ordering::SeqCst), 3);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[rstest]
#[tokio::test]
async fn test_multiple_worker_creation(
factory: impl Fn() -> WireframeApp + Send + Sync + Clone + 'static,
free_port: SocketAddr,
) {
let _ = &factory;
let call_count = Arc::new(AtomicUsize::new(0));
let call_count_clone = call_count.clone();
let factory = move || {
call_count_clone.fetch_add(1, Ordering::SeqCst);
WireframeApp::default()
};
let server = WireframeServer::new(factory)
.workers(3)
.bind(free_port)
.expect("Failed to bind");
let shutdown_future = async {
tokio::time::sleep(Duration::from_millis(10)).await;
};
let result = timeout(
Duration::from_millis(1000),
server.run_with_shutdown(shutdown_future),
)
.await;
assert!(result.is_ok());
assert!(result.unwrap().is_ok());
}
#[rstest]
#[tokio::test]
async fn test_multiple_worker_creation(
factory: impl Fn() -> WireframeApp + Send + Sync + Clone + 'static,
free_port: SocketAddr,
) {
let _ = &factory;
let call_count = Arc::new(AtomicUsize::new(0));
let call_count_clone = call_count.clone();
let factory = move || {
call_count_clone.fetch_add(1, Ordering::SeqCst);
WireframeApp::default()
};
let server = WireframeServer::new(factory)
.workers(3)
.bind(free_port)
.expect("Failed to bind");
let shutdown_future = async {
tokio::time::sleep(Duration::from_millis(10)).await;
};
let result = timeout(
Duration::from_millis(1000),
server.run_with_shutdown(shutdown_future),
)
.await;
assert!(result.is_ok());
assert!(result.unwrap().is_ok());
// Verify factory was called 3 times (once per worker)
assert_eq!(call_count.load(Ordering::SeqCst), 3);
}
🤖 Prompt for AI Agents
In tests/server_runtime_more.rs around lines 71 to 103, the test sets up a
call_count to track factory invocations but does not assert the expected number
of times the factory is called. Add an assertion after the server run completes
to verify that call_count matches the expected number of worker creations (3 in
this case) to ensure the factory was invoked correctly.

@leynos
Copy link
Owner Author

leynos commented Aug 1, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

✅ Actions performed

Review triggered.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

♻️ Duplicate comments (1)
src/server/worker.rs (1)

136-176: Add tests for error scenarios and panic handling.

As previously suggested, add tests for accept error retry logic and panic handling scenarios to improve test coverage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7a14f1 and 9f62d42.

📒 Files selected for processing (4)
  • src/server/worker.rs (1 hunks)
  • tests/server_helpers.rs (1 hunks)
  • tests/server_runtime.rs (1 hunks)
  • tests/server_runtime_more.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.rs: Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Prefer expect over allow.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines with a backslash.
Prefer semantic error enums: Derive std::error::Error (via the thiserror crate) for any condition the caller might inspect, retry, or map to an HTTP status.
Use an opaque error only at the app boundary: Use eyre::Report for human-readable logs; these should not be exposed in public APIs.
Never export the opaque type from a library: Convert to domain enums at API boundaries, and to eyre only in the main main() entrypoint or top-level async task.

Files:

  • tests/server_helpers.rs
  • src/server/worker.rs
  • tests/server_runtime_more.rs
  • tests/server_runtime.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • tests/server_helpers.rs
  • src/server/worker.rs
  • tests/server_runtime_more.rs
  • tests/server_runtime.rs
🧬 Code Graph Analysis (2)
tests/server_helpers.rs (4)
tests/server_runtime.rs (2)
  • server (56-56)
  • WireframeServer (156-158)
tests/server_runtime_more.rs (1)
  • server (115-115)
src/server/worker.rs (1)
  • factory (148-150)
src/server.rs (1)
  • bind (268-274)
tests/server_runtime.rs (6)
src/extractor.rs (1)
  • std (270-270)
tests/server_runtime_more.rs (1)
  • server (115-115)
tests/server_helpers.rs (5)
  • WireframeServer (49-49)
  • bind_server (35-42)
  • factory (18-20)
  • free_port (23-27)
  • server_with_preamble (45-50)
src/server/worker.rs (1)
  • factory (148-150)
src/server.rs (6)
  • new (91-107)
  • worker_count (227-227)
  • local_addr (231-233)
  • has_preamble_success (235-235)
  • has_preamble_failure (237-237)
  • tests (494-991)
src/session.rs (1)
  • get (43-51)
⏰ Context from checks skipped due to timeout of 240000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-test
🔇 Additional comments (6)
src/server/worker.rs (3)

69-69: Error logging correctly uses tracing.

The error logging has been properly updated to use tracing::error! as previously suggested.


103-103: Function visibility is appropriately private.

The process_stream function is correctly private (default visibility) as it's only used within this module.


118-119: Error logging correctly uses tracing.

The preamble callback error logging has been properly updated to use tracing::error! as previously suggested.

tests/server_runtime_more.rs (2)

53-87: Test correctly verifies factory invocation behaviour.

The test properly asserts that the factory is not invoked until connections are made, with the count correctly remaining at 0 when no connections occur.


160-228: Test comprehensively verifies panic logging.

The test properly captures and verifies that panics in connection tasks are logged with the expected message, task identifier, and peer address information.

tests/server_runtime.rs (1)

76-88: Bind test now properly validates privileged port binding failure.

The test has been correctly updated to check for expected binding failure on privileged ports when not running with elevated privileges.

Comment on lines +34 to +35
#[allow(dead_code)]
pub fn bind_server<F>(factory: F, addr: SocketAddr) -> WireframeServer<F>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace #[allow(dead_code)] with #[expect(...)].

The coding guidelines forbid #[allow]. Use narrowly scoped #[expect(lint, reason = "...")] instead.

-#[allow(dead_code)]
+#[expect(dead_code, reason = "Used in integration tests")]
 pub fn bind_server<F>(factory: F, addr: SocketAddr) -> WireframeServer<F>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[allow(dead_code)]
pub fn bind_server<F>(factory: F, addr: SocketAddr) -> WireframeServer<F>
#[expect(dead_code, reason = "Used in integration tests")]
pub fn bind_server<F>(factory: F, addr: SocketAddr) -> WireframeServer<F>
🤖 Prompt for AI Agents
In tests/server_helpers.rs around lines 34 to 35, replace the attribute
#[allow(dead_code)] with #[expect(dead_code, reason = "explanation here")] to
comply with coding guidelines that forbid #[allow]. Use #[expect] with a
specific lint and a clear reason for the exception instead of a broad allow.

Comment on lines +44 to +45
#[allow(dead_code)]
pub fn server_with_preamble<F>(factory: F) -> WireframeServer<F, TestPreamble>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace #[allow(dead_code)] with #[expect(...)].

The coding guidelines forbid #[allow]. Use narrowly scoped #[expect(lint, reason = "...")] instead.

-#[allow(dead_code)]
+#[expect(dead_code, reason = "Used in integration tests")]
 pub fn server_with_preamble<F>(factory: F) -> WireframeServer<F, TestPreamble>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[allow(dead_code)]
pub fn server_with_preamble<F>(factory: F) -> WireframeServer<F, TestPreamble>
#[expect(dead_code, reason = "Used in integration tests")]
pub fn server_with_preamble<F>(factory: F) -> WireframeServer<F, TestPreamble>
🤖 Prompt for AI Agents
In tests/server_helpers.rs around lines 44 to 45, replace the attribute
#[allow(dead_code)] with #[expect(dead_code, reason = "...")], providing a clear
reason for expecting this lint. This change aligns with coding guidelines that
forbid #[allow] and prefer narrowly scoped #[expect] attributes.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant