pmat 3.11.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
// Tests for MCP tool functions
// Extracted for file health compliance (CB-040)

use super::*;

mod property_tests {
    use proptest::prelude::*;

    proptest! {
        #[test]
        fn basic_property_stability(_input in ".*") {
            // Basic property test for coverage
            prop_assert!(true);
        }

        #[test]
        fn module_consistency_check(_x in 0u32..1000) {
            // Module consistency verification
            prop_assert!(_x < 1001);
        }
    }
}

mod coverage_tests {
    use super::*;
    use proptest::prelude::*;
    use std::fs;
    use tempfile::TempDir;

    // ==================== HELPER FUNCTION TESTS ====================

    #[test]
    fn test_select_quality_profile_extreme() {
        let profile = select_quality_profile(Some("extreme"));
        assert_eq!(profile.name, "extreme");
        assert_eq!(profile.thresholds.max_complexity, 5);
        assert!(profile.thresholds.zero_satd);
    }

    #[test]
    fn test_select_quality_profile_standard() {
        let profile = select_quality_profile(Some("standard"));
        assert_eq!(profile.name, "standard");
        assert_eq!(profile.thresholds.max_complexity, 10);
    }

    #[test]
    fn test_select_quality_profile_relaxed() {
        let profile = select_quality_profile(Some("relaxed"));
        assert_eq!(profile.name, "relaxed");
        assert_eq!(profile.thresholds.max_complexity, 20);
        assert!(!profile.thresholds.zero_satd);
    }

    #[test]
    fn test_select_quality_profile_default() {
        let profile = select_quality_profile(None);
        assert_eq!(profile.name, "standard");
    }

    #[test]
    fn test_select_quality_profile_unknown() {
        let profile = select_quality_profile(Some("unknown_profile"));
        assert_eq!(profile.name, "standard"); // Falls back to standard
    }

    #[test]
    fn test_parse_code_type_function() {
        let code_type = parse_code_type(Some("function"));
        assert!(matches!(code_type, CodeType::Function));
    }

    #[test]
    fn test_parse_code_type_module() {
        let code_type = parse_code_type(Some("module"));
        assert!(matches!(code_type, CodeType::Module));
    }

    #[test]
    fn test_parse_code_type_service() {
        let code_type = parse_code_type(Some("service"));
        assert!(matches!(code_type, CodeType::Service));
    }

    #[test]
    fn test_parse_code_type_test() {
        let code_type = parse_code_type(Some("test"));
        assert!(matches!(code_type, CodeType::Test));
    }

    #[test]
    fn test_parse_code_type_default() {
        let code_type = parse_code_type(None);
        assert!(matches!(code_type, CodeType::Function));
    }

    #[test]
    fn test_parse_code_type_unknown() {
        let code_type = parse_code_type(Some("unknown_type"));
        assert!(matches!(code_type, CodeType::Function)); // Falls back to Function
    }

    // ==================== INPUT VALIDATION TESTS ====================

    #[tokio::test]
    async fn test_analyze_complexity_empty_paths() {
        let result = analyze_complexity(&[], None, None).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_analyze_satd_empty_paths() {
        let result = analyze_satd(&[], false).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_analyze_dead_code_empty_paths() {
        let result = analyze_dead_code(&[], false).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_analyze_lint_hotspots_empty_paths() {
        let result = analyze_lint_hotspots(&[], None).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_analyze_churn_empty_paths() {
        let result = analyze_churn(&[], None, None).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_analyze_coupling_empty_paths() {
        let result = analyze_coupling(&[], None).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_check_quality_gates_empty_paths() {
        let result = check_quality_gates(&[], false).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_quality_gate_summary_empty_paths() {
        let result = quality_gate_summary(&[]).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_quality_gate_baseline_empty_paths() {
        let result = quality_gate_baseline(&[], None).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_quality_gate_compare_empty_paths() {
        let temp_file = TempDir::new().unwrap();
        let baseline_path = temp_file.path().join("baseline.json");
        fs::write(&baseline_path, "{}").unwrap();

        let result = quality_gate_compare(&baseline_path, &[]).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_check_quality_gate_file_nonexistent() {
        let path = Path::new("/tmp/nonexistent_file_12345.rs");
        let result = check_quality_gate_file(path, false).await;
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("does not exist"));
    }

    #[tokio::test]
    async fn test_generate_context_empty_paths() {
        let result = generate_context(&[], None, false).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_generate_deep_context_empty_paths() {
        let result = generate_deep_context(&[], None).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_analyze_context_empty_paths() {
        let result = analyze_context(&[], &[]).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_context_summary_empty_paths() {
        let result = context_summary(&[], None).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    #[tokio::test]
    async fn test_analyze_tdg_empty_paths() {
        let result = analyze_tdg(&[], None, None, None, None).await;
        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("At least one path"));
    }

    // ==================== GIT CLONE TESTS ====================

    #[tokio::test]
    async fn test_git_clone_extracts_repo_name() {
        let result = git_clone("https://github.com/user/test-repo.git", None, None, None).await;
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), PathBuf::from("test-repo"));
    }

    #[tokio::test]
    async fn test_git_clone_with_target_dir() {
        let target = Path::new("/tmp/my-target");
        let result = git_clone("https://github.com/user/repo.git", Some(target), None, None).await;
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), PathBuf::from("/tmp/my-target"));
    }

    #[tokio::test]
    async fn test_git_clone_url_without_git_suffix() {
        let result = git_clone("https://github.com/user/some-repo", None, None, None).await;
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), PathBuf::from("some-repo"));
    }

    // ==================== STORAGE BACKEND TESTS ====================

    #[test]
    fn test_create_storage_backend_inmemory() {
        let result = create_storage_backend(Some("inmemory"));
        assert!(result.is_ok());
    }

    #[test]
    fn test_create_storage_backend_libsql() {
        let result = create_storage_backend(Some("libsql"));
        assert!(result.is_ok());
    }

    #[test]
    fn test_create_storage_backend_default() {
        let result = create_storage_backend(None);
        assert!(result.is_ok()); // Defaults to libsql
    }

    #[test]
    fn test_create_storage_backend_unsupported() {
        let result = create_storage_backend(Some("nonexistent_backend"));
        assert!(result.is_err());
        assert!(result
            .err()
            .unwrap()
            .to_string()
            .contains("Unsupported storage backend"));
    }

    // ==================== RECORD CREATION TESTS ====================

    #[test]
    fn test_create_file_identity() {
        let path = Path::new("/tmp/test.rs");
        let content = b"fn main() {}";
        let hash = blake3::hash(content);

        let identity = create_file_identity(path, &hash, content);

        assert_eq!(identity.path, PathBuf::from("/tmp/test.rs"));
        assert_eq!(identity.content_hash, hash);
        assert_eq!(identity.size_bytes, 12);
    }

    #[test]
    fn test_create_component_scores() {
        let scores = create_component_scores();

        assert!(scores.complexity_breakdown.is_empty());
        assert!(scores.duplication_sources.is_empty());
        assert!(scores.coupling_dependencies.is_empty());
        assert!(scores.doc_missing_items.is_empty());
        assert!(scores.consistency_violations.is_empty());
    }

    #[test]
    fn test_create_semantic_signature() {
        let content = b"fn main() {}";
        let hash = blake3::hash(content);

        let signature = create_semantic_signature(&hash);

        assert_eq!(signature.identifier_pattern, "mcp_analysis");
        assert_eq!(signature.control_flow_pattern, "function_call");
        assert!(signature.import_dependencies.is_empty());
    }

    #[test]
    fn test_create_analysis_metadata() {
        let score = crate::tdg::TdgScore::default();

        let metadata = create_analysis_metadata(&score);

        assert_eq!(metadata.analyzer_version, "2.38.0-mcp");
        assert_eq!(metadata.analysis_duration_ms, 10);
        assert!(!metadata.cache_hit);
    }

    #[test]
    fn test_create_success_result() {
        let path = Path::new("/tmp/test");
        let project_score = crate::tdg::ProjectScore::default();

        let result = create_success_result(path, &project_score);

        assert!(result.get("path").is_some());
        assert!(result.get("total_files").is_some());
        assert!(result.get("average_score").is_some());
        assert!(result.get("average_grade").is_some());
    }

    #[test]
    fn test_create_error_result() {
        let path = Path::new("/tmp/test");
        let error = anyhow::anyhow!("Test error message");

        let result = create_error_result(path, &error);

        assert_eq!(result.get("status").unwrap(), "failed");
        assert!(result
            .get("error")
            .unwrap()
            .as_str()
            .unwrap()
            .contains("Test error message"));
    }

    // ==================== QDD OPERATION TESTS ====================

    #[tokio::test]
    async fn test_quality_driven_development_unknown_operation() {
        let result =
            quality_driven_development("unknown_op", None, None, None, None, None, None, None)
                .await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json.get("status").unwrap(), "failed");
        assert!(json
            .get("message")
            .unwrap()
            .as_str()
            .unwrap()
            .contains("Unknown QDD operation"));
    }

    #[tokio::test]
    async fn test_quality_driven_development_refactor_missing_path() {
        let result = quality_driven_development(
            "refactor",
            Some("standard"),
            None,
            Some("test_func"),
            None,
            None, // Missing file_path
            None,
            None,
        )
        .await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json.get("status").unwrap(), "failed");
        assert!(json
            .get("message")
            .unwrap()
            .as_str()
            .unwrap()
            .contains("file_path"));
    }

    // ==================== DEFECT AWARE PROMPT TESTS ====================

    #[tokio::test]
    async fn test_generate_defect_aware_prompt_missing_file() {
        let result = generate_defect_aware_prompt(
            "test task".to_string(),
            "test context".to_string(),
            PathBuf::from("/tmp/nonexistent_summary_12345.yaml"),
        )
        .await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json.get("status").unwrap(), "failed");
        assert!(json
            .get("error")
            .unwrap()
            .as_str()
            .unwrap()
            .contains("FILE_NOT_FOUND"));
    }

    // ==================== TDG STORAGE MANAGEMENT TESTS ====================

    #[tokio::test]
    async fn test_tdg_storage_management_unknown_action() {
        let result = tdg_storage_management("unknown_action".to_string(), json!({})).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json.get("status").unwrap(), "error");
        assert!(json
            .get("message")
            .unwrap()
            .as_str()
            .unwrap()
            .contains("Unknown storage action"));
    }

    // ==================== TDG CONFIGURE STORAGE TESTS ====================

    #[tokio::test]
    async fn test_tdg_configure_storage_unsupported_backend() {
        let result =
            tdg_configure_storage("unsupported_backend".to_string(), None, None, None).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json.get("status").unwrap(), "error");
    }

    #[tokio::test]
    async fn test_tdg_configure_storage_inmemory() {
        let result =
            tdg_configure_storage("inmemory".to_string(), None, Some(64), Some(true)).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json.get("status").unwrap(), "completed");
    }

    // ==================== TDG PERFORMANCE METRICS TESTS ====================

    #[tokio::test]
    async fn test_tdg_performance_metrics() {
        let result = tdg_performance_metrics().await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json.get("status").unwrap(), "completed");
        assert!(json.get("adaptive_thresholds").is_some());
        assert!(json.get("performance_stats").is_some());
        assert!(json.get("scheduler_stats").is_some());
    }

    // ==================== TDG HEALTH CHECK TESTS ====================

    #[tokio::test]
    async fn test_tdg_health_check() {
        let result = tdg_health_check().await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json.get("status").unwrap(), "completed");
        assert!(json.get("overall_status").is_some());
        assert!(json.get("health_score").is_some());
        assert!(json.get("components").is_some());
    }

    // ==================== FILE-BASED TESTS (REQUIRE TEMP FILES) ====================

    #[tokio::test]
    async fn test_analyze_complexity_with_nonexistent_paths() {
        let paths = vec![PathBuf::from("/tmp/nonexistent_12345.rs")];
        let result = analyze_complexity(&paths, None, None).await;

        // Should succeed but with 0 files analyzed
        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json["results"]["total_files"], 0);
    }

    #[tokio::test]
    async fn test_analyze_satd_with_nonexistent_paths() {
        let paths = vec![PathBuf::from("/tmp/nonexistent_12345.rs")];
        let result = analyze_satd(&paths, false).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json["results"]["total_satd"], 0);
    }

    #[tokio::test]
    async fn test_analyze_dead_code_with_nonexistent_paths() {
        let paths = vec![PathBuf::from("/tmp/nonexistent_12345.rs")];
        let result = analyze_dead_code(&paths, false).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json["results"]["total_dead_code"], 0);
    }

    #[tokio::test]
    async fn test_generate_context_with_nonexistent_paths() {
        let paths = vec![PathBuf::from("/tmp/nonexistent_12345.rs")];
        let result = generate_context(&paths, None, false).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json["context"]["total_files"], 0);
    }

    #[tokio::test]
    async fn test_analyze_complexity_with_real_file() -> Result<()> {
        let temp_dir = TempDir::new()?;
        let file_path = temp_dir.path().join("test.rs");
        fs::write(&file_path, "fn main() { println!(\"Hello\"); }")?;

        let paths = vec![file_path];
        let result = analyze_complexity(&paths, None, Some(5)).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json["status"], "completed");

        Ok(())
    }

    #[tokio::test]
    async fn test_analyze_satd_with_real_file() -> Result<()> {
        let temp_dir = TempDir::new()?;
        let file_path = temp_dir.path().join("test.rs");
        fs::write(
            &file_path,
            "fn main() {\n    // TODO: fix this\n    println!(\"Hello\");\n}",
        )?;

        let paths = vec![file_path];
        let result = analyze_satd(&paths, false).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json["status"], "completed");

        Ok(())
    }

    #[tokio::test]
    async fn test_context_summary_with_real_directory() -> Result<()> {
        let temp_dir = TempDir::new()?;
        let file_path = temp_dir.path().join("test.rs");
        fs::write(&file_path, "fn main() {}")?;

        let paths = vec![temp_dir.path().to_path_buf()];
        let result = context_summary(&paths, None).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json["status"], "completed");
        assert!(json["summary"]["total_files"].as_u64().unwrap() >= 1);

        Ok(())
    }

    #[tokio::test]
    async fn test_quality_gate_compare_missing_baseline() {
        let paths = vec![PathBuf::from("/tmp")];
        let result =
            quality_gate_compare(Path::new("/tmp/nonexistent_baseline_12345.json"), &paths).await;

        assert!(result.is_err());
        assert!(result
            .unwrap_err()
            .to_string()
            .contains("Baseline file not found"));
    }

    // ==================== PROPERTY-BASED TESTS ====================

    proptest! {
        #[test]
        fn prop_select_quality_profile_never_panics(profile_name in ".*") {
            let _ = select_quality_profile(Some(&profile_name));
        }

        #[test]
        fn prop_parse_code_type_never_panics(code_type in ".*") {
            let _ = parse_code_type(Some(&code_type));
        }

        #[test]
        fn prop_create_file_identity_with_any_content(content in proptest::collection::vec(any::<u8>(), 0..1000)) {
            let path = Path::new("/tmp/test.rs");
            let hash = blake3::hash(&content);
            let identity = create_file_identity(path, &hash, &content);

            prop_assert_eq!(identity.size_bytes, content.len() as u64);
            prop_assert_eq!(identity.content_hash, hash);
        }

        #[test]
        fn prop_create_semantic_signature_deterministic(content in proptest::collection::vec(any::<u8>(), 0..100)) {
            let hash = blake3::hash(&content);
            let sig1 = create_semantic_signature(&hash);
            let sig2 = create_semantic_signature(&hash);

            prop_assert_eq!(sig1.ast_structure_hash, sig2.ast_structure_hash);
            prop_assert_eq!(sig1.identifier_pattern, sig2.identifier_pattern);
        }

        #[test]
        fn prop_git_clone_url_parsing(repo_name in "[a-zA-Z0-9-]+") {
            let url = format!("https://github.com/user/{}.git", repo_name);
            let rt = tokio::runtime::Runtime::new().unwrap();
            let result = rt.block_on(git_clone(&url, None, None, None));

            prop_assert!(result.is_ok());
            prop_assert_eq!(result.unwrap(), PathBuf::from(&repo_name));
        }
    }

    // ==================== TDG SYSTEM DIAGNOSTICS TESTS ====================

    #[tokio::test]
    async fn test_tdg_system_diagnostics_all_components() {
        let result = tdg_system_diagnostics(true, vec!["all".to_string()]).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        // Result status depends on system state
        assert!(json.get("status").is_some());
    }

    #[tokio::test]
    async fn test_tdg_system_diagnostics_specific_components() {
        let result = tdg_system_diagnostics(false, vec!["storage".to_string()]).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert!(json.get("status").is_some());
    }

    #[tokio::test]
    async fn test_tdg_system_diagnostics_empty_components() {
        let result = tdg_system_diagnostics(false, vec![]).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert!(json.get("status").is_some());
    }

    // ==================== EDGE CASE TESTS ====================

    #[test]
    fn test_create_file_identity_empty_content() {
        let path = Path::new("/tmp/empty.rs");
        let content = b"";
        let hash = blake3::hash(content);

        let identity = create_file_identity(path, &hash, content);

        assert_eq!(identity.size_bytes, 0);
    }

    #[test]
    fn test_create_semantic_signature_hash_bytes() {
        // Test that the AST structure hash is computed from first 8 bytes
        let content = b"deterministic content";
        let hash = blake3::hash(content);
        let signature = create_semantic_signature(&hash);

        // Verify the hash is computed (non-zero for non-trivial content)
        // The actual value depends on blake3 hash of the content
        assert!(signature.ast_structure_hash > 0 || content.is_empty());
    }

    #[tokio::test]
    async fn test_analyze_lint_hotspots_file_path_error() {
        // Pass a file path instead of directory
        let temp_dir = TempDir::new().unwrap();
        let file_path = temp_dir.path().join("test.rs");
        fs::write(&file_path, "fn main() {}").unwrap();

        let paths = vec![file_path];
        let result = analyze_lint_hotspots(&paths, None).await;

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

    #[tokio::test]
    async fn test_analyze_complexity_with_threshold() -> Result<()> {
        let temp_dir = TempDir::new()?;
        let file_path = temp_dir.path().join("test.rs");
        fs::write(&file_path, "fn simple() {}")?;

        let paths = vec![file_path];
        // High threshold - no violations expected
        let result = analyze_complexity(&paths, Some(5), Some(100)).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        assert_eq!(json["results"]["violations"].as_array().unwrap().len(), 0);

        Ok(())
    }

    #[tokio::test]
    async fn test_analyze_complexity_with_top_files_limit() -> Result<()> {
        let temp_dir = TempDir::new()?;

        // Create multiple files
        for i in 0..5 {
            let file_path = temp_dir.path().join(format!("test{}.rs", i));
            fs::write(&file_path, "fn main() {}")?;
        }

        let paths: Vec<PathBuf> = (0..5)
            .map(|i| temp_dir.path().join(format!("test{}.rs", i)))
            .collect();

        let result = analyze_complexity(&paths, Some(2), None).await;

        assert!(result.is_ok());
        let json = result.unwrap();
        // top_files limits the output
        assert!(json["results"]["top_files"].as_array().unwrap().len() <= 2);

        Ok(())
    }
}