ggen-core 26.7.3

Core graph-aware code generation engine
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
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
//! Safe path handling with validation to prevent path traversal attacks
//!
//! This module provides the `SafePath` newtype that wraps `PathBuf` with validation
//! to prevent common path traversal vulnerabilities. All paths are validated on
//! construction to ensure they:
//!
//! - Do not contain parent directory references (..)
//! - Are relative paths or absolute paths within an allowed root
//! - Do not exceed maximum depth of 20 levels
//! - Do not contain symlinks outside the workspace (when resolved)
//!
//! ## Examples
//!
//! ```rust
//! use crate::utils::safe_path::SafePath;
//!
//! // Valid paths
//! let safe = SafePath::new("src/generated").unwrap();
//! let joined = safe.join("output.rs").unwrap();
//! assert_eq!(joined.as_path().to_str().unwrap(), "src/generated/output.rs");
//!
//! // Invalid paths
//! assert!(SafePath::new("../etc/passwd").is_err());
//! assert!(SafePath::new("src/../../etc/passwd").is_err());
//! ```

use crate::utils::error::{Error, Result};
use std::convert::TryFrom;
use std::fmt;
use std::path::{Path, PathBuf};

/// Maximum allowed path depth to prevent deeply nested directory attacks
const MAX_PATH_DEPTH: usize = 20;

/// A validated path that prevents path traversal attacks
///
/// This newtype wrapper around `PathBuf` ensures that all paths are validated
/// on construction and cannot be modified to violate safety constraints.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SafePath {
    /// Inner path - private to prevent direct mutation
    inner: PathBuf,
}

impl SafePath {
    /// Create a new SafePath from a string-like type
    ///
    /// # Validation Rules
    ///
    /// - No parent directory references (..)
    /// - Must be relative or within allowed root (if absolute)
    /// - Maximum depth of 20 levels
    /// - Path components must not be empty or contain only whitespace
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// // Valid paths
    /// assert!(SafePath::new("src/generated").is_ok());
    /// assert!(SafePath::new("./output").is_ok());
    /// assert!(SafePath::new("test").is_ok());
    ///
    /// // Invalid paths
    /// assert!(SafePath::new("../etc").is_err());
    /// assert!(SafePath::new("src/../../../etc").is_err());
    /// assert!(SafePath::new("").is_err());
    /// ```
    pub fn new<P: AsRef<Path>>(path: P) -> Result<Self> {
        let path = path.as_ref();
        Self::validate_path(path)?;
        Ok(Self {
            inner: Self::normalize_path(path),
        })
    }

    /// Join this path with another path component
    ///
    /// The joined path is validated to ensure safety constraints are maintained.
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// let base = SafePath::new("src").unwrap();
    /// let joined = base.join("generated").unwrap();
    /// assert_eq!(joined.as_path().to_str().unwrap(), "src/generated");
    ///
    /// // Cannot join with parent references
    /// assert!(base.join("../etc").is_err());
    /// ```
    pub fn join<P: AsRef<Path>>(&self, path: P) -> Result<Self> {
        let joined = self.inner.join(path.as_ref());
        Self::validate_path(&joined)?;
        Ok(Self {
            inner: Self::normalize_path(&joined),
        })
    }

    /// Get a reference to the inner path
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// let safe = SafePath::new("src/generated").unwrap();
    /// assert_eq!(safe.as_path().to_str().unwrap(), "src/generated");
    /// ```
    #[must_use]
    pub fn as_path(&self) -> &Path {
        &self.inner
    }

    /// Convert into the inner PathBuf
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// let safe = SafePath::new("src/generated").unwrap();
    /// let path_buf = safe.into_path_buf();
    /// assert_eq!(path_buf.to_str().unwrap(), "src/generated");
    /// ```
    #[must_use]
    pub fn into_path_buf(self) -> PathBuf {
        self.inner
    }

    /// Get the PathBuf (clone)
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// let safe = SafePath::new("src/generated").unwrap();
    /// let path_buf = safe.as_path_buf();
    /// assert_eq!(path_buf.to_str().unwrap(), "src/generated");
    /// ```
    #[must_use]
    pub fn as_path_buf(&self) -> PathBuf {
        self.inner.clone()
    }

    /// Create a SafePath allowing absolute paths (for system paths like config files)
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// let safe = SafePath::new_absolute("/tmp/config.toml").unwrap();
    /// assert!(safe.as_path().is_absolute());
    /// ```
    pub fn new_absolute<P: AsRef<Path>>(path: P) -> Result<Self> {
        let path = path.as_ref();
        // For absolute paths, we skip the relative path validation
        // but still check for parent dir components and other security issues

        // Check for empty path
        if path.as_os_str().is_empty() {
            return Err(Error::invalid_input("Path cannot be empty"));
        }

        // Check for parent directory references in original path
        for component in path.components() {
            if let std::path::Component::ParentDir = component {
                return Err(Error::invalid_input(format!(
                    "Path contains parent directory reference (..): {}",
                    path.display()
                )));
            }
        }

        // No normalization for absolute paths - use as-is
        Ok(Self {
            inner: path.to_path_buf(),
        })
    }

    /// Get current working directory as SafePath
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// let cwd = SafePath::current_dir().unwrap();
    /// assert!(cwd.as_path().is_absolute());
    /// ```
    pub fn current_dir() -> Result<Self> {
        let cwd = std::env::current_dir()
            .map_err(|e| Error::new(&format!("Failed to get current directory: {}", e)))?;
        Self::new_absolute(cwd)
    }

    /// Get the parent directory
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// let path = SafePath::new("src/generated").unwrap();
    /// let parent = path.parent().unwrap();
    /// assert_eq!(parent.as_path().to_str().unwrap(), "src");
    /// ```
    pub fn parent(&self) -> Result<Self> {
        let parent_path = self
            .inner
            .parent()
            .ok_or_else(|| Error::invalid_input("Path has no parent"))?;
        // For parent, we need to check if it's absolute or relative
        if parent_path.is_absolute() {
            Self::new_absolute(parent_path)
        } else {
            Self::new(parent_path)
        }
    }

    /// Check if path exists on filesystem
    ///
    /// # Examples
    ///
    /// ```rust
    /// use crate::utils::safe_path::SafePath;
    ///
    /// let cwd = SafePath::current_dir().unwrap();
    /// assert!(cwd.exists());
    /// ```
    #[must_use]
    pub fn exists(&self) -> bool {
        self.inner.exists()
    }

    /// Validate a path against security constraints
    ///
    /// This performs the following checks:
    /// - Path is not empty
    /// - No parent directory references (..)
    /// - Path depth does not exceed MAX_PATH_DEPTH
    /// - Path components are not empty or whitespace-only
    fn validate_path(path: &Path) -> Result<()> {
        // Check for empty path
        if path.as_os_str().is_empty() {
            return Err(Error::invalid_input("Path cannot be empty"));
        }

        // Normalize and check for parent references in the final path
        let normalized = Self::normalize_path(path);

        // Check each component
        let components: Vec<_> = normalized.components().collect();

        // Check depth
        if components.len() > MAX_PATH_DEPTH {
            return Err(Error::invalid_input(format!(
                "Path depth {} exceeds maximum allowed depth of {}",
                components.len(),
                MAX_PATH_DEPTH
            )));
        }

        // Check for parent directory references in original path
        for component in path.components() {
            if let std::path::Component::ParentDir = component {
                return Err(Error::invalid_input(format!(
                    "Path contains parent directory reference (..): {}",
                    path.display()
                )));
            }
        }

        // Check for empty or whitespace-only components
        for component in &components {
            if let std::path::Component::Normal(os_str) = component {
                if let Some(s) = os_str.to_str() {
                    if s.trim().is_empty() {
                        return Err(Error::invalid_input(
                            "Path components cannot be empty or whitespace-only",
                        ));
                    }
                }
            }
        }

        Ok(())
    }

    /// Normalize a path by removing redundant separators and current directory references
    ///
    /// This does NOT resolve symlinks or make the path absolute - it only performs
    /// basic normalization of the path string representation.
    fn normalize_path(path: &Path) -> PathBuf {
        let mut normalized = PathBuf::new();

        for component in path.components() {
            match component {
                std::path::Component::CurDir => {
                    // Skip current directory references
                }
                std::path::Component::Normal(_) => {
                    normalized.push(component);
                }
                _ => {
                    // Keep other components (RootDir, Prefix, ParentDir)
                    // Note: ParentDir will be caught by validation
                    normalized.push(component);
                }
            }
        }

        normalized
    }
}

impl TryFrom<&str> for SafePath {
    type Error = Error;

    fn try_from(value: &str) -> Result<Self> {
        Self::new(value)
    }
}

impl TryFrom<String> for SafePath {
    type Error = Error;

    fn try_from(value: String) -> Result<Self> {
        Self::new(value)
    }
}

impl TryFrom<&String> for SafePath {
    type Error = Error;

    fn try_from(value: &String) -> Result<Self> {
        Self::new(value)
    }
}

impl TryFrom<PathBuf> for SafePath {
    type Error = Error;

    fn try_from(value: PathBuf) -> Result<Self> {
        Self::new(value)
    }
}

impl TryFrom<&Path> for SafePath {
    type Error = Error;

    fn try_from(value: &Path) -> Result<Self> {
        Self::new(value)
    }
}

impl fmt::Display for SafePath {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.inner.display())
    }
}

impl AsRef<Path> for SafePath {
    fn as_ref(&self) -> &Path {
        &self.inner
    }
}

impl AsRef<PathBuf> for SafePath {
    fn as_ref(&self) -> &PathBuf {
        &self.inner
    }
}

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

    // Test Category: Basic Construction

    #[test]
    fn test_new_simple_path() {
        // Arrange
        let path = "src/generated";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_ok());
        let safe_path = result.unwrap();
        assert_eq!(safe_path.as_path().to_str().unwrap(), "src/generated");
    }

    #[test]
    fn test_new_single_component() {
        // Arrange
        let path = "test";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap().as_path().to_str().unwrap(), "test");
    }

    #[test]
    fn test_new_with_current_dir_prefix() {
        // Arrange
        let path = "./output";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_ok());
        // Current directory reference should be normalized away
        assert_eq!(result.unwrap().as_path().to_str().unwrap(), "output");
    }

    #[test]
    fn test_new_with_multiple_current_dirs() {
        // Arrange
        let path = "./src/./generated/./output";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(
            result.unwrap().as_path().to_str().unwrap(),
            "src/generated/output"
        );
    }

    // Test Category: Parent Directory Attacks

    #[test]
    fn test_new_parent_dir_fails() {
        // Arrange
        let path = "../etc/passwd";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_err());
        let err = result.unwrap_err();
        assert!(err.to_string().contains("parent directory reference"));
    }

    #[test]
    fn test_new_parent_dir_in_middle_fails() {
        // Arrange
        let path = "src/../../../etc/passwd";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("parent directory"));
    }

    #[test]
    fn test_new_parent_dir_at_end_fails() {
        // Arrange
        let path = "src/generated/..";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("parent directory"));
    }

    #[test]
    fn test_new_multiple_parent_dirs_fails() {
        // Arrange
        let path = "../../../../../../etc/passwd";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("parent directory"));
    }

    // Test Category: Empty and Invalid Paths

    #[test]
    fn test_new_empty_path_fails() {
        // Arrange
        let path = "";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("cannot be empty"));
    }

    #[test]
    fn test_new_whitespace_component_fails() {
        // Arrange
        let path = "src/   /generated";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("whitespace-only"));
    }

    // Test Category: Depth Validation

    #[test]
    fn test_new_max_depth_allowed() {
        // Arrange - Create path at exact MAX_PATH_DEPTH (20)
        let components: Vec<String> = (0..MAX_PATH_DEPTH).map(|i| format!("level{}", i)).collect();
        let path = components.join("/");

        // Act
        let result = SafePath::new(&path);

        // Assert
        assert!(result.is_ok());
    }

    #[test]
    fn test_new_exceeds_max_depth_fails() {
        // Arrange - Create path with 21 levels (exceeds MAX_PATH_DEPTH)
        let components: Vec<String> = (0..=MAX_PATH_DEPTH)
            .map(|i| format!("level{}", i))
            .collect();
        let path = components.join("/");

        // Act
        let result = SafePath::new(&path);

        // Assert
        assert!(result.is_err());
        let err = result.unwrap_err();
        assert!(err.to_string().contains("exceeds maximum allowed depth"));
        assert!(err.to_string().contains("20"));
    }

    // Test Category: Join Operations

    #[test]
    fn test_join_simple() {
        // Arrange
        let base = SafePath::new("src").unwrap();

        // Act
        let result = base.join("generated");

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap().as_path().to_str().unwrap(), "src/generated");
    }

    #[test]
    fn test_join_multiple_times() {
        // Arrange
        let base = SafePath::new("src").unwrap();

        // Act
        let step1 = base.join("generated").unwrap();
        let step2 = step1.join("output").unwrap();
        let result = step2.join("file.rs");

        // Assert
        assert!(result.is_ok());
        assert_eq!(
            result.unwrap().as_path().to_str().unwrap(),
            "src/generated/output/file.rs"
        );
    }

    #[test]
    fn test_join_with_parent_dir_fails() {
        // Arrange
        let base = SafePath::new("src").unwrap();

        // Act
        let result = base.join("../etc");

        // Assert
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("parent directory"));
    }

    #[test]
    fn test_join_exceeding_depth_fails() {
        // Arrange - Create base path at 18 levels
        let components: Vec<String> = (0..18).map(|i| format!("level{}", i)).collect();
        let base = SafePath::new(components.join("/")).unwrap();

        // Act - Try to join 3 more levels (total 21, exceeds 20)
        let result = base.join("level18/level19/level20");

        // Assert
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("exceeds maximum allowed depth"));
    }

    // Test Category: Type Conversions

    #[test]
    fn test_try_from_str() {
        // Arrange
        let path = "src/generated";

        // Act
        let result = SafePath::try_from(path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap().as_path().to_str().unwrap(), "src/generated");
    }

    #[test]
    fn test_try_from_string() {
        // Arrange
        let path = String::from("src/generated");

        // Act
        let result = SafePath::try_from(path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap().as_path().to_str().unwrap(), "src/generated");
    }

    #[test]
    fn test_try_from_string_ref() {
        // Arrange
        let path = String::from("src/generated");

        // Act
        let result = SafePath::try_from(&path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap().as_path().to_str().unwrap(), "src/generated");
    }

    #[test]
    fn test_try_from_path_buf() {
        // Arrange
        let path = PathBuf::from("src/generated");

        // Act
        let result = SafePath::try_from(path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap().as_path().to_str().unwrap(), "src/generated");
    }

    #[test]
    fn test_try_from_path() {
        // Arrange
        let path = Path::new("src/generated");

        // Act
        let result = SafePath::try_from(path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(result.unwrap().as_path().to_str().unwrap(), "src/generated");
    }

    #[test]
    fn test_try_from_invalid_str_fails() {
        // Arrange
        let path = "../etc/passwd";

        // Act
        let result = SafePath::try_from(path);

        // Assert
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("parent directory"));
    }

    // Test Category: Display and AsRef Traits

    #[test]
    fn test_display_trait() {
        // Arrange
        let safe = SafePath::new("src/generated").unwrap();

        // Act
        let display_string = format!("{}", safe);

        // Assert
        assert_eq!(display_string, "src/generated");
    }

    #[test]
    fn test_debug_trait() {
        // Arrange
        let safe = SafePath::new("src/generated").unwrap();

        // Act
        let debug_string = format!("{:?}", safe);

        // Assert
        assert!(debug_string.contains("SafePath"));
        assert!(debug_string.contains("src/generated"));
    }

    #[test]
    fn test_as_ref_path() {
        // Arrange
        let safe = SafePath::new("src/generated").unwrap();

        // Act
        let path_ref: &Path = safe.as_ref();

        // Assert
        assert_eq!(path_ref.to_str().unwrap(), "src/generated");
    }

    #[test]
    fn test_as_ref_path_buf() {
        // Arrange
        let safe = SafePath::new("src/generated").unwrap();

        // Act
        let path_buf_ref: &PathBuf = safe.as_ref();

        // Assert
        assert_eq!(path_buf_ref.to_str().unwrap(), "src/generated");
    }

    // Test Category: Equality and Cloning

    #[test]
    fn test_equality() {
        // Arrange
        let safe1 = SafePath::new("src/generated").unwrap();
        let safe2 = SafePath::new("src/generated").unwrap();
        let safe3 = SafePath::new("src/output").unwrap();

        // Act & Assert
        assert_eq!(safe1, safe2);
        assert_ne!(safe1, safe3);
    }

    #[test]
    fn test_clone() {
        // Arrange
        let safe = SafePath::new("src/generated").unwrap();

        // Act
        let cloned = safe.clone();

        // Assert
        assert_eq!(safe, cloned);
        assert_eq!(safe.as_path(), cloned.as_path());
    }

    // Test Category: Path Normalization

    #[test]
    fn test_normalization_removes_current_dir() {
        // Arrange
        let path = "./src/./generated/./output";

        // Act
        let safe = SafePath::new(path).unwrap();

        // Assert
        assert_eq!(safe.as_path().to_str().unwrap(), "src/generated/output");
    }

    #[test]
    fn test_into_path_buf() {
        // Arrange
        let safe = SafePath::new("src/generated").unwrap();

        // Act
        let path_buf = safe.into_path_buf();

        // Assert
        assert_eq!(path_buf.to_str().unwrap(), "src/generated");
    }

    // Test Category: Edge Cases

    #[test]
    fn test_path_with_file_extension() {
        // Arrange
        let path = "src/generated/output.rs";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(
            result.unwrap().as_path().to_str().unwrap(),
            "src/generated/output.rs"
        );
    }

    #[test]
    fn test_path_with_special_chars_in_name() {
        // Arrange
        let path = "src/my-project_v2.0/output";

        // Act
        let result = SafePath::new(path);

        // Assert
        assert!(result.is_ok());
        assert_eq!(
            result.unwrap().as_path().to_str().unwrap(),
            "src/my-project_v2.0/output"
        );
    }
}