bnto-spreadsheet 0.1.3

Spreadsheet processing nodes for Bnto engine — clean, convert, merge, rename
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
// Rename CSV Columns — rename column headers based on a user-provided mapping.
// Data rows are preserved unchanged; only the header row is modified.

use std::collections::HashMap;

use bnto_core::context::ProcessContext;
use bnto_core::errors::BntoError;
use bnto_core::processor::{FileData, NodeInput, NodeOutput, NodeProcessor, OutputFile};
use bnto_core::progress::ProgressReporter;

/// The spreadsheet-rename node processor. Stateless — config comes from `NodeInput.params`.
pub struct RenameColumns;

impl RenameColumns {
    pub fn new() -> Self {
        Self
    }
}

impl Default for RenameColumns {
    fn default() -> Self {
        Self::new()
    }
}

// --- NodeProcessor Implementation ---

impl NodeProcessor for RenameColumns {
    fn name(&self) -> &str {
        "spreadsheet-rename"
    }

    /// Self-describing metadata. Parameters: columns (object mapping old->new names).
    fn metadata(&self) -> bnto_core::NodeMetadata {
        use bnto_core::metadata::*;
        NodeMetadata {
            node_type: "spreadsheet-rename".to_string(),
            name: "Rename CSV Columns".to_string(),
            description: "Rename column headers in a CSV file".to_string(),
            category: NodeCategory::Spreadsheet,
            accepts: vec!["text/csv".to_string()],
            platforms: vec!["browser".to_string()],
            parameters: vec![ParameterDef {
                name: "columns".to_string(),
                label: "Column Mapping".to_string(),
                description:
                    "Map of old column names to new names (e.g., {\"Name\": \"full_name\"})"
                        .to_string(),
                param_type: ParameterType::Object,
                control: Some("keyValue".to_string()),
                ..Default::default()
            }],
            input_cardinality: InputCardinality::PerFile,
            requires: vec![],
        }
    }

    /// Rename column headers based on the `columns` parameter mapping.
    /// Missing or non-matching columns are silently preserved.
    fn process(
        &self,
        input: NodeInput,
        progress: &ProgressReporter,
        _ctx: &dyn ProcessContext,
    ) -> Result<NodeOutput, BntoError> {
        progress.report(0, "Starting column rename...");
        let data = input
            .data
            .into_bytes()
            .map_err(|e| BntoError::ProcessingFailed(format!("Failed to read input: {e}")))?;
        let csv_text = parse_utf8(&data)?;
        let column_mapping = extract_column_mapping(&input.params);

        progress.report(20, "Parsed parameters...");
        let (headers, mut reader) = read_headers(csv_text)?;

        progress.report(40, "Read headers...");
        let (new_headers, columns_renamed) = apply_column_mapping(&headers, &column_mapping);

        progress.report(60, "Renamed headers...");
        let (output_bytes, row_count) = write_renamed_csv(&new_headers, &mut reader)?;

        progress.report(90, "Wrote output CSV...");
        let metadata = build_rename_metadata(
            columns_renamed,
            &new_headers,
            row_count,
            &column_mapping,
            &headers,
        );

        progress.report(100, "Done!");
        Ok(build_rename_output(output_bytes, &input.filename, metadata))
    }
}

fn build_rename_output(
    data: Vec<u8>,
    input_filename: &str,
    metadata: serde_json::Map<String, serde_json::Value>,
) -> NodeOutput {
    NodeOutput {
        files: vec![OutputFile {
            data: FileData::Bytes(data),
            filename: build_output_filename(input_filename),
            mime_type: "text/csv".to_string(),
            metadata: serde_json::Map::new(),
        }],
        metadata,
    }
}

// --- CSV Parsing ---

/// Validate and convert raw bytes to a UTF-8 string.
fn parse_utf8(data: &[u8]) -> Result<&str, BntoError> {
    std::str::from_utf8(data)
        .map_err(|e| BntoError::InvalidInput(format!("CSV is not valid UTF-8: {e}")))
}

/// Parse CSV text and return the header record plus a positioned reader.
fn read_headers(csv_text: &str) -> Result<(csv::StringRecord, csv::Reader<&[u8]>), BntoError> {
    let mut reader = csv::ReaderBuilder::new()
        .flexible(true)
        .from_reader(csv_text.as_bytes());

    let headers = reader
        .headers()
        .map_err(|e| BntoError::ProcessingFailed(format!("Failed to read CSV headers: {e}")))?
        .clone();

    Ok((headers, reader))
}

// --- Column Mapping ---

/// Apply the rename mapping to headers. Returns (new_headers, count_renamed).
fn apply_column_mapping(
    headers: &csv::StringRecord,
    mapping: &HashMap<String, String>,
) -> (Vec<String>, u64) {
    let mut count: u64 = 0;

    let new_headers: Vec<String> = headers
        .iter()
        .map(|header| {
            if let Some(new_name) = mapping.get(header) {
                count += 1;
                new_name.clone()
            } else {
                header.to_string()
            }
        })
        .collect();

    (new_headers, count)
}

// --- CSV Output ---

/// Write renamed headers followed by all data rows unchanged.
/// Returns (output_bytes, row_count).
fn write_renamed_csv(
    new_headers: &[String],
    reader: &mut csv::Reader<&[u8]>,
) -> Result<(Vec<u8>, u64), BntoError> {
    let mut writer = csv::WriterBuilder::new()
        .flexible(true)
        .from_writer(Vec::new());

    writer
        .write_record(new_headers)
        .map_err(|e| BntoError::ProcessingFailed(format!("Failed to write headers: {e}")))?;

    let mut row_count: u64 = 0;
    for record in reader.records() {
        let record = record
            .map_err(|e| BntoError::ProcessingFailed(format!("Failed to read CSV row: {e}")))?;
        writer
            .write_record(record.iter())
            .map_err(|e| BntoError::ProcessingFailed(format!("Failed to write CSV row: {e}")))?;
        row_count += 1;
    }

    let output_bytes = writer
        .into_inner()
        .map_err(|e| BntoError::ProcessingFailed(format!("Failed to finalize CSV: {e}")))?;

    Ok((output_bytes, row_count))
}

// --- Result Metadata ---

/// Filter mapping to only columns that exist in the original headers.
fn applied_mapping(
    column_mapping: &HashMap<String, String>,
    headers: &csv::StringRecord,
) -> serde_json::Map<String, serde_json::Value> {
    column_mapping
        .iter()
        .filter(|(old, _)| headers.iter().any(|h| h == old.as_str()))
        .map(|(old, new)| (old.clone(), serde_json::Value::String(new.clone())))
        .collect()
}

/// Build metadata including rename counts and the applied mapping.
fn build_rename_metadata(
    columns_renamed: u64,
    new_headers: &[String],
    row_count: u64,
    column_mapping: &HashMap<String, String>,
    headers: &csv::StringRecord,
) -> serde_json::Map<String, serde_json::Value> {
    let mut m = serde_json::Map::new();
    m.insert(
        "columnsRenamed".to_string(),
        serde_json::Value::Number(columns_renamed.into()),
    );
    m.insert(
        "totalColumns".to_string(),
        serde_json::Value::Number((new_headers.len() as u64).into()),
    );
    m.insert(
        "dataRows".to_string(),
        serde_json::Value::Number(row_count.into()),
    );
    m.insert(
        "mapping".to_string(),
        serde_json::Value::Object(applied_mapping(column_mapping, headers)),
    );
    m
}

// --- Helper Functions ---

/// Extract `columns` param as a HashMap. Returns empty map if missing or invalid.
fn extract_column_mapping(
    params: &serde_json::Map<String, serde_json::Value>,
) -> HashMap<String, String> {
    let columns_value = match params.get("columns") {
        Some(val) => val,
        None => return HashMap::new(),
    };

    let obj = match columns_value {
        serde_json::Value::Object(obj) => obj,
        _ => return HashMap::new(),
    };

    obj.iter()
        .filter_map(|(key, value)| {
            if let serde_json::Value::String(new_name) = value {
                Some((key.clone(), new_name.clone()))
            } else {
                None
            }
        })
        .collect()
}

/// Add "-renamed" before the file extension: "data.csv" -> "data-renamed.csv"
fn build_output_filename(input_filename: &str) -> String {
    match input_filename.rfind('.') {
        Some(dot_pos) => {
            let (name, ext) = input_filename.split_at(dot_pos);
            format!("{name}-renamed{ext}")
        }
        None => format!("{input_filename}-renamed"),
    }
}

// =============================================================================
// Tests
// =============================================================================

#[cfg(test)]
mod tests {
    use super::*;
    use bnto_core::NoopContext;

    // --- Test Helpers ---

    /// Create a NodeInput from raw CSV text and optional params.
    /// This helper makes tests cleaner by handling the boilerplate.
    fn make_csv_input(csv_text: &str, params_json: &str) -> NodeInput {
        // Parse the JSON string into a serde_json::Map.
        // If parsing fails, use an empty map (same as production behavior).
        let params: serde_json::Map<String, serde_json::Value> =
            serde_json::from_str(params_json).unwrap_or_default();

        NodeInput {
            data: FileData::Bytes(csv_text.as_bytes().to_vec()),
            filename: "test.csv".to_string(),
            mime_type: Some("text/csv".to_string()),
            params,
        }
    }

    /// Extract the output CSV as a UTF-8 string from the NodeOutput.
    /// Panics if the output has no files or the data isn't valid UTF-8.
    fn output_to_string(output: &NodeOutput) -> String {
        let file = output
            .files
            .first()
            .expect("Should have at least one output file");
        let bytes = file.data.clone().into_bytes().expect("Should read bytes");
        String::from_utf8(bytes).expect("Output should be valid UTF-8")
    }

    // --- Core Functionality Tests ---

    #[test]
    fn test_rename_one_column() {
        // Rename a single column and verify the rest are unchanged.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input(
            "name,age,city\nAlice,30,NYC\nBob,25,LA\n",
            r#"{"columns": {"name": "full_name"}}"#,
        );

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        // The header "name" should be renamed to "full_name".
        assert!(csv_out.starts_with("full_name,age,city\n"));
        // Data rows should be unchanged.
        assert!(csv_out.contains("Alice,30,NYC"));
        assert!(csv_out.contains("Bob,25,LA"));
    }

    #[test]
    fn test_rename_multiple_columns() {
        // Rename multiple columns at once.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input(
            "first_name,last_name,email\nJane,Doe,jane@example.com\n",
            r#"{"columns": {"first_name": "given_name", "last_name": "surname"}}"#,
        );

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        // Both columns should be renamed; "email" stays the same.
        assert!(csv_out.starts_with("given_name,surname,email\n"));
        // Data row unchanged.
        assert!(csv_out.contains("Jane,Doe,jane@example.com"));
    }

    #[test]
    fn test_rename_nonexistent_column_ignored() {
        // If the mapping references a column that doesn't exist in the CSV,
        // it should be silently ignored — no error.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input(
            "name,age\nAlice,30\n",
            r#"{"columns": {"nonexistent": "something"}}"#,
        );

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        // Headers should be unchanged because "nonexistent" isn't in the CSV.
        assert!(csv_out.starts_with("name,age\n"));
        assert!(csv_out.contains("Alice,30"));

        // Metadata should show 0 columns renamed.
        let renamed_count = output.metadata.get("columnsRenamed").unwrap();
        assert_eq!(renamed_count, &serde_json::json!(0));
    }

    #[test]
    fn test_no_columns_param_passthrough() {
        // If no "columns" param is provided, the CSV should pass through unchanged.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input("name,age\nAlice,30\n", "{}");

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        assert!(csv_out.starts_with("name,age\n"));
        assert!(csv_out.contains("Alice,30"));

        // 0 columns renamed.
        let renamed_count = output.metadata.get("columnsRenamed").unwrap();
        assert_eq!(renamed_count, &serde_json::json!(0));
    }

    #[test]
    fn test_empty_mapping_passthrough() {
        // An empty columns mapping should also pass through unchanged.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input("name,age\nAlice,30\n", r#"{"columns": {}}"#);

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        assert!(csv_out.starts_with("name,age\n"));
        let renamed_count = output.metadata.get("columnsRenamed").unwrap();
        assert_eq!(renamed_count, &serde_json::json!(0));
    }

    #[test]
    fn test_all_columns_renamed() {
        // Rename every column in the CSV.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input(
            "a,b,c\n1,2,3\n",
            r#"{"columns": {"a": "x", "b": "y", "c": "z"}}"#,
        );

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        assert!(csv_out.starts_with("x,y,z\n"));
        assert!(csv_out.contains("1,2,3"));

        // All 3 columns renamed.
        let renamed_count = output.metadata.get("columnsRenamed").unwrap();
        assert_eq!(renamed_count, &serde_json::json!(3));
        let total_columns = output.metadata.get("totalColumns").unwrap();
        assert_eq!(total_columns, &serde_json::json!(3));
    }

    #[test]
    fn test_data_rows_preserved_unchanged() {
        // Verify that data rows are byte-for-byte preserved (no trimming,
        // no quoting changes, no reordering).
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let csv_input = "name,value,notes\nAlice,\"100,000\",\"has, commas\"\nBob,200,simple\n";
        let input = make_csv_input(csv_input, r#"{"columns": {"name": "person"}}"#);

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        // Header renamed.
        assert!(csv_out.starts_with("person,value,notes\n"));
        // Data with commas and quotes preserved.
        assert!(csv_out.contains("Alice,\"100,000\",\"has, commas\""));
        assert!(csv_out.contains("Bob,200,simple"));
    }

    #[test]
    fn test_column_order_preserved() {
        // Columns should stay in the same order — only names change.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input(
            "z_col,a_col,m_col\n1,2,3\n",
            r#"{"columns": {"m_col": "middle"}}"#,
        );

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        // Order: z_col, a_col, middle (only m_col renamed, position preserved).
        assert!(csv_out.starts_with("z_col,a_col,middle\n"));
    }

    #[test]
    fn test_variable_length_rows_handled() {
        // Some CSVs have ragged rows (not all rows have the same number of fields).
        // Our processor should handle this gracefully with flexible(true).
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input(
            "a,b,c\n1,2,3\n4,5\n6,7,8,9\n",
            r#"{"columns": {"a": "first"}}"#,
        );

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        // Header renamed.
        assert!(csv_out.starts_with("first,b,c\n"));
        // All rows should be present, including the ragged ones.
        assert!(csv_out.contains("1,2,3"));
        assert!(csv_out.contains("4,5"));
        assert!(csv_out.contains("6,7,8,9"));
    }

    #[test]
    fn test_headers_only_csv() {
        // A CSV with headers but no data rows. The headers should be renamed.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input("name,age\n", r#"{"columns": {"name": "full_name"}}"#);

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        assert!(csv_out.starts_with("full_name,age"));

        // 0 data rows.
        let data_rows = output.metadata.get("dataRows").unwrap();
        assert_eq!(data_rows, &serde_json::json!(0));
    }

    #[test]
    fn test_non_utf8_input_returns_error() {
        // Non-UTF8 input should return a clear error, not a panic.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        // Create invalid UTF-8 bytes (0xFF 0xFE is not valid UTF-8).
        let bad_bytes: Vec<u8> = vec![0xFF, 0xFE, 0x00, 0x61];
        let input = NodeInput {
            data: FileData::Bytes(bad_bytes),
            filename: "bad.csv".to_string(),
            mime_type: Some("text/csv".to_string()),
            params: serde_json::Map::new(),
        };

        let result = processor.process(input, &progress, &NoopContext);

        // Should be an error, not a panic.
        assert!(result.is_err());

        // The error message should mention UTF-8.
        //
        if let Err(e) = result {
            let error_msg = e.to_string();
            assert!(
                error_msg.contains("UTF-8"),
                "Error should mention UTF-8: got '{error_msg}'"
            );
        }
    }

    #[test]
    fn test_large_csv_only_header_changes() {
        // A large CSV (1000+ rows) should process correctly with only
        // the header row changed. This tests performance and correctness
        // at scale.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        // Build a CSV with 1000 data rows.
        let mut csv_text = String::from("id,name,value\n");
        for i in 0..1000 {
            csv_text.push_str(&format!("{i},item_{i},{}\n", i * 10));
        }

        let input = make_csv_input(
            &csv_text,
            r#"{"columns": {"id": "identifier", "name": "label"}}"#,
        );

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        // Header renamed.
        assert!(csv_out.starts_with("identifier,label,value\n"));

        // Spot-check a few data rows to verify they're unchanged.
        assert!(csv_out.contains("0,item_0,0"));
        assert!(csv_out.contains("500,item_500,5000"));
        assert!(csv_out.contains("999,item_999,9990"));

        // Metadata should show 2 columns renamed and 1000 data rows.
        let renamed_count = output.metadata.get("columnsRenamed").unwrap();
        assert_eq!(renamed_count, &serde_json::json!(2));
        let data_rows = output.metadata.get("dataRows").unwrap();
        assert_eq!(data_rows, &serde_json::json!(1000));
    }

    // --- Output Filename Tests ---

    #[test]
    fn test_output_filename_with_extension() {
        assert_eq!(build_output_filename("data.csv"), "data-renamed.csv");
    }

    #[test]
    fn test_output_filename_without_extension() {
        assert_eq!(build_output_filename("data"), "data-renamed");
    }

    #[test]
    fn test_output_filename_multiple_dots() {
        assert_eq!(
            build_output_filename("my.data.file.csv"),
            "my.data.file-renamed.csv"
        );
    }

    // --- Metadata Tests ---

    #[test]
    fn test_metadata_includes_applied_mapping() {
        // The metadata should include the mapping that was actually applied
        // (only columns that existed in the CSV).
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input(
            "name,age\nAlice,30\n",
            r#"{"columns": {"name": "full_name", "missing": "nope"}}"#,
        );

        let output = processor.process(input, &progress, &NoopContext).unwrap();

        // The "mapping" metadata should only include "name" → "full_name",
        // NOT "missing" → "nope" (because "missing" doesn't exist in the CSV).
        let mapping = output.metadata.get("mapping").unwrap();
        let mapping_obj = mapping.as_object().unwrap();
        assert_eq!(mapping_obj.len(), 1);
        assert_eq!(mapping_obj.get("name").unwrap(), "full_name");
        // "missing" should NOT be in the mapping.
        assert!(mapping_obj.get("missing").is_none());
    }

    // --- Edge Cases ---

    #[test]
    fn test_columns_param_not_object_passthrough() {
        // If "columns" is a string instead of an object, treat it as no mapping.
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input("name,age\nAlice,30\n", r#"{"columns": "not an object"}"#);

        let output = processor.process(input, &progress, &NoopContext).unwrap();
        let csv_out = output_to_string(&output);

        // Should pass through unchanged.
        assert!(csv_out.starts_with("name,age\n"));
    }

    #[test]
    fn test_processor_name() {
        let processor = RenameColumns::new();
        assert_eq!(processor.name(), "spreadsheet-rename");
    }

    #[test]
    fn test_default_creates_same_as_new() {
        // Verify that Default and new() produce equivalent processors.
        let p1 = RenameColumns::new();
        let p2 = RenameColumns;
        assert_eq!(p1.name(), p2.name());
    }

    #[test]
    fn test_output_mime_type_is_csv() {
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let input = make_csv_input("name\nAlice\n", "{}");
        let output = processor.process(input, &progress, &NoopContext).unwrap();

        assert_eq!(output.files[0].mime_type, "text/csv");
    }

    #[test]
    fn test_output_filename_has_renamed_suffix() {
        let processor = RenameColumns::new();
        let progress = ProgressReporter::new_noop();

        let mut input = make_csv_input("name\nAlice\n", "{}");
        input.filename = "my_data.csv".to_string();

        let output = processor.process(input, &progress, &NoopContext).unwrap();

        assert_eq!(output.files[0].filename, "my_data-renamed.csv");
    }
}