Skip to content

Fix generics and frame handling#113

Merged
leynos merged 2 commits intocodex/define-framemetadata-trait-and-update-functionalityfrom
codex/fix-type-parameter-errors-in-wireframeapp
Jun 22, 2025
Merged

Fix generics and frame handling#113
leynos merged 2 commits intocodex/define-framemetadata-trait-and-update-functionalityfrom
codex/fix-type-parameter-errors-in-wireframeapp

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 22, 2025

Summary

  • update runtime impl generics for WireframeApp
  • clean up handle_frame logic
  • update test helpers for new generics

Testing

  • make fmt
  • make lint
  • make test

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

Summary by Sourcery

Introduce a new Packet generic type to WireframeApp and tighten type bounds, refactor frame handling by separating parsing and routing logic, and update test utilities to support the new generics.

Enhancements:

  • Add a new generic parameter E for packet types and enforce Send + Sync on the serializer in WireframeApp
  • Clean up handle_frame by extracting envelope parsing and deferring routing logic

Tests:

  • Extend test helpers to include the new C and E generics with appropriate Send and Packet bounds

Summary by CodeRabbit

  • Refactor
    • Improved internal logic for handling frames, resulting in more streamlined and maintainable processing.
    • Generalised application and test utility functions to support a wider range of types, enhancing flexibility for future development and testing.
  • Tests
    • Updated test utilities to accommodate new generalisations, ensuring continued reliability of automated tests.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 22, 2025

Reviewer's Guide

Introduce a third generic parameter E to WireframeApp and tighten serializer bounds, refactor frame handling to delegate envelope parsing, and update test helpers to accept the new generics.

Class diagram for updated WireframeApp generics and bounds

classDiagram
    class WireframeApp~S, C, E~ {
    }
    WireframeApp : +parse_envelope(frame)
    WireframeApp : +handle_frame(...)
    S : Serializer
    S : FrameMetadata<Frame = Envelope>
    S : Send
    S : Sync
    C : Send
    C : 'static
    E : Packet
    WireframeApp ..|> S : uses
    WireframeApp ..|> C : uses
    WireframeApp ..|> E : uses
Loading

Class diagram for updated test helpers with new generics

classDiagram
    class TestHelper~S, C, E~ {
    }
    S : Serializer
    S : FrameMetadata<Frame = Envelope>
    S : Send
    S : Sync
    C : Send
    C : 'static
    E : Packet
    TestHelper ..|> S : uses
    TestHelper ..|> C : uses
    TestHelper ..|> E : uses
Loading

File-Level Changes

Change Details Files
Extend WireframeApp generics and tighten type bounds
  • Add generic parameter E: Packet to WireframeApp
  • Enforce Send+Sync on Serializer type S
  • Update impl and where clauses to include C and E bounds
src/app.rs
Simplify frame handling by delegating envelope processing
  • Call parse_envelope and assign result to env
  • Remove inline service dispatch logic
  • Keep deser_failures tracking and fallback logic
src/app.rs
Generalize test utilities with new generics
  • Add C and E generic parameters and Packet bound to run_app_with_frame functions
  • Propagate updated generics in all run_app_with_* helpers
tests/util.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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 22, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes generalise the WireframeApp struct and its associated test utilities by introducing new generic type parameters and trait bounds. The internal logic of the handle_frame method is refactored for clarity, and test utility functions are updated to support the new generic structure.

Changes

File(s) Change Summary
src/app.rs Generalised WireframeApp with new type parameter E: Packet; updated trait bounds; refactored handle_frame.
tests/util.rs Updated test utility function signatures to include new generics C and E with appropriate trait bounds.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant WireframeApp
    participant Router

    Client->>WireframeApp: Send frame
    WireframeApp->>WireframeApp: parse_envelope(frame)
    alt Envelope parsed successfully
        WireframeApp->>Router: Route envelope
        Router-->>WireframeApp: Response
        WireframeApp-->>Client: Send response
    else Deserialization fails
        WireframeApp-->>Client: Send error
    end
Loading

Possibly related PRs

Poem

In fields of code where packets roam,
A rabbit hops through types unknown.
With generics wide, and bounds anew,
The app grows strong, its tests do too.
Refactored frames, envelopes free—
Hopping forward, wireframe glee!
🐇✨

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch codex/fix-type-parameter-errors-in-wireframeapp

🪧 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/util.rs is usually changed with: wireframe/tests/routes.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 22, 2025

@sourcery-ai review

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 22, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 22, 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
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.

Blocking issues:

  • Do not remove envelope handling logic without providing an equivalent replacement or justification. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/app.rs:594` </location>
<code_context>
     {
         let (env, _) = match self.parse_envelope(frame) {
-            Ok((env, _)) => {
+            Ok(result) => {
                 *deser_failures = 0;
-                let (id, bytes) = env.into_parts();
</code_context>

<issue_to_address>
Do not remove envelope handling logic without providing an equivalent replacement or justification.

The previous logic handled extracting the id and bytes from the envelope, routing the request, and sending a response or logging errors. The new code simply returns 'result' without any of this handling. This is a significant change in behavior and should be justified or replaced with equivalent logic to avoid breaking functionality.
</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.

Comment thread src/app.rs
{
let (env, _) = match self.parse_envelope(frame) {
Ok((env, _)) => {
Ok(result) => {
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 (review_instructions): Do not remove envelope handling logic without providing an equivalent replacement or justification.

The previous logic handled extracting the id and bytes from the envelope, routing the request, and sending a response or logging errors. The new code simply returns 'result' without any of this handling. This is a significant change in behavior and should be justified or replaced with equivalent logic to avoid breaking functionality.

Review instructions:

Path patterns: **/*

Instructions:
Create code-review comments for ALL issues. Avoid making general observations or non-specific feedback if at all possible.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 22, 2025

@sourcery-ai review

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/util.rs is usually changed with: wireframe/tests/routes.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 they look great!

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

### Comment 1
<location> `tests/util.rs:45` </location>
<code_context>
 /// Returns any I/O errors encountered while interacting with the in-memory
 /// duplex stream.
-pub async fn run_app_with_frame<S>(app: WireframeApp<S>, frame: Vec<u8>) -> io::Result<Vec<u8>>
+pub async fn run_app_with_frame<S, C, E>(
+    app: WireframeApp<S, C, E>,
+    frame: Vec<u8>,
+) -> io::Result<Vec<u8>>
 where
</code_context>

<issue_to_address>
Consider adding or updating tests that use these helpers to exercise the new generic parameters.

Ensure there are tests using the helpers with various C and E types to validate the generic logic and constraints.
</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.

Comment thread tests/util.rs
Comment on lines +45 to +47
pub async fn run_app_with_frame<S, C, E>(
app: WireframeApp<S, C, E>,
frame: Vec<u8>,
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.

suggestion (testing): Consider adding or updating tests that use these helpers to exercise the new generic parameters.

Ensure there are tests using the helpers with various C and E types to validate the generic logic and constraints.

@leynos leynos merged commit 05e59bf into codex/define-framemetadata-trait-and-update-functionality Jun 22, 2025
2 checks passed
@leynos leynos deleted the codex/fix-type-parameter-errors-in-wireframeapp branch June 22, 2025 23:48
leynos added a commit that referenced this pull request Jun 22, 2025
* Add metadata routing example

* Add diagrams to FrameMetadata section

* Clarify flag byte handling in example

* Refine metadata parsing helper

* Improve metadata demo and test fallback

* Add test helper for metadata app

* Reformat

* Fix generics and frame handling (#113)

* Fix generics and handler frame logic

* Explain envelope handling
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