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
#![cfg_attr(coverage_nightly, coverage(off))]
//! Gaming Detector: Anti-Gaming Detection for Coverage and Quality Metrics
//!
//! Detects attempts to game coverage metrics through:
//! - `#[cfg(not(coverage))]` patterns
//! - `.codecov.yml` exclusion changes
//! - Test file deletions
//! - CUDA/AVX file hiding
//!
//! Based on: docs/specifications/improve-pmat-work.md
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::path::{Path, PathBuf};
/// Gaming violation detected in codebase
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GamingViolation {
/// File where violation was found
pub file: PathBuf,
/// Line number (0 if not applicable)
pub line: usize,
/// Type of gaming pattern detected
pub pattern: GamingPattern,
/// Severity of the violation
pub severity: Severity,
/// Human-readable explanation
pub explanation: String,
}
/// Types of gaming patterns we detect
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum GamingPattern {
/// `#[cfg(not(coverage))]` to exclude code from coverage
CfgNotCoverage,
/// `#[cfg(not(tarpaulin))]` to exclude from tarpaulin
CfgNotTarpaulin,
/// `#[cfg(not(llvm_cov))]` to exclude from llvm-cov
CfgNotLlvmCov,
/// New exclusion added to `.codecov.yml`
NewCodecovExclusion(String),
/// Test file deleted during work
TestFileDeletion,
/// Test module marked `#[ignore]` during work
TestModuleIgnored,
/// CUDA/AVX file removed from manifest
CriticalFileRemoved,
/// Coverage exclusion comment pattern
CoverageExclusionComment,
}
/// Severity of gaming violation
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum Severity {
/// Must be fixed before completion
Critical,
/// Should be fixed, but can be overridden
Warning,
/// Informational only
Info,
}
/// Results of gaming detection scan
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct GamingDetectionResult {
/// All violations found
pub violations: Vec<GamingViolation>,
/// Number of files scanned
pub files_scanned: usize,
/// Patterns that were checked
pub patterns_checked: Vec<String>,
}
impl GamingDetectionResult {
/// Check if any critical violations were found
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn has_critical_violations(&self) -> bool {
self.violations
.iter()
.any(|v| v.severity == Severity::Critical)
}
/// Get only critical violations
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn critical_violations(&self) -> Vec<&GamingViolation> {
self.violations
.iter()
.filter(|v| v.severity == Severity::Critical)
.collect()
}
/// Count violations by severity
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn count_by_severity(&self, severity: Severity) -> usize {
self.violations
.iter()
.filter(|v| v.severity == severity)
.count()
}
}
// --- Include files for implementation and tests ---
include!("gaming_detector_analysis.rs");
include!("gaming_detector_tests.rs");