webpage_quality_analyzer 1.0.2

High-performance webpage quality analyzer with 115 comprehensive metrics - Rust library with WASM, C++, and Python bindings
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
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
/// Profile Validation System for Phase 2
/// Validates enhanced profile configurations for correctness and consistency
use crate::config::enhanced_models::*;
use crate::metrics::definitions::{MetricCategory, ThresholdSet, METRIC_REGISTRY};
use std::collections::{HashMap, HashSet};

/// Profile validation errors
#[derive(Debug, thiserror::Error)]
pub enum ValidationError {
    #[error("Category weights validation failed: {0}")]
    CategoryWeights(String),

    #[error("Metric override validation failed: {0}")]
    MetricOverride(String),

    #[error("Threshold validation failed: {0}")]
    Threshold(String),

    #[error("Content expectation validation failed: {0}")]
    ContentExpectation(String),

    #[error("Penalty configuration validation failed: {0}")]
    PenaltyConfig(String),

    #[error("Bonus configuration validation failed: {0}")]
    BonusConfig(String),

    #[error("General validation error: {0}")]
    General(String),
}

/// Profile validator implementation
#[derive(Debug, Clone)]
pub struct ProfileValidator {
    valid_metrics: HashSet<String>,
    valid_categories: HashSet<String>,
}

impl ProfileValidator {
    pub fn new() -> Self {
        let valid_metrics = METRIC_REGISTRY
            .all_metrics()
            .iter()
            .map(|m| m.field_name.to_string())
            .collect();

        let valid_categories = MetricCategory::all()
            .iter()
            .map(|c| format!("{:?}", c).to_lowercase())
            .collect();

        Self {
            valid_metrics,
            valid_categories,
        }
    }

    /// Validate complete profile configuration
    pub fn validate_profile(
        &self,
        profile: &EnhancedScoringProfile,
    ) -> Result<ValidationReport, ValidationError> {
        let mut report = ValidationReport::new();

        // Validate metadata
        self.validate_metadata(&profile.metadata, &mut report)?;

        // Validate category weights
        self.validate_category_weights(&profile.category_weights, &mut report)?;

        // Validate metric overrides
        self.validate_metric_overrides(&profile.metric_overrides, &mut report)?;

        // Validate content expectations
        self.validate_content_expectations(&profile.content_expectations, &mut report)?;

        // Validate quality bands
        self.validate_quality_bands(&profile.quality_bands, &mut report)?;

        // Validate penalties
        self.validate_penalties(&profile.penalties, &mut report)?;

        // Validate bonuses
        self.validate_bonuses(&profile.bonuses, &mut report)?;

        // Cross-validation checks
        self.validate_consistency(profile, &mut report)?;

        Ok(report)
    }

    /// Normalize profile to ensure consistency
    pub fn normalize_profile(
        &self,
        profile: &mut EnhancedScoringProfile,
    ) -> Result<(), ValidationError> {
        // Normalize category weights to sum to 1.0
        self.normalize_category_weights(&mut profile.category_weights)?;

        // Fill in missing metric overrides with defaults
        self.apply_default_overrides(profile)?;

        // Ensure quality bands are properly ordered
        self.normalize_quality_bands(&mut profile.quality_bands)?;

        Ok(())
    }

    fn validate_metadata(
        &self,
        metadata: &ProfileMetadata,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        if metadata.name.is_empty() {
            report.add_error("Profile name cannot be empty".to_string());
        }

        if metadata.description.is_empty() {
            report.add_warning("Profile description is empty".to_string());
        }

        if metadata.target_content_types.is_empty() {
            report.add_warning("No target content types specified".to_string());
        }

        // Validate version format (basic semver check)
        if !self.is_valid_version(&metadata.version) {
            report.add_warning(format!(
                "Version format may be invalid: {}",
                metadata.version
            ));
        }

        Ok(())
    }

    fn validate_category_weights(
        &self,
        weights: &CategoryWeights,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        let weight_sum: f32 = weights.values().sum();

        // Check if weights sum to approximately 1.0
        if (weight_sum - 1.0).abs() > 0.1 {
            report.add_error(format!(
                "Category weights sum to {:.2}, should sum to approximately 1.0",
                weight_sum
            ));
        } else if (weight_sum - 1.0).abs() > 0.01 {
            report.add_warning(format!(
                "Category weights sum to {:.3}, will be normalized to 1.0",
                weight_sum
            ));
        }

        // Check for invalid weights
        for (category, weight) in weights {
            if *weight < 0.0 {
                report.add_error(format!(
                    "Category '{}' has negative weight: {}",
                    category, weight
                ));
            }

            if *weight > 1.0 {
                report.add_error(format!(
                    "Category '{}' has weight > 1.0: {}",
                    category, weight
                ));
            }

            // Check if category is valid
            if !self.valid_categories.contains(&category.to_lowercase()) {
                report.add_warning(format!("Unknown category: '{}'", category));
            }
        }

        // Suggest missing important categories
        if !weights.contains_key("content") {
            report.add_suggestion("Consider adding 'content' category weight".to_string());
        }

        Ok(())
    }

    fn validate_metric_overrides(
        &self,
        overrides: &HashMap<String, MetricOverride>,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        for (metric_name, override_config) in overrides {
            // Check if metric exists
            if !self.valid_metrics.contains(metric_name) {
                report.add_error(format!("Unknown metric in override: '{}'", metric_name));
                continue;
            }

            // Validate weight
            if override_config.weight < 0.0 {
                report.add_error(format!(
                    "Metric '{}' has negative weight: {}",
                    metric_name, override_config.weight
                ));
            }

            if override_config.weight > 1.0 {
                report.add_warning(format!(
                    "Metric '{}' has very high weight: {}",
                    metric_name, override_config.weight
                ));
            }

            // Validate penalty multiplier
            if override_config.penalty_multiplier < 0.0 {
                report.add_error(format!(
                    "Metric '{}' has negative penalty multiplier: {}",
                    metric_name, override_config.penalty_multiplier
                ));
            }

            // Validate thresholds if present
            if let Some(thresholds) = &override_config.thresholds {
                self.validate_threshold_set(metric_name, thresholds, report)?;
            }

            // Validate bonus conditions
            for (i, bonus) in override_config.bonus_conditions.iter().enumerate() {
                if bonus.bonus_points < 0.0 {
                    report.add_error(format!(
                        "Metric '{}' bonus condition {} has negative points: {}",
                        metric_name, i, bonus.bonus_points
                    ));
                }

                if bonus.bonus_points > 50.0 {
                    report.add_warning(format!(
                        "Metric '{}' bonus condition {} has very high points: {}",
                        metric_name, i, bonus.bonus_points
                    ));
                }
            }
        }

        Ok(())
    }

    fn validate_threshold_set(
        &self,
        metric_name: &str,
        thresholds: &ThresholdSet,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        // Check threshold ordering
        if thresholds.excellent < thresholds.good {
            report.add_error(format!(
                "Metric '{}': excellent threshold ({}) should be >= good threshold ({})",
                metric_name, thresholds.excellent, thresholds.good
            ));
        }

        if thresholds.good < thresholds.fair {
            report.add_error(format!(
                "Metric '{}': good threshold ({}) should be >= fair threshold ({})",
                metric_name, thresholds.good, thresholds.fair
            ));
        }

        if thresholds.fair < thresholds.poor {
            report.add_error(format!(
                "Metric '{}': fair threshold ({}) should be >= poor threshold ({})",
                metric_name, thresholds.fair, thresholds.poor
            ));
        }

        // Check for negative thresholds (might be valid for some metrics)
        if thresholds.poor < 0.0 {
            report.add_warning(format!(
                "Metric '{}' has negative poor threshold: {}",
                metric_name, thresholds.poor
            ));
        }

        Ok(())
    }

    fn validate_content_expectations(
        &self,
        expectations: &ContentExpectations,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        // Validate word count expectations
        if let Some(word_exp) = &expectations.word_count {
            if word_exp.minimum > word_exp.optimal_range.0 {
                report.add_error(format!(
                    "Word count minimum ({}) is greater than optimal range start ({})",
                    word_exp.minimum, word_exp.optimal_range.0
                ));
            }

            if word_exp.optimal_range.0 > word_exp.optimal_range.1 {
                report.add_error(format!(
                    "Word count optimal range is invalid: {} to {}",
                    word_exp.optimal_range.0, word_exp.optimal_range.1
                ));
            }

            if let Some(max) = word_exp.maximum_useful {
                if max < word_exp.optimal_range.1 {
                    report.add_warning(format!(
                        "Word count maximum useful ({}) is less than optimal range end ({})",
                        max, word_exp.optimal_range.1
                    ));
                }
            }
        }

        // Validate heading expectations
        if let Some(heading_exp) = &expectations.heading_structure {
            if heading_exp.maximum_heading_depth > 6 {
                report.add_warning("Maximum heading depth > 6 may not be meaningful".to_string());
            }

            if heading_exp.minimum_headings > 20 {
                report.add_warning(format!(
                    "Minimum headings requirement ({}) seems very high",
                    heading_exp.minimum_headings
                ));
            }

            if let Some((min, max)) = heading_exp.heading_length_limits {
                if min >= max {
                    report.add_error(format!(
                        "Heading length limits invalid: min ({}) >= max ({})",
                        min, max
                    ));
                }
            }
        }

        // Validate media expectations
        if let Some(media_exp) = &expectations.media_requirements {
            if media_exp.alt_text_coverage > 1.0 {
                report.add_error(format!(
                    "Alt text coverage cannot exceed 100%: {}",
                    media_exp.alt_text_coverage
                ));
            }

            if media_exp.alt_text_coverage < 0.0 {
                report.add_error(format!(
                    "Alt text coverage cannot be negative: {}",
                    media_exp.alt_text_coverage
                ));
            }

            if let Some((min, max)) = media_exp.image_to_text_ratio {
                if min > max {
                    report.add_error(format!(
                        "Image to text ratio invalid: min ({}) > max ({})",
                        min, max
                    ));
                }
            }
        }

        // Validate SEO expectations
        if let Some(seo_exp) = &expectations.seo_requirements {
            if let Some((min, max)) = seo_exp.title_length_range {
                if min >= max {
                    report.add_error(format!(
                        "Title length range invalid: min ({}) >= max ({})",
                        min, max
                    ));
                }
                if max > 200 {
                    report.add_warning(format!("Title length max ({}) is very long", max));
                }
            }

            if let Some((min, max)) = seo_exp.meta_description_length_range {
                if min >= max {
                    report.add_error(format!(
                        "Meta description length range invalid: min ({}) >= max ({})",
                        min, max
                    ));
                }
                if max > 300 {
                    report.add_warning(format!(
                        "Meta description max length ({}) is very long",
                        max
                    ));
                }
            }
        }

        Ok(())
    }

    fn validate_quality_bands(
        &self,
        bands: &QualityBandConfig,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        // Check band ordering
        if bands.excellent < bands.good {
            report.add_error(format!(
                "Excellent band ({}) should be >= good band ({})",
                bands.excellent, bands.good
            ));
        }

        if bands.good < bands.fair {
            report.add_error(format!(
                "Good band ({}) should be >= fair band ({})",
                bands.good, bands.fair
            ));
        }

        if bands.fair < bands.poor {
            report.add_error(format!(
                "Fair band ({}) should be >= poor band ({})",
                bands.fair, bands.poor
            ));
        }

        // Check reasonable ranges
        if bands.excellent > 100.0 {
            report.add_warning(format!("Excellent band ({}) is above 100", bands.excellent));
        }

        if bands.poor < 0.0 {
            report.add_warning(format!("Poor band ({}) is below 0", bands.poor));
        }

        Ok(())
    }

    fn validate_penalties(
        &self,
        penalties: &PenaltyConfig,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        self.validate_penalty_group("severe", &penalties.severe_penalties, report)?;
        self.validate_penalty_group("moderate", &penalties.moderate_penalties, report)?;
        self.validate_penalty_group("light", &penalties.light_penalties, report)?;

        Ok(())
    }

    fn validate_penalty_group(
        &self,
        _group_name: &str,
        penalties: &HashMap<String, GlobalPenalty>,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        for (penalty_name, penalty) in penalties {
            // Validate penalty trigger references valid metrics where applicable
            match &penalty.trigger_condition {
                PenaltyTrigger::MetricBelow { metric, .. }
                | PenaltyTrigger::MetricAbove { metric, .. }
                | PenaltyTrigger::MetricEquals { metric, .. }
                | PenaltyTrigger::MetricMissing { metric } => {
                    if !self.valid_metrics.contains(metric) {
                        report.add_error(format!(
                            "Penalty '{}' references unknown metric: '{}'",
                            penalty_name, metric
                        ));
                    }
                }
                _ => {} // Other triggers don't reference metrics
            }

            // Validate penalty magnitude
            match &penalty.penalty_type {
                PenaltyType::FixedPoints { points } => {
                    if *points < 0.0 {
                        report.add_error(format!(
                            "Penalty '{}' has negative points: {}",
                            penalty_name, points
                        ));
                    }
                    if *points > 100.0 {
                        report.add_warning(format!(
                            "Penalty '{}' has very high points: {}",
                            penalty_name, points
                        ));
                    }
                }
                PenaltyType::Multiplier { factor } => {
                    if *factor < 0.0 {
                        report.add_error(format!(
                            "Penalty '{}' has negative multiplier: {}",
                            penalty_name, factor
                        ));
                    }
                    if *factor > 1.0 {
                        report.add_warning(format!(
                            "Penalty '{}' multiplier > 1.0 increases score: {}",
                            penalty_name, factor
                        ));
                    }
                }
                PenaltyType::CategoryPenalty {
                    category,
                    multiplier,
                } => {
                    if !self.valid_categories.contains(&category.to_lowercase()) {
                        report.add_warning(format!(
                            "Penalty '{}' references unknown category: '{}'",
                            penalty_name, category
                        ));
                    }
                    if *multiplier < 0.0 {
                        report.add_error(format!(
                            "Penalty '{}' has negative category multiplier: {}",
                            penalty_name, multiplier
                        ));
                    }
                }
            }
        }

        Ok(())
    }

    fn validate_bonuses(
        &self,
        bonuses: &BonusConfig,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        self.validate_bonus_group("excellence", &bonuses.excellence_bonuses, report)?;
        self.validate_bonus_group("achievement", &bonuses.achievement_bonuses, report)?;
        self.validate_bonus_group("synergy", &bonuses.synergy_bonuses, report)?;

        Ok(())
    }

    fn validate_bonus_group(
        &self,
        _group_name: &str,
        bonuses: &HashMap<String, GlobalBonus>,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        for (bonus_name, bonus) in bonuses {
            // Validate bonus points
            if bonus.bonus_points < 0.0 {
                report.add_error(format!(
                    "Bonus '{}' has negative points: {}",
                    bonus_name, bonus.bonus_points
                ));
            }

            if bonus.bonus_points > 50.0 {
                report.add_warning(format!(
                    "Bonus '{}' has very high points: {}",
                    bonus_name, bonus.bonus_points
                ));
            }

            // Validate bonus trigger references
            match &bonus.trigger_condition {
                BonusTrigger::MetricExcellence { metric, .. } => {
                    if !self.valid_metrics.contains(metric) {
                        report.add_error(format!(
                            "Bonus '{}' references unknown metric: '{}'",
                            bonus_name, metric
                        ));
                    }
                }
                BonusTrigger::MultipleMetricsGood { metrics, .. } => {
                    for metric in metrics {
                        if !self.valid_metrics.contains(metric) {
                            report.add_error(format!(
                                "Bonus '{}' references unknown metric: '{}'",
                                bonus_name, metric
                            ));
                        }
                    }
                }
                BonusTrigger::CategoryExcellence { category, .. } => {
                    if !self.valid_categories.contains(&category.to_lowercase()) {
                        report.add_warning(format!(
                            "Bonus '{}' references unknown category: '{}'",
                            bonus_name, category
                        ));
                    }
                }
                _ => {} // Other triggers are generic
            }
        }

        Ok(())
    }

    fn validate_consistency(
        &self,
        profile: &EnhancedScoringProfile,
        report: &mut ValidationReport,
    ) -> Result<(), ValidationError> {
        // Check that categories with high weights have corresponding metric overrides
        for (category, weight) in &profile.category_weights {
            if *weight > 0.2 {
                let category_metrics = self.get_metrics_for_category(category);
                let has_overrides = category_metrics
                    .iter()
                    .any(|metric| profile.metric_overrides.contains_key(metric));

                if !has_overrides {
                    report.add_suggestion(format!(
                        "Category '{}' has high weight ({:.1}%) but no metric overrides",
                        category,
                        weight * 100.0
                    ));
                }
            }
        }

        // Check for conflicting content expectations
        if let Some(word_exp) = &profile.content_expectations.word_count {
            if let Some(word_override) = profile.metric_overrides.get("word_count") {
                if let Some(thresholds) = &word_override.thresholds {
                    if thresholds.excellent as usize > word_exp.optimal_range.1 {
                        report.add_warning("Word count metric threshold excellent is higher than content expectation optimal range".to_string());
                    }
                }
            }
        }

        Ok(())
    }

    fn normalize_category_weights(
        &self,
        weights: &mut CategoryWeights,
    ) -> Result<(), ValidationError> {
        let weight_sum: f32 = weights.values().sum();
        if weight_sum > 0.0 && (weight_sum - 1.0).abs() > 0.01 {
            for (_, weight) in weights.iter_mut() {
                *weight /= weight_sum;
            }
        }
        Ok(())
    }

    fn apply_default_overrides(
        &self,
        _profile: &mut EnhancedScoringProfile,
    ) -> Result<(), ValidationError> {
        // For now, we don't auto-add overrides, but this could be extended
        // to add default overrides for metrics that don't have them
        Ok(())
    }

    fn normalize_quality_bands(
        &self,
        bands: &mut QualityBandConfig,
    ) -> Result<(), ValidationError> {
        // Ensure proper ordering by fixing any inversions
        if bands.excellent < bands.good {
            bands.excellent = bands.good + 5.0;
        }
        if bands.good < bands.fair {
            bands.good = bands.fair + 5.0;
        }
        if bands.fair < bands.poor {
            bands.fair = bands.poor + 5.0;
        }

        // Clamp to reasonable ranges
        bands.excellent = bands.excellent.clamp(80.0, 100.0);
        bands.good = bands.good.clamp(60.0, 95.0);
        bands.fair = bands.fair.clamp(40.0, 85.0);
        bands.poor = bands.poor.clamp(0.0, 75.0);

        Ok(())
    }

    fn is_valid_version(&self, version: &str) -> bool {
        // Basic semver validation
        let parts: Vec<&str> = version.split('.').collect();
        parts.len() >= 2 && parts.len() <= 3 && parts.iter().all(|part| part.parse::<u32>().is_ok())
    }

    fn get_metrics_for_category(&self, category: &str) -> Vec<String> {
        // This is a simplified implementation - in reality, we'd query the registry
        match category.to_lowercase().as_str() {
            "content" => vec![
                "word_count".to_string(),
                "readability_fk".to_string(),
                "main_text_ratio".to_string(),
            ],
            "media" => vec!["images_count".to_string(), "alt_text_coverage".to_string()],
            "seo" => vec!["title_length".to_string(), "meta_desc_len".to_string()],
            _ => Vec::new(),
        }
    }
}

impl Default for ProfileValidator {
    fn default() -> Self {
        Self::new()
    }
}

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

    #[test]
    fn test_profile_validator_creation() {
        let validator = ProfileValidator::new();
        assert!(!validator.valid_metrics.is_empty());
        assert!(!validator.valid_categories.is_empty());
    }

    #[test]
    fn test_validate_empty_profile() {
        let validator = ProfileValidator::new();
        let profile = EnhancedScoringProfile::default();

        let result = validator.validate_profile(&profile);
        assert!(result.is_ok());

        let report = result.unwrap();
        assert!(!report.is_valid); // Should have some validation issues
    }

    #[test]
    fn test_normalize_category_weights() {
        let validator = ProfileValidator::new();
        let mut weights = HashMap::new();
        weights.insert("content".to_string(), 0.4);
        weights.insert("seo".to_string(), 0.4);

        let result = validator.normalize_category_weights(&mut weights);
        assert!(result.is_ok());

        let sum: f32 = weights.values().sum();
        assert!((sum - 1.0).abs() < 0.01);
    }

    #[test]
    fn test_threshold_validation() {
        let validator = ProfileValidator::new();
        let mut report = ValidationReport::new();

        let valid_thresholds = ThresholdSet {
            excellent: 100.0,
            good: 80.0,
            fair: 60.0,
            poor: 30.0,
        };

        let result =
            validator.validate_threshold_set("test_metric", &valid_thresholds, &mut report);
        assert!(result.is_ok());
        assert!(report.is_valid);

        let invalid_thresholds = ThresholdSet {
            excellent: 50.0, // Less than good
            good: 80.0,
            fair: 60.0,
            poor: 30.0,
        };

        let mut report2 = ValidationReport::new();
        let result2 =
            validator.validate_threshold_set("test_metric", &invalid_thresholds, &mut report2);
        assert!(result2.is_ok());
        assert!(!report2.is_valid); // Should have errors
    }

    #[test]
    fn test_version_validation() {
        let validator = ProfileValidator::new();

        assert!(validator.is_valid_version("1.0.0"));
        assert!(validator.is_valid_version("2.1"));
        assert!(!validator.is_valid_version("1.0.0.0"));
        assert!(!validator.is_valid_version("invalid"));
        assert!(!validator.is_valid_version("1.a.0"));
    }
}