sublime_standard_tools 0.0.15

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

use std::path::Path;
use std::sync::Arc;
use tempfile::TempDir;

use crate::filesystem::{AsyncFileSystem, FileSystemManager};
use crate::monorepo::MonorepoKind;
use crate::node::{PackageManager, PackageManagerKind, RepoKind};

use super::*;

#[allow(clippy::unwrap_used)]
#[allow(clippy::uninlined_format_args)]
#[allow(clippy::match_wildcard_for_single_variants)]
#[allow(clippy::panic)]
#[allow(clippy::assertions_on_constants)]
#[cfg(test)]
mod tests {
    use super::*;

    // =============================================================================
    // HELPER FUNCTIONS
    // =============================================================================

    /// Creates a temporary directory for testing
    fn setup_test_dir() -> TempDir {
        TempDir::new().unwrap()
    }

    /// Creates a basic package.json file in the given directory
    async fn create_package_json(dir: &Path, name: &str, version: &str) {
        let fs = FileSystemManager::new();
        let package_json_path = dir.join("package.json");
        let content = format!(
            r#"{{
  "name": "{}",
  "version": "{}",
  "description": "Test package",
  "main": "index.js",
  "scripts": {{
    "start": "node index.js"
  }}
}}"#,
            name, version
        );
        fs.write_file_string(&package_json_path, &content).await.unwrap();
    }

    /// Creates a package.json with specific content
    #[allow(clippy::unwrap_used)]
    async fn create_package_json_with_content(dir: &Path, content: &str) {
        let fs = FileSystemManager::new();
        let package_json_path = dir.join("package.json");
        fs.write_file_string(&package_json_path, content).await.unwrap();
    }

    /// Creates a package manager lock file in the given directory
    async fn create_lock_file(dir: &Path, kind: PackageManagerKind) {
        let fs = FileSystemManager::new();
        let lock_path = dir.join(kind.lock_file());
        fs.write_file_string(&lock_path, "# Lock file content").await.unwrap();
    }

    // =============================================================================
    // PROJECT KIND TESTS
    // =============================================================================

    #[tokio::test]
    async fn test_project_kind_simple() {
        let kind = ProjectKind::Repository(RepoKind::Simple);
        assert_eq!(kind.name(), "simple");
        assert!(!kind.is_monorepo());
    }

    #[tokio::test]
    async fn test_project_kind_monorepo() {
        let kind = ProjectKind::Repository(RepoKind::Monorepo(MonorepoKind::YarnWorkspaces));
        assert_eq!(kind.name(), "yarn monorepo");
        assert!(kind.is_monorepo());
    }

    #[tokio::test]
    async fn test_project_kind_equality() {
        let kind1 = ProjectKind::Repository(RepoKind::Simple);
        let kind2 = ProjectKind::Repository(RepoKind::Simple);
        let kind3 = ProjectKind::Repository(RepoKind::Monorepo(MonorepoKind::NpmWorkSpace));

        assert_eq!(kind1, kind2);
        assert_ne!(kind1, kind3);
    }

    #[tokio::test]
    async fn test_project_kind_comprehensive_scenarios() {
        // Test all possible ProjectKind variants
        let test_cases = vec![
            ProjectKind::Repository(RepoKind::Simple),
            ProjectKind::Repository(RepoKind::Monorepo(MonorepoKind::NpmWorkSpace)),
            ProjectKind::Repository(RepoKind::Monorepo(MonorepoKind::YarnWorkspaces)),
            ProjectKind::Repository(RepoKind::Monorepo(MonorepoKind::PnpmWorkspaces)),
            ProjectKind::Repository(RepoKind::Monorepo(MonorepoKind::BunWorkspaces)),
            ProjectKind::Repository(RepoKind::Monorepo(MonorepoKind::DenoWorkspaces)),
            ProjectKind::Repository(RepoKind::Monorepo(MonorepoKind::Custom {
                name: "custom".to_string(),
                config_file: "custom.json".to_string(),
            })),
        ];

        for kind in test_cases {
            // Test all methods
            assert!(!kind.name().is_empty());
            assert!(kind.is_monorepo() || !kind.is_monorepo());
            assert!(kind.repo_kind().is_monorepo() || !kind.repo_kind().is_monorepo());

            // Test monorepo-specific methods
            if kind.is_monorepo() {
                assert!(kind.monorepo_kind().is_some());
            } else {
                assert!(kind.monorepo_kind().is_none());
            }
        }
    }

    // =============================================================================
    // PROJECT VALIDATION STATUS TESTS
    // =============================================================================

    #[tokio::test]
    async fn test_validation_status_valid() {
        let status = ProjectValidationStatus::Valid;
        assert!(status.is_valid());
        assert!(!status.has_warnings());
        assert!(!status.has_errors());
        assert!(status.warnings().is_none());
        assert!(status.errors().is_none());
    }

    #[tokio::test]
    async fn test_validation_status_warning() {
        let warnings = vec!["Missing LICENSE".to_string()];
        let status = ProjectValidationStatus::Warning(warnings.clone());

        assert!(!status.is_valid());
        assert!(status.has_warnings());
        assert!(!status.has_errors());
        assert_eq!(status.warnings(), Some(warnings.as_slice()));
        assert!(status.errors().is_none());
    }

    #[tokio::test]
    async fn test_validation_status_error() {
        let errors = vec!["Invalid package.json".to_string()];
        let status = ProjectValidationStatus::Error(errors.clone());

        assert!(!status.is_valid());
        assert!(!status.has_warnings());
        assert!(status.has_errors());
        assert!(status.warnings().is_none());
        assert_eq!(status.errors(), Some(errors.as_slice()));
    }

    #[tokio::test]
    async fn test_validation_status_not_validated() {
        let status = ProjectValidationStatus::NotValidated;
        assert!(!status.is_valid());
        assert!(!status.has_warnings());
        assert!(!status.has_errors());
        assert!(status.warnings().is_none());
        assert!(status.errors().is_none());
    }

    #[tokio::test]
    async fn test_project_validation_status_comprehensive() {
        // Test all validation status variants
        let statuses = vec![
            ProjectValidationStatus::Valid,
            ProjectValidationStatus::Warning(vec![
                "Warning 1".to_string(),
                "Warning 2".to_string(),
            ]),
            ProjectValidationStatus::Error(vec!["Error 1".to_string(), "Error 2".to_string()]),
            ProjectValidationStatus::NotValidated,
        ];

        for status in statuses {
            // Test all methods
            assert!(status.is_valid() || !status.is_valid());
            assert!(status.has_warnings() || !status.has_warnings());
            assert!(status.has_errors() || !status.has_errors());

            // Test consistency
            match &status {
                ProjectValidationStatus::Valid => {
                    assert!(status.is_valid());
                    assert!(!status.has_warnings());
                    assert!(!status.has_errors());
                }
                ProjectValidationStatus::Warning(warnings) => {
                    assert!(!status.is_valid());
                    assert!(status.has_warnings());
                    assert!(!status.has_errors());
                    assert_eq!(status.warnings(), Some(warnings.as_slice()));
                }
                ProjectValidationStatus::Error(errors) => {
                    assert!(!status.is_valid());
                    assert!(!status.has_warnings());
                    assert!(status.has_errors());
                    assert_eq!(status.errors(), Some(errors.as_slice()));
                }
                ProjectValidationStatus::NotValidated => {
                    assert!(!status.is_valid());
                    assert!(!status.has_warnings());
                    assert!(!status.has_errors());
                }
            }
        }
    }

    // =============================================================================
    // PROJECT CONFIG TESTS
    // =============================================================================

    // Note: ProjectConfig tests removed as configuration is now handled by StandardConfig

    // Configuration tests removed - now handled by StandardConfig system

    // =============================================================================
    // SIMPLE PROJECT TESTS
    // =============================================================================

    #[tokio::test]
    async fn test_simple_project_creation() {
        let root = "/test/project".into();
        let project = Project::new(root, ProjectKind::Repository(RepoKind::Simple));

        assert_eq!(project.root(), Path::new("/test/project"));
        assert_eq!(project.kind(), ProjectKind::Repository(RepoKind::Simple));
        assert!(project.package_json().is_none());
        assert!(project.package_manager().is_none());
        assert_eq!(project.validation_status(), &ProjectValidationStatus::NotValidated);
    }

    #[tokio::test]
    async fn test_simple_project_with_validation() {
        let root = "/test/project".into();
        let status = ProjectValidationStatus::Valid;
        let mut project = Project::new(root, ProjectKind::Repository(RepoKind::Simple));
        project.set_validation_status(status);

        assert_eq!(project.root(), Path::new("/test/project"));
        assert!(project.validation_status().is_valid());
    }

    #[tokio::test]
    async fn test_simple_project_setters() {
        let root = "/test/project".into();
        let mut project = Project::new(root, ProjectKind::Repository(RepoKind::Simple));

        let package_manager = PackageManager::new(PackageManagerKind::Npm, "/test/project");
        project.package_manager = Some(package_manager);
        assert!(project.package_manager().is_some());

        project.set_validation_status(ProjectValidationStatus::Valid);
        assert!(project.validation_status().is_valid());
    }

    #[tokio::test]
    async fn test_simple_project_comprehensive() {
        let temp_dir = setup_test_dir();
        let path = temp_dir.path().to_path_buf();

        // Test all constructors
        let simple1 = Project::new(path.clone(), ProjectKind::Repository(RepoKind::Simple));
        let mut simple2 = Project::new(path.clone(), ProjectKind::Repository(RepoKind::Simple));
        simple2.set_validation_status(ProjectValidationStatus::Valid);

        // Test all methods
        assert_eq!(simple1.root(), path);
        assert_eq!(simple2.root(), path);
        assert!(simple1.package_manager().is_none());
        assert!(simple1.package_json().is_none());
        assert!(!simple1.validation_status().is_valid());
        assert!(simple2.validation_status().is_valid());

        // Test ProjectInfo trait
        let info: &dyn ProjectInfo = &simple1;
        assert_eq!(info.root(), path);
        assert_eq!(info.kind(), ProjectKind::Repository(RepoKind::Simple));
        assert!(info.package_manager().is_none());
        assert!(info.package_json().is_none());
    }

    #[tokio::test]
    async fn test_simple_project_mutations() {
        let temp_dir = setup_test_dir();
        let path = temp_dir.path().to_path_buf();
        let mut simple = Project::new(path.clone(), ProjectKind::Repository(RepoKind::Simple));

        // Test package manager mutation
        create_lock_file(&path, PackageManagerKind::Npm).await;
        let pm = PackageManager::detect(&path).unwrap();
        simple.package_manager = Some(pm);
        assert!(simple.package_manager().is_some());

        // Test validation status mutation
        simple.set_validation_status(ProjectValidationStatus::Valid);
        assert!(simple.validation_status().is_valid());

        // Test direct status mutation
        simple
            .set_validation_status(ProjectValidationStatus::Error(vec!["Test error".to_string()]));
        assert!(simple.validation_status().has_errors());
    }

    #[tokio::test]
    async fn test_project_descriptor_trait_object() {
        let temp_dir = setup_test_dir();
        let path = temp_dir.path().to_path_buf();

        let project = Project::new(path.clone(), ProjectKind::Repository(RepoKind::Simple));
        let descriptor = ProjectDescriptor::NodeJs(project);

        // Test trait object access
        let info = descriptor.as_project_info();
        assert_eq!(info.root(), path);
        assert_eq!(info.kind(), ProjectKind::Repository(RepoKind::Simple));
    }

    // =============================================================================
    // PROJECT DETECTOR TESTS
    // =============================================================================

    #[tokio::test]
    async fn test_detector_creation() {
        let _detector = ProjectDetector::new();
        // Just ensure it can be created without panicking
        assert!(true);
    }

    #[tokio::test]
    async fn test_is_valid_project_with_valid_project() {
        let temp_dir = setup_test_dir();
        let detector = ProjectDetector::new();

        // Create a valid project
        create_package_json(temp_dir.path(), "test-project", "1.0.0").await;

        assert!(detector.is_valid_project(temp_dir.path()).await);
    }

    #[tokio::test]
    async fn test_is_valid_project_without_package_json() {
        let temp_dir = setup_test_dir();
        let detector = ProjectDetector::new();

        // Directory exists but no package.json
        assert!(!detector.is_valid_project(temp_dir.path()).await);
    }

    #[tokio::test]
    async fn test_is_valid_project_with_invalid_package_json() {
        let temp_dir = setup_test_dir();
        let detector = ProjectDetector::new();
        let fs = FileSystemManager::new();

        // Create invalid package.json
        let package_json_path = temp_dir.path().join("package.json");
        fs.write_file_string(&package_json_path, "invalid json content").await.unwrap();

        assert!(!detector.is_valid_project(temp_dir.path()).await);
    }

    #[tokio::test]
    async fn test_detect_kind_simple_project() {
        let temp_dir = setup_test_dir();
        let detector = ProjectDetector::new();

        create_package_json(temp_dir.path(), "test-project", "1.0.0").await;

        let kind = detector.detect_kind(temp_dir.path()).await.unwrap();
        assert_eq!(kind, ProjectKind::Repository(RepoKind::Simple));
    }

    #[tokio::test]
    async fn test_detect_simple_project() {
        let temp_dir = setup_test_dir();
        let detector = ProjectDetector::new();

        create_package_json(temp_dir.path(), "test-project", "1.0.0").await;
        create_lock_file(temp_dir.path(), PackageManagerKind::Npm).await;

        let result = detector.detect(temp_dir.path(), None).await;
        assert!(result.is_ok());

        let project = result.unwrap();
        match project {
            ProjectDescriptor::NodeJs(project) => {
                assert_eq!(project.root(), temp_dir.path());
                assert_eq!(project.kind(), ProjectKind::Repository(RepoKind::Simple));
                assert!(project.package_json().is_some());
                assert!(project.package_manager().is_some());
            }
        }
    }

    #[tokio::test]
    async fn test_project_detector_error_conditions() {
        let detector = ProjectDetector::new();
        let config: Option<&crate::config::StandardConfig> = None;

        // Test with non-existent path
        let non_existent = "/non/existent/path/to/project";
        let result = detector.detect(non_existent, config).await;
        assert!(result.is_err());

        // Test with path without package.json
        let temp_dir = setup_test_dir();
        let path = temp_dir.path();
        let result = detector.detect(path, config).await;
        assert!(result.is_err());

        // Test with invalid package.json
        create_package_json_with_content(path, "invalid json content").await;
        let result = detector.detect(path, config).await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_project_detector_with_malformed_json() {
        let detector = ProjectDetector::new();
        let config: Option<&crate::config::StandardConfig> = None;
        let temp_dir = setup_test_dir();
        let path = temp_dir.path();

        let malformed_json_cases = vec![
            "{ incomplete json",
            "{ \"name\": \"test\", \"version\": }",
            "{ \"name\": \"test\", \"version\": \"1.0.0\", }",
            "not json at all",
            "",
            "null",
            "[]",
            "\"string\"",
            "123",
        ];

        for malformed in malformed_json_cases {
            create_package_json_with_content(path, malformed).await;
            let result = detector.detect(path, config).await;
            assert!(result.is_err(), "Should fail for malformed JSON: {malformed}");
        }
    }

    #[tokio::test]
    async fn test_project_detector_is_valid_project_edge_cases() {
        let detector = ProjectDetector::new();

        // Test with non-existent path
        assert!(!detector.is_valid_project("/non/existent/path").await);

        // Test with directory but no package.json
        let temp_dir = setup_test_dir();
        let path = temp_dir.path();
        assert!(!detector.is_valid_project(path).await);

        // Test with invalid package.json
        create_package_json_with_content(path, "invalid json").await;
        assert!(!detector.is_valid_project(path).await);

        // Test with valid package.json
        create_package_json_with_content(path, r#"{"name": "test", "version": "1.0.0"}"#).await;
        assert!(detector.is_valid_project(path).await);
    }

    #[tokio::test]
    async fn test_project_detector_detect_kind_comprehensive() {
        let detector = ProjectDetector::new();
        let temp_dir = setup_test_dir();
        let path = temp_dir.path();

        // Test with simple project
        create_package_json_with_content(path, r#"{"name": "test", "version": "1.0.0"}"#).await;
        let kind = detector.detect_kind(path).await.unwrap();
        assert_eq!(kind, ProjectKind::Repository(RepoKind::Simple));

        // Test with monorepo detection disabled
        let kind = detector.detect_kind(path).await.unwrap();
        assert_eq!(kind, ProjectKind::Repository(RepoKind::Simple));
    }

    #[tokio::test]
    async fn test_project_detector_concurrent_access() {
        let detector = Arc::new(ProjectDetector::new());
        let config: Option<&crate::config::StandardConfig> = None;
        let temp_dir = setup_test_dir();
        let path = Arc::new(temp_dir.path().to_path_buf());

        // Create a valid project
        create_package_json_with_content(&path, r#"{"name": "test", "version": "1.0.0"}"#).await;

        // Run detection from multiple async tasks
        let mut handles = vec![];
        for _ in 0..10 {
            let handle = tokio::spawn({
                let detector_clone = Arc::clone(&detector);
                let path_clone = Arc::clone(&path);
                let config_clone = config;
                async move { detector_clone.detect(path_clone.as_ref(), config_clone).await }
            });
            handles.push(handle);
        }

        // All should succeed
        for handle in handles {
            let result = handle.await.unwrap();
            assert!(result.is_ok());
        }
    }

    // =============================================================================
    // PROJECT MANAGER TESTS
    // =============================================================================

    #[tokio::test]
    async fn test_manager_creation() {
        let _manager = ProjectManager::new();
        // Just ensure it can be created without panicking
        assert!(true);
    }

    #[tokio::test]
    async fn test_is_valid_project() {
        let temp_dir = setup_test_dir();
        let manager = ProjectManager::new();

        create_package_json(temp_dir.path(), "test-project", "1.0.0").await;
        assert!(manager.is_valid_project(temp_dir.path()).await);
    }

    #[tokio::test]
    async fn test_create_project() {
        let temp_dir = setup_test_dir();
        let manager = ProjectManager::new();

        create_package_json(temp_dir.path(), "test-project", "1.0.0").await;
        create_lock_file(temp_dir.path(), PackageManagerKind::Npm).await;

        let result = manager.create_project(temp_dir.path(), None).await;
        assert!(result.is_ok());

        let project = result.unwrap();
        let info = project.as_project_info();
        assert_eq!(info.root(), temp_dir.path());
        assert_eq!(info.kind(), ProjectKind::Repository(RepoKind::Simple));
    }

    #[tokio::test]
    async fn test_find_project_root() {
        let temp_dir = setup_test_dir();
        let manager = ProjectManager::new();

        // Create nested directory structure
        let nested_dir = temp_dir.path().join("src").join("components");
        std::fs::create_dir_all(&nested_dir).unwrap();

        // Create package.json at root
        create_package_json(temp_dir.path(), "test-project", "1.0.0").await;

        // Should find root from nested path
        let root = manager.find_project_root(&nested_dir).await;
        assert_eq!(root, Some(temp_dir.path().to_path_buf()));
    }

    #[tokio::test]
    async fn test_find_project_root_not_found() {
        let temp_dir = setup_test_dir();
        let manager = ProjectManager::new();

        // No package.json anywhere
        let root = manager.find_project_root(temp_dir.path()).await;
        assert!(root.is_none());
    }

    // =============================================================================
    // PROJECT VALIDATOR TESTS
    // =============================================================================

    #[tokio::test]
    async fn test_validator_creation() {
        let _validator = ProjectValidator::new();
        // Just ensure it can be created without panicking
        assert!(true);
    }

    #[tokio::test]
    async fn test_validate_project_descriptor_valid() {
        let temp_dir = setup_test_dir();
        let validator = ProjectValidator::new();

        create_package_json(temp_dir.path(), "test-project", "1.0.0").await;
        create_lock_file(temp_dir.path(), PackageManagerKind::Npm).await;

        let package_manager = PackageManager::new(PackageManagerKind::Npm, temp_dir.path());
        let fs = FileSystemManager::new();
        let content = fs.read_file_string(&temp_dir.path().join("package.json")).await.unwrap();
        let package_json = serde_json::from_str(&content).unwrap();

        let mut unified_project =
            Project::new(temp_dir.path().to_path_buf(), ProjectKind::Repository(RepoKind::Simple));
        unified_project.package_manager = Some(package_manager);
        unified_project.package_json = Some(package_json);

        let mut project = ProjectDescriptor::NodeJs(unified_project);

        let result = validator.validate_project(&mut project).await;
        assert!(result.is_ok());

        // The project should have some validation status (not NotValidated)
        match project.as_project_info().validation_status() {
            ProjectValidationStatus::NotValidated => panic!("Project should be validated"),
            _ => {} // Valid, Warning, or Error are all acceptable
        }
    }

    #[tokio::test]
    async fn test_validate_project_descriptor_missing_package_json() {
        let temp_dir = setup_test_dir();
        let validator = ProjectValidator::new();

        // No package.json created
        let unified_project =
            Project::new(temp_dir.path().to_path_buf(), ProjectKind::Repository(RepoKind::Simple));
        let mut project = ProjectDescriptor::NodeJs(unified_project);

        let result = validator.validate_project(&mut project).await;
        assert!(result.is_ok());

        // Should have errors
        assert!(project.as_project_info().validation_status().has_errors());
    }

    #[tokio::test]
    async fn test_validate_project_descriptor_with_warnings() {
        let temp_dir = setup_test_dir();
        let validator = ProjectValidator::new();

        // Create package.json with potential warning conditions
        let fs = FileSystemManager::new();
        let package_json_path = temp_dir.path().join("package.json");
        let content = r#"{
  "name": "test-project",
  "version": "1.0.0"
}"#;
        fs.write_file_string(&package_json_path, content).await.unwrap();

        let package_json = serde_json::from_str(content).unwrap();
        let mut unified_project =
            Project::new(temp_dir.path().to_path_buf(), ProjectKind::Repository(RepoKind::Simple));
        unified_project.package_json = Some(package_json);

        let mut project = ProjectDescriptor::NodeJs(unified_project);

        let result = validator.validate_project(&mut project).await;
        assert!(result.is_ok());

        // Should have warnings (missing description, license, etc.)
        assert!(project.as_project_info().validation_status().has_warnings());
    }

    // =============================================================================
    // GENERIC PROJECT TESTS
    // =============================================================================

    #[tokio::test]
    async fn test_generic_project_comprehensive() {
        let temp_dir = setup_test_dir();
        let path = temp_dir.path().to_path_buf();
        //let _config: Option<&crate::config::StandardConfig> = None;

        let mut project = Project::new(path.clone(), ProjectKind::Repository(RepoKind::Simple));

        // Test all methods
        assert_eq!(project.root, path);
        assert!(project.package_manager.is_none());
        assert!(project.package_json.is_none());
        assert!(!project.validation_status.is_valid());

        // Test mutations
        create_lock_file(&path, PackageManagerKind::Yarn).await;
        let pm = PackageManager::detect(&path).unwrap();
        project.package_manager = Some(pm);
        assert!(project.package_manager.is_some());

        project.validation_status = ProjectValidationStatus::Valid;
        assert!(project.validation_status.is_valid());
    }

    // =============================================================================
    // STRESS TESTING AND EDGE CASES
    // =============================================================================

    #[tokio::test]
    async fn test_project_stress_testing() {
        let detector = ProjectDetector::new();
        let config: Option<&crate::config::StandardConfig> = None;

        // Test with many sequential detections
        for i in 0..50 {
            let temp_dir = setup_test_dir();
            let path = temp_dir.path();

            create_package_json_with_content(
                path,
                &format!(r#"{{"name": "test-{i}", "version": "1.0.0"}}"#),
            )
            .await;

            let result = detector.detect(path, config).await;
            assert!(result.is_ok());
        }
    }

    #[tokio::test]
    async fn test_project_deep_nesting() {
        let detector = ProjectDetector::new();
        let config: Option<&crate::config::StandardConfig> = None;
        let temp_dir = setup_test_dir();
        let mut path = temp_dir.path().to_path_buf();

        // Create deeply nested structure
        for i in 0..10 {
            path = path.join(format!("level_{i}"));
            std::fs::create_dir_all(&path).unwrap();
        }

        create_package_json_with_content(&path, r#"{"name": "deeply-nested", "version": "1.0.0"}"#)
            .await;

        let result = detector.detect(&path, config).await;
        assert!(result.is_ok());
    }
}