lib3mf 0.1.6

Pure Rust implementation for 3MF (3D Manufacturing Format) parsing and writing
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
//! Production extension validation

use crate::error::{Error, Result};
use crate::model::{Extension, Model, ParserConfig};
use std::collections::HashSet;

/// Validates production extension path format and usage
pub fn validate_production_extension(model: &Model) -> Result<()> {
    // Helper function to validate p:path format
    let validate_path = |path: &str, context: &str| -> Result<()> {
        // Per 3MF Production Extension spec:
        // - Path MUST start with / (absolute path within the package)
        // - Path MUST NOT contain .. (no parent directory references)
        // - Path MUST NOT end with / (must reference a file, not a directory)
        // - Filename MUST NOT start with . (hidden files not allowed)

        if !path.starts_with('/') {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' must start with / (absolute path required)",
                context, path
            )));
        }

        if path.contains("..") {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' must not contain .. (parent directory traversal not allowed)",
                context, path
            )));
        }

        if path.ends_with('/') {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' must not end with / (must reference a file)",
                context, path
            )));
        }

        // Check for hidden files (filename starting with .)
        if let Some(filename) = path.rsplit('/').next()
            && filename.starts_with('.')
        {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' references a hidden file (filename cannot start with .)",
                context, path
            )));
        }

        // Path should reference a .model file
        if !path.ends_with(".model") {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' must reference a .model file",
                context, path
            )));
        }

        Ok(())
    };

    // Check all objects to validate production paths
    for object in &model.resources.objects {
        // Note: The thumbnail attribute is deprecated in 3MF v1.4+ when production extension is used,
        // but deprecation doesn't make it invalid. Per the official 3MF test suite, files with
        // thumbnail attributes and production extension should still parse successfully.
        // Therefore, we do not reject files with thumbnail attributes.

        // Validate production extension usage
        if let Some(ref prod_info) = object.production {
            // If object has production path, validate it
            if let Some(ref path) = prod_info.path {
                validate_path(path, &format!("Object {}", object.id))?;
            }
        }

        // Check components
        for (idx, component) in object.components.iter().enumerate() {
            if let Some(ref prod_info) = component.production {
                // Validate production path format if present
                // Note: component.path is set from prod_info.path during parsing
                // Per 3MF Production Extension spec:
                // - p:UUID can be used on components to uniquely identify them
                // - p:path is only required when referencing external objects (not in current file)
                // - A component with p:UUID but no p:path references a local object
                if let Some(ref path) = prod_info.path {
                    validate_path(path, &format!("Object {}, Component {}", object.id, idx))?;
                }
            }
        }
    }

    // Check build items for production path validation
    for (idx, item) in model.build.items.iter().enumerate() {
        if let Some(ref path) = item.production_path {
            validate_path(path, &format!("Build Item {}", idx))?;
        }
    }

    // Note: We don't validate that production attributes require the production extension
    // to be in requiredextensions, because per the 3MF spec, extensions can be declared
    // in namespaces (xmlns:p) without being in requiredextensions - they are then optional
    // extensions. The parser already validates that the production namespace is declared
    // when production attributes are used.

    Ok(())
}

/// Validate production extension requirements with parser configuration
///
/// This is a variant of `validate_production_extension` that accepts a parser config.
/// When the parser config explicitly supports the production extension, we allow
/// production attributes to be used even if the file doesn't declare the production
/// extension in requiredextensions. This is useful for backward compatibility and
/// for files that use production attributes but were created before strict validation.
pub fn validate_production_extension_with_config(
    model: &Model,
    config: &ParserConfig,
) -> Result<()> {
    // Check if production extension is required in the file
    let has_production = model.required_extensions.contains(&Extension::Production);

    // Check if the parser config explicitly supports production extension
    let config_supports_production = config.supports(&Extension::Production);

    // Track whether any production attributes are used (for validation later)
    let mut has_production_attrs = false;

    // Helper function to validate p:path format
    let validate_path = |path: &str, context: &str| -> Result<()> {
        // Per 3MF Production Extension spec:
        // - Path MUST start with / (absolute path within the package)
        // - Path MUST NOT contain .. (no parent directory references)
        // - Path MUST NOT end with / (must reference a file, not a directory)
        // - Filename MUST NOT start with . (hidden files not allowed)

        if !path.starts_with('/') {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' must start with / (absolute path required)",
                context, path
            )));
        }

        if path.contains("..") {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' must not contain .. (parent directory traversal not allowed)",
                context, path
            )));
        }

        if path.ends_with('/') {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' must not end with / (must reference a file)",
                context, path
            )));
        }

        // Check for hidden files (filename starting with .)
        if let Some(filename) = path.rsplit('/').next()
            && filename.starts_with('.')
        {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' references a hidden file (filename cannot start with .)",
                context, path
            )));
        }

        // Path should reference a .model file
        if !path.ends_with(".model") {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' must reference a .model file",
                context, path
            )));
        }

        Ok(())
    };

    // Check all objects to validate production paths
    for object in &model.resources.objects {
        // Note: The thumbnail attribute is deprecated in 3MF v1.4+ when production extension is used,
        // but deprecation doesn't make it invalid. Per the official 3MF test suite, files with
        // thumbnail attributes and production extension should still parse successfully.
        // Therefore, we do not reject files with thumbnail attributes.

        // Validate production extension usage and track attributes
        if let Some(ref prod_info) = object.production {
            has_production_attrs = true;

            // If object has production path, validate it
            if let Some(ref path) = prod_info.path {
                validate_path(path, &format!("Object {}", object.id))?;
            }
        }

        // Check components
        for (idx, component) in object.components.iter().enumerate() {
            if let Some(ref prod_info) = component.production {
                has_production_attrs = true;

                // Per 3MF Production Extension spec:
                // - p:UUID can be used on components to uniquely identify them
                // - p:path is only required when referencing external objects (not in current file)
                // - A component with p:UUID but no p:path references a local object
                // - When p:path is used (external reference), p:UUID is REQUIRED to identify the object

                // Validate that p:UUID is present when p:path is used
                if prod_info.path.is_some() && prod_info.uuid.is_none() {
                    return Err(Error::InvalidModel(format!(
                        "Object {}, Component {}: Component has p:path but missing required p:UUID.\n\
                         Per 3MF Production Extension spec, components with external references (p:path) \
                         must have p:UUID to identify the referenced object.\n\
                         Add p:UUID attribute to the component element.",
                        object.id, idx
                    )));
                }

                // Validate production path format if present
                // Note: component.path is set from prod_info.path during parsing
                if let Some(ref path) = prod_info.path {
                    validate_path(path, &format!("Object {}, Component {}", object.id, idx))?;
                }
            }
        }
    }

    // Check build items for production path validation
    for (idx, item) in model.build.items.iter().enumerate() {
        if item.production_uuid.is_some() || item.production_path.is_some() {
            has_production_attrs = true;
        }

        if let Some(ref path) = item.production_path {
            validate_path(path, &format!("Build Item {}", idx))?;
        }
    }

    // Check build production UUID
    if model.build.production_uuid.is_some() {
        has_production_attrs = true;
    }

    // Validate that production attributes are only used when production extension is declared
    // UNLESS the parser config explicitly supports production extension (for backward compatibility)
    if has_production_attrs && !has_production && !config_supports_production {
        return Err(Error::InvalidModel(
            "Production extension attributes (p:UUID, p:path) are used but production extension \
             is not declared in requiredextensions.\n\
             Per 3MF Production Extension specification, when using production attributes, \
             you must add 'p' to the requiredextensions attribute in the <model> element.\n\
             Example: requiredextensions=\"p\" or requiredextensions=\"m p\" for materials and production."
                .to_string(),
        ));
    }

    Ok(())
}

/// Validate displacement extension usage
///
/// Per Displacement Extension spec:
/// - Displacement2D resources must reference existing texture files in the package
/// - Disp2DGroup must reference existing Displacement2D and NormVectorGroup resources
/// - Disp2DCoord must reference valid normvector indices
/// - NormVectors must be normalized (unit length)
/// - DisplacementTriangle did must reference existing Disp2DGroup resources
/// - DisplacementTriangle d1, d2, d3 must reference valid displacement coordinates
///
/// Validates that production paths don't reference OPC internal files
pub fn validate_production_paths(model: &Model) -> Result<()> {
    // Helper function to validate that a path doesn't reference OPC internal files
    let validate_not_opc_internal = |path: &str, context: &str| -> Result<()> {
        // OPC internal paths that should not be referenced:
        // - /_rels/.rels or any path starting with /_rels/
        // - /[Content_Types].xml

        if path.starts_with("/_rels/") || path == "/_rels" {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' references OPC internal relationships directory.\n\
                 Production paths must not reference package internal files.",
                context, path
            )));
        }

        if path == "/[Content_Types].xml" {
            return Err(Error::InvalidModel(format!(
                "{}: Production path '{}' references OPC content types file.\n\
                 Production paths must not reference package internal files.",
                context, path
            )));
        }

        Ok(())
    };

    // Check all objects
    for object in &model.resources.objects {
        if let Some(ref prod_info) = object.production
            && let Some(ref path) = prod_info.path
        {
            validate_not_opc_internal(path, &format!("Object {}", object.id))?;
        }

        // Check components
        for (idx, component) in object.components.iter().enumerate() {
            if let Some(ref prod_info) = component.production
                && let Some(ref path) = prod_info.path
            {
                validate_not_opc_internal(
                    path,
                    &format!("Object {}, Component {}", object.id, idx),
                )?;
            }
        }
    }

    // Check build items - validate p:path doesn't reference OPC internal files
    for (idx, item) in model.build.items.iter().enumerate() {
        if let Some(ref path) = item.production_path {
            validate_not_opc_internal(path, &format!("Build item {}", idx))?;
        }
    }

    Ok(())
}

/// Validate transform matrices for build items
///
/// Per 3MF spec, transform matrices must have a non-negative determinant.
/// A negative determinant indicates a mirror transformation which would
/// invert the object's orientation (inside-out).
///
/// Exception: For sliced objects (objects with slicestackid), the transform
/// restrictions are different per the 3MF Slice Extension spec. Sliced objects
/// must have planar transforms (validated separately in validate_slice_extension),
/// but can have negative determinants (mirror transformations).
/// Validates that required UUIDs are present when production extension is used
pub fn validate_production_uuids_required(model: &Model) -> Result<()> {
    // Only validate if production extension is explicitly required in the model
    // The config.supports() tells us what the parser accepts, but we need to check
    // what the model file actually requires
    let production_required = model.required_extensions.contains(&Extension::Production);

    if !production_required {
        return Ok(());
    }

    // When production extension is required:
    // 1. Build MUST have UUID (Chapter 4.1) if it has items
    // Per spec, the build UUID is required to identify builds across devices/jobs
    if !model.build.items.is_empty() && model.build.production_uuid.is_none() {
        return Err(Error::InvalidModel(
            "Production extension requires build to have p:UUID attribute when build items are present".to_string(),
        ));
    }

    // 2. Build items MUST have UUID (Chapter 4.1.1)
    for (idx, item) in model.build.items.iter().enumerate() {
        if item.production_uuid.is_none() {
            return Err(Error::InvalidModel(format!(
                "Production extension requires build item {} to have p:UUID attribute",
                idx
            )));
        }
    }

    // 3. Objects MUST have UUID (Chapter 4.2)
    for object in &model.resources.objects {
        // Check if object has production info with UUID
        let has_uuid = object
            .production
            .as_ref()
            .and_then(|p| p.uuid.as_ref())
            .is_some();

        if !has_uuid {
            return Err(Error::InvalidModel(format!(
                "Production extension requires object {} to have p:UUID attribute",
                object.id
            )));
        }
    }

    Ok(())
}

/// Validate UUID format per RFC 4122
///
/// UUIDs must follow the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
/// where x is a hexadecimal digit (0-9, a-f, A-F).
pub fn validate_uuid_formats(model: &Model) -> Result<()> {
    // Helper function to validate a single UUID
    let validate_uuid = |uuid: &str, context: &str| -> Result<()> {
        // UUID format: 8-4-4-4-12 hexadecimal digits separated by hyphens
        // Example: 550e8400-e29b-41d4-a716-446655440000

        // Check length (36 characters including hyphens)
        if uuid.len() != 36 {
            return Err(Error::InvalidModel(format!(
                "{}: Invalid UUID '{}' - must be 36 characters in format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                context, uuid
            )));
        }

        // Check hyphen positions (at indices 8, 13, 18, 23)
        if uuid.chars().nth(8) != Some('-')
            || uuid.chars().nth(13) != Some('-')
            || uuid.chars().nth(18) != Some('-')
            || uuid.chars().nth(23) != Some('-')
        {
            return Err(Error::InvalidModel(format!(
                "{}: Invalid UUID '{}' - hyphens must be at positions 8, 13, 18, and 23",
                context, uuid
            )));
        }

        // Check that all other characters are hexadecimal digits
        for (idx, ch) in uuid.chars().enumerate() {
            if idx == 8 || idx == 13 || idx == 18 || idx == 23 {
                continue; // Skip hyphens
            }
            if !ch.is_ascii_hexdigit() {
                return Err(Error::InvalidModel(format!(
                    "{}: Invalid UUID '{}' - character '{}' at position {} is not a hexadecimal digit",
                    context, uuid, ch, idx
                )));
            }
        }

        Ok(())
    };

    // Validate build UUID
    if let Some(ref uuid) = model.build.production_uuid {
        validate_uuid(uuid, "Build")?;
    }

    // Validate build item UUIDs
    for (idx, item) in model.build.items.iter().enumerate() {
        if let Some(ref uuid) = item.production_uuid {
            validate_uuid(uuid, &format!("Build item {}", idx))?;
        }
    }

    // Validate object UUIDs
    for object in &model.resources.objects {
        if let Some(ref prod_info) = object.production
            && let Some(ref uuid) = prod_info.uuid
        {
            validate_uuid(uuid, &format!("Object {}", object.id))?;
        }

        // Validate component UUIDs
        for (idx, component) in object.components.iter().enumerate() {
            if let Some(ref prod_info) = component.production
                && let Some(ref uuid) = prod_info.uuid
            {
                validate_uuid(uuid, &format!("Object {}, Component {}", object.id, idx))?;
            }
        }
    }

    Ok(())
}

/// Validates that all UUIDs in the model are unique
///
/// Per 3MF Production Extension spec, UUIDs must be unique across:
/// - Build section
/// - Build items
/// - Objects
/// - Components
pub fn validate_duplicate_uuids(model: &Model) -> Result<()> {
    let mut uuids = HashSet::new();

    // Check build UUID
    if let Some(ref uuid) = model.build.production_uuid
        && !uuids.insert(uuid.clone())
    {
        return Err(Error::InvalidModel(format!(
            "Duplicate UUID '{}' found in build",
            uuid
        )));
    }

    // Check build item UUIDs
    for (idx, item) in model.build.items.iter().enumerate() {
        if let Some(ref uuid) = item.production_uuid
            && !uuids.insert(uuid.clone())
        {
            return Err(Error::InvalidModel(format!(
                "Duplicate UUID '{}' found in build item {}",
                uuid, idx
            )));
        }
    }

    // Check object UUIDs
    for object in &model.resources.objects {
        if let Some(ref production) = object.production
            && let Some(ref uuid) = production.uuid
            && !uuids.insert(uuid.clone())
        {
            return Err(Error::InvalidModel(format!(
                "Duplicate UUID '{}' found on object {}",
                uuid, object.id
            )));
        }

        // Check component UUIDs within each object
        for (comp_idx, component) in object.components.iter().enumerate() {
            if let Some(ref production) = component.production
                && let Some(ref uuid) = production.uuid
                && !uuids.insert(uuid.clone())
            {
                return Err(Error::InvalidModel(format!(
                    "Duplicate UUID '{}' found in object {} component {}",
                    uuid, object.id, comp_idx
                )));
            }
        }
    }
    Ok(())
}

/// N_XPX_0803_01: Validate no component reference chains across multiple model parts
///
/// **Note: This validation is intentionally disabled.**
///
/// Detecting component reference chains requires parsing and analyzing external
/// model files referenced via `p:path`. Since the parser only loads the root model
/// file, we cannot reliably detect multi-level chains.
///
/// A full implementation would require:
/// 1. Loading all referenced external model files
/// 2. Building a dependency graph across files
/// 3. Detecting cycles or chains longer than allowed depth
///
/// This is beyond the scope of single-file validation and would require
/// significant architectural changes to support multi-file analysis.
pub fn validate_component_chain(_model: &Model) -> Result<()> {
    // N_XPM_0803_01: Component reference chain validation
    //
    // The validation for components with p:path referencing local objects
    // is complex and requires more investigation of the 3MF Production Extension spec.
    // The current understanding is insufficient to implement this correctly.
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::model::{BuildItem, Component, Object, ProductionInfo};

    #[test]
    fn test_validate_empty_model() {
        let model = Model::new();
        assert!(validate_production_extension(&model).is_ok());
    }

    #[test]
    fn test_validate_path_invalid_no_leading_slash() {
        let mut model = Model::new();
        let mut item = BuildItem::new(1);
        item.production_path = Some("relative/path.3mf".to_string());
        model.build.items.push(item);
        let result = validate_production_extension(&model);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("start with /"));
    }

    #[test]
    fn test_validate_path_with_parent_dir() {
        let mut model = Model::new();
        let mut item = BuildItem::new(1);
        item.production_path = Some("/../secret.3mf".to_string());
        model.build.items.push(item);
        let result = validate_production_extension(&model);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains(".."));
    }

    #[test]
    fn test_validate_path_with_trailing_slash() {
        let mut model = Model::new();
        let mut item = BuildItem::new(1);
        item.production_path = Some("/3D/parts/".to_string());
        model.build.items.push(item);
        let result = validate_production_extension(&model);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("end with /"));
    }

    #[test]
    fn test_validate_valid_path() {
        let mut model = Model::new();
        let mut item = BuildItem::new(1);
        item.production_path = Some("/3D/parts/part.model".to_string()); // must end with .model
        model.build.items.push(item);
        assert!(validate_production_extension(&model).is_ok());
    }

    #[test]
    fn test_validate_path_opc_rels_dir() {
        let mut model = Model::new();
        let mut item = BuildItem::new(1);
        item.production_path = Some("/_rels/somefile".to_string());
        model.build.items.push(item);
        let result = validate_production_paths(&model);
        assert!(result.is_err());
        assert!(
            result
                .unwrap_err()
                .to_string()
                .contains("OPC internal relationships")
        );
    }

    #[test]
    fn test_validate_path_opc_content_types() {
        let mut model = Model::new();
        let mut item = BuildItem::new(1);
        item.production_path = Some("/[Content_Types].xml".to_string());
        model.build.items.push(item);
        let result = validate_production_paths(&model);
        assert!(result.is_err());
        assert!(
            result
                .unwrap_err()
                .to_string()
                .contains("OPC content types")
        );
    }

    #[test]
    fn test_validate_invalid_uuid_format() {
        let mut model = Model::new();
        let mut obj = Object::new(1);
        let mut info = ProductionInfo::default();
        info.uuid = Some("not-a-valid-uuid".to_string());
        obj.production = Some(info);
        model.resources.objects.push(obj);
        let result = validate_uuid_formats(&model);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("Invalid UUID"));
    }

    #[test]
    fn test_validate_valid_uuid_format() {
        let mut model = Model::new();
        let mut obj = Object::new(1);
        let mut info = ProductionInfo::default();
        info.uuid = Some("550e8400-e29b-41d4-a716-446655440000".to_string());
        obj.production = Some(info);
        model.resources.objects.push(obj);
        assert!(validate_uuid_formats(&model).is_ok());
    }

    #[test]
    fn test_validate_duplicate_uuids() {
        let mut model = Model::new();
        let uuid = "550e8400-e29b-41d4-a716-446655440000".to_string();
        let mut obj1 = Object::new(1);
        let mut info1 = ProductionInfo::default();
        info1.uuid = Some(uuid.clone());
        obj1.production = Some(info1);
        model.resources.objects.push(obj1);

        let mut obj2 = Object::new(2);
        let mut info2 = ProductionInfo::default();
        info2.uuid = Some(uuid.clone());
        obj2.production = Some(info2);
        model.resources.objects.push(obj2);

        let result = validate_duplicate_uuids(&model);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("Duplicate UUID"));
    }

    #[test]
    fn test_validate_component_path_without_uuid() {
        let mut model = Model::new();
        model.required_extensions.push(Extension::Production);

        let mut obj = Object::new(1);
        let config = ParserConfig::default();
        let mut prod_info = ProductionInfo::default();
        prod_info.path = Some("/3D/part.3mf".to_string());
        prod_info.uuid = None; // Missing UUID
        let mut component = Component::new(2);
        component.production = Some(prod_info);
        obj.components.push(component);
        model.resources.objects.push(obj);

        let result = validate_production_extension_with_config(&model, &config);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("p:UUID"));
    }
}