@robhowley/pi-structured-return 1.8.0 → 1.10.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/README.md +84 -73
- package/extensions/structured-return/config/project-config.ts +10 -0
- package/extensions/structured-return/config/registry.ts +306 -0
- package/extensions/structured-return/examples/.pi/machine-readable.json +18 -0
- package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +25 -0
- package/extensions/structured-return/{src/index.ts → index.ts} +94 -69
- package/extensions/structured-return/{src/parsers → parsers}/ava-text.ts +23 -15
- package/extensions/structured-return/{src/parsers → parsers}/bandit-json.ts +17 -15
- package/extensions/structured-return/{src/parsers → parsers}/black-text.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/cargo-build.ts +19 -14
- package/extensions/structured-return/{src/parsers → parsers}/cargo-test.ts +20 -19
- package/extensions/structured-return/parsers/checkstyle-xml.ts +183 -0
- package/extensions/structured-return/{src/parsers → parsers}/clang-text.ts +15 -13
- package/extensions/structured-return/{src/parsers → parsers}/dbt-json.ts +28 -23
- package/extensions/structured-return/{src/parsers → parsers}/dotnet-build-text.ts +10 -8
- package/extensions/structured-return/{src/parsers → parsers}/eslint-json.ts +15 -9
- package/extensions/structured-return/{src/parsers → parsers}/go-test-json.ts +23 -21
- package/extensions/structured-return/{src/parsers → parsers}/hadolint-json.ts +18 -12
- package/extensions/structured-return/{src/parsers → parsers}/htmlhint-json.ts +15 -13
- package/extensions/structured-return/{src/parsers → parsers}/isort-text.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/javac-text.ts +14 -12
- package/extensions/structured-return/{src/parsers → parsers}/jsonlint-text.ts +16 -14
- package/extensions/structured-return/{src/parsers → parsers}/junit-xml.ts +149 -50
- package/extensions/structured-return/{src/parsers → parsers}/markdownlint-json.ts +19 -17
- package/extensions/structured-return/{src/parsers → parsers}/minitest-text.ts +24 -15
- package/extensions/structured-return/{src/parsers → parsers}/mocha-json.ts +17 -10
- package/extensions/structured-return/{src/parsers → parsers}/mypy-json.ts +16 -16
- package/extensions/structured-return/{src/parsers → parsers}/node-test-text.ts +17 -14
- package/extensions/structured-return/{src/parsers → parsers}/npm-audit-json.ts +19 -16
- package/extensions/structured-return/{src/parsers → parsers}/prettier-text.ts +21 -17
- package/extensions/structured-return/{src/parsers → parsers}/pylint-json.ts +17 -17
- package/extensions/structured-return/{src/parsers → parsers}/pyright-json.ts +20 -18
- package/extensions/structured-return/{src/parsers → parsers}/rspec-json.ts +14 -14
- package/extensions/structured-return/{src/parsers → parsers}/rubocop-json.ts +22 -11
- package/extensions/structured-return/{src/parsers → parsers}/ruff-json.ts +7 -7
- package/extensions/structured-return/{src/parsers → parsers}/shellcheck-json.ts +14 -14
- package/extensions/structured-return/{src/parsers → parsers}/stylelint-json.ts +21 -13
- package/extensions/structured-return/{src/parsers → parsers}/swiftc-text.ts +16 -10
- package/extensions/structured-return/parsers/tail-fallback.ts +20 -0
- package/extensions/structured-return/{src/parsers → parsers}/tidy-text.ts +13 -13
- package/extensions/structured-return/{src/parsers → parsers}/tsc-text.ts +11 -11
- package/extensions/structured-return/{src/parsers → parsers}/unittest-text.ts +24 -14
- package/extensions/structured-return/{src/parsers → parsers}/utils.ts +9 -6
- package/extensions/structured-return/{src/parsers → parsers}/vale-json.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/vitest-json.ts +14 -14
- package/extensions/structured-return/{src/storage → storage}/log-store.ts +5 -5
- package/extensions/structured-return/{src/storage → storage}/session-stats.ts +11 -11
- package/extensions/structured-return/{src/types.ts → types.ts} +4 -2
- package/package.json +27 -43
- package/skills/structured-return/SKILL.md +62 -1
- package/LICENSE +0 -21
- package/extensions/structured-return/src/config/project-config.ts +0 -10
- package/extensions/structured-return/src/config/registry.test.ts +0 -171
- package/extensions/structured-return/src/config/registry.ts +0 -282
- package/extensions/structured-return/src/index.test.ts +0 -220
- package/extensions/structured-return/src/parsers/ava-text.test.ts +0 -116
- package/extensions/structured-return/src/parsers/bandit-json.test.ts +0 -90
- package/extensions/structured-return/src/parsers/black-text.test.ts +0 -67
- package/extensions/structured-return/src/parsers/cargo-build.test.ts +0 -170
- package/extensions/structured-return/src/parsers/cargo-test.test.ts +0 -191
- package/extensions/structured-return/src/parsers/clang-text.test.ts +0 -61
- package/extensions/structured-return/src/parsers/dbt-json.test.ts +0 -172
- package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +0 -85
- package/extensions/structured-return/src/parsers/eslint-json.test.ts +0 -60
- package/extensions/structured-return/src/parsers/go-test-json.test.ts +0 -119
- package/extensions/structured-return/src/parsers/hadolint-json.test.ts +0 -73
- package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +0 -72
- package/extensions/structured-return/src/parsers/isort-text.test.ts +0 -58
- package/extensions/structured-return/src/parsers/javac-text.test.ts +0 -75
- package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +0 -52
- package/extensions/structured-return/src/parsers/junit-xml.test.ts +0 -410
- package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +0 -76
- package/extensions/structured-return/src/parsers/minitest-text.test.ts +0 -110
- package/extensions/structured-return/src/parsers/mocha-json.test.ts +0 -108
- package/extensions/structured-return/src/parsers/mypy-json.test.ts +0 -101
- package/extensions/structured-return/src/parsers/node-test-text.test.ts +0 -117
- package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +0 -83
- package/extensions/structured-return/src/parsers/prettier-text.test.ts +0 -76
- package/extensions/structured-return/src/parsers/pylint-json.test.ts +0 -120
- package/extensions/structured-return/src/parsers/pyright-json.test.ts +0 -112
- package/extensions/structured-return/src/parsers/rspec-json.test.ts +0 -126
- package/extensions/structured-return/src/parsers/rubocop-json.test.ts +0 -118
- package/extensions/structured-return/src/parsers/ruff-json.test.ts +0 -57
- package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +0 -110
- package/extensions/structured-return/src/parsers/stylelint-json.test.ts +0 -120
- package/extensions/structured-return/src/parsers/swiftc-text.test.ts +0 -73
- package/extensions/structured-return/src/parsers/tail-fallback.test.ts +0 -41
- package/extensions/structured-return/src/parsers/tail-fallback.ts +0 -20
- package/extensions/structured-return/src/parsers/tidy-text.test.ts +0 -74
- package/extensions/structured-return/src/parsers/tsc-text.test.ts +0 -81
- package/extensions/structured-return/src/parsers/unittest-text.test.ts +0 -126
- package/extensions/structured-return/src/parsers/vale-json.test.ts +0 -84
- package/extensions/structured-return/src/parsers/vitest-json.test.ts +0 -118
- package/extensions/structured-return/src/storage/session-stats.test.ts +0 -156
- package/extensions/structured-return/tsconfig.json +0 -11
- package/extensions/structured-return/vitest.config.ts +0 -9
- /package/extensions/structured-return/{src/ui → ui}/widget.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { ParserModule, ParsedFailure } from
|
|
3
|
-
import { safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
+
import { safeReadFile } from './utils';
|
|
4
4
|
|
|
5
5
|
interface HadolintItem {
|
|
6
6
|
code: string;
|
|
@@ -12,11 +12,17 @@ interface HadolintItem {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const parser: ParserModule = {
|
|
15
|
-
id:
|
|
15
|
+
id: 'hadolint-json',
|
|
16
16
|
async parse(ctx) {
|
|
17
17
|
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
18
|
-
if (!stdout || stdout ===
|
|
19
|
-
return {
|
|
18
|
+
if (!stdout || stdout === '[]') {
|
|
19
|
+
return {
|
|
20
|
+
tool: 'hadolint',
|
|
21
|
+
status: 'pass',
|
|
22
|
+
summary: 'no lint errors',
|
|
23
|
+
failures: [],
|
|
24
|
+
logPath: ctx.logPath,
|
|
25
|
+
};
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
let items: HadolintItem[];
|
|
@@ -24,9 +30,9 @@ const parser: ParserModule = {
|
|
|
24
30
|
items = JSON.parse(stdout) as HadolintItem[];
|
|
25
31
|
} catch {
|
|
26
32
|
return {
|
|
27
|
-
tool:
|
|
28
|
-
status:
|
|
29
|
-
summary:
|
|
33
|
+
tool: 'hadolint',
|
|
34
|
+
status: 'error',
|
|
35
|
+
summary: 'failed to parse hadolint JSON output',
|
|
30
36
|
logPath: ctx.logPath,
|
|
31
37
|
};
|
|
32
38
|
}
|
|
@@ -43,9 +49,9 @@ const parser: ParserModule = {
|
|
|
43
49
|
});
|
|
44
50
|
|
|
45
51
|
return {
|
|
46
|
-
tool:
|
|
47
|
-
status: failures.length > 0 ?
|
|
48
|
-
summary: failures.length > 0 ? `${failures.length} lint errors` :
|
|
52
|
+
tool: 'hadolint',
|
|
53
|
+
status: failures.length > 0 ? 'fail' : 'pass',
|
|
54
|
+
summary: failures.length > 0 ? `${failures.length} lint errors` : 'no lint errors',
|
|
49
55
|
failures,
|
|
50
56
|
logPath: ctx.logPath,
|
|
51
57
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { ParserModule, ParsedFailure } from
|
|
3
|
-
import { safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
+
import { safeReadFile } from './utils';
|
|
4
4
|
|
|
5
5
|
interface HtmlHintMessage {
|
|
6
6
|
type: string;
|
|
@@ -16,15 +16,15 @@ interface HtmlHintFile {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const parser: ParserModule = {
|
|
19
|
-
id:
|
|
19
|
+
id: 'htmlhint-json',
|
|
20
20
|
async parse(ctx) {
|
|
21
21
|
// htmlhint --format json writes JSON to stderr (not stdout), so read stderr first.
|
|
22
22
|
const output = (safeReadFile(ctx.stderrPath) + safeReadFile(ctx.stdoutPath)).trim();
|
|
23
23
|
if (!output) {
|
|
24
24
|
return {
|
|
25
|
-
tool:
|
|
26
|
-
status:
|
|
27
|
-
summary:
|
|
25
|
+
tool: 'htmlhint',
|
|
26
|
+
status: 'pass',
|
|
27
|
+
summary: 'no lint errors',
|
|
28
28
|
failures: [],
|
|
29
29
|
logPath: ctx.logPath,
|
|
30
30
|
};
|
|
@@ -35,9 +35,9 @@ const parser: ParserModule = {
|
|
|
35
35
|
files = JSON.parse(output);
|
|
36
36
|
} catch {
|
|
37
37
|
return {
|
|
38
|
-
tool:
|
|
39
|
-
status:
|
|
40
|
-
summary:
|
|
38
|
+
tool: 'htmlhint',
|
|
39
|
+
status: 'error',
|
|
40
|
+
summary: 'failed to parse htmlhint JSON output',
|
|
41
41
|
logPath: ctx.logPath,
|
|
42
42
|
};
|
|
43
43
|
}
|
|
@@ -57,11 +57,13 @@ const parser: ParserModule = {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const summary =
|
|
60
|
-
failures.length > 0
|
|
60
|
+
failures.length > 0
|
|
61
|
+
? `${failures.length} lint error${failures.length !== 1 ? 's' : ''}`
|
|
62
|
+
: 'no lint errors';
|
|
61
63
|
|
|
62
64
|
return {
|
|
63
|
-
tool:
|
|
64
|
-
status: failures.length > 0 ?
|
|
65
|
+
tool: 'htmlhint',
|
|
66
|
+
status: failures.length > 0 ? 'fail' : 'pass',
|
|
65
67
|
summary,
|
|
66
68
|
failures,
|
|
67
69
|
logPath: ctx.logPath,
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { ParserModule, ParsedFailure } from
|
|
3
|
-
import { safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
+
import { safeReadFile } from './utils';
|
|
4
4
|
|
|
5
5
|
// ERROR: /path/to/file.py Imports are incorrectly sorted and/or formatted.
|
|
6
6
|
const ERROR_LINE = /^ERROR: (.+?) Imports are incorrectly sorted/;
|
|
7
7
|
const parser: ParserModule = {
|
|
8
|
-
id:
|
|
8
|
+
id: 'isort-text',
|
|
9
9
|
async parse(ctx) {
|
|
10
|
-
const combined = (safeReadFile(ctx.stdoutPath) +
|
|
10
|
+
const combined = (safeReadFile(ctx.stdoutPath) + '\n' + safeReadFile(ctx.stderrPath)).trim();
|
|
11
11
|
if (!combined) {
|
|
12
12
|
return {
|
|
13
|
-
tool:
|
|
14
|
-
status:
|
|
15
|
-
summary:
|
|
13
|
+
tool: 'isort',
|
|
14
|
+
status: 'pass',
|
|
15
|
+
summary: 'all imports sorted',
|
|
16
16
|
failures: [],
|
|
17
17
|
logPath: ctx.logPath,
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const lines = combined.split(
|
|
21
|
+
const lines = combined.split('\n');
|
|
22
22
|
const failures: ParsedFailure[] = [];
|
|
23
23
|
|
|
24
24
|
for (const line of lines) {
|
|
@@ -28,16 +28,16 @@ const parser: ParserModule = {
|
|
|
28
28
|
failures.push({
|
|
29
29
|
id: relPath,
|
|
30
30
|
file: relPath,
|
|
31
|
-
message:
|
|
31
|
+
message: 'imports are incorrectly sorted',
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (failures.length === 0 && !combined.includes(
|
|
36
|
+
if (failures.length === 0 && !combined.includes('ERROR')) {
|
|
37
37
|
return {
|
|
38
|
-
tool:
|
|
39
|
-
status:
|
|
40
|
-
summary:
|
|
38
|
+
tool: 'isort',
|
|
39
|
+
status: 'pass',
|
|
40
|
+
summary: 'all imports sorted',
|
|
41
41
|
failures: [],
|
|
42
42
|
logPath: ctx.logPath,
|
|
43
43
|
};
|
|
@@ -46,14 +46,14 @@ const parser: ParserModule = {
|
|
|
46
46
|
const n = failures.length;
|
|
47
47
|
const summary =
|
|
48
48
|
n === 0
|
|
49
|
-
?
|
|
49
|
+
? 'all imports sorted'
|
|
50
50
|
: n === 1
|
|
51
|
-
?
|
|
51
|
+
? '1 file has incorrectly sorted imports'
|
|
52
52
|
: `${n} files have incorrectly sorted imports`;
|
|
53
53
|
|
|
54
54
|
return {
|
|
55
|
-
tool:
|
|
56
|
-
status: n > 0 ?
|
|
55
|
+
tool: 'isort',
|
|
56
|
+
status: n > 0 ? 'fail' : 'pass',
|
|
57
57
|
summary,
|
|
58
58
|
failures,
|
|
59
59
|
logPath: ctx.logPath,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { ParserModule, ParsedFailure } from
|
|
3
|
-
import { safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
+
import { safeReadFile } from './utils';
|
|
4
4
|
|
|
5
5
|
const ERROR_LINE = /^(.+?):(\d+): error: (.+)$/;
|
|
6
6
|
const SYMBOL_LINE = /^\s+symbol:\s+(.+)$/;
|
|
@@ -9,22 +9,22 @@ const CARET_LINE = /^\s+\^/;
|
|
|
9
9
|
const SOURCE_SNIPPET = /^\s{8,}\S/;
|
|
10
10
|
|
|
11
11
|
const parser: ParserModule = {
|
|
12
|
-
id:
|
|
12
|
+
id: 'javac-text',
|
|
13
13
|
async parse(ctx) {
|
|
14
14
|
const stderr = safeReadFile(ctx.stderrPath).trim();
|
|
15
15
|
if (!stderr) {
|
|
16
16
|
return {
|
|
17
|
-
tool:
|
|
18
|
-
status:
|
|
19
|
-
summary:
|
|
17
|
+
tool: 'javac',
|
|
18
|
+
status: 'pass',
|
|
19
|
+
summary: 'compilation successful',
|
|
20
20
|
failures: [],
|
|
21
21
|
logPath: ctx.logPath,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const lines = stderr.split(
|
|
25
|
+
const lines = stderr.split('\n');
|
|
26
26
|
const failures: ParsedFailure[] = [];
|
|
27
|
-
let summaryLine =
|
|
27
|
+
let summaryLine = '';
|
|
28
28
|
|
|
29
29
|
for (let i = 0; i < lines.length; i++) {
|
|
30
30
|
const errorMatch = lines[i].match(ERROR_LINE);
|
|
@@ -66,11 +66,13 @@ const parser: ParserModule = {
|
|
|
66
66
|
|
|
67
67
|
const summary =
|
|
68
68
|
summaryLine ||
|
|
69
|
-
(failures.length > 0
|
|
69
|
+
(failures.length > 0
|
|
70
|
+
? `${failures.length} error${failures.length !== 1 ? 's' : ''}`
|
|
71
|
+
: 'compilation successful');
|
|
70
72
|
|
|
71
73
|
return {
|
|
72
|
-
tool:
|
|
73
|
-
status: failures.length > 0 ?
|
|
74
|
+
tool: 'javac',
|
|
75
|
+
status: failures.length > 0 ? 'fail' : 'pass',
|
|
74
76
|
summary,
|
|
75
77
|
failures,
|
|
76
78
|
logPath: ctx.logPath,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ParserModule, ParsedFailure } from
|
|
2
|
-
import { safeReadFile } from
|
|
1
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
2
|
+
import { safeReadFile } from './utils';
|
|
3
3
|
|
|
4
4
|
// Error: Parse error on line N:
|
|
5
5
|
const ERROR_HEADER = /^Error: Parse error on line (\d+):$/;
|
|
@@ -7,14 +7,14 @@ const ERROR_HEADER = /^Error: Parse error on line (\d+):$/;
|
|
|
7
7
|
const EXPECTING_LINE = /^(Expecting .+)$/;
|
|
8
8
|
|
|
9
9
|
const parser: ParserModule = {
|
|
10
|
-
id:
|
|
10
|
+
id: 'jsonlint-text',
|
|
11
11
|
async parse(ctx) {
|
|
12
|
-
const combined = (safeReadFile(ctx.stdoutPath) +
|
|
12
|
+
const combined = (safeReadFile(ctx.stdoutPath) + '\n' + safeReadFile(ctx.stderrPath)).trim();
|
|
13
13
|
if (!combined) {
|
|
14
14
|
return {
|
|
15
|
-
tool:
|
|
16
|
-
status:
|
|
17
|
-
summary:
|
|
15
|
+
tool: 'jsonlint',
|
|
16
|
+
status: 'pass',
|
|
17
|
+
summary: 'valid JSON',
|
|
18
18
|
failures: [],
|
|
19
19
|
logPath: ctx.logPath,
|
|
20
20
|
};
|
|
@@ -22,12 +22,14 @@ const parser: ParserModule = {
|
|
|
22
22
|
|
|
23
23
|
// Derive filename from argv — use last non-flag arg since earlier positional
|
|
24
24
|
// args may be flag values (e.g. npx --yes jsonlint file.json).
|
|
25
|
-
const file =
|
|
25
|
+
const file =
|
|
26
|
+
ctx.argv.filter((a) => !a.startsWith('-') && a !== 'jsonlint' && a !== 'npx').pop() ??
|
|
27
|
+
'input';
|
|
26
28
|
|
|
27
|
-
const lines = combined.split(
|
|
29
|
+
const lines = combined.split('\n');
|
|
28
30
|
const failures: ParsedFailure[] = [];
|
|
29
31
|
let line: number | undefined;
|
|
30
|
-
let message =
|
|
32
|
+
let message = '';
|
|
31
33
|
|
|
32
34
|
for (const l of lines) {
|
|
33
35
|
const headerMatch = l.match(ERROR_HEADER);
|
|
@@ -47,14 +49,14 @@ const parser: ParserModule = {
|
|
|
47
49
|
id: `${file}:${line}`,
|
|
48
50
|
file,
|
|
49
51
|
line,
|
|
50
|
-
message: message ||
|
|
52
|
+
message: message || 'parse error',
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
return {
|
|
55
|
-
tool:
|
|
56
|
-
status: failures.length > 0 ?
|
|
57
|
-
summary: failures.length > 0 ?
|
|
57
|
+
tool: 'jsonlint',
|
|
58
|
+
status: failures.length > 0 ? 'fail' : 'pass',
|
|
59
|
+
summary: failures.length > 0 ? 'parse error' : 'valid JSON',
|
|
58
60
|
failures,
|
|
59
61
|
logPath: ctx.logPath,
|
|
60
62
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import { XMLParser } from
|
|
3
|
-
import type { ParserModule, ParsedFailure } from
|
|
4
|
-
import { safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
3
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
4
|
+
import { safeReadFile } from './utils';
|
|
5
5
|
|
|
6
6
|
interface JUnitFailureOrError {
|
|
7
7
|
message?: string;
|
|
8
8
|
type?: string;
|
|
9
|
-
|
|
9
|
+
'#text'?: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
interface JUnitTestCase {
|
|
@@ -25,7 +25,8 @@ interface JUnitTestSuite {
|
|
|
25
25
|
failures?: string | number;
|
|
26
26
|
errors?: string | number;
|
|
27
27
|
testcase?: JUnitTestCase[];
|
|
28
|
-
|
|
28
|
+
testsuite?: JUnitTestSuite[]; // PHPUnit nests testsuites
|
|
29
|
+
'system-out'?: string;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
interface JUnitDocument {
|
|
@@ -35,8 +36,8 @@ interface JUnitDocument {
|
|
|
35
36
|
|
|
36
37
|
const xmlParser = new XMLParser({
|
|
37
38
|
ignoreAttributes: false,
|
|
38
|
-
attributeNamePrefix:
|
|
39
|
-
isArray: (name) => [
|
|
39
|
+
attributeNamePrefix: '',
|
|
40
|
+
isArray: (name) => ['testsuite', 'testcase'].includes(name),
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
/** Decode numeric XML character references (e.g. 
 → newline) in attribute values. */
|
|
@@ -46,32 +47,69 @@ function decodeXmlEntities(s: string): string {
|
|
|
46
47
|
.replace(/&#(\d+);/g, (_, dec) => String.fromCharCode(Number(dec)));
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
/** Strip a Pest-style test name prefix from a failure body.
|
|
51
|
+
* Pest can concatenate the test name directly with the error message, e.g.
|
|
52
|
+
* "it multiplies two numbers correctlyFailed asserting that 12 is identical to 99." */
|
|
53
|
+
function stripPestTestNamePrefix(text: string, testName?: string): string {
|
|
54
|
+
if (!testName || !text.startsWith(testName)) return text;
|
|
55
|
+
return text.slice(testName.length).trimStart();
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
/** Extract Expected/Received/Actual diff lines from a failure body, e.g. Jest assertion output. */
|
|
50
59
|
function extractAssertionDiff(text: string): string | undefined {
|
|
51
60
|
const diffLines: string[] = [];
|
|
52
|
-
for (const line of text.split(
|
|
61
|
+
for (const line of text.split('\n')) {
|
|
53
62
|
const trimmed = line.trim();
|
|
54
63
|
if (/^(Expected|Received|Actual)\s*:/.test(trimmed)) diffLines.push(trimmed);
|
|
55
64
|
}
|
|
56
|
-
return diffLines.length > 0 ? diffLines.join(
|
|
65
|
+
return diffLines.length > 0 ? diffLines.join('\n') : undefined;
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
/** Extract file, line, and message from failure body text.
|
|
60
69
|
* Handles:
|
|
61
70
|
* - pytest-style: "file.py:line: message"
|
|
62
71
|
* - Go-style: " file.go:line: message"
|
|
72
|
+
* - Playwright-style: "at /path/file.ts:line:col"
|
|
73
|
+
* - Pest-style: "at tests/MathTest.php:8"
|
|
74
|
+
* - PHPUnit-style: "/path/to/File.php:21" trailer lines
|
|
63
75
|
* - .NET-style: "in /path/File.cs:line N"
|
|
64
76
|
* - Java/JVM-style: "at [module/]pkg.Class.method(File.java:N)"
|
|
65
77
|
* preferring the frame whose class matches `classname`. */
|
|
66
78
|
function parseBodyLocation(
|
|
67
79
|
text: string,
|
|
68
|
-
classname?: string
|
|
80
|
+
classname?: string,
|
|
69
81
|
): { file: string; line: number; message?: string } | undefined {
|
|
70
82
|
const lines = text
|
|
71
|
-
.split(
|
|
83
|
+
.split('\n')
|
|
72
84
|
.map((l) => l.trim())
|
|
73
85
|
.filter(Boolean);
|
|
74
86
|
|
|
87
|
+
const phpMessage = () =>
|
|
88
|
+
lines.find(
|
|
89
|
+
(l) => !/^\w+::\w+/.test(l) && !/^at\s+.+?\.php:\d+$/.test(l) && !/^.+?\.php:\d+$/.test(l),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Check stack frames first so Playwright/Jest locations win over header lines like
|
|
93
|
+
// "math.test.ts:8:7 › suite › test", which would otherwise match the generic file:line pattern.
|
|
94
|
+
for (const line of lines) {
|
|
95
|
+
const m = line.match(/^at\s+\S+\s+\(([^)]+\.(?:[jt]sx?|mjs|cjs)):(\d+):\d+\)/);
|
|
96
|
+
if (m && !m[1].includes('node_modules')) {
|
|
97
|
+
return { file: path.basename(m[1]), line: Number(m[2]) };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (const line of lines) {
|
|
102
|
+
const m = line.match(/^at\s+(.+?\.(?:[jt]sx?|mjs|cjs)):(\d+):\d+$/);
|
|
103
|
+
if (m && !m[1].includes('node_modules')) {
|
|
104
|
+
return { file: path.basename(m[1]), line: Number(m[2]) };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for (const line of lines) {
|
|
109
|
+
const m = line.match(/^at\s+(.+?\.php):(\d+)$/);
|
|
110
|
+
if (m) return { file: m[1], line: Number(m[2]) };
|
|
111
|
+
}
|
|
112
|
+
|
|
75
113
|
// pytest / Go: "file.ext:line: message"
|
|
76
114
|
for (const line of lines) {
|
|
77
115
|
const m = line.match(/^([^:\s]+\.\w+):(\d+):\s*(.*)/);
|
|
@@ -84,18 +122,18 @@ function parseBodyLocation(
|
|
|
84
122
|
if (m) return { file: path.basename(m[1]), line: Number(m[2]) };
|
|
85
123
|
}
|
|
86
124
|
|
|
87
|
-
// Jest/Node-style: " at Something (file.js:line:col)" — skip node_modules frames
|
|
88
|
-
for (const line of lines) {
|
|
89
|
-
const m = line.match(/^at\s+\S+\s+\(([^)]+\.(?:[jt]sx?|mjs|cjs)):(\d+):\d+\)/);
|
|
90
|
-
if (m && !m[1].includes("node_modules")) {
|
|
91
|
-
return { file: path.basename(m[1]), line: Number(m[2]) };
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
125
|
// Java/JVM: "at [module/]pkg.Class.method(File.java:N)"
|
|
96
126
|
const javaRe = /^at (?:[\w.$]+\/)?([\w.$]+)\.\w+\(([\w]+\.(?:java|kt|scala|groovy)):(\d+)\)$/;
|
|
97
|
-
const frameworkPrefixes = [
|
|
98
|
-
|
|
127
|
+
const frameworkPrefixes = [
|
|
128
|
+
'java.',
|
|
129
|
+
'javax.',
|
|
130
|
+
'sun.',
|
|
131
|
+
'com.sun.',
|
|
132
|
+
'org.junit.',
|
|
133
|
+
'org.opentest4j.',
|
|
134
|
+
'junit.',
|
|
135
|
+
];
|
|
136
|
+
const simpleClass = classname?.split('.').pop();
|
|
99
137
|
let firstUserFrame: { file: string; line: number } | undefined;
|
|
100
138
|
|
|
101
139
|
for (const line of lines) {
|
|
@@ -109,43 +147,82 @@ function parseBodyLocation(
|
|
|
109
147
|
}
|
|
110
148
|
|
|
111
149
|
if (firstUserFrame) return firstUserFrame;
|
|
150
|
+
|
|
151
|
+
for (const line of lines) {
|
|
152
|
+
const m = line.match(/^(.+?\.php):(\d+)$/);
|
|
153
|
+
if (m) return { file: m[1], line: Number(m[2]), message: phpMessage() };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (const line of lines) {
|
|
157
|
+
const m = line.match(/(?:^#\d+\s+)?(.+?\.php)\((\d+)\)(?::|$)/);
|
|
158
|
+
if (m) return { file: m[1], line: Number(m[2]), message: phpMessage() };
|
|
159
|
+
}
|
|
160
|
+
|
|
112
161
|
return undefined;
|
|
113
162
|
}
|
|
114
163
|
|
|
115
164
|
/** Extract panic message and file:line for a specific test from Go's system-out. */
|
|
116
165
|
function parsePanicInfo(
|
|
117
166
|
systemOut: string,
|
|
118
|
-
testName: string
|
|
167
|
+
testName: string,
|
|
119
168
|
): { message?: string; file?: string; line?: number } | undefined {
|
|
120
|
-
const lines = systemOut.split(
|
|
121
|
-
const panicLine = lines.find((l) => l.trim().startsWith(
|
|
169
|
+
const lines = systemOut.split('\n');
|
|
170
|
+
const panicLine = lines.find((l) => l.trim().startsWith('panic:'));
|
|
122
171
|
if (!panicLine) return undefined;
|
|
123
172
|
const message = panicLine
|
|
124
173
|
.trim()
|
|
125
|
-
.replace(/^panic:\s*/,
|
|
126
|
-
.replace(/\s*\[.*\]$/,
|
|
174
|
+
.replace(/^panic:\s*/, '')
|
|
175
|
+
.replace(/\s*\[.*\]$/, '')
|
|
127
176
|
.trim();
|
|
128
177
|
|
|
129
178
|
// Find the stack frame for this test function, then grab the file:line on the next line
|
|
130
179
|
for (let i = 0; i < lines.length - 1; i++) {
|
|
131
180
|
if (lines[i].includes(`.${testName}(`)) {
|
|
132
181
|
const m = lines[i + 1].trim().match(/^([^:]+\.go):(\d+)/);
|
|
133
|
-
if (m) return { message, file: m[1].split(
|
|
182
|
+
if (m) return { message, file: m[1].split('/').pop(), line: Number(m[2]) };
|
|
134
183
|
}
|
|
135
184
|
}
|
|
136
185
|
return { message };
|
|
137
186
|
}
|
|
138
187
|
|
|
188
|
+
function resolveClassnameFile(classname?: string): string | undefined {
|
|
189
|
+
if (!classname) return undefined;
|
|
190
|
+
const normalized = classname.replace(/\\/g, '/');
|
|
191
|
+
if (/\.(?:[jt]sx?|mjs|cjs|py|rb|go|php|cs|fs|vb|java|kt|scala|groovy)$/.test(normalized)) {
|
|
192
|
+
return normalized;
|
|
193
|
+
}
|
|
194
|
+
if (normalized.includes('/')) return undefined;
|
|
195
|
+
if (/^[\w$]+(?:\.[\w$]+)*$/.test(classname)) {
|
|
196
|
+
return classname.replace(/\./g, '/') + '.java';
|
|
197
|
+
}
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
|
|
139
201
|
function resolveFile(tc: JUnitTestCase, suite: JUnitTestSuite, cwd: string): string | undefined {
|
|
140
|
-
const raw = tc.file ?? suite.file;
|
|
202
|
+
const raw = (tc.file ?? suite.file)?.split('::')[0];
|
|
141
203
|
if (raw) return path.relative(cwd, path.resolve(cwd, raw));
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
204
|
+
return resolveClassnameFile(tc.classname);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function isPhpFile(candidate?: string): boolean {
|
|
208
|
+
if (!candidate) return false;
|
|
209
|
+
return candidate.split('::')[0].replace(/\\/g, '/').endsWith('.php');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Recursively collect all testsuites including nested ones (PHPUnit/Pest style). */
|
|
213
|
+
function flattenSuites(suites: JUnitTestSuite[]): JUnitTestSuite[] {
|
|
214
|
+
const result: JUnitTestSuite[] = [];
|
|
215
|
+
for (const suite of suites) {
|
|
216
|
+
result.push(suite);
|
|
217
|
+
if (suite.testsuite) {
|
|
218
|
+
result.push(...flattenSuites(suite.testsuite));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
145
222
|
}
|
|
146
223
|
|
|
147
224
|
const parser: ParserModule = {
|
|
148
|
-
id:
|
|
225
|
+
id: 'junit-xml',
|
|
149
226
|
async parse(ctx) {
|
|
150
227
|
const artifactSources = ctx.artifactPaths.length > 0 ? ctx.artifactPaths : [ctx.stdoutPath];
|
|
151
228
|
|
|
@@ -158,50 +235,72 @@ const parser: ParserModule = {
|
|
|
158
235
|
if (!xml.trim()) continue;
|
|
159
236
|
const doc = xmlParser.parse(xml) as JUnitDocument;
|
|
160
237
|
|
|
161
|
-
const
|
|
238
|
+
const topLevelSuites: JUnitTestSuite[] = doc.testsuites?.testsuite ?? doc.testsuite ?? [];
|
|
162
239
|
|
|
163
|
-
|
|
240
|
+
// Count tests/failures from top-level only (nested suites report aggregates)
|
|
241
|
+
for (const suite of topLevelSuites) {
|
|
164
242
|
totalTests += Number(suite.tests ?? 0);
|
|
165
243
|
totalFailed += Number(suite.failures ?? 0) + Number(suite.errors ?? 0);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Process testcases from all suites including nested ones (PHPUnit nests testsuites)
|
|
247
|
+
const allSuites = flattenSuites(topLevelSuites);
|
|
166
248
|
|
|
249
|
+
for (const suite of allSuites) {
|
|
167
250
|
for (const tc of suite.testcase ?? []) {
|
|
168
251
|
const rawProblem = tc.failure ?? tc.error;
|
|
169
252
|
if (!rawProblem) continue;
|
|
170
|
-
const problem: JUnitFailureOrError =
|
|
253
|
+
const problem: JUnitFailureOrError =
|
|
254
|
+
typeof rawProblem === 'string' ? { '#text': rawProblem } : rawProblem;
|
|
171
255
|
|
|
172
|
-
const bodyLocation = problem[
|
|
256
|
+
const bodyLocation = problem['#text']
|
|
257
|
+
? parseBodyLocation(problem['#text'], tc.classname)
|
|
258
|
+
: undefined;
|
|
173
259
|
const panicInfo =
|
|
174
|
-
!bodyLocation && suite[
|
|
260
|
+
!bodyLocation && suite['system-out'] && tc.name
|
|
261
|
+
? parsePanicInfo(suite['system-out'], tc.name)
|
|
262
|
+
: undefined;
|
|
175
263
|
const file =
|
|
176
264
|
(tc.file ?? suite.file)
|
|
177
265
|
? resolveFile(tc, suite, ctx.cwd)
|
|
178
266
|
: (bodyLocation?.file ?? panicInfo?.file ?? resolveFile(tc, suite, ctx.cwd));
|
|
179
|
-
const
|
|
180
|
-
|
|
267
|
+
const tcLine = tc.line !== undefined ? Number(tc.line) : undefined;
|
|
268
|
+
// PHPUnit/Pest report tc.line as the test method definition line, not the failure line.
|
|
269
|
+
// Other JUnit producers historically prefer tc.line when it is present.
|
|
270
|
+
const preferBodyLine =
|
|
271
|
+
isPhpFile(file) ||
|
|
272
|
+
isPhpFile(tc.file) ||
|
|
273
|
+
isPhpFile(suite.file) ||
|
|
274
|
+
isPhpFile(bodyLocation?.file);
|
|
275
|
+
const line = preferBodyLine
|
|
276
|
+
? (bodyLocation?.line ?? panicInfo?.line ?? tcLine)
|
|
277
|
+
: (tcLine ?? bodyLocation?.line ?? panicInfo?.line);
|
|
278
|
+
const id = [file, line, tc.name].filter(Boolean).join(':');
|
|
181
279
|
|
|
182
280
|
failures.push({
|
|
183
281
|
id: id || String(failures.length),
|
|
184
282
|
file,
|
|
185
283
|
line: Number.isNaN(line) ? undefined : line,
|
|
186
284
|
message: (() => {
|
|
187
|
-
|
|
188
|
-
problem.message && problem.message.toLowerCase() !==
|
|
285
|
+
let raw =
|
|
286
|
+
problem.message && problem.message.toLowerCase() !== 'failed'
|
|
189
287
|
? problem.message
|
|
190
288
|
: (bodyLocation?.message ??
|
|
191
289
|
panicInfo?.message ??
|
|
192
290
|
problem.message ??
|
|
193
|
-
problem[
|
|
291
|
+
problem['#text']?.trim().split('\n')[0]);
|
|
194
292
|
if (!raw) return undefined;
|
|
293
|
+
raw = stripPestTestNamePrefix(raw, tc.name);
|
|
195
294
|
const decoded = decodeXmlEntities(raw);
|
|
196
295
|
// Append assertion diff lines (Expected/Received/Actual) from the body when not already present.
|
|
197
296
|
// Covers Jest-style failures where the diff follows the error type line in #text.
|
|
198
297
|
if (
|
|
199
|
-
problem[
|
|
200
|
-
!decoded.includes(
|
|
201
|
-
!decoded.includes(
|
|
202
|
-
!decoded.includes(
|
|
298
|
+
problem['#text'] &&
|
|
299
|
+
!decoded.includes('Expected') &&
|
|
300
|
+
!decoded.includes('Received') &&
|
|
301
|
+
!decoded.includes('Actual')
|
|
203
302
|
) {
|
|
204
|
-
const diff = extractAssertionDiff(problem[
|
|
303
|
+
const diff = extractAssertionDiff(problem['#text']);
|
|
205
304
|
if (diff) return `${decoded}\n${diff}`;
|
|
206
305
|
}
|
|
207
306
|
return decoded;
|
|
@@ -215,8 +314,8 @@ const parser: ParserModule = {
|
|
|
215
314
|
const passed = totalTests - totalFailed;
|
|
216
315
|
|
|
217
316
|
return {
|
|
218
|
-
tool:
|
|
219
|
-
status: totalFailed > 0 ?
|
|
317
|
+
tool: 'junit',
|
|
318
|
+
status: totalFailed > 0 ? 'fail' : 'pass',
|
|
220
319
|
summary: totalFailed > 0 ? `${totalFailed} failed, ${passed} passed` : `${passed} passed`,
|
|
221
320
|
failures,
|
|
222
321
|
logPath: ctx.logPath,
|