Fix serde field-naming bug that blanked show/episode names, real renames, and Undo

`#[serde(tag = "status", rename_all = "camelCase")]` on a tagged enum only
renames the tag's own values ("Found" -> "found"), not the field names
inside each struct-like variant - so `series_name` stayed `series_name` on
the wire instead of becoming `seriesName`. The frontend only ever reads
camelCase, so these fields came back `undefined`, and JSON.stringify
silently drops undefined keys when Tauri invoke args are serialized -
making the bug invisible rather than throwing.

This is why Fetch Data (TMDB/TVmaze/OMDb) blanked out {show name} and
{episode name} in naming schemes even on a full "found" result: reported
by the user with screenshots showing the naming preview correct after
Match but blank after Fetch Data.

The same pattern existed in 4 more places, fixed identically by adding
`rename_all_fields = "camelCase"` alongside the existing tag/rename_all:
- metadata.rs: FetchOutcome (the reported bug) and MovieFetchOutcome
- episodes.rs: EpisodeListOutcome
- history/mod.rs: RevertOutcome (restoredPath) - broke Undo reconciliation
- rename/mod.rs: RenameOutcome (newPath) - broke post-rename item tracking
  after a REAL on-disk rename; RenamePanel.tsx calls
  fileNameFromPath(result.outcome.newPath), which throws on undefined,
  so this was likely the most severe of the five.

No frontend changes needed - the TypeScript side already expected
camelCase throughout. Added 5 permanent regression tests (one per fixed
enum, two in metadata.rs) that assert the exact camelCase JSON keys and
assert the old snake_case keys are absent. cargo test --workspace: 186 ->
191 passing. npm run build: clean, no frontend diff.
This commit is contained in:
Renamr Scaffold
2026-08-30 04:12:17 +00:00
parent e219e8f2a8
commit ecd98d6c57
4 changed files with 101 additions and 5 deletions
+17 -1
View File
@@ -43,7 +43,7 @@ pub struct HistoryBatch {
/// What happened when reverting one entry of a batch.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "status", rename_all = "camelCase")]
#[serde(tag = "status", rename_all = "camelCase", rename_all_fields = "camelCase")]
pub enum RevertOutcome {
/// For a Move batch: successfully moved back to its original path. For a Copy or
/// Symlink batch: the copy/symlink that was created has been removed - the original
@@ -180,6 +180,22 @@ mod tests {
dir
}
// Same gotcha and same fix as `rename::RenameOutcome` and `metadata.rs`'s
// `FetchOutcome` - `rename_all` alone on a tagged enum doesn't reach the field
// names inside a struct-like variant; `rename_all_fields` does. Pinned here too.
#[test]
fn revert_outcome_serializes_with_camel_case_field_names() {
let reverted = RevertOutcome::Reverted { restored_path: "/media/Show/original.mkv".to_string() };
let json = serde_json::to_string(&reverted).unwrap();
assert!(json.contains("\"restoredPath\":\"/media/Show/original.mkv\""), "got: {json}");
assert!(!json.contains("restored_path"));
let conflict = RevertOutcome::SkippedConflict { existing_path: "/media/Show/original.mkv".to_string() };
let json = serde_json::to_string(&conflict).unwrap();
assert!(json.contains("\"existingPath\":\"/media/Show/original.mkv\""), "got: {json}");
assert!(!json.contains("existing_path"));
}
#[test]
fn reverts_a_renamed_file_back_to_its_original_path() {
let dir = temp_dir();
+23 -1
View File
@@ -93,7 +93,7 @@ impl Default for ConflictPolicy {
/// What happened to one planned rename.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "status", rename_all = "camelCase")]
#[serde(tag = "status", rename_all = "camelCase", rename_all_fields = "camelCase")]
pub enum RenameOutcome {
/// Renamed successfully; `new_path` is the file's new full path.
Renamed { new_path: String },
@@ -329,6 +329,28 @@ mod tests {
(dir, file)
}
// `#[serde(tag = "status", rename_all = "camelCase")]` alone only renames the tag's
// own values ("Renamed", "SkippedConflict") to their lowercase/camelCase form - it
// does NOT rename the field names inside a struct-like variant the way a plain
// (non-tagged) `#[serde(rename_all = "camelCase")]` struct would. Without the
// separate `rename_all_fields = "camelCase"` this enum now also carries,
// `Renamed { new_path }` serialized as a literal `new_path` key, and the frontend's
// `newPath`/`existingPath` destructuring silently got `undefined` for both - a real
// bug caught in `metadata.rs`'s `FetchOutcome` sibling of this exact pattern (see
// that module's `serde_wire_format` tests). This pins the fix here too.
#[test]
fn rename_outcome_serializes_with_camel_case_field_names() {
let renamed = RenameOutcome::Renamed { new_path: "/media/Show/S01E01.mkv".to_string() };
let json = serde_json::to_string(&renamed).unwrap();
assert!(json.contains("\"newPath\":\"/media/Show/S01E01.mkv\""), "got: {json}");
assert!(!json.contains("new_path"));
let conflict = RenameOutcome::SkippedConflict { existing_path: "/media/Show/S01E01.mkv".to_string() };
let json = serde_json::to_string(&conflict).unwrap();
assert!(json.contains("\"existingPath\":\"/media/Show/S01E01.mkv\""), "got: {json}");
assert!(!json.contains("existing_path"));
}
#[test]
fn renames_a_file_successfully() {
let (dir, file) = temp_file_setup("old.txt", "hello");