Repository navigation
refactor(runtime): encode menu lifetime states in an enum - #499
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (2)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
🟢 Approval recommended
The enum refactor is a faithful, self-contained translation of the prior two-field logic with no external callers affected and comprehensive test coverage for the lifecycle transitions.
0 open findings
What changed in this PR
This PR refactors the menu lifetime tracking in the display runtime's menu session. Previously, MenuLifetime stored two independent Option<MenuToken> fields (active and latest), which could in principle represent contradictory states. The change replaces them with a single MenuLifetimeState enum (Unseen, Open(token), Closed(token)), making an open menu always carry its latest accepted token and encoding the valid states explicitly.
I verified the translation is semantically faithful:
showrejects when the previous (open or closed) token is>=the incoming token (same as the oldlatest-based guard), otherwise transitions toOpen.close/finishmoveOpen -> Closed(equivalent to clearingactivewhile keepinglatest).hideacceptance matches the old boolean logic case-by-case:Unseenaccepts,Openaccepts only an exact token match,Closedacceptsprevious <= token(the old==plus<branches combine to<=).reject/take_resultare unchanged, preserving FIFO result ordering.
The old invariant that active is Some only when it equals latest holds across all mutators, so no reachable behavior is lost. No external callers referenced the removed fields (controller.rs only uses the public methods).
Changes:
- Introduce
MenuLifetimeStateenum and replaceactive/latestfields with a singlestatefield. - Rewrite
show,close,hide, andfinishto operate on the enum while preserving revision ordering, stale-request rejection, and hide-before-show tombstones. - Add three focused tests covering close-without-result, newer-hide-after-close, and exactly-once delivery after a rejection.
| File | Description |
|---|---|
| crates/neomacs-display-runtime/src/menus/session.rs | Replaces the two-field menu lifetime representation with a MenuLifetimeState enum and rewrites the lifecycle methods equivalently. |
| crates/neomacs-display-runtime/src/menus/session/tests/session_test.rs | Adds three tests covering close behavior, newer hide requests, and exactly-once result delivery after rejection. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Menu lifetime tracking stored the active and latest snapshot tokens independently, allowing contradictory states to be represented. Replace those fields with
Unseen,Open(token), andClosed(token)so an open menu always carries its latest accepted token.Preserve revision ordering, stale-request rejection, hide-before-show tombstones, and queued result delivery. Closed snapshots retain their revision, and only open snapshots can produce a selection result. No dependencies or public API changes.
Validation: all 59 focused menu session tests pass, including three additional tests covering close behavior, newer hide requests, and exactly-once result delivery after rejection. Formatting and diff checks pass. Test cases remain in the related
tests/session_test.rsfile.