Skip to content

refactor(runtime): derive clipboard text MIME conversions - #502

Merged
eval-exec merged 1 commit into
mainfrom
refactor/clipboard-text-mime-enum
Oct 7, 2026
Merged

eval-exec merged 1 commit into
mainfrom
refactor/clipboard-text-mime-enum

Conversation

@eval-exec

Copy link
Copy Markdown
Owner

Clipboard MIME recognition and formatting duplicated the same three string literals. Derive strum::EnumString and IntoStaticStr on TextMime, 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.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 17:50
@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aa818845-e9c3-461e-b4ed-ea8cd38fccb7
📥 Commits

Reviewing files that changed from the base of the PR and between 5a97f2f and 510d1a4.

📒 Files selected for processing (2)
  • crates/neomacs-display-runtime/src/clipboard/tests/text_policy_test.rs
  • crates/neomacs-display-runtime/src/clipboard/text_policy.rs
 __________________________________________
< Lint long and prosper with cleaner code. >
 ------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@eval-exec
eval-exec merged commit c17e6c6 into main Oct 7, 2026
26 of 34 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::IntoStaticStr for TextMime and replace manual string matching with typed parsing.
  • Simplify TextMime::as_str() by delegating to IntoStaticStr.
  • 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.

Comment on lines +229 to +258
#[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}");
}
}
Comment on lines +124 to +128
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(_) => {}
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.

2 participants