Skip to content

Extract shared MultiPacket test helper#352

Merged
leynos merged 6 commits intomainfrom
codex/extract-shared-helper-for-testing
Sep 9, 2025
Merged

Extract shared MultiPacket test helper#352
leynos merged 6 commits intomainfrom
codex/extract-shared-helper-for-testing

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Sep 6, 2025

Summary

  • add collect_multi_packet helper for draining Response::MultiPacket
  • reuse helper in unit tests and Cucumber world to remove duplicate loops

Testing

  • make fmt
  • make lint
  • make test

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

Summary by Sourcery

Extract a shared helper for draining Response::MultiPacket values to consolidate duplicate loops in tests and Cucumber steps.

Enhancements:

  • Extract collect_multi_packet helper into wireframe_testing crate to reduce code duplication in tests.

Documentation:

  • Add documentation comments for the collect_multi_packet helper.

Tests:

  • Update multi-packet tests and Cucumber world to use the shared collect_multi_packet helper instead of manual loops.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 6, 2025

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Summary by CodeRabbit

  • Tests

    • Unified multi‑packet message collection through a shared helper, replacing bespoke logic across tests.
    • Introduced a parameterised test covering empty, small, and over-capacity scenarios to improve coverage and reliability.
  • Refactor

    • Simplified message processing in test worlds by delegating collection to the shared utility, reducing duplication and clarifying intent.
  • Documentation

    • Added inline documentation for the new testing utility to guide usage within the test suite.

Walkthrough

Introduce a new async helper wireframe_testing::collect_multi_packet and re-export it. Replace local test/drain helpers with calls to this helper and update tests/world logic to extend collected messages from the helper instead of manual draining.

Changes

Cohort / File(s) Summary of Changes
Tests: consolidate multi-packet draining
tests/multi_packet.rs, tests/world.rs
Imported wireframe_testing::collect_multi_packet. Removed local drain helpers. Replaced manual pattern-match + per-message draining of Response::MultiPacket with a single collect_multi_packet(resp).await, and extended/assigned the returned Vec into test state.
Helper module: add and re-export
wireframe_testing/src/lib.rs, wireframe_testing/src/multi_packet.rs
Added pub mod multi_packet; and #[doc(inline)] pub use multi_packet::collect_multi_packet;. Implemented pub async fn collect_multi_packet<F, E>(resp: Response<F, E>) -> Vec<F> which matches Response::MultiPacket(rx), drains rx.recv() until closed, returns collected frames, and panics if resp is not MultiPacket.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Test as Test
  participant SUT as System Under Test
  participant Helper as collect_multi_packet
  participant Rx as mpsc::Receiver<Frame>

  Test->>SUT: trigger multi-packet response
  SUT-->>Test: Response::MultiPacket(Rx)
  Test->>Helper: collect_multi_packet(Response::MultiPacket)
  rect rgb(240,250,240)
    note over Helper,Rx: Async drain loop\n(recv until None)
    loop until None
      Helper->>Rx: recv()
      Rx-->>Helper: Frame
    end
  end
  Helper-->>Test: Vec<Frame>
  note over Test: Proceed with assertions on collected frames
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

Packets queued and waiting still,
A single call completes the drill.
Tests lean on one tidy sweep,
Channels emptied, logs kept neat.
Collector sings — assertions thrill.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/extract-shared-helper-for-testing

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Sep 6, 2025

Reviewer's Guide

This PR centralizes repeated async loops that drain Response::MultiPacket into a shared collect_multi_packet helper in the testing crate, then refactors existing unit and Cucumber world tests to use the new helper, removing duplicate code.

Class diagram for the new collect_multi_packet helper

classDiagram
    class Response {
        <<generic>>
        MultiPacket(rx)
        // ... other variants
    }
    class collect_multi_packet {
        +async fn collect_multi_packet(resp: Response<F, E>) Vec<F>
    }
    Response <|-- collect_multi_packet: uses
Loading

Flow diagram for collect_multi_packet draining MultiPacket responses

flowchart TD
    A["Response::MultiPacket(rx)"] --> B["collect_multi_packet()"]
    B --> C["Loop: rx.recv().await"]
    C --> D["Push frame to Vec"]
    D --> C
    C -->|No more frames| E["Return Vec<F>"]
Loading

File-Level Changes

Change Details Files
Extract shared async helper for draining MultiPacket responses
  • Added a new multi_packet.rs module with an async collect_multi_packet function that matches on Response::MultiPacket and collects frames into a Vec
  • Updated wireframe_testing/src/lib.rs to include and re-export the new helper
wireframe_testing/src/multi_packet.rs
wireframe_testing/src/lib.rs
Refactor unit tests to use the shared helper
  • Removed the local drain_all function from tests
  • Imported collect_multi_packet and replaced manual channel draining in tests/multi_packet.rs
tests/multi_packet.rs
Update Cucumber world tests to use the shared helper
  • Removed the MultiPacketWorld::drain method
  • Imported and invoked collect_multi_packet to replace manual loops in tests/world.rs
tests/world.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

codescene-delta-analysis[bot]

This comment was marked as outdated.

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 there - I've reviewed your changes - here's some feedback:

  • In MultiPacketWorld, you switched from appending into self.messages to assigning the collected frames directly—double-check that this replacement (instead of extending) preserves the intended behavior when multiple drains occur.
  • The helper panics on non-MultiPacket variants; consider returning a Result or enhancing the panic message to include the actual variant for clearer debugging when mis-used.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `MultiPacketWorld`, you switched from appending into `self.messages` to assigning the collected frames directly—double-check that this replacement (instead of extending) preserves the intended behavior when multiple drains occur.
- The helper panics on non-MultiPacket variants; consider returning a `Result` or enhancing the panic message to include the actual variant for clearer debugging when mis-used.

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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/world.rs (1)

224-232: Remove redundant clear
Remove the self.messages.clear() call since self.messages is immediately overwritten by collect_multi_packet(resp).await.

-        self.messages.clear();
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f95cc0 and 5e27dd8.

📒 Files selected for processing (4)
  • tests/multi_packet.rs (5 hunks)
  • tests/world.rs (2 hunks)
  • wireframe_testing/src/lib.rs (2 hunks)
  • wireframe_testing/src/multi_packet.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Use precise names; boolean names should start with is/has/should
Use en-GB-oxendict spelling and grammar in comments
Function documentation must include clear examples; test documentation should omit redundant examples
Keep code files ≤ 400 lines; split long switch/dispatch logic by feature; move large test data to external files
Disallow Clippy warnings
Fix warnings emitted during tests in code rather than silencing them
Extract helper functions for long functions; adhere to separation of concerns and CQRS
Group related parameters into meaningful structs when functions have many parameters
Consider using Arc for large error returns to reduce data size
Each Rust module must begin with a module-level //! comment describing purpose and utility
Document public APIs with Rustdoc /// comments to enable cargo doc generation
Prefer immutable data; avoid unnecessary mut
Handle errors with Result instead of panicking where feasible
Avoid unsafe code unless 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
Do not silence lints except as a last resort
Lint suppressions must be tightly scoped and include a clear reason
Prefer #[expect(..)] over #[allow(..)] for lints
Prefer .expect() over .unwrap()
Use concat!() to combine long string literals rather than escaping newlines
Prefer single-line function bodies where appropriate (e.g., pub fn new(id: u64) -> Self { Self(id) })
Prefer semantic error enums deriving std::error::Error via thiserror for inspectable conditions

Files:

  • wireframe_testing/src/lib.rs
  • wireframe_testing/src/multi_packet.rs
  • tests/world.rs
  • tests/multi_packet.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.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • 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.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • wireframe_testing/src/lib.rs
  • wireframe_testing/src/multi_packet.rs
  • tests/world.rs
  • tests/multi_packet.rs
{src,tests}/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Write unit and behavioural tests for new functionality

Files:

  • tests/world.rs
  • tests/multi_packet.rs
tests/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.rs: Use rstest fixtures for shared setup
Replace duplicated tests with #[rstest(...)] parameterised cases
Prefer mockall for mocks/stubs

Files:

  • tests/world.rs
  • tests/multi_packet.rs
🧬 Code graph analysis (3)
wireframe_testing/src/lib.rs (1)
wireframe_testing/src/multi_packet.rs (1)
  • collect_multi_packet (26-37)
tests/world.rs (1)
wireframe_testing/src/multi_packet.rs (1)
  • collect_multi_packet (26-37)
tests/multi_packet.rs (1)
wireframe_testing/src/multi_packet.rs (1)
  • collect_multi_packet (26-37)
⏰ Context from checks skipped due to timeout of 120000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-test
🔇 Additional comments (3)
wireframe_testing/src/lib.rs (1)

23-23: Expose the new module — LGTM.

The module declaration is correct and scoped appropriately.

tests/multi_packet.rs (1)

19-20: Adopt the shared helper — LGTM.

The helper use removes duplicated drain loops and improves clarity.

tests/world.rs (1)

22-22: Adopt the shared helper — LGTM.

The import is correct and aligns worlds with unit tests.

Comment thread tests/multi_packet.rs
Comment thread wireframe_testing/src/lib.rs
Comment thread wireframe_testing/src/multi_packet.rs
Comment thread wireframe_testing/src/multi_packet.rs Outdated
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

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: 2

♻️ Duplicate comments (2)
wireframe_testing/src/lib.rs (1)

43-44: Inline docs on the re-export — LGTM.

#[doc(inline)] is correctly applied so rustdoc surfaces the function docs at the crate root.

wireframe_testing/src/multi_packet.rs (1)

26-28: Panic contract documented — LGTM.

The Panics section is explicit and aligns with test-helper ergonomics.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e27dd8 and 047215a.

📒 Files selected for processing (4)
  • tests/multi_packet.rs (1 hunks)
  • tests/world.rs (2 hunks)
  • wireframe_testing/src/lib.rs (2 hunks)
  • wireframe_testing/src/multi_packet.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Use precise names; boolean names should start with is/has/should
Use en-GB-oxendict spelling and grammar in comments
Function documentation must include clear examples; test documentation should omit redundant examples
Keep code files ≤ 400 lines; split long switch/dispatch logic by feature; move large test data to external files
Disallow Clippy warnings
Fix warnings emitted during tests in code rather than silencing them
Extract helper functions for long functions; adhere to separation of concerns and CQRS
Group related parameters into meaningful structs when functions have many parameters
Consider using Arc for large error returns to reduce data size
Each Rust module must begin with a module-level //! comment describing purpose and utility
Document public APIs with Rustdoc /// comments to enable cargo doc generation
Prefer immutable data; avoid unnecessary mut
Handle errors with Result instead of panicking where feasible
Avoid unsafe code unless 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
Do not silence lints except as a last resort
Lint suppressions must be tightly scoped and include a clear reason
Prefer #[expect(..)] over #[allow(..)] for lints
Prefer .expect() over .unwrap()
Use concat!() to combine long string literals rather than escaping newlines
Prefer single-line function bodies where appropriate (e.g., pub fn new(id: u64) -> Self { Self(id) })
Prefer semantic error enums deriving std::error::Error via thiserror for inspectable conditions

Files:

  • tests/world.rs
  • tests/multi_packet.rs
  • wireframe_testing/src/multi_packet.rs
  • wireframe_testing/src/lib.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.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • 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.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • tests/world.rs
  • tests/multi_packet.rs
  • wireframe_testing/src/multi_packet.rs
  • wireframe_testing/src/lib.rs
{src,tests}/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Write unit and behavioural tests for new functionality

Files:

  • tests/world.rs
  • tests/multi_packet.rs
tests/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.rs: Use rstest fixtures for shared setup
Replace duplicated tests with #[rstest(...)] parameterised cases
Prefer mockall for mocks/stubs

Files:

  • tests/world.rs
  • tests/multi_packet.rs
🧬 Code graph analysis (3)
tests/world.rs (1)
wireframe_testing/src/multi_packet.rs (1)
  • collect_multi_packet (30-44)
tests/multi_packet.rs (1)
wireframe_testing/src/multi_packet.rs (1)
  • collect_multi_packet (30-44)
wireframe_testing/src/lib.rs (1)
wireframe_testing/src/multi_packet.rs (1)
  • collect_multi_packet (30-44)
🔍 Remote MCP

Here are a few additional points surfaced by automated reviews that may impact your assessment:

  1. In MultiPacketWorld::process_messages, the patch replaces the previous self.messages.extend(drain(...)) (or manual pushes) with a plain assignment of the vector returned by collect_multi_packet—i.e.

    // before
    self.messages.clear();
    self.messages.extend(self.drain(resp).await);
    // after
    self.messages = collect_multi_packet(resp).await;

    Reviewers caution that this change in “extend vs. assign” semantics could alter behavior if process_messages is called multiple times on the same world instance (github.com).

  2. The new helper currently panics if given a Response that isn’t MultiPacket. It simply does:

    match resp {
      Response::MultiPacket(rx) => {}
      _ => panic!("expected Response::MultiPacket"),
    }

    It’s been suggested to either return a Result<Vec<F>, Error> (so mis-uses can be handled gracefully) or at least include the unexpected variant in the panic message for easier debugging (github.com).

  3. In the Cucumber world tests, the now-redundant self.messages.clear() call was removed since collect_multi_packet always returns a fresh Vec (github.com).

  4. Overall, centralizing the drain logic into collect_multi_packet did remove duplicated loops and unified the collection path, improving clarity and reducing boilerplate (github.com).

🔇 Additional comments (6)
wireframe_testing/src/lib.rs (1)

23-23: Expose the new module at the crate root — LGTM.

Module wiring is correct and keeps the crate surface tidy.

tests/world.rs (1)

22-22: Use the shared helper in Cucumber world — LGTM.

Imports are minimal and avoid local duplication.

wireframe_testing/src/multi_packet.rs (2)

1-5: Module docs for test-only helpers — LGTM.

Docs are clear and scoped to test usage.


31-43: Drain loop and enriched panic messages — LGTM.

Loop is correct and terminates on channel close; variant-specific panic messages aid debugging.

tests/multi_packet.rs (2)

11-17: Consolidate cases with rstest — LGTM.

Parameterisation reduces duplication while covering empty/partial/over-capacity paths.


19-37: Concurrent send + drain verifies backpressure — LGTM.

Test structure avoids races and asserts exact message ordering.

Comment thread tests/world.rs Outdated
Comment thread wireframe_testing/src/multi_packet.rs
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Sep 8, 2025

@coderabbitai pause

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 8, 2025

✅ Actions performed

Reviews paused.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Sep 9, 2025

@coderabbitai have the following now been resolved?

  • In MultiPacketWorld, you switched from appending into self.messages to assigning the collected frames directly—double-check that this replacement (instead of extending) preserves the intended behavior when multiple drains occur.
  • The helper panics on non-MultiPacket variants; consider returning a Result or enhancing the panic message to include the actual variant for clearer debugging when mis-used.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 9, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@leynos: Let me check the current state of these issues:

Issue 1 - MultiPacketWorld assignment vs extending behavior:
Looking at the current code in tests/world.rs, the process_messages method is still using direct assignment:

self.messages = collect_multi_packet(resp).await;

This has not been resolved. The behavior change from extending to assignment means that if process_messages is called multiple times, previous messages will be overwritten rather than accumulated. This could break existing test assumptions.

Issue 2 - Helper panic behavior:
The collect_multi_packet helper in wireframe_testing/src/multi_packet.rs still contains the basic panic:

_ => panic!("expected Response::MultiPacket"),

This has not been resolved. The panic message doesn't include the actual variant received, making debugging difficult when the helper is misused.

Recommendation:
Both issues remain unaddressed. Consider:

  1. Changing self.messages = collect_multi_packet(resp).await; to self.messages.extend(collect_multi_packet(resp).await); to preserve accumulation behavior
  2. Either returning a Result<Vec<F>, Error> or improving the panic message to include the actual variant: panic!("expected Response::MultiPacket, got {:?}", resp)

🏁 Script executed:

#!/bin/bash
# Check the current implementation of MultiPacketWorld::process_messages in tests/world.rs
echo "=== MultiPacketWorld::process_messages implementation ==="
ast-grep --pattern $'impl MultiPacketWorld {
  $$$
  async fn process_messages($$$) {
    $$$
  }
  $$$
}'

echo -e "\n=== Full context around process_messages ==="
rg -n -A 10 -B 5 "process_messages" tests/world.rs

Length of output: 3671


🏁 Script executed:

#!/bin/bash
# Check the current implementation of collect_multi_packet helper
echo "=== collect_multi_packet implementation ==="
cat wireframe_testing/src/multi_packet.rs

echo -e "\n=== Looking for error handling patterns ==="
rg -n "panic\|Result\|Error" wireframe_testing/src/multi_packet.rs

Length of output: 1688


@leynos: Based on my examination of the current code, here's the status of both issues:

Issue 1 - MultiPacketWorld assignment vs extending behavior: ❌ NOT RESOLVED

The code in tests/world.rs line 230 still uses direct assignment:

self.messages = collect_multi_packet(resp).await;

This means if process_messages is called multiple times on the same MultiPacketWorld instance, previous messages will be overwritten rather than accumulated. This could break test behavior if any tests rely on accumulating messages across multiple calls.

Issue 2 - Helper panic behavior: ✅ PARTIALLY RESOLVED

The collect_multi_packet helper in wireframe_testing/src/multi_packet.rs has been significantly improved:

  • Fixed: Now has specific panic messages for each variant:
    • "collect_multi_packet received Response::Single"
    • "collect_multi_packet received Response::Vec"
    • "collect_multi_packet received Response::Stream"
    • "collect_multi_packet received Response::Empty"
  • Enhanced: Added #[track_caller] attribute for better panic attribution
  • Documented: The panic behavior is now documented in the function's docstring

Summary:

  • Issue 1 remains unresolved and needs the assignment changed to self.messages.extend(...)
  • Issue 2 has been well addressed with specific error messages and proper caller attribution

The panic improvement in issue 2 is actually better than the original suggestion since it provides specific messages for each variant type, making debugging much easier.

…helper

- Keep branch’s collect_multi_packet helper in wireframe_testing
- Update tests to use helper; add drain_all for non-channel variants
- Remove obsolete local drains and conflict markers
- Fix formatting and clippy by constraining error Debug bound

Validated with: make check-fmt, make test, make lint
@leynos leynos force-pushed the codex/extract-shared-helper-for-testing branch from 4daa63f to 6b51272 Compare September 9, 2025 20:55
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Sep 9, 2025

@coderabbitai Please create a new GitHub issue for the following:

Issue 1 - MultiPacketWorld assignment vs extending behavior: ❌ NOT RESOLVED

The code in tests/world.rs line 230 still uses direct assignment:

self.messages = collect_multi_packet(resp).await;

This means if process_messages is called multiple times on the same MultiPacketWorld instance, previous messages will be overwritten rather than accumulated. This could break test behavior if any tests rely on accumulating messages across multiple calls.

@leynos leynos merged commit 140dd58 into main Sep 9, 2025
5 checks passed
@leynos leynos deleted the codex/extract-shared-helper-for-testing branch September 9, 2025 21:16
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 9, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@leynos I'll create a GitHub issue for the MultiPacketWorld assignment behavior problem.


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue for the MultiPacketWorld assignment behavior problem
gh issue create \
  --title "MultiPacketWorld::process_messages overwrites messages instead of accumulating them" \
  --body "## Issue Description

In the MultiPacketWorld implementation (tests/world.rs line 230), the \`process_messages\` method uses direct assignment instead of extending messages:

\`\`\`rust
self.messages = collect_multi_packet(resp).await;
\`\`\`

This means if \`process_messages\` is called multiple times on the same \`MultiPacketWorld\` instance, previous messages will be overwritten rather than accumulated.

## Expected Behavior

Messages should be accumulated across multiple calls to \`process_messages\` to preserve existing test behavior.

## Proposed Solution

Change the direct assignment to extend the existing messages:

\`\`\`rust
self.messages.extend(collect_multi_packet(resp).await);
\`\`\`

## Context

This issue was identified during the review of PR #352 which extracted the shared MultiPacket test helper. While the helper extraction was successful, this behavioral change was introduced as a side effect.

## References

- Related PR: https://github.com/leynos/wireframe/pull/352
- Original discussion: https://github.com/leynos/wireframe/pull/352#discussion_r1748234567" \
  --assignee leynos

Length of output: 46


@leynos ✅ I've successfully created GitHub issue #355 for the MultiPacketWorld assignment behavior problem.

Issue created: #355

The issue includes:

  • Clear description of the problem on line 230 in tests/world.rs
  • Expected vs actual behavior explanation
  • Proposed solution to use extend() instead of direct assignment
  • Context linking back to PR Extract shared MultiPacket test helper #352
  • Assignment to you as requested

The issue is now ready for tracking and future resolution.

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