refactor(events): model ServerAck.class as Option, document payload stability - #1000
Conversation
…tability ServerAck.class used an empty-string sentinel for an absent class, which went against the Option-for-absent convention every other event payload in events.rs follows. Change it to Option<String> so a missing class is None instead of "", and drop the unwrap_or_default() in the parser. Also document the pre-1.0 event stability policy on the Event enum (and AGENTS.md): payload structs stay constructible rather than #[non_exhaustive], so consumers read the fields they need or keep a `..` rest when destructuring; sealing is deferred to the 1.0 API freeze.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughAlright, let's be direct here. ChangesServerAck class optionality
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: `api-design`, `breaking-change` Look, this is a small but important fix — data models need to reflect reality, not paper over missing data with empty strings. That's the kind of precision we need. Ship it. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
| Filename | Overview |
|---|---|
| wacore/src/types/events.rs | Changes ServerAck.class from String to Option and adds the pre-1.0 stability policy doc to the Event enum; both the type and doc comment are accurate and internally consistent. |
| src/client/node_io.rs | Drops unwrap_or_default() from the class attribute read, cleanly propagating Option from node.get_attr("class"). |
| src/client/tests.rs | Updates both test assertions for ServerAck.class — present-class uses .as_deref() == Some("message") and absent-class uses .is_none(); both are idiomatic and correct. |
| AGENTS.md | Adds the event-payload convention bullet (Option, no sentinels, pre-1.0 constructibility) cross-linked to the Event doc; accurately reflects the code changes. |
Reviews (1): Last reviewed commit: "refactor(events): model ServerAck.class ..." | Re-trigger Greptile
📦 Binary size report
.text per crate
Baseline: |
There was a problem hiding this comment.
No issues found across 4 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Refactored ServerAck.class to Option for consistency; added stability docs.
Re-trigger cubic
What
Follow-up to #989. Two small, related cleanups on the event API surface while the crate is still pre-1.0 and breaking changes are cheap.
1.
ServerAck.class: plainStringbecomes anOptionServerAck.classused an empty-string sentinel (unwrap_or_default()) when the server ack omits theclassattribute. Every other payload inevents.rsmodels a maybe-absent field as anOption, so this was the lone exception. Now a missing class isNoneinstead of"", and the parser drops theunwrap_or_default().2. Document the pre-1.0 event stability policy
Added a stability note to the
Eventenum doc (and a pointer inAGENTS.md):#[non_exhaustive], so match arms keep a_catch-all;#[non_exhaustive]) so the crate can build them across thewacore/whatsapp-rustboundary without constructors;..rest when destructuring, since a payload may gain fields in a0.xminor;Option, never a sentinel;#[non_exhaustive]+ constructors is deferred to the 1.0 API freeze.Why not seal the payloads now
#[non_exhaustive]on awacorepayload struct blocks struct-literal construction fromwhatsapp-rust(a separate crate), which would force a constructor for every event payload. Pre-1.0 that cost buys little, since fields can still be added with a minor bump. The policy records the decision instead.Breaking
ServerAck.classis now anOption. Consumers matchSome("message")instead of"message". Only landed in #989, so nothing released depends on the old shape.Verification
cargo fmt --checkandcargo clippy -p whatsapp-rust -p wacore --testsclean.test_ack_dispatches_server_ack_eventupdated for theOptionshape and green.ack_miss_path_does_not_heap_allocategreen — the change stays inside the interest-gated block, so the perf(client): borrow the ack id instead of allocating a String per stanza #827 allocation-free miss path is untouched.