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
//! Normalized runner evidence types.
use serde::{Deserialize, Serialize};
use thiserror::Error;
/// One normalized runner invocation.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NormalizedTestRun {
/// Test cases in source order.
pub cases: Vec<TestCaseResult>,
/// Optional mapped coverage.
pub coverage: Option<CoverageArtifact>,
/// Raw artifact handles (paths/kinds), not file bodies.
pub raw_artifacts: Vec<ArtifactDescriptor>,
}
/// One test case after runner-specific parsing.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TestCaseResult {
/// Case name.
pub name: String,
/// Suite / package / file.
pub suite: String,
/// Outcome.
pub status: TestStatus,
/// Duration in milliseconds when the runner reported it.
pub duration_ms: Option<u64>,
/// Failure/skip message, if any.
pub message: Option<String>,
}
/// Normalized case status.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TestStatus {
/// Passed.
Pass,
/// Failed assertion.
Fail,
/// Skipped / ignored.
Skip,
/// Runner/infrastructure error.
Error,
}
/// Coverage mapped to source line ranges.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CoverageArtifact {
/// Per-file ranges.
pub files: Vec<FileCoverage>,
}
/// Coverage of one source file.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FileCoverage {
/// Repository-relative path.
pub path: String,
/// Covered inclusive line ranges.
pub covered: Vec<LineRange>,
/// Uncovered inclusive line ranges.
pub uncovered: Vec<LineRange>,
}
/// Inclusive 1-based line range.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct LineRange {
/// First line.
pub start: u32,
/// Last line, inclusive.
pub end: u32,
}
/// Handle for a raw runner artifact.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ArtifactDescriptor {
/// `junit`, `lcov`, or `go-json`.
pub kind: String,
/// Optional filesystem path.
pub path: Option<String>,
}
/// Why runner evidence could not be normalized.
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum RuntimeError {
/// XML/JSON/LCOV could not be parsed.
#[error("malformed {kind} evidence: {message}")]
Malformed {
/// Artifact kind.
kind: String,
/// Parser detail.
message: String,
},
/// Stream ended before a complete record.
#[error("truncated {kind} evidence")]
Truncated {
/// Artifact kind.
kind: String,
},
/// Executor id is not in the registry.
#[error("unknown executor `{0}`")]
UnknownExecutor(String),
/// Typed args contained a forbidden key or unsafe value.
#[error("invalid executor argument: {0}")]
InvalidArg(String),
/// Process exceeded its deadline.
#[error("executor deadline exceeded")]
DeadlineExceeded,
/// Combined stdout+stderr exceeded the byte cap.
#[error("executor output exceeded {max} bytes")]
OutputLimit {
/// Configured cap.
max: usize,
},
/// Caller cancelled the run.
#[error("executor cancelled")]
Cancelled,
/// OS could not start the registered program.
#[error("executor spawn failed: {0}")]
Spawn(String),
}
impl NormalizedTestRun {
/// Attach coverage to an already-normalized case list.
#[must_use]
pub fn with_coverage(mut self, coverage: CoverageArtifact) -> Self {
self.coverage = Some(coverage);
self
}
}
/// Parse a runner-reported seconds field into milliseconds.
pub(crate) fn seconds_to_ms(raw: &str) -> Option<u64> {
let raw = raw.trim();
if raw.is_empty() {
return None;
}
let (whole, frac) = raw.split_once('.').unwrap_or((raw, "0"));
let secs: u64 = whole.parse().ok()?;
let frac = frac.chars().take(3).collect::<String>();
let millis: u64 = format!("{frac:0<3}").parse().ok()?;
Some(secs.saturating_mul(1000).saturating_add(millis))
}