compose-lens 0.2.0

Loss-aware parsing, processing, validation, and rendering of Compose projects
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
//! Typed service-volume mounts that preserve their authored syntax form.

use super::{BooleanValue, ComposeScalar, FieldReference, Labels, Located};
use crate::source::SourceSpan;

/// The authored Compose syntax form of a service-volume mount.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VolumeSyntax {
    /// A colon-delimited scalar such as `./data:/var/lib/data:Z`.
    Short,
    /// A mapping with fields such as `type`, `source`, and `target`.
    Long,
}

/// A requested `SELinux` relabel mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SelinuxRelabel {
    /// Shared relabeling, spelled `z`.
    Shared,
    /// Private relabeling, spelled `Z`.
    Private,
}

/// A container-side mount path classified independently of the host operating system.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ContainerPath {
    raw: String,
    kind: ContainerPathKind,
}

impl ContainerPath {
    fn parse(raw: String) -> Self {
        let kind = if raw.starts_with('/') {
            ContainerPathKind::UnixAbsolute
        } else if is_windows_drive_absolute(&raw) {
            ContainerPathKind::WindowsDriveAbsolute
        } else if raw.starts_with(r"\\") || raw.starts_with("//") {
            ContainerPathKind::WindowsUnc
        } else if raw.contains('$') {
            ContainerPathKind::Deferred
        } else {
            ContainerPathKind::Relative
        };
        Self { raw, kind }
    }

    /// Returns the target path without changing separators or spelling.
    #[must_use]
    pub fn raw(&self) -> &str {
        &self.raw
    }

    /// Returns the container-platform lexical path kind.
    #[must_use]
    pub const fn kind(&self) -> ContainerPathKind {
        self.kind
    }
}

/// The lexical family of a container-side path.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ContainerPathKind {
    /// A `/`-prefixed Unix container path.
    UnixAbsolute,
    /// A drive-letter Windows container path.
    WindowsDriveAbsolute,
    /// A Windows UNC container path.
    WindowsUnc,
    /// A relative path retained for later validation.
    Relative,
    /// A path whose shape depends on interpolation.
    Deferred,
}

/// A long-syntax service-volume mount type.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum MountType {
    /// A named or anonymous container volume.
    Volume,
    /// A host bind mount.
    Bind,
    /// An in-memory temporary filesystem.
    Tmpfs,
    /// A Windows named pipe.
    NamedPipe,
    /// An image-backed mount.
    Image,
    /// A cluster-managed mount.
    Cluster,
    /// A value not recognized by this `ComposeLens` release.
    Other(String),
}

impl MountType {
    pub(crate) fn from_text(value: String) -> Self {
        match value.as_str() {
            "volume" => Self::Volume,
            "bind" => Self::Bind,
            "tmpfs" => Self::Tmpfs,
            "npipe" => Self::NamedPipe,
            "image" => Self::Image,
            "cluster" => Self::Cluster,
            _ => Self::Other(value),
        }
    }
}

/// A short-syntax service-volume mount.
///
/// `source`, `target`, and `options` are a conservative decomposition for common Compose
/// strings. [`Self::raw`] remains authoritative because platform-specific path grammars and
/// implementation extensions can make a short string ambiguous.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShortVolumeMount {
    raw: Located<String>,
    source: Option<String>,
    target: Option<String>,
    target_path: Option<ContainerPath>,
    options: Vec<String>,
}

impl ShortVolumeMount {
    pub(crate) fn new(raw: Located<String>) -> Self {
        let (source, target, options) = split_short_volume(raw.value());
        Self {
            raw,
            source,
            target_path: target.as_ref().map(|value| ContainerPath::parse(value.clone())),
            target,
            options,
        }
    }

    /// Returns the unquoted semantic scalar and its source span.
    #[must_use]
    pub const fn raw(&self) -> &Located<String> {
        &self.raw
    }

    /// Returns the conservatively parsed source, if one was present.
    #[must_use]
    pub fn source(&self) -> Option<&str> {
        self.source.as_deref()
    }

    /// Returns the conservatively parsed container target.
    #[must_use]
    pub fn target(&self) -> Option<&str> {
        self.target.as_deref()
    }

    /// Returns the target classified using container-platform lexical rules.
    ///
    /// This does not consult the host operating system, so `/project/node_modules` remains an
    /// anonymous Unix-container target even when `ComposeLens` runs on Windows.
    #[must_use]
    pub const fn target_path(&self) -> Option<&ContainerPath> {
        self.target_path.as_ref()
    }

    /// Returns access-mode tokens in authored order.
    #[must_use]
    pub fn options(&self) -> &[String] {
        &self.options
    }

    /// Returns the requested `SELinux` relabel mode, if present.
    #[must_use]
    pub fn selinux_relabel(&self) -> Option<SelinuxRelabel> {
        self.options.iter().find_map(|option| match option.as_str() {
            "z" => Some(SelinuxRelabel::Shared),
            "Z" => Some(SelinuxRelabel::Private),
            _ => None,
        })
    }
}

/// Bind-specific options in a long-syntax mount.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BindOptions {
    span: SourceSpan,
    propagation: Option<Located<String>>,
    create_host_path: Option<Located<BooleanValue>>,
    selinux: Option<Located<SelinuxRelabel>>,
    recursive: Option<Located<String>>,
    extension_fields: Vec<FieldReference>,
    unknown_fields: Vec<FieldReference>,
}

impl BindOptions {
    pub(crate) fn new(span: SourceSpan) -> Self {
        Self {
            span,
            propagation: None,
            create_host_path: None,
            selinux: None,
            recursive: None,
            extension_fields: Vec::new(),
            unknown_fields: Vec::new(),
        }
    }

    pub(crate) fn set_propagation(&mut self, value: Located<String>) {
        self.propagation = Some(value);
    }

    pub(crate) fn set_create_host_path(&mut self, value: Located<BooleanValue>) {
        self.create_host_path = Some(value);
    }

    pub(crate) fn set_selinux(&mut self, value: Located<SelinuxRelabel>) {
        self.selinux = Some(value);
    }

    pub(crate) fn set_recursive(&mut self, value: Located<String>) {
        self.recursive = Some(value);
    }

    pub(crate) fn push_extension(&mut self, field: FieldReference) {
        self.extension_fields.push(field);
    }

    pub(crate) fn push_unknown(&mut self, field: FieldReference) {
        self.unknown_fields.push(field);
    }

    /// Returns the complete `bind` mapping span.
    #[must_use]
    pub const fn span(&self) -> SourceSpan {
        self.span
    }

    /// Returns the requested bind-propagation mode.
    #[must_use]
    pub const fn propagation(&self) -> Option<&Located<String>> {
        self.propagation.as_ref()
    }

    /// Returns the explicitly authored host-path creation setting.
    ///
    /// `None` means the field was omitted; it is deliberately not replaced by an
    /// implementation default during typed parsing.
    #[must_use]
    pub const fn create_host_path(&self) -> Option<&Located<BooleanValue>> {
        self.create_host_path.as_ref()
    }

    /// Returns the requested `SELinux` relabel mode.
    #[must_use]
    pub const fn selinux(&self) -> Option<&Located<SelinuxRelabel>> {
        self.selinux.as_ref()
    }

    /// Returns the authored recursive bind mode without interpreting host mount behavior.
    #[must_use]
    pub const fn recursive(&self) -> Option<&Located<String>> {
        self.recursive.as_ref()
    }

    /// Returns `x-` extension fields retained from the bind mapping.
    #[must_use]
    pub fn extension_fields(&self) -> &[FieldReference] {
        &self.extension_fields
    }

    /// Returns unrecognized bind fields retained from the source.
    #[must_use]
    pub fn unknown_fields(&self) -> &[FieldReference] {
        &self.unknown_fields
    }
}

/// Image-specific options in a long-syntax service-volume mount.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ImageMountOptions {
    span: SourceSpan,
    subpath: Option<Located<String>>,
    extension_fields: Vec<FieldReference>,
    unknown_fields: Vec<FieldReference>,
}

impl ImageMountOptions {
    pub(crate) fn new(span: SourceSpan) -> Self {
        Self {
            span,
            subpath: None,
            extension_fields: Vec::new(),
            unknown_fields: Vec::new(),
        }
    }
    pub(crate) fn set_subpath(&mut self, value: Located<String>) {
        self.subpath = Some(value);
    }
    pub(crate) fn push_extension(&mut self, field: FieldReference) {
        self.extension_fields.push(field);
    }
    pub(crate) fn push_unknown(&mut self, field: FieldReference) {
        self.unknown_fields.push(field);
    }
    /// Returns the complete `image` mapping span.
    #[must_use]
    pub const fn span(&self) -> SourceSpan {
        self.span
    }
    /// Returns the authored image subpath without resolving an image or filesystem.
    #[must_use]
    pub const fn subpath(&self) -> Option<&Located<String>> {
        self.subpath.as_ref()
    }
    /// Returns retained `x-` image fields.
    #[must_use]
    pub fn extension_fields(&self) -> &[FieldReference] {
        &self.extension_fields
    }
    /// Returns unrecognized or malformed image fields retained from source.
    #[must_use]
    pub fn unknown_fields(&self) -> &[FieldReference] {
        &self.unknown_fields
    }
}

/// Tmpfs-specific options in a long-syntax service-volume mount.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TmpfsMountOptions {
    span: SourceSpan,
    size: Option<Located<ComposeScalar>>,
    mode: Option<Located<ComposeScalar>>,
    extension_fields: Vec<FieldReference>,
    unknown_fields: Vec<FieldReference>,
}

impl TmpfsMountOptions {
    pub(crate) fn new(span: SourceSpan) -> Self {
        Self {
            span,
            size: None,
            mode: None,
            extension_fields: Vec::new(),
            unknown_fields: Vec::new(),
        }
    }
    pub(crate) fn set_size(&mut self, value: Located<ComposeScalar>) {
        self.size = Some(value);
    }
    pub(crate) fn set_mode(&mut self, value: Located<ComposeScalar>) {
        self.mode = Some(value);
    }
    pub(crate) fn push_extension(&mut self, field: FieldReference) {
        self.extension_fields.push(field);
    }
    pub(crate) fn push_unknown(&mut self, field: FieldReference) {
        self.unknown_fields.push(field);
    }
    /// Returns the complete `tmpfs` mapping span.
    #[must_use]
    pub const fn span(&self) -> SourceSpan {
        self.span
    }
    /// Returns the raw size scalar without parsing units or consulting runtime defaults.
    #[must_use]
    pub const fn size(&self) -> Option<&Located<ComposeScalar>> {
        self.size.as_ref()
    }
    /// Returns the raw mode scalar without interpreting permission bits.
    #[must_use]
    pub const fn mode(&self) -> Option<&Located<ComposeScalar>> {
        self.mode.as_ref()
    }
    /// Returns retained `x-` tmpfs fields.
    #[must_use]
    pub fn extension_fields(&self) -> &[FieldReference] {
        &self.extension_fields
    }
    /// Returns unrecognized or malformed tmpfs fields retained from source.
    #[must_use]
    pub fn unknown_fields(&self) -> &[FieldReference] {
        &self.unknown_fields
    }
}

/// Volume-specific options in a long-syntax service-volume mount.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VolumeMountOptions {
    span: SourceSpan,
    nocopy: Option<Located<BooleanValue>>,
    subpath: Option<Located<String>>,
    labels: Option<Labels>,
    extension_fields: Vec<FieldReference>,
    unknown_fields: Vec<FieldReference>,
}

impl VolumeMountOptions {
    pub(crate) fn new(span: SourceSpan) -> Self {
        Self {
            span,
            nocopy: None,
            subpath: None,
            labels: None,
            extension_fields: Vec::new(),
            unknown_fields: Vec::new(),
        }
    }
    pub(crate) fn set_nocopy(&mut self, value: Located<BooleanValue>) {
        self.nocopy = Some(value);
    }
    pub(crate) fn set_subpath(&mut self, value: Located<String>) {
        self.subpath = Some(value);
    }
    pub(crate) fn set_labels(&mut self, value: Labels) {
        self.labels = Some(value);
    }
    pub(crate) fn push_extension(&mut self, field: FieldReference) {
        self.extension_fields.push(field);
    }
    pub(crate) fn push_unknown(&mut self, field: FieldReference) {
        self.unknown_fields.push(field);
    }
    /// Returns the complete `volume` mapping span.
    #[must_use]
    pub const fn span(&self) -> SourceSpan {
        self.span
    }
    /// Returns the explicit copy-prevention setting without inferring a runtime default.
    #[must_use]
    pub const fn nocopy(&self) -> Option<&Located<BooleanValue>> {
        self.nocopy.as_ref()
    }
    /// Returns the authored named-volume subpath without resolving a volume or filesystem.
    #[must_use]
    pub const fn subpath(&self) -> Option<&Located<String>> {
        self.subpath.as_ref()
    }
    /// Returns named-volume labels in their authored list or mapping form.
    #[must_use]
    pub const fn labels(&self) -> Option<&Labels> {
        self.labels.as_ref()
    }
    /// Returns retained `x-` volume-option fields.
    #[must_use]
    pub fn extension_fields(&self) -> &[FieldReference] {
        &self.extension_fields
    }
    /// Returns unrecognized or malformed volume-option fields retained from source.
    #[must_use]
    pub fn unknown_fields(&self) -> &[FieldReference] {
        &self.unknown_fields
    }
}

/// A long-syntax service-volume mount.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LongVolumeMount {
    span: SourceSpan,
    mount_type: Option<Located<MountType>>,
    source: Option<Located<String>>,
    target: Option<Located<String>>,
    target_path: Option<Located<ContainerPath>>,
    read_only: Option<Located<BooleanValue>>,
    consistency: Option<Located<String>>,
    bind: Option<BindOptions>,
    image: Option<ImageMountOptions>,
    tmpfs: Option<TmpfsMountOptions>,
    volume: Option<VolumeMountOptions>,
    extension_fields: Vec<FieldReference>,
    unknown_fields: Vec<FieldReference>,
}

impl LongVolumeMount {
    pub(crate) fn new(span: SourceSpan) -> Self {
        Self {
            span,
            mount_type: None,
            source: None,
            target: None,
            target_path: None,
            read_only: None,
            consistency: None,
            bind: None,
            image: None,
            tmpfs: None,
            volume: None,
            extension_fields: Vec::new(),
            unknown_fields: Vec::new(),
        }
    }

    pub(crate) fn set_mount_type(&mut self, value: Located<MountType>) {
        self.mount_type = Some(value);
    }

    pub(crate) fn set_source(&mut self, value: Located<String>) {
        self.source = Some(value);
    }

    pub(crate) fn set_target(&mut self, value: Located<String>) {
        self.target_path = Some(Located::new(ContainerPath::parse(value.value.clone()), value.span));
        self.target = Some(value);
    }

    pub(crate) fn set_read_only(&mut self, value: Located<BooleanValue>) {
        self.read_only = Some(value);
    }

    pub(crate) fn set_consistency(&mut self, value: Located<String>) {
        self.consistency = Some(value);
    }

    pub(crate) fn set_bind(&mut self, value: BindOptions) {
        self.bind = Some(value);
    }
    pub(crate) fn set_image(&mut self, value: ImageMountOptions) {
        self.image = Some(value);
    }
    pub(crate) fn set_tmpfs(&mut self, value: TmpfsMountOptions) {
        self.tmpfs = Some(value);
    }
    pub(crate) fn set_volume(&mut self, value: VolumeMountOptions) {
        self.volume = Some(value);
    }

    pub(crate) fn push_extension(&mut self, field: FieldReference) {
        self.extension_fields.push(field);
    }

    pub(crate) fn push_unknown(&mut self, field: FieldReference) {
        self.unknown_fields.push(field);
    }

    /// Returns the complete mapping span.
    #[must_use]
    pub const fn span(&self) -> SourceSpan {
        self.span
    }

    /// Returns the explicitly authored mount type.
    #[must_use]
    pub const fn mount_type(&self) -> Option<&Located<MountType>> {
        self.mount_type.as_ref()
    }

    /// Returns the mount source.
    #[must_use]
    pub const fn source(&self) -> Option<&Located<String>> {
        self.source.as_ref()
    }

    /// Returns the container target.
    #[must_use]
    pub const fn target(&self) -> Option<&Located<String>> {
        self.target.as_ref()
    }

    /// Returns the target classified using container-platform lexical rules.
    #[must_use]
    pub const fn target_path(&self) -> Option<&Located<ContainerPath>> {
        self.target_path.as_ref()
    }

    /// Returns the explicitly authored read-only setting.
    #[must_use]
    pub const fn read_only(&self) -> Option<&Located<BooleanValue>> {
        self.read_only.as_ref()
    }

    /// Returns the authored consistency token without provider/default interpretation.
    #[must_use]
    pub const fn consistency(&self) -> Option<&Located<String>> {
        self.consistency.as_ref()
    }

    /// Returns long-syntax bind options.
    #[must_use]
    pub const fn bind(&self) -> Option<&BindOptions> {
        self.bind.as_ref()
    }

    /// Returns long-syntax image-mount options.
    #[must_use]
    pub const fn image(&self) -> Option<&ImageMountOptions> {
        self.image.as_ref()
    }
    /// Returns long-syntax tmpfs-mount options.
    #[must_use]
    pub const fn tmpfs(&self) -> Option<&TmpfsMountOptions> {
        self.tmpfs.as_ref()
    }
    /// Returns long-syntax named-volume options.
    #[must_use]
    pub const fn volume(&self) -> Option<&VolumeMountOptions> {
        self.volume.as_ref()
    }

    /// Returns `x-` extension fields retained from the mount mapping.
    #[must_use]
    pub fn extension_fields(&self) -> &[FieldReference] {
        &self.extension_fields
    }

    /// Returns recognized-by-Compose but not-yet-typed and unrecognized fields.
    #[must_use]
    pub fn unknown_fields(&self) -> &[FieldReference] {
        &self.unknown_fields
    }
}

/// A service-volume mount with its authored syntax form retained.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum VolumeMount {
    /// Colon-delimited short syntax.
    Short(ShortVolumeMount),
    /// Mapping-based long syntax.
    Long(Box<LongVolumeMount>),
}

impl VolumeMount {
    /// Returns the authored syntax form.
    #[must_use]
    pub const fn syntax(&self) -> VolumeSyntax {
        match self {
            Self::Short(_) => VolumeSyntax::Short,
            Self::Long(_) => VolumeSyntax::Long,
        }
    }

    /// Returns the complete source span of the mount value.
    #[must_use]
    pub const fn span(&self) -> SourceSpan {
        match self {
            Self::Short(value) => value.raw().span(),
            Self::Long(value) => value.span(),
        }
    }

    /// Returns the requested `SELinux` relabel mode without erasing syntax provenance.
    #[must_use]
    pub fn selinux_relabel(&self) -> Option<SelinuxRelabel> {
        match self {
            Self::Short(value) => value.selinux_relabel(),
            Self::Long(value) => value.bind()?.selinux().map(|mode| *mode.value()),
        }
    }
}

fn split_short_volume(value: &str) -> (Option<String>, Option<String>, Vec<String>) {
    let fields = split_colon_fields(value);
    match fields.as_slice() {
        [] => (None, None, Vec::new()),
        [target] => (None, Some((*target).to_owned()), Vec::new()),
        [source, target] => (Some((*source).to_owned()), Some((*target).to_owned()), Vec::new()),
        [source, middle @ .., options] => (
            Some((*source).to_owned()),
            Some(middle.join(":")),
            options.split(',').map(str::to_owned).collect(),
        ),
    }
}

fn split_colon_fields(value: &str) -> Vec<&str> {
    let mut fields = Vec::new();
    let mut start = 0;
    for (index, character) in value.char_indices() {
        if character != ':' || is_drive_separator(value, start, index) {
            continue;
        }
        fields.push(&value[start..index]);
        start = index + character.len_utf8();
    }
    fields.push(&value[start..]);
    fields
}

fn is_drive_separator(value: &str, field_start: usize, colon_index: usize) -> bool {
    let field = &value[field_start..colon_index];
    let next = value[colon_index + 1..].chars().next();
    field.len() == 1 && field.as_bytes()[0].is_ascii_alphabetic() && matches!(next, Some('/' | '\\'))
}

fn is_windows_drive_absolute(value: &str) -> bool {
    value.as_bytes().get(1) == Some(&b':')
        && value.as_bytes().first().is_some_and(u8::is_ascii_alphabetic)
        && matches!(value.as_bytes().get(2), Some(b'/' | b'\\'))
}

#[cfg(test)]
mod tests {
    use super::{ContainerPathKind, ShortVolumeMount, split_short_volume};
    use crate::model::Located;
    use crate::source::{SourceId, SourceSpan};

    #[test]
    fn conservatively_splits_linux_and_windows_short_mounts() {
        assert_eq!(
            split_short_volume("./data:/var/lib/data:Z,ro"),
            (
                Some("./data".to_owned()),
                Some("/var/lib/data".to_owned()),
                vec!["Z".to_owned(), "ro".to_owned()]
            )
        );
        assert_eq!(
            split_short_volume(r"C:\data:/var/lib/data:z"),
            (
                Some(r"C:\data".to_owned()),
                Some("/var/lib/data".to_owned()),
                vec!["z".to_owned()]
            )
        );
        assert_eq!(
            split_short_volume("cache:/cache"),
            (Some("cache".to_owned()), Some("/cache".to_owned()), Vec::new())
        );
    }

    #[test]
    fn classifies_anonymous_targets_without_host_path_apis() -> Result<(), &'static str> {
        let raw = "/project/node_modules";
        let span = SourceSpan::new(SourceId::new(1), 0, raw.len()).ok_or("valid test span expected")?;
        let mount = ShortVolumeMount::new(Located::new(raw.to_owned(), span));
        assert_eq!(mount.source(), None);
        assert_eq!(
            mount.target_path().map(super::ContainerPath::kind),
            Some(ContainerPathKind::UnixAbsolute)
        );
        Ok(())
    }
}