mixtape-tools 0.4.0

Ready-to-use tool implementations for the mixtape agent framework
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
use crate::filesystem::validate_path;
use crate::prelude::*;
use futures::stream::{self, StreamExt};
use std::path::PathBuf;

/// Result for a single file read operation
#[derive(Debug, Serialize, JsonSchema)]
pub struct FileReadResult {
    /// Path that was attempted
    pub path: String,
    /// Content of the file if successful
    pub content: Option<String>,
    /// Error message if failed
    pub error: Option<String>,
}

/// Input for reading multiple files
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ReadMultipleFilesInput {
    /// List of file paths to read (relative to base path)
    pub paths: Vec<PathBuf>,

    /// Maximum number of files to read concurrently (default: 10)
    #[serde(default = "default_concurrency")]
    pub concurrency: usize,
}

fn default_concurrency() -> usize {
    10
}

/// Tool for reading multiple files concurrently
pub struct ReadMultipleFilesTool {
    base_path: PathBuf,
}

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

impl ReadMultipleFilesTool {
    /// Creates a new tool using the current working directory as the base path.
    ///
    /// Equivalent to `Default::default()`.
    ///
    /// # Panics
    ///
    /// Panics if the current working directory cannot be determined.
    /// Use [`try_new`](Self::try_new) or [`with_base_path`](Self::with_base_path) instead.
    pub fn new() -> Self {
        Self {
            base_path: std::env::current_dir().expect("Failed to get current working directory"),
        }
    }

    /// Creates a new tool using the current working directory as the base path.
    ///
    /// Returns an error if the current working directory cannot be determined.
    pub fn try_new() -> std::io::Result<Self> {
        Ok(Self {
            base_path: std::env::current_dir()?,
        })
    }

    /// Creates a tool with a custom base directory.
    ///
    /// All file operations will be constrained to this directory.
    pub fn with_base_path(base_path: PathBuf) -> Self {
        Self { base_path }
    }

    async fn read_single_file(&self, path: PathBuf) -> FileReadResult {
        let path_str = path.display().to_string();

        match validate_path(&self.base_path, &path) {
            Ok(validated_path) => match tokio::fs::read_to_string(&validated_path).await {
                Ok(content) => FileReadResult {
                    path: path_str,
                    content: Some(content),
                    error: None,
                },
                Err(e) => FileReadResult {
                    path: path_str,
                    content: None,
                    error: Some(format!("Failed to read file: {}", e)),
                },
            },
            Err(e) => FileReadResult {
                path: path_str,
                content: None,
                error: Some(e.to_string()),
            },
        }
    }
}

impl Tool for ReadMultipleFilesTool {
    type Input = ReadMultipleFilesInput;

    fn name(&self) -> &str {
        "read_multiple_files"
    }

    fn description(&self) -> &str {
        "Read multiple files concurrently. Returns results for all files, including errors for files that couldn't be read."
    }

    fn format_output_plain(&self, result: &ToolResult) -> String {
        let output = result.as_text();
        let lines: Vec<&str> = output.lines().collect();
        if lines.is_empty() {
            return output.to_string();
        }

        let mut out = String::new();
        if let Some(header) = lines.first() {
            if header.starts_with("Read ") {
                out.push_str(&"".repeat(50));
                out.push_str(&format!("\n  {}\n", header));
                out.push_str(&"".repeat(50));
                out.push('\n');
            }
        }

        let mut in_file = false;
        for line in lines.iter().skip(1) {
            if let Some(path) = line.strip_prefix("") {
                if in_file {
                    out.push('\n');
                }
                out.push_str(&format!("[OK] {}\n", path));
                in_file = true;
            } else if let Some(path) = line.strip_prefix("") {
                if in_file {
                    out.push('\n');
                }
                out.push_str(&format!("[ERR] {}\n", path));
                in_file = true;
            } else if line.starts_with("Error:") {
                out.push_str(&format!("      {}\n", line));
            } else if !line.is_empty() {
                out.push_str(&format!("{}\n", line));
            }
        }
        out
    }

    fn format_output_ansi(&self, result: &ToolResult) -> String {
        let output = result.as_text();
        let lines: Vec<&str> = output.lines().collect();
        if lines.is_empty() {
            return output.to_string();
        }

        let mut out = String::new();
        if let Some(header) = lines.first() {
            if header.starts_with("Read ") {
                let mut success = 0;
                let mut failed = 0;
                if let Some(paren_start) = header.find('(') {
                    let stats = &header[paren_start..];
                    if let Some(s) = stats.split_whitespace().next() {
                        success = s.trim_start_matches('(').parse().unwrap_or(0);
                    }
                    if let Some(f_idx) = stats.find("failed") {
                        if let Some(num) = stats[..f_idx].split_whitespace().last() {
                            failed = num.parse().unwrap_or(0);
                        }
                    }
                }

                out.push_str(&format!(
                    "\x1b[2m{}\x1b[0m\n  \x1b[1mFiles Read\x1b[0m  ",
                    "".repeat(50)
                ));
                if success > 0 {
                    out.push_str(&format!("\x1b[32m● {} ok\x1b[0m  ", success));
                }
                if failed > 0 {
                    out.push_str(&format!("\x1b[31m● {} failed\x1b[0m", failed));
                }
                out.push_str(&format!("\n\x1b[2m{}\x1b[0m\n", "".repeat(50)));
            }
        }

        let mut in_file = false;
        for line in lines.iter().skip(1) {
            if let Some(path) = line.strip_prefix("") {
                if in_file {
                    out.push('\n');
                }
                out.push_str(&format!("\x1b[32m●\x1b[0m \x1b[36m{}\x1b[0m\n", path));
                in_file = true;
            } else if let Some(path) = line.strip_prefix("") {
                if in_file {
                    out.push('\n');
                }
                out.push_str(&format!("\x1b[31m●\x1b[0m \x1b[36m{}\x1b[0m\n", path));
                in_file = true;
            } else if line.starts_with("Error:") {
                out.push_str(&format!("  \x1b[31m{}\x1b[0m\n", line));
            } else if !line.is_empty() {
                out.push_str(&format!("  \x1b[2m│\x1b[0m {}\n", line));
            }
        }
        out
    }

    fn format_output_markdown(&self, result: &ToolResult) -> String {
        let output = result.as_text();
        let lines: Vec<&str> = output.lines().collect();
        if lines.is_empty() {
            return output.to_string();
        }

        let mut out = String::new();
        if let Some(header) = lines.first() {
            if header.starts_with("Read ") {
                out.push_str(&format!("### {}\n\n", header));
            }
        }

        let mut current_file: Option<&str> = None;
        let mut content_lines: Vec<&str> = Vec::new();

        for line in lines.iter().skip(1) {
            let (is_file_line, is_success, path) = if let Some(p) = line.strip_prefix("") {
                (true, true, p)
            } else if let Some(p) = line.strip_prefix("") {
                (true, false, p)
            } else {
                (false, false, "")
            };

            if is_file_line {
                if current_file.is_some() {
                    if !content_lines.is_empty() {
                        out.push_str(&format!("```\n{}\n```\n\n", content_lines.join("\n")));
                        content_lines.clear();
                    } else {
                        out.push('\n');
                    }
                }
                out.push_str(&format!(
                    "{} `{}`\n",
                    if is_success { "" } else { "" },
                    path
                ));
                current_file = Some(path);
            } else if line.starts_with("Error:") {
                out.push_str(&format!("> ⚠️ {}\n", line));
            } else if !line.is_empty() {
                content_lines.push(line);
            }
        }

        if current_file.is_some() && !content_lines.is_empty() {
            out.push_str(&format!("```\n{}\n```\n", content_lines.join("\n")));
        }
        out
    }

    async fn execute(&self, input: Self::Input) -> std::result::Result<ToolResult, ToolError> {
        let concurrency = input.concurrency.min(50); // Cap at 50 to prevent resource exhaustion

        let results: Vec<FileReadResult> = stream::iter(input.paths)
            .map(|path| self.read_single_file(path))
            .buffer_unordered(concurrency)
            .collect()
            .await;

        let total = results.len();
        let successful = results.iter().filter(|r| r.content.is_some()).count();
        let failed = total - successful;

        let mut content = format!(
            "Read {} files ({} successful, {} failed):\n\n",
            total, successful, failed
        );

        for result in &results {
            match (&result.content, &result.error) {
                (Some(file_content), None) => {
                    let preview = if file_content.len() > 200 {
                        format!(
                            "{}... ({} bytes total)",
                            &file_content[..200],
                            file_content.len()
                        )
                    } else {
                        file_content.clone()
                    };
                    content.push_str(&format!("{}\n{}\n\n", result.path, preview));
                }
                (None, Some(error)) => {
                    content.push_str(&format!("{}\nError: {}\n\n", result.path, error));
                }
                _ => unreachable!(),
            }
        }

        Ok(content.into())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::fs;
    use tempfile::TempDir;

    #[test]
    fn test_format_methods() {
        let tool = ReadMultipleFilesTool::new();
        let params = serde_json::json!({"paths": ["file1.txt", "file2.txt"]});

        // All format methods should return non-empty strings
        assert!(!tool.format_input_plain(&params).is_empty());
        assert!(!tool.format_input_ansi(&params).is_empty());
        assert!(!tool.format_input_markdown(&params).is_empty());

        let result = ToolResult::from("Read 2 files");
        assert!(!tool.format_output_plain(&result).is_empty());
        assert!(!tool.format_output_ansi(&result).is_empty());
        assert!(!tool.format_output_markdown(&result).is_empty());
    }

    // ===== Execution Tests =====

    #[tokio::test]
    async fn test_read_multiple_files() {
        let temp_dir = TempDir::new().unwrap();
        fs::write(temp_dir.path().join("file1.txt"), "content1").unwrap();
        fs::write(temp_dir.path().join("file2.txt"), "content2").unwrap();
        fs::write(temp_dir.path().join("file3.txt"), "content3").unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![
                PathBuf::from("file1.txt"),
                PathBuf::from("file2.txt"),
                PathBuf::from("file3.txt"),
            ],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        assert!(result.as_text().contains("3 successful, 0 failed"));
        assert!(result.as_text().contains("content1"));
        assert!(result.as_text().contains("content2"));
        assert!(result.as_text().contains("content3"));
    }

    #[test]
    fn test_tool_metadata() {
        let tool: ReadMultipleFilesTool = Default::default();
        assert_eq!(tool.name(), "read_multiple_files");
        assert!(!tool.description().is_empty());

        let tool2 = ReadMultipleFilesTool::new();
        assert_eq!(tool2.name(), "read_multiple_files");
    }

    #[test]
    fn test_try_new() {
        let tool = ReadMultipleFilesTool::try_new();
        assert!(tool.is_ok());
    }

    #[test]
    fn test_default_concurrency() {
        // Deserialize without specifying concurrency to trigger default_concurrency()
        let input: ReadMultipleFilesInput = serde_json::from_value(serde_json::json!({
            "paths": ["file.txt"]
        }))
        .unwrap();

        assert_eq!(input.concurrency, 10, "Default concurrency should be 10");
    }

    #[tokio::test]
    async fn test_read_multiple_files_with_errors() {
        let temp_dir = TempDir::new().unwrap();
        fs::write(temp_dir.path().join("exists.txt"), "content").unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![PathBuf::from("exists.txt"), PathBuf::from("missing.txt")],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        assert!(result.as_text().contains("1 successful, 1 failed"));
        assert!(result.as_text().contains("content"));
        assert!(result.as_text().contains("✗ missing.txt"));
    }

    // ===== Coverage Gap Tests =====

    #[tokio::test]
    async fn test_concurrency_capped_at_50() {
        // Test that concurrency is capped at 50 to prevent resource exhaustion
        // even when a much larger value is requested
        let temp_dir = TempDir::new().unwrap();

        // Create 100 small files
        for i in 0..100 {
            fs::write(temp_dir.path().join(format!("file{}.txt", i)), "content").unwrap();
        }

        let paths: Vec<PathBuf> = (0..100)
            .map(|i| PathBuf::from(format!("file{}.txt", i)))
            .collect();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths,
            concurrency: 10000, // Request absurdly high concurrency
        };

        // Should complete successfully without panicking or exhausting resources
        let result = tool.execute(input).await.unwrap();
        assert!(result.as_text().contains("100 successful, 0 failed"));
    }

    #[tokio::test]
    async fn test_large_file_content_truncation() {
        // Test that file content longer than 200 characters is truncated
        // in the output with a byte count indicator
        let temp_dir = TempDir::new().unwrap();
        let large_content = "x".repeat(500);
        fs::write(temp_dir.path().join("large.txt"), &large_content).unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![PathBuf::from("large.txt")],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        let text = result.as_text();

        // Should show truncation marker and total byte count
        assert!(text.contains("... (500 bytes total)"));

        // Verify content is actually truncated (contains first 200 chars but not beyond)
        assert!(text.contains(&"x".repeat(200)));
        assert!(!text.contains(&"x".repeat(300)));
    }

    #[tokio::test]
    async fn test_path_validation_errors_reported() {
        // Test that path validation failures (directory traversal attempts)
        // are properly caught and reported in the results
        let temp_dir = TempDir::new().unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![
                PathBuf::from("../../etc/passwd"),
                PathBuf::from("../../../secret.txt"),
            ],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        let text = result.as_text();

        // Both paths should fail validation
        assert!(text.contains("0 successful, 2 failed"));
        assert!(text.contains("✗ ../../etc/passwd"));
        assert!(text.contains("✗ ../../../secret.txt"));

        // Error messages should indicate path validation failure
        assert!(text.contains("escapes") || text.contains("Path"));
    }

    #[tokio::test]
    async fn test_empty_file_list() {
        // Test edge case of reading zero files - should not panic or produce
        // invalid output
        let temp_dir = TempDir::new().unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        let text = result.as_text();

        assert!(text.contains("Read 0 files (0 successful, 0 failed)"));
    }

    #[tokio::test]
    async fn test_formatter_handles_mixed_results() {
        // Test that formatters correctly handle and display both successful
        // and failed file reads with appropriate visual indicators
        let temp_dir = TempDir::new().unwrap();
        fs::write(temp_dir.path().join("exists.txt"), "content").unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![PathBuf::from("exists.txt"), PathBuf::from("missing.txt")],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();

        // Test ANSI formatter includes color codes and stats
        let ansi = tool.format_output_ansi(&result);
        assert!(ansi.contains("\x1b[32m")); // Green for success
        assert!(ansi.contains("\x1b[31m")); // Red for failure
        assert!(ansi.contains("1 ok"));
        assert!(ansi.contains("1 failed"));

        // Test Markdown formatter uses appropriate emoji and code blocks
        let markdown = tool.format_output_markdown(&result);
        assert!(markdown.contains(""));
        assert!(markdown.contains(""));
        assert!(markdown.contains("```"));

        // Test plain formatter
        let plain = tool.format_output_plain(&result);
        assert!(plain.contains("[OK]"));
        assert!(plain.contains("[ERR]"));
    }

    #[tokio::test]
    #[cfg(unix)]
    async fn test_symlink_inside_base() {
        // Test that symlinks pointing to files within the base directory
        // are allowed and properly dereferenced
        let temp_dir = TempDir::new().unwrap();
        let real_file = temp_dir.path().join("real.txt");
        let symlink = temp_dir.path().join("link.txt");

        fs::write(&real_file, "real content").unwrap();
        std::os::unix::fs::symlink(&real_file, &symlink).unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![PathBuf::from("link.txt")],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        let text = result.as_text();

        assert!(text.contains("1 successful, 0 failed"));
        assert!(text.contains("real content"));
    }

    #[tokio::test]
    #[cfg(unix)]
    async fn test_symlink_escaping_base_rejected() {
        // Test that symlinks pointing outside the base directory are rejected
        // for security reasons
        let temp_dir = TempDir::new().unwrap();
        let outside_dir = TempDir::new().unwrap();
        let outside_file = outside_dir.path().join("secret.txt");
        fs::write(&outside_file, "secret").unwrap();

        let symlink = temp_dir.path().join("escape_link.txt");
        std::os::unix::fs::symlink(&outside_file, &symlink).unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![PathBuf::from("escape_link.txt")],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        let text = result.as_text();

        // Should fail validation
        assert!(text.contains("0 successful, 1 failed"));
        assert!(text.contains("✗ escape_link.txt"));
        assert!(text.contains("escapes"));
    }

    #[tokio::test]
    async fn test_relative_path_with_dots() {
        // Test that paths with . and .. components are properly validated
        let temp_dir = TempDir::new().unwrap();
        fs::create_dir(temp_dir.path().join("subdir")).unwrap();
        fs::write(temp_dir.path().join("subdir/file.txt"), "content").unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![PathBuf::from("./subdir/../subdir/./file.txt")],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        assert!(result.as_text().contains("1 successful, 0 failed"));
        assert!(result.as_text().contains("content"));
    }

    #[tokio::test]
    async fn test_batch_read_with_permission_errors() {
        // Test handling of permission denied errors during batch reads
        // Note: This test is platform-specific and may behave differently on Windows
        #[cfg(unix)]
        {
            let temp_dir = TempDir::new().unwrap();
            let unreadable = temp_dir.path().join("unreadable.txt");
            fs::write(&unreadable, "secret").unwrap();

            // Remove read permissions
            let mut perms = fs::metadata(&unreadable).unwrap().permissions();
            use std::os::unix::fs::PermissionsExt;
            perms.set_mode(0o000);
            fs::set_permissions(&unreadable, perms).unwrap();

            let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
            let input = ReadMultipleFilesInput {
                paths: vec![PathBuf::from("unreadable.txt")],
                concurrency: 10,
            };

            let result = tool.execute(input).await.unwrap();
            let text = result.as_text();

            // Should fail to read with permission error
            assert!(text.contains("0 successful, 1 failed"));
            assert!(text.contains("✗ unreadable.txt"));
            assert!(text.contains("Failed to read file") || text.contains("Permission denied"));

            // Clean up: restore permissions so temp_dir can be deleted
            let mut perms = fs::metadata(&unreadable).unwrap().permissions();
            perms.set_mode(0o644);
            fs::set_permissions(&unreadable, perms).unwrap();
        }
    }

    #[tokio::test]
    async fn test_mixed_success_and_validation_errors() {
        // Test that both successful reads and validation errors can occur
        // in the same batch
        let temp_dir = TempDir::new().unwrap();
        fs::write(temp_dir.path().join("good1.txt"), "content1").unwrap();
        fs::write(temp_dir.path().join("good2.txt"), "content2").unwrap();

        let tool = ReadMultipleFilesTool::with_base_path(temp_dir.path().to_path_buf());
        let input = ReadMultipleFilesInput {
            paths: vec![
                PathBuf::from("good1.txt"),
                PathBuf::from("../../etc/passwd"),
                PathBuf::from("good2.txt"),
                PathBuf::from("missing.txt"),
            ],
            concurrency: 10,
        };

        let result = tool.execute(input).await.unwrap();
        let text = result.as_text();

        assert!(text.contains("2 successful, 2 failed"));
        assert!(text.contains("✓ good1.txt"));
        assert!(text.contains("✓ good2.txt"));
        assert!(text.contains("✗ ../../etc/passwd"));
        assert!(text.contains("✗ missing.txt"));
    }
}