actr-cli 0.1.15

Command line tool for Actor-RTC framework 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
//! Fingerprint command implementation
//!
//! Computes and displays semantic fingerprints for proto files

use crate::core::{Command, CommandContext, CommandResult, ComponentType};
use actr_config::ConfigParser;
use actr_version::{Fingerprint, ProtoFile};
use anyhow::{Context, Result};
use async_trait::async_trait;
use clap::Args;
use std::fs;
use std::path::Path;
use tracing::{error, info};

/// Verification status
#[derive(Debug, Clone)]
enum VerificationStatus {
    Passed {
        matched_fingerprint: String,
    },
    Failed {
        mismatches: Vec<(String, String, String)>,
    }, // (file_path, expected_fingerprint, actual_fingerprint)
    NoLockFile,
    NotRequested,
}

/// Fingerprint command - computes semantic fingerprints
#[derive(Args, Debug)]
#[command(
    about = "Compute project and service fingerprints",
    long_about = "Compute and display semantic fingerprints for proto files and services"
)]
pub struct FingerprintCommand {
    /// Configuration file path
    #[arg(short, long, default_value = "Actr.toml")]
    pub config: String,

    /// Output format (text, json, yaml)
    #[arg(long, default_value = "text")]
    pub format: String,

    /// Calculate fingerprint for a specific proto file
    #[arg(long)]
    pub proto: Option<String>,

    /// Calculate service-level fingerprint (default)
    #[arg(long)]
    pub service_level: bool,

    /// Verify fingerprint against lock file
    #[arg(long)]
    pub verify: bool,
}

#[async_trait]
impl Command for FingerprintCommand {
    async fn execute(&self, _context: &CommandContext) -> Result<CommandResult> {
        if let Some(proto_path) = &self.proto {
            // Calculate fingerprint for a specific proto file
            info!(
                "🔍 Computing proto semantic fingerprint for: {}",
                proto_path
            );
            execute_proto_fingerprint(self, proto_path).await?;
        } else {
            // Calculate service-level fingerprint (default)
            info!("🔍 Computing service semantic fingerprint...");
            execute_service_fingerprint(self).await?;
        }

        Ok(CommandResult::Success(
            "Fingerprint calculation completed".to_string(),
        ))
    }

    fn required_components(&self) -> Vec<ComponentType> {
        vec![] // Fingerprint calculation doesn't require external components
    }

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

    fn description(&self) -> &str {
        "Compute semantic fingerprints for proto files and services"
    }
}

/// Execute proto-level fingerprint calculation
async fn execute_proto_fingerprint(args: &FingerprintCommand, proto_path: &str) -> Result<()> {
    let path = Path::new(proto_path);
    if !path.exists() {
        return Err(anyhow::anyhow!("Proto file not found: {}", proto_path));
    }

    let content = fs::read_to_string(path)
        .with_context(|| format!("Failed to read proto file: {}", proto_path))?;

    let fingerprint = Fingerprint::calculate_proto_semantic_fingerprint(&content)
        .context("Failed to calculate proto fingerprint")?;

    // Output
    match args.format.as_str() {
        "text" => show_proto_text_output(&fingerprint, proto_path),
        "json" => show_proto_json_output(&fingerprint, proto_path)?,
        "yaml" => show_proto_yaml_output(&fingerprint, proto_path)?,
        _ => {
            error!("Unsupported output format: {}", args.format);
            return Err(anyhow::anyhow!("Unsupported format: {}", args.format));
        }
    }

    Ok(())
}

/// Execute service-level fingerprint calculation
async fn execute_service_fingerprint(args: &FingerprintCommand) -> Result<()> {
    // Load configuration
    let config_path = Path::new(&args.config);
    let config = ConfigParser::from_file(config_path)
        .with_context(|| format!("Failed to load config from {}", args.config))?;

    // Convert actr_config::ProtoFile to actr_version::ProtoFile
    let mut proto_files: Vec<ProtoFile> = config
        .exports
        .iter()
        .map(|pf| ProtoFile {
            name: pf.file_name().unwrap_or("unknown.proto").to_string(),
            content: pf.content.clone(),
            path: Some(pf.path.to_string_lossy().to_string()),
        })
        .collect();

    // If verifying, also collect proto files from protos/remote directory
    if args.verify {
        let config_dir = config_path.parent().unwrap_or(Path::new("."));
        let remote_dir = config_dir.join("protos").join("remote");

        if remote_dir.exists() {
            collect_proto_files_from_directory(&remote_dir, &mut proto_files)?;
        }
    }

    if proto_files.is_empty() {
        // No proto files to calculate fingerprint for, but we can still verify lock file
        if args.verify {
            let verification_status = verify_fingerprint_against_lock("", &[], config_path)?;
            match args.format.as_str() {
                "text" => {
                    show_verification_status_only(&verification_status);
                }
                "json" => {
                    let verification_info = match verification_status {
                        VerificationStatus::Passed { .. } => {
                            serde_json::json!({"status": "passed"})
                        }
                        VerificationStatus::Failed { mismatches } => serde_json::json!({
                            "status": "failed",
                            "mismatches": mismatches.iter().map(|(file_path, expected, actual)| {
                                serde_json::json!({
                                    "file_path": file_path,
                                    "expected": expected,
                                    "actual": actual
                                })
                            }).collect::<Vec<_>>()
                        }),
                        VerificationStatus::NoLockFile => {
                            serde_json::json!({"status": "no_lock_file"})
                        }
                        _ => serde_json::json!({"status": "not_requested"}),
                    };
                    println!(
                        "{}",
                        serde_json::to_string_pretty(&verification_info).unwrap()
                    );
                }
                "yaml" => {
                    let verification_info = match verification_status {
                        VerificationStatus::Passed { .. } => {
                            let mut map = serde_yaml::Mapping::new();
                            map.insert(
                                serde_yaml::Value::String("status".to_string()),
                                serde_yaml::Value::String("passed".to_string()),
                            );
                            map
                        }
                        VerificationStatus::Failed { mismatches } => {
                            let mut map = serde_yaml::Mapping::new();
                            map.insert(
                                serde_yaml::Value::String("status".to_string()),
                                serde_yaml::Value::String("failed".to_string()),
                            );
                            map.insert(
                                serde_yaml::Value::String("mismatches".to_string()),
                                serde_yaml::Value::Sequence(
                                    mismatches
                                        .iter()
                                        .map(|(file_path, expected, actual)| {
                                            let mut mismatch_map = serde_yaml::Mapping::new();
                                            mismatch_map.insert(
                                                serde_yaml::Value::String("file_path".to_string()),
                                                serde_yaml::Value::String(file_path.clone()),
                                            );
                                            mismatch_map.insert(
                                                serde_yaml::Value::String("expected".to_string()),
                                                serde_yaml::Value::String(expected.clone()),
                                            );
                                            mismatch_map.insert(
                                                serde_yaml::Value::String("actual".to_string()),
                                                serde_yaml::Value::String(actual.clone()),
                                            );
                                            serde_yaml::Value::Mapping(mismatch_map)
                                        })
                                        .collect(),
                                ),
                            );
                            map
                        }
                        VerificationStatus::NoLockFile => {
                            let mut map = serde_yaml::Mapping::new();
                            map.insert(
                                serde_yaml::Value::String("status".to_string()),
                                serde_yaml::Value::String("no_lock_file".to_string()),
                            );
                            map
                        }
                        _ => {
                            let mut map = serde_yaml::Mapping::new();
                            map.insert(
                                serde_yaml::Value::String("status".to_string()),
                                serde_yaml::Value::String("not_requested".to_string()),
                            );
                            map
                        }
                    };
                    println!(
                        "{}",
                        serde_yaml::to_string(&serde_yaml::Value::Mapping(verification_info))
                            .unwrap()
                    );
                }
                _ => {
                    show_verification_status_only(&verification_status);
                }
            }
        } else {
            match args.format.as_str() {
                "text" => {
                    println!("ℹ️  No proto files found in exports");
                    println!(
                        "   Add proto files to the 'exports' array in {} to calculate fingerprints",
                        args.config
                    );
                }
                "json" => {
                    let output = serde_json::json!({
                        "status": "no_exports",
                        "message": "No proto files found in exports",
                        "config_file": args.config
                    });
                    println!("{}", serde_json::to_string_pretty(&output).unwrap());
                }
                "yaml" => {
                    let output = serde_yaml::Value::Mapping({
                        let mut map = serde_yaml::Mapping::new();
                        map.insert(
                            serde_yaml::Value::String("status".to_string()),
                            serde_yaml::Value::String("no_exports".to_string()),
                        );
                        map.insert(
                            serde_yaml::Value::String("message".to_string()),
                            serde_yaml::Value::String(
                                "No proto files found in exports".to_string(),
                            ),
                        );
                        map.insert(
                            serde_yaml::Value::String("config_file".to_string()),
                            serde_yaml::Value::String(args.config.clone()),
                        );
                        map
                    });
                    println!("{}", serde_yaml::to_string(&output).unwrap());
                }
                _ => {
                    println!("ℹ️  No proto files found in exports");
                }
            }
        }
        return Ok(());
    }

    // Calculate semantic fingerprint
    let fingerprint = Fingerprint::calculate_service_semantic_fingerprint(&proto_files)
        .context("Failed to calculate service fingerprint")?;

    // Verify against lock file if requested
    let verification_status = if args.verify {
        verify_fingerprint_against_lock(&fingerprint, &proto_files, config_path)?
    } else {
        VerificationStatus::NotRequested
    };

    // Output
    match args.format.as_str() {
        "text" => show_text_output(&fingerprint, &proto_files, &verification_status),
        "json" => show_json_output(&fingerprint, &proto_files, &verification_status)?,
        "yaml" => show_yaml_output(&fingerprint, &proto_files, &verification_status)?,
        _ => {
            error!("Unsupported output format: {}", args.format);
            return Err(anyhow::anyhow!("Unsupported format: {}", args.format));
        }
    }

    Ok(())
}

/// Show proto text output format
fn show_proto_text_output(fingerprint: &str, proto_path: &str) {
    println!("📋 Proto Semantic Fingerprint:");
    println!("  File: {}", proto_path);
    println!("  {fingerprint}");
}

/// Show proto JSON output format
fn show_proto_json_output(fingerprint: &str, proto_path: &str) -> Result<()> {
    let output = ProtoJsonOutput {
        proto_file: proto_path.to_string(),
        fingerprint: fingerprint.to_string(),
    };

    let json = serde_json::to_string_pretty(&output).context("Failed to serialize output")?;
    println!("{json}");

    Ok(())
}

/// Show proto YAML output format
fn show_proto_yaml_output(fingerprint: &str, proto_path: &str) -> Result<()> {
    let output = ProtoJsonOutput {
        proto_file: proto_path.to_string(),
        fingerprint: fingerprint.to_string(),
    };

    let yaml = serde_yaml::to_string(&output).context("Failed to serialize output")?;
    println!("{yaml}");

    Ok(())
}

/// Collect proto files from a directory recursively
fn collect_proto_files_from_directory(dir: &Path, proto_files: &mut Vec<ProtoFile>) -> Result<()> {
    fn visit_dir(dir: &Path, proto_files: &mut Vec<ProtoFile>, base_dir: &Path) -> Result<()> {
        if let Ok(entries) = fs::read_dir(dir) {
            for entry in entries {
                let entry = entry?;
                let path = entry.path();

                if path.is_dir() {
                    visit_dir(&path, proto_files, base_dir)?;
                } else if path.extension().and_then(|s| s.to_str()) == Some("proto") {
                    let content = fs::read_to_string(&path).with_context(|| {
                        format!("Failed to read proto file: {}", path.display())
                    })?;

                    // Get relative path from the base directory
                    let relative_path = path.strip_prefix(base_dir).unwrap_or(&path);
                    let name = path
                        .file_name()
                        .and_then(|n| n.to_str())
                        .unwrap_or("unknown.proto")
                        .to_string();

                    proto_files.push(ProtoFile {
                        name,
                        content,
                        path: Some(relative_path.to_string_lossy().to_string()),
                    });
                }
            }
        }
        Ok(())
    }

    visit_dir(dir, proto_files, dir)
}

/// Show verification status only (for cases where no proto files are available)
fn show_verification_status_only(verification_status: &VerificationStatus) {
    match verification_status {
        VerificationStatus::Passed { .. } => {
            println!("✅ Fingerprint verification: PASSED");
            println!("  All lock file fingerprints verified against actual files");
        }
        VerificationStatus::Failed { mismatches } => {
            println!("❌ Fingerprint verification: FAILED");
            println!("  File-level mismatches:");
            for (file_path, expected, actual) in mismatches {
                println!("    File: {}", file_path);
                println!("      Expected: {}", expected);
                println!("      Actual:   {}", actual);
            }
        }
        VerificationStatus::NoLockFile => {
            println!("⚠️  Fingerprint verification: No lock file found");
        }
        VerificationStatus::NotRequested => {
            // No verification requested, don't show anything
        }
    }
}

/// Show text output format
fn show_text_output(
    fingerprint: &str,
    proto_files: &[ProtoFile],
    verification_status: &VerificationStatus,
) {
    println!("📋 Service Semantic Fingerprint:");
    println!("  {fingerprint}");
    println!("\n📦 Proto Files ({}):", proto_files.len());
    for pf in proto_files {
        println!("  - {}", pf.name);
    }

    // Show verification status
    match verification_status {
        VerificationStatus::Passed {
            matched_fingerprint: _,
        } => {
            println!("\n✅ Fingerprint verification: PASSED");
            println!("  All lock file fingerprints verified against actual files");
        }
        VerificationStatus::Failed { mismatches } => {
            println!("\n❌ Fingerprint verification: FAILED");
            println!("  File-level mismatches:");
            for (file_path, expected, actual) in mismatches {
                println!("    File: {}", file_path);
                println!("      Expected: {}", expected);
                println!("      Actual:   {}", actual);
            }
        }
        VerificationStatus::NoLockFile => {
            println!("\n⚠️  Fingerprint verification: No lock file found");
        }
        VerificationStatus::NotRequested => {
            // No verification requested, don't show anything
        }
    }
}

/// Show JSON output format
fn show_json_output(
    fingerprint: &str,
    proto_files: &[ProtoFile],
    verification_status: &VerificationStatus,
) -> Result<()> {
    let verification_info = match verification_status {
        VerificationStatus::Passed {
            matched_fingerprint,
        } => serde_json::json!({
            "status": "passed",
            "matched_fingerprint": matched_fingerprint
        }),
        VerificationStatus::Failed { mismatches } => serde_json::json!({
            "status": "failed",
            "mismatches": mismatches.iter().map(|(file_path, expected, actual)| {
                serde_json::json!({
                    "file_path": file_path,
                    "expected": expected,
                    "actual": actual
                })
            }).collect::<Vec<_>>()
        }),
        VerificationStatus::NoLockFile => serde_json::json!({
            "status": "no_lock_file"
        }),
        VerificationStatus::NotRequested => serde_json::json!({
            "status": "not_requested"
        }),
    };

    let output = serde_json::json!({
        "service_fingerprint": fingerprint,
        "proto_files": proto_files.iter().map(|pf| pf.name.clone()).collect::<Vec<_>>(),
        "verification": verification_info
    });

    let json = serde_json::to_string_pretty(&output).context("Failed to serialize output")?;
    println!("{json}");

    Ok(())
}

/// Show YAML output format
fn show_yaml_output(
    fingerprint: &str,
    proto_files: &[ProtoFile],
    verification_status: &VerificationStatus,
) -> Result<()> {
    let verification_info = match verification_status {
        VerificationStatus::Passed {
            matched_fingerprint,
        } => serde_yaml::Value::Mapping({
            let mut map = serde_yaml::Mapping::new();
            map.insert(
                serde_yaml::Value::String("status".to_string()),
                serde_yaml::Value::String("passed".to_string()),
            );
            map.insert(
                serde_yaml::Value::String("matched_fingerprint".to_string()),
                serde_yaml::Value::String(matched_fingerprint.clone()),
            );
            map
        }),
        VerificationStatus::Failed { mismatches } => serde_yaml::Value::Mapping({
            let mut map = serde_yaml::Mapping::new();
            map.insert(
                serde_yaml::Value::String("status".to_string()),
                serde_yaml::Value::String("failed".to_string()),
            );
            map.insert(
                serde_yaml::Value::String("mismatches".to_string()),
                serde_yaml::Value::Sequence(
                    mismatches
                        .iter()
                        .map(|(file_path, expected, actual)| {
                            let mut mismatch_map = serde_yaml::Mapping::new();
                            mismatch_map.insert(
                                serde_yaml::Value::String("file_path".to_string()),
                                serde_yaml::Value::String(file_path.clone()),
                            );
                            mismatch_map.insert(
                                serde_yaml::Value::String("expected".to_string()),
                                serde_yaml::Value::String(expected.clone()),
                            );
                            mismatch_map.insert(
                                serde_yaml::Value::String("actual".to_string()),
                                serde_yaml::Value::String(actual.clone()),
                            );
                            serde_yaml::Value::Mapping(mismatch_map)
                        })
                        .collect(),
                ),
            );
            map
        }),
        VerificationStatus::NoLockFile => serde_yaml::Value::Mapping({
            let mut map = serde_yaml::Mapping::new();
            map.insert(
                serde_yaml::Value::String("status".to_string()),
                serde_yaml::Value::String("no_lock_file".to_string()),
            );
            map
        }),
        VerificationStatus::NotRequested => serde_yaml::Value::Mapping({
            let mut map = serde_yaml::Mapping::new();
            map.insert(
                serde_yaml::Value::String("status".to_string()),
                serde_yaml::Value::String("not_requested".to_string()),
            );
            map
        }),
    };

    let output = serde_yaml::Value::Mapping({
        let mut map = serde_yaml::Mapping::new();
        map.insert(
            serde_yaml::Value::String("service_fingerprint".to_string()),
            serde_yaml::Value::String(fingerprint.to_string()),
        );
        map.insert(
            serde_yaml::Value::String("proto_files".to_string()),
            serde_yaml::Value::Sequence(
                proto_files
                    .iter()
                    .map(|pf| serde_yaml::Value::String(pf.name.clone()))
                    .collect(),
            ),
        );
        map.insert(
            serde_yaml::Value::String("verification".to_string()),
            verification_info,
        );
        map
    });

    let yaml = serde_yaml::to_string(&output).context("Failed to serialize output")?;
    println!("{yaml}");

    Ok(())
}

/// Verify fingerprint against lock file
fn verify_fingerprint_against_lock(
    current_fingerprint: &str,
    proto_files: &[ProtoFile],
    config_path: &Path,
) -> Result<VerificationStatus> {
    let lock_path = config_path.with_file_name("actr.lock.toml");
    if !lock_path.exists() {
        return Ok(VerificationStatus::NoLockFile);
    }

    let lock_content = fs::read_to_string(&lock_path)
        .with_context(|| format!("Failed to read lock file: {}", lock_path.display()))?;

    let lock_file: toml::Value = toml::from_str(&lock_content)
        .with_context(|| format!("Failed to parse lock file: {}", lock_path.display()))?;

    let mut mismatches = Vec::new();
    let mut service_fingerprint_mismatch = None;

    // Check service-level fingerprints first
    if let Some(dependencies) = lock_file.get("dependency").and_then(|d| d.as_array()) {
        for dep in dependencies {
            if let Some(expected_service_fp) = dep.get("fingerprint").and_then(|f| f.as_str())
                && expected_service_fp.starts_with("service_semantic:")
            {
                // Use the current fingerprint passed in
                let expected_fp = expected_service_fp.to_string();
                let actual_fp = current_fingerprint.to_string();

                if expected_fp != actual_fp {
                    service_fingerprint_mismatch = Some((expected_fp, actual_fp));
                }
                break; // Only check the first dependency for now
            }
        }
    }

    // Check each proto file from lock file against actual proto files
    if let Some(dependencies) = lock_file.get("dependency").and_then(|d| d.as_array()) {
        for dep in dependencies {
            if let Some(files) = dep.get("files").and_then(|f| f.as_array()) {
                for file in files {
                    if let (Some(lock_path), Some(expected_fp)) = (
                        file.get("path").and_then(|p| p.as_str()),
                        file.get("fingerprint").and_then(|f| f.as_str()),
                    ) {
                        // Empty fingerprints in lock file are considered mismatches
                        if expected_fp.is_empty() {
                            mismatches.push((
                                lock_path.to_string(),
                                expected_fp.to_string(),
                                "ERROR: Empty fingerprint in lock file".to_string(),
                            ));
                            continue;
                        }

                        // Find the corresponding proto file in our proto_files list
                        let mut found = false;
                        for proto_file in proto_files {
                            if let Some(proto_path) = &proto_file.path
                                && proto_path == lock_path
                            {
                                match Fingerprint::calculate_proto_semantic_fingerprint(
                                    &proto_file.content,
                                ) {
                                    Ok(actual_fp) => {
                                        if actual_fp != expected_fp {
                                            mismatches.push((
                                                lock_path.to_string(),
                                                expected_fp.to_string(),
                                                actual_fp,
                                            ));
                                        }
                                    }
                                    Err(e) => {
                                        // Could not calculate fingerprint for this file
                                        mismatches.push((
                                            lock_path.to_string(),
                                            expected_fp.to_string(),
                                            format!("ERROR: {}", e),
                                        ));
                                    }
                                }
                                found = true;
                                break;
                            }
                        }

                        if !found {
                            // Proto file not found in our list
                            mismatches.push((
                                lock_path.to_string(),
                                expected_fp.to_string(),
                                "ERROR: Proto file not found".to_string(),
                            ));
                        }
                    }
                }
            }
        }
    }

    // If there are service fingerprint mismatches, add them to the mismatches list
    if let Some((expected, actual)) = service_fingerprint_mismatch {
        mismatches.push(("SERVICE_FINGERPRINT".to_string(), expected, actual));
    }

    if mismatches.is_empty() {
        // All proto files match
        Ok(VerificationStatus::Passed {
            matched_fingerprint: "all_files_verified".to_string(),
        })
    } else {
        // Some proto files don't match
        Ok(VerificationStatus::Failed { mismatches })
    }
}

/// JSON output structure for proto files
#[derive(serde::Serialize)]
struct ProtoJsonOutput {
    proto_file: String,
    fingerprint: String,
}