Skip to content

Conversation

@insipx
Copy link
Contributor

@insipx insipx commented Dec 8, 2025

just a QoL change that removes some lines and allows more assumptions to be made in Cursor type implementation

@insipx
Copy link
Contributor Author

insipx commented Dec 8, 2025

This PR is part of a stack of 1 bookmark:

  1. trunk()
  2. insipx/seal-cursor ← this PR

Created with jj-stack

@claude
Copy link

claude bot commented Dec 8, 2025

Claude finished @insipx's task —— View job


Code Review Complete ✅

Review Date: December 11, 2025, 16:30 UTC

Tasks

  • Read core cursor type changes
  • Review constructor patterns and API design
  • Check for unreported bugs or issues
  • Assess test coverage gaps
  • Provide final review feedback

Summary

This PR successfully refactors Cursor to be non-exhaustive, forcing constructor usage instead of struct literals. The change is well-executed with excellent test coverage. I found one additional issue beyond what's already been commented on.

Issues Found

1. Missing Test Coverage for #[cfg(test)] Generate Implementation

Location: xmtp_proto/src/types/cursor.rs:86-94

The Generate trait implementation for Cursor still uses direct struct construction in test code:

#[cfg(any(test, feature = "test-utils"))]
impl xmtp_common::Generate for Cursor {
    fn generate() -> Self {
        Cursor {                           // Direct construction
            sequence_id: xmtp_common::rand_u64(),
            originator_id: openmls::test_utils::random_u32(),
        }
    }
}

Issue: While this is allowed within the same crate due to the #[cfg(test)] gate, it bypasses the constructor pattern. If Cursor gains new fields in the future, this test utility won't enforce proper initialization.

Recommendation: Update to use Cursor::new() for consistency:

fn generate() -> Self {
    Cursor::new(xmtp_common::rand_u64(), openmls::test_utils::random_u32())
}

2. Hardcoded Cursor in stream_messages.rs (Already Noted)

Location: xmtp_mls/src/subscriptions/stream_messages.rs:262

Macroscope already identified this issue - the hardcoded cursor ignores the topic_cursor parameter and contradicts the function documentation.

Positive Observations

  1. Excellent API Design: The typed constructors (v3_welcomes(), mls_commits(), etc.) provide a type-safe, self-documenting API that's superior to raw struct construction.

  2. Comprehensive Refactoring: The PR touches 23 files and successfully eliminates 390 lines of boilerplate while improving API safety.

  3. Strong Test Coverage: 89.69% patch coverage with thorough tests for the constructor methods (xmtp_proto/src/types/cursor.rs:140-164).

  4. Good Use of const fn: All typed constructors are const, allowing compile-time evaluation when possible.

  5. Proper IntoIterator Implementation: The PR maintains the existing iterator implementations, ensuring no breaking changes to iteration patterns.

Minor Notes

  • The new() constructor uses a generic Into<u32> for originator_id, which provides nice ergonomics for passing both u32 and the Originators constants.
  • The code quality is high with appropriate use of #[non_exhaustive] to prevent ad-hoc construction while maintaining field access.

@macroscopeapp
Copy link
Contributor

macroscopeapp bot commented Dec 9, 2025

Make xmtp_proto::types::Cursor non-exhaustive and replace all struct literals with Cursor::new(...) across protocol, DB, MLS, and tests

Annotates xmtp_proto::types::Cursor with #[non_exhaustive] and refactors all call sites to construct cursors via Cursor::new(...) (and helpers like Cursor::mls_commits(...) and Cursor::v3_welcomes(...)), replacing direct struct literals in protocol extractors, DB stores/queries, MLS subscriptions/streams, and tests. Key definition change is in cursor.rs.

📍Where to Start

Start with the Cursor definition and constructors in cursor.rs, then review call-site refactors such as GlobalCursor usage in global_cursor.rs.


Macroscope summarized 5f7751f.

@insipx insipx force-pushed the insipx/test-ordering branch from d39a146 to 69942d5 Compare December 9, 2025 20:30
@insipx insipx force-pushed the insipx/seal-cursor branch from cd215c2 to e70a63d Compare December 9, 2025 20:30
@insipx insipx force-pushed the insipx/test-ordering branch from 69942d5 to 461cc93 Compare December 9, 2025 20:36
@insipx insipx force-pushed the insipx/seal-cursor branch from e70a63d to 08f98e2 Compare December 9, 2025 20:36
@insipx insipx force-pushed the insipx/test-ordering branch from 461cc93 to c3c2c48 Compare December 9, 2025 20:39
@insipx insipx force-pushed the insipx/seal-cursor branch from 08f98e2 to 9cc1584 Compare December 9, 2025 20:39
@insipx insipx changed the title seal cursor struct fields to disallow ad-hoc construction make Cursor non-exhaustive Dec 9, 2025
@insipx insipx force-pushed the insipx/seal-cursor branch from 9cc1584 to 61ec15f Compare December 9, 2025 20:46
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 96.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.69%. Comparing base (418c978) to head (5f7751f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
xmtp_proto/src/types/global_cursor.rs 66.66% 2 Missing ⚠️
xmtp_mls/src/subscriptions/process_welcome.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2917      +/-   ##
==========================================
- Coverage   73.78%   73.69%   -0.10%     
==========================================
  Files         401      401              
  Lines       51265    51031     -234     
==========================================
- Hits        37828    37609     -219     
+ Misses      13437    13422      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@insipx insipx force-pushed the insipx/test-ordering branch from c3c2c48 to cb3d961 Compare December 10, 2025 16:20
@insipx insipx force-pushed the insipx/seal-cursor branch from 61ec15f to 2e74327 Compare December 10, 2025 16:20
This was referenced Dec 10, 2025
@insipx insipx force-pushed the insipx/seal-cursor branch 2 times, most recently from 39b43bd to b65db13 Compare December 10, 2025 21:02
@insipx insipx force-pushed the insipx/test-ordering branch 2 times, most recently from 0e3eaf3 to 2e3d8a4 Compare December 10, 2025 21:26
@insipx insipx force-pushed the insipx/seal-cursor branch 2 times, most recently from 2b9ddbf to b4c17ae Compare December 10, 2025 21:28
@insipx insipx force-pushed the insipx/test-ordering branch 2 times, most recently from 700aa21 to ede61ed Compare December 10, 2025 21:38
@insipx insipx force-pushed the insipx/seal-cursor branch from b4c17ae to ccbce66 Compare December 10, 2025 21:38
@insipx insipx force-pushed the insipx/test-ordering branch from ede61ed to 64c04b6 Compare December 10, 2025 21:39
@insipx insipx force-pushed the insipx/seal-cursor branch 2 times, most recently from 1f0f0e9 to c7ae33f Compare December 10, 2025 22:04
@insipx insipx force-pushed the insipx/test-ordering branch from 64c04b6 to 7b85061 Compare December 10, 2025 22:04
@insipx insipx force-pushed the insipx/test-ordering branch from 241233c to f2e74fa Compare December 11, 2025 19:43
@insipx insipx changed the base branch from insipx/test-ordering to main December 11, 2025 19:45
@insipx insipx force-pushed the insipx/seal-cursor branch from 83c306b to c61636b Compare December 11, 2025 19:45
@insipx insipx enabled auto-merge (squash) December 11, 2025 19:46
@insipx insipx force-pushed the insipx/seal-cursor branch from c61636b to 5f7751f Compare December 11, 2025 19:46
@insipx insipx merged commit fc5cf12 into main Dec 11, 2025
15 of 16 checks passed
@insipx insipx deleted the insipx/seal-cursor branch December 11, 2025 20:10
rygine pushed a commit that referenced this pull request Dec 28, 2025
just a QoL change that removes some lines and allows more assumptions to
be made in `Cursor` type implementation
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.

3 participants