data-modelling-core 2.4.0

Core SDK library for model operations across platforms
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
//! YAML to Database sync logic
//!
//! Provides bidirectional synchronization between YAML files and the database.
//! Uses SHA256 hashing for change detection to enable incremental syncs.
//!
//! ## File Naming Convention
//!
//! All files use a flat naming pattern:
//! - `workspace.yaml` - workspace metadata with references to all assets
//! - `{workspace}_{domain}_{system}_{resource}.odcs.yaml` - ODCS table files
//! - `{workspace}_{domain}_{system}_{resource}.odps.yaml` - ODPS product files
//! - `{workspace}_{domain}_{system}_{resource}.cads.yaml` - CADS asset files
//! - `relationships.yaml` - relationship definitions
//!
//! Where `{system}` is optional if the resource is at the domain level.

use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use uuid::Uuid;

use super::{DatabaseBackend, DatabaseError, DatabaseResult, SyncStatus};
use crate::models::decision::Decision;
use crate::models::knowledge::KnowledgeArticle;
use crate::models::workspace::AssetType;
use crate::models::{Domain, Relationship, Table, Workspace};

/// Result of a sync operation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SyncResult {
    /// Workspace ID that was synced
    pub workspace_id: Uuid,
    /// Number of tables synced
    pub tables_synced: usize,
    /// Number of columns synced
    pub columns_synced: usize,
    /// Number of relationships synced
    pub relationships_synced: usize,
    /// Number of domains synced
    pub domains_synced: usize,
    /// Number of decisions synced
    pub decisions_synced: usize,
    /// Number of knowledge articles synced
    pub knowledge_synced: usize,
    /// Files that were skipped (unchanged)
    pub files_skipped: usize,
    /// Errors encountered during sync
    pub errors: Vec<String>,
    /// Duration of sync in milliseconds
    pub duration_ms: u64,
}

impl SyncResult {
    /// Create a new empty sync result
    pub fn new(workspace_id: Uuid) -> Self {
        Self {
            workspace_id,
            tables_synced: 0,
            columns_synced: 0,
            relationships_synced: 0,
            domains_synced: 0,
            decisions_synced: 0,
            knowledge_synced: 0,
            files_skipped: 0,
            errors: Vec::new(),
            duration_ms: 0,
        }
    }

    /// Check if sync was successful (no errors)
    pub fn is_success(&self) -> bool {
        self.errors.is_empty()
    }

    /// Get total items synced
    pub fn total_synced(&self) -> usize {
        self.tables_synced
            + self.relationships_synced
            + self.domains_synced
            + self.decisions_synced
            + self.knowledge_synced
    }
}

/// File information for sync
#[derive(Debug, Clone)]
pub struct FileInfo {
    /// Relative path from workspace root
    pub path: String,
    /// SHA256 hash of file content
    pub hash: String,
    /// File content
    pub content: Vec<u8>,
}

impl FileInfo {
    /// Create new file info with computed hash
    pub fn new(path: impl Into<String>, content: Vec<u8>) -> Self {
        let hash = compute_hash(&content);
        Self {
            path: path.into(),
            hash,
            content,
        }
    }
}

/// Sync engine for YAML to database synchronization
pub struct SyncEngine<B: DatabaseBackend> {
    backend: B,
}

impl<B: DatabaseBackend> SyncEngine<B> {
    /// Create a new sync engine with the given database backend
    pub fn new(backend: B) -> Self {
        Self { backend }
    }

    /// Get reference to the database backend
    pub fn backend(&self) -> &B {
        &self.backend
    }

    /// Initialize the database (run migrations)
    pub async fn initialize(&self) -> DatabaseResult<()> {
        self.backend.initialize().await
    }

    /// Sync a workspace from YAML files to database
    ///
    /// # Arguments
    /// * `workspace` - Workspace metadata
    /// * `tables` - Tables to sync
    /// * `relationships` - Relationships to sync
    /// * `domains` - Domains to sync
    /// * `force` - If true, ignore change detection and sync everything
    ///
    /// # Returns
    /// Sync result with counts and any errors
    pub async fn sync_workspace(
        &self,
        workspace: &Workspace,
        tables: &[Table],
        relationships: &[Relationship],
        domains: &[Domain],
        force: bool,
    ) -> DatabaseResult<SyncResult> {
        let start = std::time::Instant::now();
        let mut result = SyncResult::new(workspace.id);

        // Upsert workspace first
        self.backend.upsert_workspace(workspace).await?;

        // Sync domains
        if !domains.is_empty() || force {
            match self.backend.sync_domains(workspace.id, domains).await {
                Ok(count) => result.domains_synced = count,
                Err(e) => result.errors.push(format!("Domain sync error: {}", e)),
            }
        }

        // Sync tables
        if !tables.is_empty() || force {
            match self.backend.sync_tables(workspace.id, tables).await {
                Ok(count) => {
                    result.tables_synced = count;
                    // Count columns
                    result.columns_synced = tables.iter().map(|t| t.columns.len()).sum();
                }
                Err(e) => result.errors.push(format!("Table sync error: {}", e)),
            }
        }

        // Sync relationships
        if !relationships.is_empty() || force {
            match self
                .backend
                .sync_relationships(workspace.id, relationships)
                .await
            {
                Ok(count) => result.relationships_synced = count,
                Err(e) => result
                    .errors
                    .push(format!("Relationship sync error: {}", e)),
            }
        }

        result.duration_ms = start.elapsed().as_millis() as u64;
        Ok(result)
    }

    /// Sync a workspace with decisions and knowledge articles
    ///
    /// Extended version of sync_workspace that includes DDL and KB sync.
    ///
    /// # Arguments
    /// * `workspace` - Workspace metadata
    /// * `tables` - Tables to sync
    /// * `relationships` - Relationships to sync
    /// * `domains` - Domains to sync
    /// * `decisions` - Decisions to sync
    /// * `knowledge` - Knowledge articles to sync
    /// * `force` - If true, ignore change detection and sync everything
    ///
    /// # Returns
    /// Sync result with counts and any errors
    #[allow(clippy::too_many_arguments)]
    pub async fn sync_workspace_full(
        &self,
        workspace: &Workspace,
        tables: &[Table],
        relationships: &[Relationship],
        domains: &[Domain],
        decisions: &[Decision],
        knowledge: &[KnowledgeArticle],
        force: bool,
    ) -> DatabaseResult<SyncResult> {
        let start = std::time::Instant::now();

        // First sync the basic workspace data
        let mut result = self
            .sync_workspace(workspace, tables, relationships, domains, force)
            .await?;

        // Sync decisions
        if !decisions.is_empty() || force {
            match self.backend.sync_decisions(workspace.id, decisions).await {
                Ok(count) => result.decisions_synced = count,
                Err(e) => result.errors.push(format!("Decision sync error: {}", e)),
            }
        }

        // Sync knowledge articles
        if !knowledge.is_empty() || force {
            match self.backend.sync_knowledge(workspace.id, knowledge).await {
                Ok(count) => result.knowledge_synced = count,
                Err(e) => result.errors.push(format!("Knowledge sync error: {}", e)),
            }
        }

        result.duration_ms = start.elapsed().as_millis() as u64;
        Ok(result)
    }

    /// Sync only decisions for a workspace
    ///
    /// # Arguments
    /// * `workspace_id` - Workspace UUID
    /// * `decisions` - Decisions to sync
    ///
    /// # Returns
    /// Number of decisions synced
    pub async fn sync_decisions(
        &self,
        workspace_id: Uuid,
        decisions: &[Decision],
    ) -> DatabaseResult<usize> {
        self.backend.sync_decisions(workspace_id, decisions).await
    }

    /// Sync only knowledge articles for a workspace
    ///
    /// # Arguments
    /// * `workspace_id` - Workspace UUID
    /// * `articles` - Knowledge articles to sync
    ///
    /// # Returns
    /// Number of articles synced
    pub async fn sync_knowledge(
        &self,
        workspace_id: Uuid,
        articles: &[KnowledgeArticle],
    ) -> DatabaseResult<usize> {
        self.backend.sync_knowledge(workspace_id, articles).await
    }

    /// Sync tables with change detection
    ///
    /// Only syncs tables whose YAML file has changed since last sync.
    pub async fn sync_tables_incremental(
        &self,
        workspace_id: Uuid,
        tables: &[Table],
        file_hashes: &HashMap<Uuid, String>,
    ) -> DatabaseResult<SyncResult> {
        let start = std::time::Instant::now();
        let mut result = SyncResult::new(workspace_id);

        let mut tables_to_sync = Vec::new();

        for table in tables {
            let new_hash = file_hashes.get(&table.id);

            // Check if file has changed
            let should_sync = if let Some(new_hash) = new_hash {
                // Get stored hash
                let stored_hash = self
                    .backend
                    .get_file_hash(workspace_id, &table.id.to_string())
                    .await?;

                match stored_hash {
                    Some(stored) => &stored != new_hash,
                    None => true, // No stored hash, need to sync
                }
            } else {
                true // No hash provided, sync anyway
            };

            if should_sync {
                tables_to_sync.push(table.clone());
            } else {
                result.files_skipped += 1;
            }
        }

        // Sync changed tables
        if !tables_to_sync.is_empty() {
            result.tables_synced = self
                .backend
                .sync_tables(workspace_id, &tables_to_sync)
                .await?;
            result.columns_synced = tables_to_sync.iter().map(|t| t.columns.len()).sum();

            // Update file hashes
            for table in &tables_to_sync {
                if let Some(hash) = file_hashes.get(&table.id) {
                    self.backend
                        .record_file_hash(workspace_id, &table.id.to_string(), hash)
                        .await?;
                }
            }
        }

        result.duration_ms = start.elapsed().as_millis() as u64;
        Ok(result)
    }

    /// Export workspace from database to models
    pub async fn export_workspace(
        &self,
        workspace_id: Uuid,
    ) -> DatabaseResult<(
        Option<Workspace>,
        Vec<Table>,
        Vec<Relationship>,
        Vec<Domain>,
    )> {
        let workspace = self.backend.get_workspace(workspace_id).await?;
        let tables = self.backend.export_tables(workspace_id).await?;
        let relationships = self.backend.export_relationships(workspace_id).await?;
        let domains = self.backend.export_domains(workspace_id).await?;

        Ok((workspace, tables, relationships, domains))
    }

    /// Export workspace from database to models including decisions and knowledge
    pub async fn export_workspace_full(
        &self,
        workspace_id: Uuid,
    ) -> DatabaseResult<(
        Option<Workspace>,
        Vec<Table>,
        Vec<Relationship>,
        Vec<Domain>,
        Vec<Decision>,
        Vec<KnowledgeArticle>,
    )> {
        let workspace = self.backend.get_workspace(workspace_id).await?;
        let tables = self.backend.export_tables(workspace_id).await?;
        let relationships = self.backend.export_relationships(workspace_id).await?;
        let domains = self.backend.export_domains(workspace_id).await?;
        let decisions = self.backend.export_decisions(workspace_id).await?;
        let knowledge = self.backend.export_knowledge(workspace_id).await?;

        Ok((
            workspace,
            tables,
            relationships,
            domains,
            decisions,
            knowledge,
        ))
    }

    /// Export only decisions from database
    pub async fn export_decisions(&self, workspace_id: Uuid) -> DatabaseResult<Vec<Decision>> {
        self.backend.export_decisions(workspace_id).await
    }

    /// Export only knowledge articles from database
    pub async fn export_knowledge(
        &self,
        workspace_id: Uuid,
    ) -> DatabaseResult<Vec<KnowledgeArticle>> {
        self.backend.export_knowledge(workspace_id).await
    }

    /// Get sync status for a workspace
    pub async fn get_status(&self, workspace_id: Uuid) -> DatabaseResult<SyncStatus> {
        self.backend.get_sync_status(workspace_id).await
    }

    /// Check database health
    pub async fn health_check(&self) -> DatabaseResult<bool> {
        self.backend.health_check().await
    }

    /// Execute a raw SQL query
    pub async fn query(&self, sql: &str) -> DatabaseResult<super::QueryResult> {
        self.backend.execute_query(sql).await
    }

    /// Close the database connection
    pub async fn close(&self) -> DatabaseResult<()> {
        self.backend.close().await
    }
}

/// Compute SHA256 hash of content
pub fn compute_hash(content: &[u8]) -> String {
    let mut hasher = Sha256::new();
    hasher.update(content);
    let result = hasher.finalize();
    format!("{:x}", result)
}

/// Compute SHA256 hash of a file
pub fn compute_file_hash(path: &Path) -> DatabaseResult<String> {
    let content = std::fs::read(path)
        .map_err(|e| DatabaseError::IoError(format!("Failed to read file: {}", e)))?;
    Ok(compute_hash(&content))
}

/// Parse flat filename to extract workspace, domain, system, and resource name
///
/// Format: `{workspace}_{domain}_{system}_{resource}.{type}.yaml`
/// Where system is optional.
///
/// Returns: (workspace, domain, system, resource_name, asset_type)
pub fn parse_flat_filename(
    filename: &str,
) -> Option<(String, String, Option<String>, String, AssetType)> {
    // Get asset type from filename
    let asset_type = AssetType::from_filename(filename)?;

    // Skip workspace-level files
    if asset_type.is_workspace_level() {
        return None;
    }

    // Remove file extension based on asset type
    let base = match asset_type {
        AssetType::Odcs => filename.strip_suffix(".odcs.yaml")?,
        AssetType::Odps => filename.strip_suffix(".odps.yaml")?,
        AssetType::Cads => filename.strip_suffix(".cads.yaml")?,
        AssetType::Bpmn => filename.strip_suffix(".bpmn.xml")?,
        AssetType::Dmn => filename.strip_suffix(".dmn.xml")?,
        AssetType::Openapi => filename
            .strip_suffix(".openapi.yaml")
            .or_else(|| filename.strip_suffix(".openapi.json"))?,
        _ => return None,
    };

    let parts: Vec<&str> = base.split('_').collect();

    match parts.len() {
        // workspace_domain_resource (no system)
        3 => Some((
            parts[0].to_string(),
            parts[1].to_string(),
            None,
            parts[2].to_string(),
            asset_type,
        )),
        // workspace_domain_system_resource
        4 => Some((
            parts[0].to_string(),
            parts[1].to_string(),
            Some(parts[2].to_string()),
            parts[3].to_string(),
            asset_type,
        )),
        // More than 4 parts - treat remaining as resource name with underscores
        n if n > 4 => Some((
            parts[0].to_string(),
            parts[1].to_string(),
            Some(parts[2].to_string()),
            parts[3..].join("_"),
            asset_type,
        )),
        _ => None,
    }
}

/// Generate flat filename from workspace, domain, system, and resource name
///
/// Format: `{workspace}_{domain}_{system}_{resource}.{type}.yaml`
pub fn generate_flat_filename(
    workspace_name: &str,
    domain_name: &str,
    system_name: Option<&str>,
    resource_name: &str,
    asset_type: &AssetType,
) -> String {
    let mut parts = vec![sanitize_name(workspace_name), sanitize_name(domain_name)];

    if let Some(system) = system_name {
        parts.push(sanitize_name(system));
    }

    parts.push(sanitize_name(resource_name));

    format!("{}.{}", parts.join("_"), asset_type.extension())
}

/// Sanitize a name for use in filenames (replace spaces/special chars with hyphens, lowercase)
fn sanitize_name(name: &str) -> String {
    name.chars()
        .map(|c| match c {
            ' ' | '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|' => '-',
            _ => c,
        })
        .collect::<String>()
        .to_lowercase()
}

/// Scan workspace directory for supported YAML/XML files
///
/// Only scans the root directory for flat files using the naming convention.
/// Does not scan subdirectories (legacy domain directory structure is not supported).
///
/// Returns a list of file paths relative to the workspace root.
pub fn scan_workspace_files(workspace_path: &Path) -> DatabaseResult<Vec<PathBuf>> {
    let mut files = Vec::new();

    // Scan root directory for flat files only
    if let Ok(entries) = std::fs::read_dir(workspace_path) {
        for entry in entries.flatten() {
            let path = entry.path();
            if path.is_file()
                && let Some(name) = path.file_name().and_then(|n| n.to_str())
                && AssetType::is_supported_file(name)
            {
                files.push(path.strip_prefix(workspace_path).unwrap().to_path_buf());
            }
        }
    }

    Ok(files)
}

/// Detect changes between stored and current file hashes
pub fn detect_changes(
    stored_hashes: &HashMap<String, String>,
    current_hashes: &HashMap<String, String>,
) -> (Vec<String>, Vec<String>, Vec<String>) {
    let mut added = Vec::new();
    let mut modified = Vec::new();
    let mut deleted = Vec::new();

    // Find added and modified files
    for (path, hash) in current_hashes {
        match stored_hashes.get(path) {
            Some(stored_hash) => {
                if stored_hash != hash {
                    modified.push(path.clone());
                }
            }
            None => {
                added.push(path.clone());
            }
        }
    }

    // Find deleted files
    for path in stored_hashes.keys() {
        if !current_hashes.contains_key(path) {
            deleted.push(path.clone());
        }
    }

    (added, modified, deleted)
}

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

    #[test]
    fn test_compute_hash() {
        let content = b"hello world";
        let hash = compute_hash(content);
        // SHA256 of "hello world"
        assert_eq!(
            hash,
            "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
        );
    }

    #[test]
    fn test_parse_flat_filename() {
        // workspace_domain_system_resource
        let result = parse_flat_filename("enterprise_sales_kafka_orders.odcs.yaml");
        assert!(result.is_some());
        let (workspace, domain, system, resource, asset_type) = result.unwrap();
        assert_eq!(workspace, "enterprise");
        assert_eq!(domain, "sales");
        assert_eq!(system, Some("kafka".to_string()));
        assert_eq!(resource, "orders");
        assert_eq!(asset_type, AssetType::Odcs);

        // workspace_domain_resource (no system)
        let result = parse_flat_filename("enterprise_sales_orders.odcs.yaml");
        assert!(result.is_some());
        let (workspace, domain, system, resource, _) = result.unwrap();
        assert_eq!(workspace, "enterprise");
        assert_eq!(domain, "sales");
        assert_eq!(system, None);
        assert_eq!(resource, "orders");

        // with underscores in resource name
        let result = parse_flat_filename("enterprise_sales_kafka_order_items.odcs.yaml");
        assert!(result.is_some());
        let (_, _, system, resource, _) = result.unwrap();
        assert_eq!(system, Some("kafka".to_string()));
        assert_eq!(resource, "order_items");

        // ODPS type
        let result = parse_flat_filename("enterprise_sales_analytics.odps.yaml");
        assert!(result.is_some());
        let (_, _, _, _, asset_type) = result.unwrap();
        assert_eq!(asset_type, AssetType::Odps);

        // workspace.yaml should return None (workspace-level file)
        let result = parse_flat_filename("workspace.yaml");
        assert!(result.is_none());

        // relationships.yaml should return None (workspace-level file)
        let result = parse_flat_filename("relationships.yaml");
        assert!(result.is_none());

        // Invalid format (less than 3 parts)
        let result = parse_flat_filename("orders.odcs.yaml");
        assert!(result.is_none());
    }

    #[test]
    fn test_generate_flat_filename() {
        assert_eq!(
            generate_flat_filename(
                "enterprise",
                "sales",
                Some("kafka"),
                "orders",
                &AssetType::Odcs
            ),
            "enterprise_sales_kafka_orders.odcs.yaml"
        );

        assert_eq!(
            generate_flat_filename("enterprise", "sales", None, "orders", &AssetType::Odcs),
            "enterprise_sales_orders.odcs.yaml"
        );

        assert_eq!(
            generate_flat_filename("enterprise", "finance", None, "accounts", &AssetType::Odps),
            "enterprise_finance_accounts.odps.yaml"
        );

        // Test with spaces in names (should be sanitized)
        assert_eq!(
            generate_flat_filename(
                "My Workspace",
                "Sales Domain",
                None,
                "Order Items",
                &AssetType::Odcs
            ),
            "my-workspace_sales-domain_order-items.odcs.yaml"
        );
    }

    #[test]
    fn test_sanitize_name() {
        assert_eq!(sanitize_name("Hello World"), "hello-world");
        assert_eq!(sanitize_name("Test/Path"), "test-path");
        assert_eq!(sanitize_name("Normal"), "normal");
        assert_eq!(sanitize_name("UPPERCASE"), "uppercase");
    }

    #[test]
    fn test_detect_changes() {
        let mut stored = HashMap::new();
        stored.insert("a.yaml".to_string(), "hash1".to_string());
        stored.insert("b.yaml".to_string(), "hash2".to_string());
        stored.insert("c.yaml".to_string(), "hash3".to_string());

        let mut current = HashMap::new();
        current.insert("a.yaml".to_string(), "hash1".to_string()); // unchanged
        current.insert("b.yaml".to_string(), "hash2_modified".to_string()); // modified
        current.insert("d.yaml".to_string(), "hash4".to_string()); // added

        let (added, modified, deleted) = detect_changes(&stored, &current);

        assert_eq!(added, vec!["d.yaml"]);
        assert_eq!(modified, vec!["b.yaml"]);
        assert_eq!(deleted, vec!["c.yaml"]);
    }

    #[test]
    fn test_sync_result() {
        let result = SyncResult::new(Uuid::new_v4());
        assert!(result.is_success());
        assert_eq!(result.total_synced(), 0);
    }
}