Skip to content

Add documentation for test helpers#236

Merged
leynos merged 1 commit intomainfrom
codex/add-doc-comments-for-public-functions
Aug 1, 2025
Merged

Add documentation for test helpers#236
leynos merged 1 commit intomainfrom
codex/add-doc-comments-for-public-functions

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Aug 1, 2025

Summary

  • document all public async helpers in wireframe_testing

Testing

  • make fmt
  • make lint
  • make test

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

Summary by Sourcery

Document all public asynchronous test helper functions in wireframe_testing by adding descriptive doc comments and usage examples.

Documentation:

  • Add doc comments and examples for drive_with_frame, drive_with_frame_with_capacity, drive_with_frames, and drive_with_frames_with_capacity functions.
  • Add doc comments and examples for mutable variants drive_with_frame_mut, drive_with_frame_with_capacity_mut, drive_with_frames_mut, and drive_with_frames_with_capacity_mut.
  • Add doc comments and examples for drive_with_bincode helper.
  • Add doc comments and examples for run_app_with_frame, run_app_with_frame_with_capacity, run_app_with_frames, run_app_with_frames_with_capacity, and run_with_duplex_server functions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 1, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new helper function for driving the app with bincode-encoded messages.
  • Documentation

    • Added comprehensive documentation and usage examples for all asynchronous helper functions related to driving or running the app with input frames.

Walkthrough

Add comprehensive Rustdoc documentation and usage examples to all public asynchronous helper functions in wireframe_testing/src/helpers.rs for driving a WireframeApp with input frames. Introduce a new helper, drive_with_bincode, for encoding messages with bincode and driving the app. Do not alter any core logic or control flow.

Changes

Cohort / File(s) Change Summary
Async Helper Documentation & Examples
wireframe_testing/src/helpers.rs
Add detailed Rustdoc comments and illustrative usage examples to all public async helper functions. Introduce new helper function drive_with_bincode for bincode-encoded frame driving. No logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant Tester
    participant Helpers
    participant WireframeApp

    Tester->>Helpers: Call drive_with_bincode(msg)
    Helpers->>Helpers: Encode msg with bincode
    Helpers->>WireframeApp: Drive app with framed bytes
    WireframeApp-->>Helpers: Return output
    Helpers-->>Tester: Return result
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • codescene-delta-analysis

Poem

Rustdoc blooms on helpers bright,
Usage guides now clear as light.
Bincode joins the testing dance,
Framed bytes given every chance.
No logic changed, just wisdom grown—
Let documentation seeds be sown!
📚✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent 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 3f06b7a.

📒 Files selected for processing (1)
  • wireframe_testing/src/helpers.rs (14 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:

  • wireframe_testing/src/helpers.rs
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: leynos/wireframe#0
File: docs/wireframe-testing-crate.md:0-0
Timestamp: 2025-07-31T19:23:31.827Z
Learning: Applies to docs/wireframe_testing/src/lib.rs : Expose asynchronous test helper functions (such as `drive_with_frame`, `drive_with_frames`, `drive_with_frame_with_capacity`, `drive_with_frames_with_capacity`, and `drive_with_bincode`) from `wireframe_testing/src/lib.rs`.
📚 Learning: applies to docs/wireframe_testing/src/lib.rs : expose asynchronous test helper functions (such as `d...
Learnt from: CR
PR: leynos/wireframe#0
File: docs/wireframe-testing-crate.md:0-0
Timestamp: 2025-07-31T19:23:31.827Z
Learning: Applies to docs/wireframe_testing/src/lib.rs : Expose asynchronous test helper functions (such as `drive_with_frame`, `drive_with_frames`, `drive_with_frame_with_capacity`, `drive_with_frames_with_capacity`, and `drive_with_bincode`) from `wireframe_testing/src/lib.rs`.

Applied to files:

  • wireframe_testing/src/helpers.rs
📚 Learning: applies to docs/wireframe_testing/src/helpers.rs : provide mutable variants of helper functions (suc...
Learnt from: CR
PR: leynos/wireframe#0
File: docs/wireframe-testing-crate.md:0-0
Timestamp: 2025-07-31T19:23:31.827Z
Learning: Applies to docs/wireframe_testing/src/helpers.rs : Provide mutable variants of helper functions (such as `drive_with_frame_mut` and `drive_with_frames_mut`) that borrow the `WireframeApp` mutably for scenarios where a single app instance should be reused across calls.

Applied to files:

  • wireframe_testing/src/helpers.rs
✨ 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/add-doc-comments-for-public-functions

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

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 1, 2025

Reviewer's Guide

This PR enriches the wireframe_testing helpers module by adding comprehensive Rustdoc comments and usage examples to all public async test helper functions, improving discoverability and guiding developers on how to integrate these utilities in their tests.

Class diagram for documented async test helpers in wireframe_testing

classDiagram
    class WireframeApp
    class TestSerializer

    class wireframe_testing_helpers {
        <<module>>
        +drive_with_frame(app, frame)
        +drive_with_frame_with_capacity(app, frame, capacity)
        +drive_with_frames(app, frames)
        +drive_with_frames_with_capacity(app, frames, capacity)
        +drive_with_frame_mut(&mut app, frame)
        +drive_with_frame_with_capacity_mut(&mut app, frame, capacity)
        +drive_with_frames_mut(&mut app, frames)
        +drive_with_frames_with_capacity_mut(&mut app, frames, capacity)
        +drive_with_bincode(app, msg)
        +run_app_with_frame(app, frame)
        +run_app_with_frame_with_capacity(app, frame, capacity)
        +run_app_with_frames(app, frames)
        +run_app_with_frames_with_capacity(app, frames, capacity)
        +run_with_duplex_server(app)
    }

    wireframe_testing_helpers ..> WireframeApp : uses
    wireframe_testing_helpers ..> TestSerializer : uses
    WireframeApp <|.. TestSerializer : trait bound
Loading

File-Level Changes

Change Details Files
Document frame-based helper functions
  • Add Rustdoc comments and examples to drive_with_frame and drive_with_frame_with_capacity
  • Add Rustdoc comments and examples to drive_with_frames and drive_with_frames_with_capacity
wireframe_testing/src/helpers.rs
Document mutable app helper functions
  • Add Rustdoc comments and examples to drive_with_frame_mut and drive_with_frame_with_capacity_mut
  • Add Rustdoc comments and examples to drive_with_frames_mut and drive_with_frames_with_capacity_mut
wireframe_testing/src/helpers.rs
Document serialization and run helpers
  • Add Rustdoc comments and examples to drive_with_bincode
  • Add Rustdoc comments and examples to run_app_with_frame variants, run_app_with_frames variants, and run_with_duplex_server
wireframe_testing/src/helpers.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
Copy Markdown
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.

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `wireframe_testing/src/helpers.rs:51` </location>
<code_context>
+/// # Ok(())
+/// # }
+/// ```
 pub async fn drive_with_frame<S, C, E>(
     app: WireframeApp<S, C, E>,
     frame: Vec<u8>,
</code_context>

<issue_to_address>
Consider replacing the many nearly identical forwarding helper functions with a small set of macros to generate them automatically.

Here’s one way to collapse all of those identical “forwarding” helpers into a tiny `macro_rules!` rather than hand‐writing each one.  You still keep the exact same public API, docs, and calls under the hood, but you remove dozens of near‐duplicate lines:

```rust
// before your helpers:
const DEFAULT_CAPACITY: usize = 4096;

// 1) define a small macro for the two shapes of forwarding functions
macro_rules! forward_default {
    // `drive_with_frame(mut)?`, `run_app_with_frame(mut)?`, etc.
    (
        /// $docs:tt
        $vis:vis fn $fn_name:ident ( $app:ident : $app_ty:ty, $arg:ident : $arg_ty:ty ) -> $ret:ty
        => $inner:ident ( $app, $arg, DEFAULT_CAPACITY )
    ) => {
        #[doc = $docs]
        $vis async fn $fn_name<S, C, E>(
            $app: $app_ty,
            $arg: $arg_ty,
        ) -> $ret
        where
            S: TestSerializer,
            C: Send + 'static,
            E: Packet,
        {
            $inner($app, $arg, DEFAULT_CAPACITY).await
        }
    };
}

macro_rules! forward_with_capacity {
    (
        /// $docs:tt
        $vis:vis fn $fn_name:ident ( $app:ident : $app_ty:ty, $arg:ident : $arg_ty:ty, capacity: usize ) -> $ret:ty
        => $inner:ident ( $app, $arg, capacity )
    ) => {
        #[doc = $docs]
        $vis async fn $fn_name<S, C, E>(
            $app: $app_ty,
            $arg: $arg_ty,
            capacity: usize,
        ) -> $ret
        where
            S: TestSerializer,
            C: Send + 'static,
            E: Packet,
        {
            $inner($app, $arg, capacity).await
        }
    };
}

// 2) invoke it for each variant.  Note how all the `drive_*`, `run_*`, `*_mut`
//    helpers collapse into four macro‐invocations:
forward_default! {
    /// Drive `app` with a single length‐prefixed `frame` and return the bytes
    pub fn drive_with_frame(app: WireframeApp<S, C, E>, frame: Vec<u8>) -> io::Result<Vec<u8>>
    => drive_with_frame_with_capacity(app, frame, DEFAULT_CAPACITY)
}

forward_with_capacity! {
    /// Drive `app` with a single frame using a duplex buffer of `capacity` bytes.
    pub fn drive_with_frame_with_capacity(app: WireframeApp<S, C, E>, frame: Vec<u8>, capacity: usize) -> io::Result<Vec<u8>>
    => drive_with_frames_with_capacity(app, frame, capacity)
}

// …and repeat for `drive_with_frames`, `drive_with_frames_with_capacity`,
//  `drive_with_frame_mut`, `drive_with_frame_with_capacity_mut`, etc.
//  Since each block is just forwarding, you now get all of them
//  from 4–8 lines of macro invocations instead of 50+ near‐dupes.
```

You can apply the same two macros for your `run_*` set, too.  This keeps the signatures and docs exactly the same but collapses yourdozens of almost identical functionsto just a handful of macro invocations.
</issue_to_address>

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.

/// # Ok(())
/// # }
/// ```
pub async fn drive_with_frame<S, C, E>(
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.

issue (complexity): Consider replacing the many nearly identical forwarding helper functions with a small set of macros to generate them automatically.

Here’s one way to collapse all of those identical “forwarding” helpers into a tiny macro_rules! rather than hand‐writing each one. You still keep the exact same public API, docs, and calls under the hood, but you remove dozens of near‐duplicate lines:

// before your helpers:
const DEFAULT_CAPACITY: usize = 4096;

// 1) define a small macro for the two shapes of forwarding functions
macro_rules! forward_default {
    // `drive_with_frame(mut)?`, `run_app_with_frame(mut)?`, etc.
    (
        /// $docs:tt
        $vis:vis fn $fn_name:ident ( $app:ident : $app_ty:ty, $arg:ident : $arg_ty:ty ) -> $ret:ty
        => $inner:ident ( $app, $arg, DEFAULT_CAPACITY )
    ) => {
        #[doc = $docs]
        $vis async fn $fn_name<S, C, E>(
            $app: $app_ty,
            $arg: $arg_ty,
        ) -> $ret
        where
            S: TestSerializer,
            C: Send + 'static,
            E: Packet,
        {
            $inner($app, $arg, DEFAULT_CAPACITY).await
        }
    };
}

macro_rules! forward_with_capacity {
    (
        /// $docs:tt
        $vis:vis fn $fn_name:ident ( $app:ident : $app_ty:ty, $arg:ident : $arg_ty:ty, capacity: usize ) -> $ret:ty
        => $inner:ident ( $app, $arg, capacity )
    ) => {
        #[doc = $docs]
        $vis async fn $fn_name<S, C, E>(
            $app: $app_ty,
            $arg: $arg_ty,
            capacity: usize,
        ) -> $ret
        where
            S: TestSerializer,
            C: Send + 'static,
            E: Packet,
        {
            $inner($app, $arg, capacity).await
        }
    };
}

// 2) invoke it for each variant.  Note how all the `drive_*`, `run_*`, `*_mut`
//    helpers collapse into four macro‐invocations:
forward_default! {
    /// Drive `app` with a single length‐prefixed `frame` and return the bytes
    pub fn drive_with_frame(app: WireframeApp<S, C, E>, frame: Vec<u8>) -> io::Result<Vec<u8>>
    => drive_with_frame_with_capacity(app, frame, DEFAULT_CAPACITY)
}

forward_with_capacity! {
    /// Drive `app` with a single frame using a duplex buffer of `capacity` bytes.
    pub fn drive_with_frame_with_capacity(app: WireframeApp<S, C, E>, frame: Vec<u8>, capacity: usize) -> io::Result<Vec<u8>>
    => drive_with_frames_with_capacity(app, frame, capacity)
}

// …and repeat for `drive_with_frames`, `drive_with_frames_with_capacity`,
//  `drive_with_frame_mut`, `drive_with_frame_with_capacity_mut`, etc.
//  Since each block is just forwarding, you now get all of them
//  from 4–8 lines of macro invocations instead of 50+ near‐dupes.

You can apply the same two macros for your run_* set, too. This keeps the signatures and docs exactly the same but collapses your “dozens of almost identical functions” to just a handful of macro invocations.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 1, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
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.

@leynos leynos merged commit 79244ac into main Aug 1, 2025
5 checks passed
@leynos leynos deleted the codex/add-doc-comments-for-public-functions branch August 1, 2025 15:06
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