Skip to content

Add wireframe_testing crate#115

Merged
leynos merged 4 commits intomainfrom
49h8ga-codex/implement-wireframe-testing-crate
Jun 23, 2025
Merged

Add wireframe_testing crate#115
leynos merged 4 commits intomainfrom
49h8ga-codex/implement-wireframe-testing-crate

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 23, 2025

Summary

  • add a new wireframe_testing crate with helpers for driving apps using in-memory streams
  • replace the old tests/util.rs helpers with the new crate
  • update tests to use wireframe_testing

Testing

  • make lint
  • make test

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

Summary by Sourcery

Introduce a dedicated wireframe_testing crate for driving WireframeApp instances over in-memory streams and migrate existing tests to use its utilities

New Features:

  • Add wireframe_testing crate with TestSerializer trait and drive_with_frame(s)/drive_with_bincode helpers

Enhancements:

  • Remove legacy tests/util.rs and update metadata.rs and routes.rs to use wireframe_testing helpers

Build:

  • Add wireframe_testing as a dev-dependency in Cargo.toml

Tests:

  • Refactor all existing tests to call drive_with_frame and drive_with_frames from wireframe_testing instead of the old util module

Summary by CodeRabbit

  • Chores
    • Moved internal test utilities to a new external development dependency, streamlining test code and imports.
  • Refactor
    • Updated test files to use shared testing helpers from the new dependency, improving maintainability.
  • New Features
    • Introduced a reusable testing library with helper functions to facilitate testing of the application.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 23, 2025

Reviewer's Guide

This PR introduces a new wireframe_testing crate with in-memory stream drivers, removes the old test utilities, and updates existing tests and workspace configuration to use the new crate.

Class diagram for the new wireframe_testing crate

classDiagram
    class TestSerializer {
        <<trait>>
        +Serializer
        +FrameMetadata<Frame = Envelope>
        +Send
        +Sync
        +'static
    }
    class WireframeApp {
    }
    class Packet {
        <<trait>>
    }
    class drive_with_frame {
        +async fn drive_with_frame(app, frame) -> io::Result<Vec<u8>>
    }
    class drive_with_frame_with_capacity {
        +async fn drive_with_frame_with_capacity(app, frame, capacity) -> io::Result<Vec<u8>>
    }
    class drive_with_frames {
        +async fn drive_with_frames(app, frames) -> io::Result<Vec<u8>>
    }
    class drive_with_frames_with_capacity {
        +async fn drive_with_frames_with_capacity(app, frames, capacity) -> io::Result<Vec<u8>>
    }
    class drive_with_bincode {
        +async fn drive_with_bincode(app, msg) -> io::Result<Vec<u8>>
    }
    TestSerializer <|.. WireframeApp : uses
    drive_with_frame ..> WireframeApp : app param
    drive_with_frame_with_capacity ..> WireframeApp : app param
    drive_with_frames ..> WireframeApp : app param
    drive_with_frames_with_capacity ..> WireframeApp : app param
    drive_with_bincode ..> WireframeApp : app param
    drive_with_bincode ..> TestSerializer : S param
    drive_with_frame ..> TestSerializer : S param
    drive_with_frame_with_capacity ..> TestSerializer : S param
    drive_with_frames ..> TestSerializer : S param
    drive_with_frames_with_capacity ..> TestSerializer : S param
    drive_with_bincode ..> Packet : E param
    drive_with_frame ..> Packet : E param
    drive_with_frame_with_capacity ..> Packet : E param
    drive_with_frames ..> Packet : E param
    drive_with_frames_with_capacity ..> Packet : E param
Loading

File-Level Changes

Change Details Files
Introduce wireframe_testing crate to drive apps over in-memory streams
  • Add helpers.rs with drive and serializer utilities
  • Add lib.rs re-exporting helper functions
  • Create Cargo.toml defining the new crate and its dependencies
wireframe_testing/src/helpers.rs
wireframe_testing/src/lib.rs
wireframe_testing/Cargo.toml
Remove legacy test utility module
  • Delete tests/util.rs
tests/util.rs
Update tests to use the new testing crate
  • Replace use util::{…} with use wireframe_testing::{…} imports
  • Replace calls to run_app_with_frame and run_app_with_frames with drive_with_frame and drive_with_frames
tests/metadata.rs
tests/routes.rs
Add wireframe_testing as a dev-dependency in the workspace
  • Add wireframe_testing = { path = "./wireframe_testing" } under [dev-dependencies]
Cargo.toml

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 23, 2025

Walkthrough

This change removes local test utilities for driving the WireframeApp and replaces them with equivalent functions from a new external crate, wireframe_testing. The new crate is added as a development dependency and provides helper functions for test scenarios. Test files are updated to use these external helpers, and the local util.rs is deleted.

Changes

File(s) Change Summary
Cargo.toml Added wireframe_testing as a local development dependency.
tests/metadata.rs, tests/routes.rs Replaced imports and usage of local util helpers with equivalent functions from wireframe_testing.
tests/util.rs Deleted file. Removed all test helper traits and functions for running WireframeApp with frames.
wireframe_testing/Cargo.toml Added new manifest for the wireframe_testing crate, specifying dependencies and metadata.
wireframe_testing/src/helpers.rs Added new helper module with async functions and a trait alias for driving WireframeApp in tests.
wireframe_testing/src/lib.rs Declared and re-exported the helpers module and its public items for external use.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Function
    participant Helpers as wireframe_testing::helpers
    participant App as WireframeApp
    participant Stream as DuplexStream

    Test->>Helpers: drive_with_frame(app, frame)
    Helpers->>Stream: Create duplex stream
    Helpers->>App: Spawn handle_connection(server_side)
    Helpers->>Stream: Write frame(s) to client_side
    Helpers->>Stream: Shutdown client_side write
    Helpers->>Stream: Read all output from client_side
    Helpers->>App: Await handle_connection completion
    Helpers-->>Test: Return output bytes
Loading

Possibly related PRs

Poem

A helper’s hop from here to there,
Now lives within a crate so fair.
No more local tricks or hacks,
Just import and test—relax!
With frames and streams, we bound along,
Our tests now cheerful, swift, and strong.
🐇✨


📜 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 f868861 and d7659b7.

📒 Files selected for processing (5)
  • tests/metadata.rs (3 hunks)
  • tests/routes.rs (3 hunks)
  • wireframe_testing/Cargo.toml (1 hunks)
  • wireframe_testing/src/helpers.rs (1 hunks)
  • wireframe_testing/src/lib.rs (1 hunks)
🔇 Additional comments (12)
wireframe_testing/Cargo.toml (1)

1-14: LGTM: Well-configured testing crate manifest.

The Cargo.toml is properly structured with appropriate dependencies for a testing utility crate. The explicit semver ranges and version pinning align with best practices for dependency management.

tests/routes.rs (3)

15-15: LGTM: Clean migration to external testing utilities.

The import of testing helpers from the new wireframe_testing crate properly replaces the previous local utilities.


59-61: LGTM: Proper usage of drive_with_bincode helper.

The function call correctly uses .expect() with a descriptive error message, addressing previous feedback about error handling clarity.


103-105: LGTM: Appropriate usage of drive_with_frames helper.

The multi-frame test helper is used correctly with proper error handling via .expect().

tests/metadata.rs (3)

11-11: LGTM: Appropriate imports for testing utilities.

The import of TestSerializer trait and drive_with_bincode function properly supports the test infrastructure migration.


13-23: LGTM: Well-designed mock function with proper trait bounds.

The mock_wireframe_app_with_serializer function correctly uses the TestSerializer trait bound, ensuring type safety whilst maintaining flexibility for different serializer implementations.


61-63: LGTM: Consistent error handling in test helpers.

Both test functions properly use .expect() with descriptive messages, providing clear diagnostics for test failures.

Also applies to: 106-108

wireframe_testing/src/lib.rs (1)

1-28: LGTM: Well-documented crate with ergonomic API.

The crate provides comprehensive documentation with usage examples and clean public re-exports. The API design makes the testing utilities easily accessible whilst maintaining good organisation through the helpers module.

wireframe_testing/src/helpers.rs (4)

10-17: LGTM: Well-designed trait abstraction.

The TestSerializer trait elegantly combines the required traits (Serializer, FrameMetadata<Frame = Envelope>, and concurrency traits) into a single bound, simplifying the API whilst maintaining type safety.


58-88: LGTM: Robust duplex stream testing implementation.

The core implementation correctly handles the duplex stream pattern:

  • Proper task spawning and coordination
  • Correct shutdown sequence to avoid deadlocks
  • Enhanced error handling for server task failures (addresses previous feedback)

The logic ensures the server sees EOF by shutting down the client write side before reading responses.


127-153: LGTM: Efficient concurrent implementation for mutable references.

The mutable reference variant correctly uses tokio::join! to run server and client futures concurrently, providing an efficient alternative when app ownership transfer isn't desired.


155-174: LGTM: Robust convenience function with proper error handling.

The drive_with_bincode function provides a clean abstraction for common test scenarios. The error handling for bincode encoding has been improved with descriptive error messages (addresses previous feedback).

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch 49h8ga-codex/implement-wireframe-testing-crate

🪧 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 auto-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
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/tests/routes.rs is usually changed with: wireframe/tests/util.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

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.


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.

Copy link
Copy Markdown
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: 7

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a63bfa and f868861.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • Cargo.toml (1 hunks)
  • tests/metadata.rs (3 hunks)
  • tests/routes.rs (3 hunks)
  • tests/util.rs (0 hunks)
  • wireframe_testing/Cargo.toml (1 hunks)
  • wireframe_testing/src/helpers.rs (1 hunks)
  • wireframe_testing/src/lib.rs (1 hunks)
💤 Files with no reviewable changes (1)
  • tests/util.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test
🔇 Additional comments (8)
wireframe_testing/Cargo.toml (1)

1-4: Verify Rust edition and complete package metadata.

Rust currently recognises editions "2015", "2018", and "2021". Please confirm that "2024" is supported by your toolchain. Additionally, consider adding standard manifest fields (authors, description, license) to make this crate ready for future publishing.

⛔ Skipped due to learnings
Learnt from: leynos
PR: leynos/mxd#137
File: postgres_setup_unpriv/Cargo.toml:4-4
Timestamp: 2025-06-16T23:32:38.317Z
Learning: Rust Edition 2024 is a valid and finalized edition that was officially released as part of Rust 1.85.0 on February 20, 2025. It can be used in Cargo.toml files with `edition = "2024"`.
Cargo.toml (1)

4-4: Verify Rust edition and development path.

Ensure that "edition = \"2024\"" is valid in your Rust toolchain, and confirm that the wireframe_testing dev-dependency path correctly points to the new crate location.

Also applies to: 17-17

tests/metadata.rs (1)

12-12: LGTM: external test helper import.

Replacing the old local util with wireframe_testing::drive_with_frame cleanly centralises test utilities.

tests/routes.rs (1)

15-15: LGTM: import external test helpers.

Switching to wireframe_testing::{drive_with_frame, drive_with_frames} aligns with the new crate structure.

wireframe_testing/src/lib.rs (1)

1-1: Confirm presence of the helpers module.

The declaration pub mod helpers; requires a corresponding src/helpers.rs or src/helpers/mod.rs. Please verify that it was included in the PR to avoid build errors.

wireframe_testing/src/helpers.rs (3)

1-8: Imports look comprehensive and appropriate.

All necessary dependencies are imported for the testing functionality provided by this module.


10-17: Well-designed trait alias for test requirements.

The TestSerializer trait effectively combines all the necessary bounds for testing scenarios, and the blanket implementation provides a clean interface.


21-56: Good layered design with sensible defaults.

The helper functions provide a clean API with appropriate defaults, properly delegating to the core implementation with capacity control.

Comment thread wireframe_testing/Cargo.toml Outdated
Comment thread tests/metadata.rs Outdated
Comment thread tests/routes.rs Outdated
Comment thread tests/routes.rs Outdated
Comment thread wireframe_testing/src/lib.rs
Comment thread wireframe_testing/src/helpers.rs Outdated
Comment thread wireframe_testing/src/helpers.rs Outdated
Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
metadata.rs 9.39 → 10.00 Code Duplication

Absence of Expected Change Pattern

  • wireframe/tests/routes.rs is usually changed with: wireframe/tests/util.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
metadata.rs 9.39 → 10.00 Code Duplication

Absence of Expected Change Pattern

  • wireframe/tests/routes.rs is usually changed with: wireframe/tests/util.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
metadata.rs 9.39 → 10.00 Code Duplication

Absence of Expected Change Pattern

  • wireframe/tests/routes.rs is usually changed with: wireframe/tests/util.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 23, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 23, 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 78e2bda into main Jun 23, 2025
5 checks passed
@leynos leynos deleted the 49h8ga-codex/implement-wireframe-testing-crate branch June 23, 2025 01:53
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