@robhowley/pi-structured-return 1.10.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +33 -83
- package/extensions/structured-return/config/registry.ts +4 -30
- package/extensions/structured-return/index.ts +105 -76
- package/extensions/structured-return/native.ts +223 -0
- package/extensions/structured-return/parsers/ava-text.ts +2 -168
- package/extensions/structured-return/parsers/bandit-json.ts +2 -79
- package/extensions/structured-return/parsers/black-text.ts +2 -73
- package/extensions/structured-return/parsers/cargo-build.ts +2 -78
- package/extensions/structured-return/parsers/cargo-test.ts +2 -135
- package/extensions/structured-return/parsers/checkstyle-xml.ts +2 -182
- package/extensions/structured-return/parsers/clang-text.ts +2 -60
- package/extensions/structured-return/parsers/dbt-json.ts +2 -135
- package/extensions/structured-return/parsers/dotnet-build-text.ts +2 -49
- package/extensions/structured-return/parsers/eslint-json.ts +2 -38
- package/extensions/structured-return/parsers/go-test-json.ts +2 -138
- package/extensions/structured-return/parsers/hadolint-json.ts +2 -60
- package/extensions/structured-return/parsers/htmlhint-json.ts +2 -73
- package/extensions/structured-return/parsers/isort-text.ts +2 -63
- package/extensions/structured-return/parsers/javac-text.ts +2 -82
- package/extensions/structured-return/parsers/jsonlint-text.ts +2 -65
- package/extensions/structured-return/parsers/junit-xml.ts +2 -325
- package/extensions/structured-return/parsers/markdownlint-json.ts +2 -74
- package/extensions/structured-return/parsers/minitest-text.ts +2 -107
- package/extensions/structured-return/parsers/mocha-json.ts +2 -83
- package/extensions/structured-return/parsers/mypy-json.ts +2 -79
- package/extensions/structured-return/parsers/node-test-text.ts +2 -92
- package/extensions/structured-return/parsers/npm-audit-json.ts +2 -90
- package/extensions/structured-return/parsers/prettier-text.ts +2 -66
- package/extensions/structured-return/parsers/pylint-json.ts +2 -63
- package/extensions/structured-return/parsers/pyright-json.ts +2 -82
- package/extensions/structured-return/parsers/rspec-json.ts +2 -75
- package/extensions/structured-return/parsers/rubocop-json.ts +2 -75
- package/extensions/structured-return/parsers/ruff-json.ts +2 -36
- package/extensions/structured-return/parsers/shellcheck-json.ts +2 -60
- package/extensions/structured-return/parsers/stylelint-json.ts +2 -75
- package/extensions/structured-return/parsers/swiftc-text.ts +2 -52
- package/extensions/structured-return/parsers/tail-fallback.ts +2 -19
- package/extensions/structured-return/parsers/tidy-text.ts +2 -66
- package/extensions/structured-return/parsers/tsc-text.ts +2 -46
- package/extensions/structured-return/parsers/unittest-text.ts +2 -125
- package/extensions/structured-return/parsers/utils.ts +28 -0
- package/extensions/structured-return/parsers/vale-json.ts +2 -79
- package/extensions/structured-return/parsers/vitest-json.ts +2 -59
- package/extensions/structured-return/storage/log-store.ts +0 -15
- package/extensions/structured-return/types.ts +1 -14
- package/native/Cargo.lock +193 -0
- package/native/Cargo.toml +21 -0
- package/native/THIRD-PARTY-LICENSES.txt +3660 -0
- package/native/bin/darwin-arm64/build.json +7 -0
- package/native/bin/darwin-arm64/structured-return-native +0 -0
- package/native/bin/darwin-x64/build.json +7 -0
- package/native/bin/darwin-x64/structured-return-native +0 -0
- package/native/bin/linux-arm64-musl/build.json +7 -0
- package/native/bin/linux-arm64-musl/structured-return-native +0 -0
- package/native/bin/linux-x64-musl/build.json +7 -0
- package/native/bin/linux-x64-musl/structured-return-native +0 -0
- package/native/src/common.rs +118 -0
- package/native/src/main.rs +55 -0
- package/native/src/parsers/ava_text.rs +125 -0
- package/native/src/parsers/bandit_json.rs +120 -0
- package/native/src/parsers/black_text.rs +45 -0
- package/native/src/parsers/cargo_build.rs +96 -0
- package/native/src/parsers/cargo_test.rs +140 -0
- package/native/src/parsers/checkstyle_xml.rs +137 -0
- package/native/src/parsers/clang_text.rs +39 -0
- package/native/src/parsers/compiler_helpers.rs +74 -0
- package/native/src/parsers/dbt_json.rs +243 -0
- package/native/src/parsers/dotnet_build_text.rs +50 -0
- package/native/src/parsers/eslint_json.rs +58 -0
- package/native/src/parsers/go_test_json.rs +346 -0
- package/native/src/parsers/hadolint_json.rs +37 -0
- package/native/src/parsers/htmlhint_json.rs +71 -0
- package/native/src/parsers/isort_text.rs +22 -0
- package/native/src/parsers/javac_text.rs +49 -0
- package/native/src/parsers/json_support.rs +287 -0
- package/native/src/parsers/jsonlint_text.rs +50 -0
- package/native/src/parsers/junit_xml.rs +430 -0
- package/native/src/parsers/markdownlint_json.rs +68 -0
- package/native/src/parsers/minitest_text.rs +91 -0
- package/native/src/parsers/mocha_json.rs +75 -0
- package/native/src/parsers/mod.rs +119 -0
- package/native/src/parsers/mypy_json.rs +93 -0
- package/native/src/parsers/node_test_text.rs +106 -0
- package/native/src/parsers/npm_audit_json.rs +119 -0
- package/native/src/parsers/prettier_text.rs +34 -0
- package/native/src/parsers/pylint_json.rs +44 -0
- package/native/src/parsers/pyright_json.rs +88 -0
- package/native/src/parsers/rspec_json.rs +84 -0
- package/native/src/parsers/rubocop_json.rs +46 -0
- package/native/src/parsers/ruff_json.rs +30 -0
- package/native/src/parsers/shellcheck_json.rs +40 -0
- package/native/src/parsers/stylelint_json.rs +46 -0
- package/native/src/parsers/swiftc_text.rs +38 -0
- package/native/src/parsers/tail_fallback.rs +51 -0
- package/native/src/parsers/test_helpers.rs +172 -0
- package/native/src/parsers/tidy_text.rs +77 -0
- package/native/src/parsers/tsc_text.rs +28 -0
- package/native/src/parsers/unittest_text.rs +125 -0
- package/native/src/parsers/vale_json.rs +66 -0
- package/native/src/parsers/vitest_json.rs +71 -0
- package/native/src/parsers/xml_support.rs +241 -0
- package/native/src/runner.rs +252 -0
- package/package.json +22 -7
- package/scripts/build-native.mjs +73 -0
- package/scripts/native-artifacts.mjs +69 -0
- package/skills/structured-return/SKILL.md +103 -249
- package/extensions/structured-return/config/project-config.ts +0 -10
- package/extensions/structured-return/examples/.pi/machine-readable.json +0 -18
- package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +0 -25
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
use super::json_support::{num_string, num_value, number_text, optional_string};
|
|
2
|
+
use super::xml_support::{parse_xml, Node};
|
|
3
|
+
use crate::common::{basename, read_file, relative, result, Context};
|
|
4
|
+
use regex::Regex;
|
|
5
|
+
use serde_json::{Map, Value};
|
|
6
|
+
use std::sync::LazyLock;
|
|
7
|
+
|
|
8
|
+
#[derive(Clone, Default)]
|
|
9
|
+
struct Location {
|
|
10
|
+
file: Option<String>,
|
|
11
|
+
line: Option<f64>,
|
|
12
|
+
message: Option<String>,
|
|
13
|
+
}
|
|
14
|
+
static LOCATIONS: LazyLock<Vec<Regex>> = LazyLock::new(|| {
|
|
15
|
+
[
|
|
16
|
+
r"^at\s+\S+\s+\(([^)]+\.(?:[jt]sx?|mjs|cjs)):([0-9]+):[0-9]+\)",
|
|
17
|
+
r"^at\s+(.+?\.(?:[jt]sx?|mjs|cjs)):([0-9]+):[0-9]+$",
|
|
18
|
+
r"^at\s+(.+?\.php):([0-9]+)$",
|
|
19
|
+
r"^([^:\s]+\.[A-Za-z0-9_]+):([0-9]+):\s*(.*)",
|
|
20
|
+
r"\bin ([^\s]+\.(?:cs|fs|vb)):line ([0-9]+)",
|
|
21
|
+
r"^at (?:[A-Za-z0-9_.$]+/)?([A-Za-z0-9_.$]+)\.[A-Za-z0-9_]+\(([A-Za-z0-9_]+\.(?:java|kt|scala|groovy)):([0-9]+)\)$",
|
|
22
|
+
r"^(.+?\.php):([0-9]+)$",
|
|
23
|
+
r"(?:^#[0-9]+\s+)?(.+?\.php)\(([0-9]+)\)(?::|$)",
|
|
24
|
+
].iter().map(|p| Regex::new(p).unwrap()).collect()
|
|
25
|
+
});
|
|
26
|
+
static PHP_SKIP: LazyLock<Vec<Regex>> = LazyLock::new(|| {
|
|
27
|
+
[
|
|
28
|
+
r"^[A-Za-z0-9_]+::[A-Za-z0-9_]+",
|
|
29
|
+
r"^at\s+.+?\.php:[0-9]+$",
|
|
30
|
+
r"^.+?\.php:[0-9]+$",
|
|
31
|
+
]
|
|
32
|
+
.iter()
|
|
33
|
+
.map(|p| Regex::new(p).unwrap())
|
|
34
|
+
.collect()
|
|
35
|
+
});
|
|
36
|
+
static CLASS_FILE: LazyLock<Regex> = LazyLock::new(|| {
|
|
37
|
+
Regex::new(r"\.(?:[jt]sx?|mjs|cjs|py|rb|go|php|cs|fs|vb|java|kt|scala|groovy)$").unwrap()
|
|
38
|
+
});
|
|
39
|
+
static CLASS_NAME: LazyLock<Regex> =
|
|
40
|
+
LazyLock::new(|| Regex::new(r"^[A-Za-z0-9_$]+(?:\.[A-Za-z0-9_$]+)*$").unwrap());
|
|
41
|
+
static PANIC_SUFFIX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\s*\[.*\]$").unwrap());
|
|
42
|
+
static PANIC_FRAME: LazyLock<Regex> =
|
|
43
|
+
LazyLock::new(|| Regex::new(r"^([^:]+\.go):([0-9]+)").unwrap());
|
|
44
|
+
static ASSERTION_DIFF: LazyLock<Regex> =
|
|
45
|
+
LazyLock::new(|| Regex::new(r"^(Expected|Received|Actual)\s*:").unwrap());
|
|
46
|
+
static HEX_ENTITY: LazyLock<Regex> =
|
|
47
|
+
LazyLock::new(|| Regex::new(r"&#[xX]([0-9a-fA-F]+);").unwrap());
|
|
48
|
+
static DEC_ENTITY: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"&#([0-9]+);").unwrap());
|
|
49
|
+
|
|
50
|
+
fn location(file: String, line: &str, message: Option<String>) -> Location {
|
|
51
|
+
Location {
|
|
52
|
+
file: Some(file),
|
|
53
|
+
line: Some(number_text(line)),
|
|
54
|
+
message,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
fn body_location(text: &str, classname: Option<&str>) -> Option<Location> {
|
|
58
|
+
let lines: Vec<_> = text
|
|
59
|
+
.split('\n')
|
|
60
|
+
.map(str::trim)
|
|
61
|
+
.filter(|s| !s.is_empty())
|
|
62
|
+
.collect();
|
|
63
|
+
for regex in &LOCATIONS[0..2] {
|
|
64
|
+
for line in &lines {
|
|
65
|
+
if let Some(m) = regex.captures(line) {
|
|
66
|
+
if !m[1].contains("node_modules") {
|
|
67
|
+
return Some(location(basename(&m[1]), &m[2], None));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for line in &lines {
|
|
73
|
+
if let Some(m) = LOCATIONS[2].captures(line) {
|
|
74
|
+
return Some(location(m[1].into(), &m[2], None));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for line in &lines {
|
|
78
|
+
if let Some(m) = LOCATIONS[3].captures(line) {
|
|
79
|
+
return Some(location(
|
|
80
|
+
m[1].into(),
|
|
81
|
+
&m[2],
|
|
82
|
+
if m[3].is_empty() {
|
|
83
|
+
None
|
|
84
|
+
} else {
|
|
85
|
+
Some(m[3].into())
|
|
86
|
+
},
|
|
87
|
+
));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for line in &lines {
|
|
91
|
+
if let Some(m) = LOCATIONS[4].captures(line) {
|
|
92
|
+
return Some(location(basename(&m[1]), &m[2], None));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
let prefixes = [
|
|
96
|
+
"java.",
|
|
97
|
+
"javax.",
|
|
98
|
+
"sun.",
|
|
99
|
+
"com.sun.",
|
|
100
|
+
"org.junit.",
|
|
101
|
+
"org.opentest4j.",
|
|
102
|
+
"junit.",
|
|
103
|
+
];
|
|
104
|
+
let simple_class = classname.and_then(|s| s.rsplit('.').next());
|
|
105
|
+
let mut first = None;
|
|
106
|
+
for line in &lines {
|
|
107
|
+
if let Some(m) = LOCATIONS[5].captures(line) {
|
|
108
|
+
// Prefer the testcase's qualified class; preserve short-name reports.
|
|
109
|
+
if classname.is_some_and(|name| !name.is_empty() && name == &m[1])
|
|
110
|
+
|| simple_class.is_some_and(|name| !name.is_empty() && name == &m[1])
|
|
111
|
+
{
|
|
112
|
+
return Some(location(m[2].into(), &m[3], None));
|
|
113
|
+
}
|
|
114
|
+
if first.is_none() && !prefixes.iter().any(|p| m[1].starts_with(p)) {
|
|
115
|
+
first = Some(location(m[2].into(), &m[3], None));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if first.is_some() {
|
|
120
|
+
return first;
|
|
121
|
+
}
|
|
122
|
+
let php_message = || {
|
|
123
|
+
lines
|
|
124
|
+
.iter()
|
|
125
|
+
.find(|line| !PHP_SKIP.iter().any(|r| r.is_match(line)))
|
|
126
|
+
.map(|s| (*s).to_owned())
|
|
127
|
+
};
|
|
128
|
+
for regex in &LOCATIONS[6..8] {
|
|
129
|
+
for line in &lines {
|
|
130
|
+
if let Some(m) = regex.captures(line) {
|
|
131
|
+
return Some(location(m[1].into(), &m[2], php_message()));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
None
|
|
136
|
+
}
|
|
137
|
+
fn panic_info(text: &str, test_name: &str) -> Option<Location> {
|
|
138
|
+
let lines: Vec<_> = text.split('\n').collect();
|
|
139
|
+
let panic = lines
|
|
140
|
+
.iter()
|
|
141
|
+
.find(|s| s.trim().starts_with("panic:"))?
|
|
142
|
+
.trim();
|
|
143
|
+
let message = PANIC_SUFFIX
|
|
144
|
+
.replace(panic.strip_prefix("panic:").unwrap().trim_start(), "")
|
|
145
|
+
.trim()
|
|
146
|
+
.to_owned();
|
|
147
|
+
let marker = format!(".{test_name}(");
|
|
148
|
+
for pair in lines.windows(2) {
|
|
149
|
+
if pair[0].contains(&marker) {
|
|
150
|
+
if let Some(m) = PANIC_FRAME.captures(pair[1].trim()) {
|
|
151
|
+
return Some(location(
|
|
152
|
+
m[1].rsplit('/').next().unwrap_or("").into(),
|
|
153
|
+
&m[2],
|
|
154
|
+
Some(message),
|
|
155
|
+
));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
Some(Location {
|
|
160
|
+
message: Some(message),
|
|
161
|
+
..Location::default()
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
fn classname_file(classname: Option<&str>) -> Option<String> {
|
|
165
|
+
let classname = classname.filter(|s| !s.is_empty())?;
|
|
166
|
+
let normalized = classname.replace('\\', "/");
|
|
167
|
+
if CLASS_FILE.is_match(&normalized) {
|
|
168
|
+
return Some(normalized);
|
|
169
|
+
}
|
|
170
|
+
if normalized.contains('/') {
|
|
171
|
+
return None;
|
|
172
|
+
}
|
|
173
|
+
CLASS_NAME
|
|
174
|
+
.is_match(classname)
|
|
175
|
+
.then(|| format!("{}.java", classname.replace('.', "/")))
|
|
176
|
+
}
|
|
177
|
+
fn resolve_file(tc: &Node, suite: &Node, cwd: &str) -> Option<String> {
|
|
178
|
+
let raw = tc
|
|
179
|
+
.attr("file")
|
|
180
|
+
.or_else(|| suite.attr("file"))
|
|
181
|
+
.and_then(|s| s.split("::").next());
|
|
182
|
+
if let Some(raw) = raw.filter(|s| !s.is_empty()) {
|
|
183
|
+
Some(relative(cwd, raw))
|
|
184
|
+
} else {
|
|
185
|
+
classname_file(tc.attr("classname"))
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
fn is_php(file: Option<&str>) -> bool {
|
|
189
|
+
file.is_some_and(|s| {
|
|
190
|
+
s.split("::")
|
|
191
|
+
.next()
|
|
192
|
+
.unwrap_or("")
|
|
193
|
+
.replace('\\', "/")
|
|
194
|
+
.ends_with(".php")
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
fn decode_entities(s: &str) -> String {
|
|
198
|
+
let decode = |digits: &str, radix| {
|
|
199
|
+
let n = u64::from_str_radix(digits, radix).unwrap_or(0) as u16;
|
|
200
|
+
char::from_u32(n as u32).unwrap_or('\u{fffd}').to_string()
|
|
201
|
+
};
|
|
202
|
+
let hex = HEX_ENTITY.replace_all(s, |c: ®ex::Captures<'_>| decode(&c[1], 16));
|
|
203
|
+
DEC_ENTITY
|
|
204
|
+
.replace_all(&hex, |c: ®ex::Captures<'_>| decode(&c[1], 10))
|
|
205
|
+
.into_owned()
|
|
206
|
+
}
|
|
207
|
+
fn process_suite(suite: &Node, ctx: &Context, failures: &mut Vec<Value>) -> Result<(), String> {
|
|
208
|
+
for tc in suite.children_named("testcase") {
|
|
209
|
+
let Some(problem) = tc.child("failure").or_else(|| tc.child("error")) else {
|
|
210
|
+
continue;
|
|
211
|
+
};
|
|
212
|
+
// Element presence marks failure independently of its textual content.
|
|
213
|
+
let empty_problem = problem.body().is_empty();
|
|
214
|
+
let body = (!empty_problem).then(|| problem.body());
|
|
215
|
+
let body_loc = body.and_then(|s| body_location(s, tc.attr("classname")));
|
|
216
|
+
let panic = if body_loc.is_none() {
|
|
217
|
+
suite
|
|
218
|
+
.child("system-out")
|
|
219
|
+
.filter(|n| !n.body().is_empty())
|
|
220
|
+
.and_then(|n| {
|
|
221
|
+
tc.attr("name")
|
|
222
|
+
.filter(|s| !s.is_empty())
|
|
223
|
+
.and_then(|name| panic_info(n.body(), name))
|
|
224
|
+
})
|
|
225
|
+
} else {
|
|
226
|
+
None
|
|
227
|
+
};
|
|
228
|
+
let file = if tc
|
|
229
|
+
.attr("file")
|
|
230
|
+
.or_else(|| suite.attr("file"))
|
|
231
|
+
.is_some_and(|s| !s.is_empty())
|
|
232
|
+
{
|
|
233
|
+
resolve_file(tc, suite, &ctx.cwd)
|
|
234
|
+
} else {
|
|
235
|
+
body_loc
|
|
236
|
+
.as_ref()
|
|
237
|
+
.and_then(|l| l.file.clone())
|
|
238
|
+
.or_else(|| panic.as_ref().and_then(|l| l.file.clone()))
|
|
239
|
+
.or_else(|| resolve_file(tc, suite, &ctx.cwd))
|
|
240
|
+
};
|
|
241
|
+
let tc_line = tc.attr("line").map(number_text);
|
|
242
|
+
let body_line = body_loc.as_ref().and_then(|l| l.line);
|
|
243
|
+
let panic_line = panic.as_ref().and_then(|l| l.line);
|
|
244
|
+
let prefer_body = is_php(file.as_deref())
|
|
245
|
+
|| is_php(tc.attr("file"))
|
|
246
|
+
|| is_php(suite.attr("file"))
|
|
247
|
+
|| is_php(body_loc.as_ref().and_then(|l| l.file.as_deref()));
|
|
248
|
+
let line = if prefer_body {
|
|
249
|
+
body_line.or(panic_line).or(tc_line)
|
|
250
|
+
} else {
|
|
251
|
+
tc_line.or(body_line).or(panic_line)
|
|
252
|
+
};
|
|
253
|
+
let mut id_parts = Vec::new();
|
|
254
|
+
if let Some(file) = file.as_ref().filter(|s| !s.is_empty()) {
|
|
255
|
+
id_parts.push(file.clone());
|
|
256
|
+
}
|
|
257
|
+
if let Some(line) = line.filter(|n| *n != 0.0 && !n.is_nan()) {
|
|
258
|
+
id_parts.push(num_string(line));
|
|
259
|
+
}
|
|
260
|
+
if let Some(name) = tc.attr("name").filter(|s| !s.is_empty()) {
|
|
261
|
+
id_parts.push(name.to_owned());
|
|
262
|
+
}
|
|
263
|
+
let id = if id_parts.is_empty() {
|
|
264
|
+
failures.len().to_string()
|
|
265
|
+
} else {
|
|
266
|
+
id_parts.join(":")
|
|
267
|
+
};
|
|
268
|
+
let problem_message = problem.attr("message");
|
|
269
|
+
let raw = if problem_message.is_some_and(|s| !s.is_empty() && s.to_lowercase() != "failed")
|
|
270
|
+
{
|
|
271
|
+
problem_message.map(str::to_owned)
|
|
272
|
+
} else {
|
|
273
|
+
body_loc
|
|
274
|
+
.as_ref()
|
|
275
|
+
.and_then(|l| l.message.clone())
|
|
276
|
+
.or_else(|| panic.as_ref().and_then(|l| l.message.clone()))
|
|
277
|
+
.or_else(|| body.map(|s| s.trim().split('\n').next().unwrap_or("").to_owned()))
|
|
278
|
+
.or_else(|| problem_message.map(str::to_owned))
|
|
279
|
+
};
|
|
280
|
+
let raw = raw.filter(|s| !s.is_empty()).or_else(|| {
|
|
281
|
+
empty_problem.then(|| {
|
|
282
|
+
if problem.name == "error" {
|
|
283
|
+
"test error".into()
|
|
284
|
+
} else {
|
|
285
|
+
"test failed".into()
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
});
|
|
289
|
+
let message = raw.filter(|s| !s.is_empty()).map(|raw| {
|
|
290
|
+
let raw = tc
|
|
291
|
+
.attr("name")
|
|
292
|
+
.filter(|name| !name.is_empty())
|
|
293
|
+
.and_then(|name| raw.strip_prefix(name))
|
|
294
|
+
.map(|s| s.trim_start().to_owned())
|
|
295
|
+
.unwrap_or(raw);
|
|
296
|
+
let decoded = decode_entities(&raw);
|
|
297
|
+
if let Some(body) = body.filter(|_| {
|
|
298
|
+
!decoded.contains("Expected")
|
|
299
|
+
&& !decoded.contains("Received")
|
|
300
|
+
&& !decoded.contains("Actual")
|
|
301
|
+
}) {
|
|
302
|
+
let diff: Vec<_> = body
|
|
303
|
+
.split('\n')
|
|
304
|
+
.map(str::trim)
|
|
305
|
+
.filter(|l| ASSERTION_DIFF.is_match(l))
|
|
306
|
+
.collect();
|
|
307
|
+
if !diff.is_empty() {
|
|
308
|
+
return format!("{decoded}\n{}", diff.join("\n"));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
decoded
|
|
312
|
+
});
|
|
313
|
+
let mut out = Map::new();
|
|
314
|
+
out.insert("id".into(), Value::String(id));
|
|
315
|
+
optional_string(&mut out, "file", file);
|
|
316
|
+
if let Some(line) = line.filter(|n| !n.is_nan()) {
|
|
317
|
+
out.insert("line".into(), num_value(line));
|
|
318
|
+
}
|
|
319
|
+
optional_string(&mut out, "message", message);
|
|
320
|
+
optional_string(&mut out, "rule", problem.attr("type").map(str::to_owned));
|
|
321
|
+
failures.push(Value::Object(out));
|
|
322
|
+
}
|
|
323
|
+
for child in suite.children_named("testsuite") {
|
|
324
|
+
process_suite(child, ctx, failures)?;
|
|
325
|
+
}
|
|
326
|
+
Ok(())
|
|
327
|
+
}
|
|
328
|
+
fn count_attr(node: &Node, name: &str) -> Option<f64> {
|
|
329
|
+
node.attr(name)
|
|
330
|
+
.map(number_text)
|
|
331
|
+
.filter(|n| n.is_finite() && *n >= 0.0 && n.fract() == 0.0)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
fn suite_counts(suite: &Node) -> [f64; 4] {
|
|
335
|
+
let mut counts = [
|
|
336
|
+
suite.direct_cases.tests as f64,
|
|
337
|
+
suite.direct_cases.failures as f64,
|
|
338
|
+
suite.direct_cases.errors as f64,
|
|
339
|
+
suite.direct_cases.skipped as f64,
|
|
340
|
+
];
|
|
341
|
+
for child in suite.children_named("testsuite") {
|
|
342
|
+
let nested = suite_counts(child);
|
|
343
|
+
for (total, value) in counts.iter_mut().zip(nested) {
|
|
344
|
+
*total += value;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// A suite's declared totals already include its nested suites.
|
|
348
|
+
for (index, name) in ["tests", "failures", "errors", "skipped"]
|
|
349
|
+
.iter()
|
|
350
|
+
.enumerate()
|
|
351
|
+
{
|
|
352
|
+
if let Some(value) = count_attr(suite, name) {
|
|
353
|
+
counts[index] = value;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
counts
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
pub fn parse(ctx: &Context) -> Result<Value, String> {
|
|
360
|
+
let sources: Vec<&str> = if ctx.artifact_paths.is_empty() {
|
|
361
|
+
vec![&ctx.stdout_path]
|
|
362
|
+
} else {
|
|
363
|
+
ctx.artifact_paths.iter().map(String::as_str).collect()
|
|
364
|
+
};
|
|
365
|
+
let mut tests = 0.0;
|
|
366
|
+
let mut failed = 0.0;
|
|
367
|
+
let mut skipped = 0.0;
|
|
368
|
+
let mut failures = Vec::new();
|
|
369
|
+
for source in sources {
|
|
370
|
+
let xml = read_file(source)?;
|
|
371
|
+
if xml.trim().is_empty() {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
let doc = parse_xml(&xml)?;
|
|
375
|
+
let suites: Vec<&Node> = match doc.child("testsuites") {
|
|
376
|
+
Some(root) if root.children_named("testsuite").next().is_some() => {
|
|
377
|
+
root.children_named("testsuite").collect()
|
|
378
|
+
}
|
|
379
|
+
_ => doc.children_named("testsuite").collect(),
|
|
380
|
+
};
|
|
381
|
+
let mut counts = [0.0; 4];
|
|
382
|
+
for suite in &suites {
|
|
383
|
+
let local = suite_counts(suite);
|
|
384
|
+
for (total, value) in counts.iter_mut().zip(local) {
|
|
385
|
+
*total += value;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if let Some(container) = doc.child("testsuites") {
|
|
389
|
+
// Some reporters put totals only on the container. Prefer a suite's
|
|
390
|
+
// own declared totals when present, and otherwise use the container.
|
|
391
|
+
for (index, name) in ["tests", "failures", "errors", "skipped"]
|
|
392
|
+
.iter()
|
|
393
|
+
.enumerate()
|
|
394
|
+
{
|
|
395
|
+
if !suites.iter().any(|suite| count_attr(suite, name).is_some()) {
|
|
396
|
+
if let Some(value) = count_attr(container, name) {
|
|
397
|
+
counts[index] = value;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
tests += counts[0];
|
|
403
|
+
failed += counts[1] + counts[2];
|
|
404
|
+
skipped += counts[3];
|
|
405
|
+
for suite in suites {
|
|
406
|
+
process_suite(suite, ctx, &mut failures)?;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
let summary = if failed > 0.0 {
|
|
410
|
+
format!(
|
|
411
|
+
"{} failed, {} passed",
|
|
412
|
+
num_string(failed),
|
|
413
|
+
num_string(tests - failed - skipped)
|
|
414
|
+
)
|
|
415
|
+
} else {
|
|
416
|
+
format!("{} passed", num_string(tests - failed - skipped))
|
|
417
|
+
};
|
|
418
|
+
let summary = if skipped > 0.0 {
|
|
419
|
+
format!("{summary}, {} skipped", num_string(skipped))
|
|
420
|
+
} else {
|
|
421
|
+
summary
|
|
422
|
+
};
|
|
423
|
+
Ok(result(
|
|
424
|
+
"junit",
|
|
425
|
+
if failed > 0.0 { "fail" } else { "pass" },
|
|
426
|
+
summary,
|
|
427
|
+
failures,
|
|
428
|
+
ctx,
|
|
429
|
+
))
|
|
430
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
use super::json_support::{
|
|
2
|
+
array, copy_field, js_string, parse_error, relative_input, required_array, required_string,
|
|
3
|
+
};
|
|
4
|
+
use crate::common::{read_file, result, trim, truthy, Context};
|
|
5
|
+
use serde_json::{json, Map, Value};
|
|
6
|
+
|
|
7
|
+
pub fn parse(ctx: &Context) -> Result<Value, String> {
|
|
8
|
+
let source = read_file(&ctx.stdout_path)?;
|
|
9
|
+
if trim(&source).is_empty() {
|
|
10
|
+
return Ok(result(
|
|
11
|
+
"markdownlint",
|
|
12
|
+
"pass",
|
|
13
|
+
"no lint errors",
|
|
14
|
+
Vec::new(),
|
|
15
|
+
ctx,
|
|
16
|
+
));
|
|
17
|
+
}
|
|
18
|
+
let report: Value = match super::json_support::parse_json(trim(&source)) {
|
|
19
|
+
Ok(v) => v,
|
|
20
|
+
Err(_) => return Ok(parse_error("markdownlint", ctx)),
|
|
21
|
+
};
|
|
22
|
+
let mut failures = Vec::new();
|
|
23
|
+
for item in array(&report) {
|
|
24
|
+
let file = relative_input(&ctx.cwd, required_string(item.get("fileName"), "fileName")?);
|
|
25
|
+
let rule = required_array(item.get("ruleNames"), "ruleNames")?.first();
|
|
26
|
+
let message = if item.get("errorDetail").is_some_and(truthy) {
|
|
27
|
+
Some(json!(format!(
|
|
28
|
+
"{}: {}",
|
|
29
|
+
js_string(item.get("ruleDescription")),
|
|
30
|
+
js_string(item.get("errorDetail"))
|
|
31
|
+
)))
|
|
32
|
+
} else {
|
|
33
|
+
item.get("ruleDescription").cloned()
|
|
34
|
+
};
|
|
35
|
+
let mut out = Map::new();
|
|
36
|
+
out.insert(
|
|
37
|
+
"id".into(),
|
|
38
|
+
json!(format!(
|
|
39
|
+
"{}:{}:{}",
|
|
40
|
+
file,
|
|
41
|
+
js_string(item.get("lineNumber")),
|
|
42
|
+
js_string(rule)
|
|
43
|
+
)),
|
|
44
|
+
);
|
|
45
|
+
out.insert("file".into(), json!(file));
|
|
46
|
+
copy_field(&mut out, "line", item.get("lineNumber"));
|
|
47
|
+
copy_field(&mut out, "message", message.as_ref());
|
|
48
|
+
copy_field(&mut out, "rule", rule);
|
|
49
|
+
failures.push(Value::Object(out));
|
|
50
|
+
}
|
|
51
|
+
let failed = !failures.is_empty();
|
|
52
|
+
let summary = if failed {
|
|
53
|
+
format!(
|
|
54
|
+
"{} lint error{}",
|
|
55
|
+
failures.len(),
|
|
56
|
+
if failures.len() == 1 { "" } else { "s" }
|
|
57
|
+
)
|
|
58
|
+
} else {
|
|
59
|
+
"no lint errors".into()
|
|
60
|
+
};
|
|
61
|
+
Ok(result(
|
|
62
|
+
"markdownlint",
|
|
63
|
+
if failed { "fail" } else { "pass" },
|
|
64
|
+
summary,
|
|
65
|
+
failures,
|
|
66
|
+
ctx,
|
|
67
|
+
))
|
|
68
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
use super::test_helpers::without_failures;
|
|
2
|
+
use crate::common::{read_file, relative, result, Context};
|
|
3
|
+
use regex::Regex;
|
|
4
|
+
use serde_json::{json, Map, Value};
|
|
5
|
+
|
|
6
|
+
pub fn parse(ctx: &Context) -> Result<Value, String> {
|
|
7
|
+
let output = read_file(&ctx.stdout_path)?;
|
|
8
|
+
let summary_re = Regex::new(r"([0-9]+) runs?, [0-9]+ assertions?, ([0-9]+) failures?, ([0-9]+) errors?, ([0-9]+) skips?").unwrap();
|
|
9
|
+
let Some(summary) = summary_re.captures(&output) else {
|
|
10
|
+
return Ok(without_failures(
|
|
11
|
+
"minitest",
|
|
12
|
+
"error",
|
|
13
|
+
"no minitest output found",
|
|
14
|
+
ctx,
|
|
15
|
+
));
|
|
16
|
+
};
|
|
17
|
+
let count = |index: usize| summary[index].parse::<i64>().unwrap_or(0);
|
|
18
|
+
let failed = count(2) + count(3);
|
|
19
|
+
let passed = count(1) - failed - count(4);
|
|
20
|
+
let header_re = Regex::new(r"^\s+[0-9]+\) (Failure|Error):$").unwrap();
|
|
21
|
+
let failure_re = Regex::new(r"^(.+?)\s+\[(.+):([0-9]+)\]:$").unwrap();
|
|
22
|
+
let error_re = Regex::new(r"^(.+):$").unwrap();
|
|
23
|
+
let backtrace_re = Regex::new(r"^\s+(.+\.rb):([0-9]+):").unwrap();
|
|
24
|
+
let lines: Vec<_> = output.lines().collect();
|
|
25
|
+
let mut i = 0;
|
|
26
|
+
let mut failures = Vec::new();
|
|
27
|
+
while i < lines.len() {
|
|
28
|
+
let Some(header) = header_re.captures(lines[i]) else {
|
|
29
|
+
i += 1;
|
|
30
|
+
continue;
|
|
31
|
+
};
|
|
32
|
+
let kind = header[1].to_owned();
|
|
33
|
+
i += 1;
|
|
34
|
+
if kind == "Failure" {
|
|
35
|
+
if let Some(m) = lines.get(i).and_then(|line| failure_re.captures(line)) {
|
|
36
|
+
i += 1;
|
|
37
|
+
let mut messages = Vec::new();
|
|
38
|
+
while i < lines.len() && !lines[i].trim().is_empty() {
|
|
39
|
+
messages.push(lines[i].trim());
|
|
40
|
+
i += 1;
|
|
41
|
+
}
|
|
42
|
+
let mut failure = Map::new();
|
|
43
|
+
failure.insert("id".to_owned(), json!(&m[1]));
|
|
44
|
+
failure.insert("file".to_owned(), json!(relative(&ctx.cwd, &m[2])));
|
|
45
|
+
failure.insert("line".to_owned(), json!(m[3].parse::<u64>().unwrap_or(0)));
|
|
46
|
+
let message = messages
|
|
47
|
+
.into_iter()
|
|
48
|
+
.filter(|message| !message.is_empty())
|
|
49
|
+
.collect::<Vec<_>>()
|
|
50
|
+
.join(" / ");
|
|
51
|
+
if !message.is_empty() {
|
|
52
|
+
failure.insert("message".to_owned(), json!(message));
|
|
53
|
+
}
|
|
54
|
+
failures.push(Value::Object(failure));
|
|
55
|
+
}
|
|
56
|
+
} else if let Some(m) = lines.get(i).and_then(|line| error_re.captures(line)) {
|
|
57
|
+
let id = m[1].to_owned();
|
|
58
|
+
i += 1;
|
|
59
|
+
let exception = lines.get(i).map(|line| line.trim()).unwrap_or("");
|
|
60
|
+
let message = exception
|
|
61
|
+
.split_once(": ")
|
|
62
|
+
.map(|(_, message)| message)
|
|
63
|
+
.unwrap_or(exception);
|
|
64
|
+
i += 1;
|
|
65
|
+
let mut failure = Map::new();
|
|
66
|
+
failure.insert("id".to_owned(), json!(id));
|
|
67
|
+
if let Some(backtrace) = lines.get(i).and_then(|line| backtrace_re.captures(line)) {
|
|
68
|
+
failure.insert("file".to_owned(), json!(relative(&ctx.cwd, &backtrace[1])));
|
|
69
|
+
failure.insert(
|
|
70
|
+
"line".to_owned(),
|
|
71
|
+
json!(backtrace[2].parse::<u64>().unwrap_or(0)),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if !message.is_empty() {
|
|
75
|
+
failure.insert("message".to_owned(), json!(message));
|
|
76
|
+
}
|
|
77
|
+
failures.push(Value::Object(failure));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
Ok(result(
|
|
81
|
+
"minitest",
|
|
82
|
+
if failed > 0 { "fail" } else { "pass" },
|
|
83
|
+
if failed > 0 {
|
|
84
|
+
format!("{failed} failed, {passed} passed")
|
|
85
|
+
} else {
|
|
86
|
+
format!("{passed} passed")
|
|
87
|
+
},
|
|
88
|
+
failures,
|
|
89
|
+
ctx,
|
|
90
|
+
))
|
|
91
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
use super::test_helpers::{js_string, number, optional, stack_location, text, without_failures};
|
|
2
|
+
use crate::common::{read_file, relative, result, trim, Context};
|
|
3
|
+
use serde_json::{json, Map, Value};
|
|
4
|
+
|
|
5
|
+
pub fn parse(ctx: &Context) -> Result<Value, String> {
|
|
6
|
+
let stdout = read_file(&ctx.stdout_path)?;
|
|
7
|
+
let stdout = trim(&stdout);
|
|
8
|
+
if stdout.is_empty() {
|
|
9
|
+
return Ok(without_failures("mocha", "error", "no output", ctx));
|
|
10
|
+
}
|
|
11
|
+
let report: Value = match super::json_support::parse_json(stdout) {
|
|
12
|
+
Ok(value) => value,
|
|
13
|
+
Err(_) => {
|
|
14
|
+
return Ok(without_failures(
|
|
15
|
+
"mocha",
|
|
16
|
+
"error",
|
|
17
|
+
"failed to parse mocha JSON output",
|
|
18
|
+
ctx,
|
|
19
|
+
))
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
let tests = report
|
|
23
|
+
.get("failures")
|
|
24
|
+
.and_then(Value::as_array)
|
|
25
|
+
.ok_or("Mocha failures must be an array")?;
|
|
26
|
+
let mut failures = Vec::new();
|
|
27
|
+
for test in tests {
|
|
28
|
+
let err = test
|
|
29
|
+
.get("err")
|
|
30
|
+
.filter(|value| !value.is_null())
|
|
31
|
+
.ok_or("Mocha test err is missing")?;
|
|
32
|
+
let location = stack_location(err.get("stack"))?;
|
|
33
|
+
let mut failure = Map::new();
|
|
34
|
+
optional(&mut failure, "id", test.get("fullTitle"));
|
|
35
|
+
if let Some((file, line)) = location {
|
|
36
|
+
failure.insert("file".to_owned(), json!(relative(&ctx.cwd, &file)));
|
|
37
|
+
failure.insert("line".to_owned(), json!(line));
|
|
38
|
+
}
|
|
39
|
+
let message = if err.get("actual").is_some() && err.get("expected").is_some() {
|
|
40
|
+
format!(
|
|
41
|
+
"expected {}, got {}",
|
|
42
|
+
js_string(err.get("expected")),
|
|
43
|
+
js_string(err.get("actual"))
|
|
44
|
+
)
|
|
45
|
+
} else {
|
|
46
|
+
let message = match err.get("message").filter(|v| !v.is_null()) {
|
|
47
|
+
Some(value) => text(Some(value), "err.message")?,
|
|
48
|
+
None => "test failed".to_owned(),
|
|
49
|
+
};
|
|
50
|
+
message.split('\n').next().unwrap_or("").trim().to_owned()
|
|
51
|
+
};
|
|
52
|
+
failure.insert("message".to_owned(), json!(message));
|
|
53
|
+
optional(
|
|
54
|
+
&mut failure,
|
|
55
|
+
"rule",
|
|
56
|
+
err.get("code")
|
|
57
|
+
.filter(|v| !v.is_null())
|
|
58
|
+
.or_else(|| err.get("name")),
|
|
59
|
+
);
|
|
60
|
+
failures.push(Value::Object(failure));
|
|
61
|
+
}
|
|
62
|
+
let stats = report
|
|
63
|
+
.get("stats")
|
|
64
|
+
.filter(|v| !v.is_null())
|
|
65
|
+
.ok_or("Mocha stats are missing")?;
|
|
66
|
+
let failed = stats.get("failures");
|
|
67
|
+
let passed = stats.get("passes");
|
|
68
|
+
let status = if number(failed) > 0.0 { "fail" } else { "pass" };
|
|
69
|
+
let summary = if status == "fail" {
|
|
70
|
+
format!("{} failed, {} passed", js_string(failed), js_string(passed))
|
|
71
|
+
} else {
|
|
72
|
+
format!("{} passed", js_string(passed))
|
|
73
|
+
};
|
|
74
|
+
Ok(result("mocha", status, summary, failures, ctx))
|
|
75
|
+
}
|