Skip to main content

gts_validator/
report.rs

1//! Validation report types.
2
3use serde::Serialize;
4
5use crate::error::{ScanError, ValidationError};
6
7/// Result of a validation run.
8///
9/// CI pipelines must check both `validation_errors` and `scan_errors`.
10/// A non-empty `scan_errors` means the validator did not fully run —
11/// treat this as a build failure regardless of `validation_errors`.
12#[derive(Debug, Clone, Serialize)]
13#[non_exhaustive]
14pub struct ValidationReport {
15    /// Number of files successfully scanned (read + parsed).
16    pub scanned_files: usize,
17    /// Number of files that could not be scanned (read/parse failures).
18    pub failed_files: usize,
19    /// Whether all scanned files passed validation AND no scan errors occurred.
20    pub ok: bool,
21    /// Individual GTS ID validation errors found in scanned files.
22    pub validation_errors: Vec<ValidationError>,
23    /// Scan-level errors: files that could not be read or parsed.
24    /// Non-empty means the validator did not fully cover the repository.
25    pub scan_errors: Vec<ScanError>,
26}
27
28impl ValidationReport {
29    /// Total number of files attempted (scanned + failed).
30    #[must_use]
31    pub fn files_attempted(&self) -> usize {
32        self.scanned_files + self.failed_files
33    }
34
35    /// Number of validation errors found.
36    #[must_use]
37    pub fn errors_count(&self) -> usize {
38        self.validation_errors.len()
39    }
40}