Repository navigation
feat(payload): add Payload tagged union for widget output (#18) - #21
Conversation
Foundation type for the 3-axis (fetcher / render / layout) architecture. Serves as both internal Rust type and plugin subprocess JSON wire format. - Seven render variants: text / list / gauge / sparkline / chart / bignum / image - Common meta fields: title, icon, status, format template - Round-trip + spec-example tests for all variants Refs #18 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThe changes introduce foundational serialization infrastructure by adding Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/payload.rs (2)
59-87: Numeric type inconsistency between Gauge and Chart.
GaugeData::valueisf32whileChartSeries::pointsuses(f64, f64). For a JSON wire format consumed across fetcher/renderer boundaries, picking a single floating-point width (typicallyf64, since that matchesserde_json::Numberprecision) avoids surprises with rounding on round-trip and keeps the public data model uniform. Not a blocker, but worth aligning before this type is depended on widely.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/payload.rs` around lines 59 - 87, The GaugeData numeric type should be aligned with the rest of the public model: change GaugeData::value from f32 to f64 so it matches ChartSeries::points' (f64, f64) and serde_json/serde precision expectations; update any constructors/uses of GaugeData::value (e.g., builders, tests, deserialization helpers) to use f64 and run tests to ensure no signature mismatches remain.
207-213: Brittle substring assertion.
json.contains("title")/"icon"will produce false positives the moment a body variant happens to contain those substrings in user-provided data (e.g., aTextDataline or aListItem::key). Safer to parse back into aserde_json::Valueand assert the object does not contain those keys.♻️ Proposed fix
#[test] fn optional_fields_absent_in_serialization() { let p = bare(Body::Text(TextData { lines: vec![] })); - let json = serde_json::to_string(&p).unwrap(); - assert!(!json.contains("title")); - assert!(!json.contains("icon")); + let v: serde_json::Value = serde_json::to_value(&p).unwrap(); + let obj = v.as_object().unwrap(); + assert!(!obj.contains_key("title")); + assert!(!obj.contains_key("icon")); + assert!(!obj.contains_key("status")); + assert!(!obj.contains_key("format")); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/payload.rs` around lines 207 - 213, The test optional_fields_absent_in_serialization is using brittle substring checks on the serialized JSON; instead, deserialize the JSON string back into a serde_json::Value (via serde_json::from_str) and assert the top-level object does not contain the "title" and "icon" keys (e.g., v.get("title").is_none() and v.get("icon").is_none()). Keep the test using the existing bare(Body::Text(...)) setup and replace the json.contains(...) assertions with these Value-based key-absence checks to avoid false positives from user data containing those substrings.
🤖 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/payload.rs`:
- Around line 59-87: The GaugeData numeric type should be aligned with the rest
of the public model: change GaugeData::value from f32 to f64 so it matches
ChartSeries::points' (f64, f64) and serde_json/serde precision expectations;
update any constructors/uses of GaugeData::value (e.g., builders, tests,
deserialization helpers) to use f64 and run tests to ensure no signature
mismatches remain.
- Around line 207-213: The test optional_fields_absent_in_serialization is using
brittle substring checks on the serialized JSON; instead, deserialize the JSON
string back into a serde_json::Value (via serde_json::from_str) and assert the
top-level object does not contain the "title" and "icon" keys (e.g.,
v.get("title").is_none() and v.get("icon").is_none()). Keep the test using the
existing bare(Body::Text(...)) setup and replace the json.contains(...)
assertions with these Value-based key-absence checks to avoid false positives
from user data containing those substrings.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f6e45f5c-5917-4253-880e-99df225f4fbf
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (3)
Cargo.tomlsrc/main.rssrc/payload.rs
Align data shapes with concrete Ratatui widgets: - LineChart: series of (x, y) points → Ratatui `Chart` - BarChart: labeled magnitudes (label, u64) → Ratatui `BarChart` Previously the `Chart` variant forced BarChart's labeled bars through a LineChart-shaped series+points schema. Splitting keeps each render type's data contract tight against its renderer. Also widen GaugeData.value to f64 to match Ratatui's `Gauge::ratio`. Switch the Body enum tag renaming to snake_case so LineChart / BarChart serialize as "line_chart" / "bar_chart". Refs #18 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Payload— the foundation type for the 3-axis (fetcher / render / layout) architecture. Every fetcher produces one, every renderer consumes one, and the same shape is the plugin subprocess JSON wire format.text/list/gauge/sparkline/line_chart/bar_chart/bignum/image.line_chartandbar_chartare kept separate because their underlying Ratatui widgets have fundamentally different data shapes (XY series vs labeled magnitudes).title,icon,status,format) flattened alongside the render-tagged body.Closes #18.
Wire format example
{ "render": "text", "data": { "lines": ["main"] }, "title": "Git" } { "render": "bar_chart", "data": { "bars": [{ "label": "a", "value": 3 }] } }Test plan
cargo buildcargo test(12 passed)cargo clippy --all-targets -- -D warningscargo fmt --check🤖 Generated with Claude Code