Repository navigation
refactor(runtime): derive clipboard text MIME conversions - #502
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.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open findings
What changed in this PR
Refactors Linux clipboard text MIME handling to define canonical MIME spellings once on TextMime variants and to parse/format via strum, while keeping selection logic and behavior unchanged.
Changes:
- Derive
strum::EnumString/strum::IntoStaticStrforTextMimeand replace manual string matching with typed parsing. - Simplify
TextMime::as_str()by delegating toIntoStaticStr. - Add tests to pin exact round-trip MIME spellings and reject aliases/normalization.
| File | Description |
|---|---|
| crates/neomacs-display-runtime/src/clipboard/text_policy.rs | Centralizes MIME spellings on enum variants and switches offer recognition to strum parsing. |
| crates/neomacs-display-runtime/src/clipboard/tests/text_policy_test.rs | Adds tests asserting canonical spellings round-trip and that non-canonical inputs are rejected. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| #[test] | ||
| fn text_mime_spellings_round_trip_exactly() { | ||
| for (mime, spelling) in [ | ||
| (TextMime::TextPlainUtf8, "text/plain;charset=utf-8"), | ||
| (TextMime::Utf8String, "UTF8_STRING"), | ||
| (TextMime::TextPlain, "text/plain"), | ||
| ] { | ||
| assert_eq!(mime.as_str(), spelling); | ||
| assert_eq!(spelling.parse::<TextMime>(), Ok(mime)); | ||
| assert_eq!(TextMime::choose(&offered(&[spelling])), Some(mime)); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn text_mime_recognition_does_not_accept_aliases_or_normalize_names() { | ||
| for spelling in [ | ||
| "TextPlainUtf8", | ||
| "Utf8String", | ||
| "TextPlain", | ||
| "utf8_string", | ||
| "TEXT/PLAIN", | ||
| "text/plain;charset=UTF-8", | ||
| " text/plain", | ||
| "text/plain ", | ||
| "text/plain; charset=utf-8", | ||
| ] { | ||
| assert!(spelling.parse::<TextMime>().is_err(), "{spelling}"); | ||
| assert_eq!(TextMime::choose(&offered(&[spelling])), None, "{spelling}"); | ||
| } | ||
| } |
| match mime.parse::<Self>() { | ||
| Ok(Self::TextPlainUtf8) => return Some(Self::TextPlainUtf8), | ||
| Ok(Self::Utf8String) => return Some(Self::Utf8String), | ||
| Ok(Self::TextPlain) => fallback = Some(Self::TextPlain), | ||
| Err(_) => {} |


Clipboard MIME recognition and formatting duplicated the same three string literals. Derive
strum::EnumStringandIntoStaticStronTextMime, with each exact MIME spelling defined once on its variant.Parse offers into typed variants and retain an exhaustive selection match: the first UTF-8 offer wins, with plain text as a fallback. Preserve lossy UTF-8 decoding, line-ending normalization, and exact case-sensitive recognition. Reuse the existing strum dependency; no dependency or lockfile changes.
Validation: all 20 focused clipboard text policy tests pass. Added tests pin canonical spellings in both directions and reject Rust variant names, case changes, and extra whitespace. Existing tests cover offer ordering, fallback behavior, decoding, and error classification. Formatting and diff checks pass. Tests remain in
clipboard/tests/text_policy_test.rs.