Skip to content

Fix: updates restore models#130

Merged
grunch merged 4 commits intoMostroP2P:mainfrom
BraCR10:fix/update-restore-models
Feb 20, 2026
Merged

Fix: updates restore models#130
grunch merged 4 commits intoMostroP2P:mainfrom
BraCR10:fix/update-restore-models

Conversation

@BraCR10
Copy link
Member

@BraCR10 BraCR10 commented Feb 17, 2026

RestoredDisputesInfo was missing the initiator field. The struct is used in the restore-session response sent to clients.

Proposed changes:

  • Added initiator: Option<String> to RestoredDisputesInfo
  • Added buyer_dispute: bool and seller_dispute: bool to RestoredDisputeHelper so the encrypted-DB path in mostro can carry those values into Rust and derive the initiator after decryption

Closes #129

Summary by CodeRabbit

  • New Features
    • Improved dispute tracking with per-order flags for buyer vs. seller disputes.
    • Records who initiated a dispute (buyer, seller, or unknown) so initiator is visible where available.
    • More reliable display and restoration of dispute history when viewing orders.

Adds `buyer_dispute` and `seller_dispute` fields to `RestoredDisputeHelper` struct.

Also, adds `initiator` field to the `RestoredDisputesInfo` struct
to indicate who initiated the dispute.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2026

Warning

Rate limit exceeded

@BraCR10 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

RestoredDisputeHelper gains two booleans (buyer_dispute, seller_dispute) and a new DisputeInitiator enum is introduced. RestoredDisputesInfo adds initiator: Option<DisputeInitiator>. Tests updated to exercise serialization/deserialization and multiple initiator states.

Changes

Cohort / File(s) Summary
Message types & tests
src/message.rs, tests/*
Added pub buyer_dispute: bool and pub seller_dispute: bool to RestoredDisputeHelper; added pub enum DisputeInitiator { Buyer, Seller }; added pub initiator: Option<DisputeInitiator> to RestoredDisputesInfo; updated tests to cover roundtrip serialization and multiple initiator states.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I nibbled bytes and dug up clues,
Two flags for disputes, a seed to choose,
Buyer or seller, now clearly shown,
An initiator sprouted, neatly known.
Hooray — the restore knows who made the moan!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix: updates restore models' is vague and generic, failing to clearly communicate the specific changes made to the restore-related structs and the addition of dispute initiator tracking. Use a more specific title like 'Add initiator field to RestoredDisputesInfo and update RestoredDisputeHelper' to clearly convey the main changes.
Out of Scope Changes check ❓ Inconclusive The PR includes a scope enhancement beyond issue #129 requirements: replacing the string-based initiator with a DisputeInitiator enum for stronger typing instead of Option, which improves type safety. Clarify whether the enum-based initiator design change was intentional and approved, since it differs from the original String-based requirement in issue #129.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully implements the required changes: adds initiator field to RestoredDisputesInfo, adds buyer_dispute and seller_dispute fields to RestoredDisputeHelper, and includes comprehensive tests for serialization/deserialization.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@BraCR10 BraCR10 changed the title FIx: updates restore models Fix: updates restore models Feb 17, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
src/message.rs (3)

279-280: Consider adding /// doc comments for the new boolean fields.

The existing fields in this struct lack doc comments too, but since these booleans carry specific semantics (per the PR: used to derive initiator in Rust after decryption), brief docs would help future readers understand their purpose. As per coding guidelines: "Document public APIs with /// comments."

Also, there's no test coverage for RestoredDisputeHelper with these new fields — a serialization round-trip test would be valuable given the sqlx feature gate.

📝 Suggested doc comments
+    /// Whether the buyer initiated the dispute (used to derive `initiator` after decryption)
     pub buyer_dispute: bool,
+    /// Whether the seller initiated the dispute (used to derive `initiator` after decryption)
     pub seller_dispute: bool,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/message.rs` around lines 279 - 280, Add /// doc comments to the new
boolean fields buyer_dispute and seller_dispute in the RestoredDisputeHelper
struct describing their semantics (e.g., which party they indicate and that they
are used to derive initiator after decryption), and update the public API docs
accordingly; then add a serialization round-trip test for RestoredDisputeHelper
that constructs an instance with buyer_dispute/seller_dispute set, serializes
and deserializes (or uses sqlx row round-trip under the sqlx feature gate) and
asserts the booleans are preserved to cover the new fields.

761-767: Test only covers initiator: Some("buyer") — add a case for None.

The initiator field can be None (unknown initiator). Adding a second dispute entry with initiator: None to this test vector would verify that the Option serialization/deserialization handles the absent case correctly.

📝 Suggested addition
 let restored_disputes = vec![crate::message::RestoredDisputesInfo {
     dispute_id: uuid!("508e1272-d5f4-47e6-bd97-3504baea9c25"),
     order_id: uuid!("308e1272-d5f4-47e6-bd97-3504baea9c23"),
     trade_index: 1,
     status: "initiated".to_string(),
     initiator: Some("buyer".to_string()),
-}];
+},
+crate::message::RestoredDisputesInfo {
+    dispute_id: uuid!("608e1272-d5f4-47e6-bd97-3504baea9c26"),
+    order_id: uuid!("408e1272-d5f4-47e6-bd97-3504baea9c24"),
+    trade_index: 2,
+    status: "initiated".to_string(),
+    initiator: None,
+}];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/message.rs` around lines 761 - 767, The test vector restored_disputes
currently only includes a RestoredDisputesInfo with initiator: Some("buyer");
add a second RestoredDisputesInfo entry to restored_disputes with a different
dispute_id/order_id/trade_index and initiator: None to ensure Option
serialization/deserialization is exercised for the absent case; update any
assertions to expect two entries (including the one with initiator == None) and
reuse the same RestoredDisputesInfo struct name to locate the code block.

307-308: Free-form String for a field with a fixed set of values — consider a typed enum.

The initiator field is documented as "buyer", "seller", or null, which maps naturally to an Option<DisputeInitiator> enum. A string allows arbitrary values (e.g., "Buyer", "BUYER", typos) that would silently pass deserialization. If backward compatibility with existing JSON or SQL output requires a string, a #[serde(rename_all = ...)] enum can still produce the same wire format.

Not blocking, but worth considering for type safety — especially since this is a public API consumed by clients.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/message.rs` around lines 307 - 308, Replace the free-form initiator:
Option<String> with a typed enum to enforce allowed values: define an enum
DisputeInitiator (e.g., enum DisputeInitiator { Buyer, Seller }) derived
Serialize/Deserialize and annotate with #[serde(rename_all = "lowercase")] so
the wire format remains "buyer"/"seller", then change the field to pub
initiator: Option<DisputeInitiator> in the same struct; update any
serialization/deserialization call sites/tests that assume a raw string
accordingly. Ensure the enum derives Debug/Clone/PartialEq (and any other traits
used in this crate) to keep parity with the previous String usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/message.rs`:
- Around line 279-280: Add /// doc comments to the new boolean fields
buyer_dispute and seller_dispute in the RestoredDisputeHelper struct describing
their semantics (e.g., which party they indicate and that they are used to
derive initiator after decryption), and update the public API docs accordingly;
then add a serialization round-trip test for RestoredDisputeHelper that
constructs an instance with buyer_dispute/seller_dispute set, serializes and
deserializes (or uses sqlx row round-trip under the sqlx feature gate) and
asserts the booleans are preserved to cover the new fields.
- Around line 761-767: The test vector restored_disputes currently only includes
a RestoredDisputesInfo with initiator: Some("buyer"); add a second
RestoredDisputesInfo entry to restored_disputes with a different
dispute_id/order_id/trade_index and initiator: None to ensure Option
serialization/deserialization is exercised for the absent case; update any
assertions to expect two entries (including the one with initiator == None) and
reuse the same RestoredDisputesInfo struct name to locate the code block.
- Around line 307-308: Replace the free-form initiator: Option<String> with a
typed enum to enforce allowed values: define an enum DisputeInitiator (e.g.,
enum DisputeInitiator { Buyer, Seller }) derived Serialize/Deserialize and
annotate with #[serde(rename_all = "lowercase")] so the wire format remains
"buyer"/"seller", then change the field to pub initiator:
Option<DisputeInitiator> in the same struct; update any
serialization/deserialization call sites/tests that assume a raw string
accordingly. Ensure the enum derives Debug/Clone/PartialEq (and any other traits
used in this crate) to keep parity with the previous String usage.

@arkanoider
Copy link
Collaborator

uTACK for me!

@grunch grunch requested a review from mostronator February 19, 2026 21:21
Copy link
Member

@grunch grunch left a comment

Choose a reason for hiding this comment

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

please address rabbit nitpicks

Updates the `RestoredDisputesInfo` model to use an enum
(`DisputeInitiator`) instead of a string for representing
who initiated a dispute.

This provides type safety and better represents the possible
states. Also adds test coverage for serialization and
deserialization.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/message.rs`:
- Line 785: The tests use the wrong status string: update the status field in
the test fixtures inside test_restore_session_message and
test_restored_dispute_helper_serialization_roundtrip to use "in-progress"
(hyphen) instead of "in_progress" (underscore) so they match the canonical
status parsed by the Dispute/Status parsing logic; locate the two occurrences of
status: "in_progress".to_string() and replace them with status:
"in-progress".to_string().
- Around line 788-794: The third RestoredDisputesInfo test entry duplicates the
first entry's dispute_id (and order_id) due to a copy/paste; update the third
RestoredDisputesInfo struct instance so its dispute_id (and order_id if
appropriate) use distinct UUIDs (for example
"708e1272-d5f4-47e6-bd97-3504baea9c27") instead of reusing
uuid!("508e1272-d5f4-47e6-bd97-3504baea9c25"), ensuring each
RestoredDisputesInfo has a unique dispute_id (and unique order_id when
required).

Adds SQLx compatibility to the `DisputeInitiator` enum, enabling database storage.

The changes involve adding the `sqlx::Type` derive and specifying the
`type_name` and `rename_all` attributes for proper mapping in SQLx.
Updates the restored disputes info to ensure data integrity and
consistency in dispute-related operations.

Corrects the dispute status from "in_progress" to "in-progress"
and updates dispute IDs, order IDs, and trade indices for better
accuracy.
@BraCR10 BraCR10 requested a review from mostronator February 20, 2026 07:56
Copy link
Member

@grunch grunch left a comment

Choose a reason for hiding this comment

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

LGTM

@grunch grunch merged commit 69080c0 into MostroP2P:main Feb 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Add initiator to RestoredDisputesInfo and update RestoredDisputeHelper

3 participants