@robhowley/pi-structured-return 1.10.1 → 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.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -83
  3. package/extensions/structured-return/config/registry.ts +4 -30
  4. package/extensions/structured-return/index.ts +105 -76
  5. package/extensions/structured-return/native.ts +223 -0
  6. package/extensions/structured-return/parsers/ava-text.ts +2 -168
  7. package/extensions/structured-return/parsers/bandit-json.ts +2 -79
  8. package/extensions/structured-return/parsers/black-text.ts +2 -73
  9. package/extensions/structured-return/parsers/cargo-build.ts +2 -78
  10. package/extensions/structured-return/parsers/cargo-test.ts +2 -135
  11. package/extensions/structured-return/parsers/checkstyle-xml.ts +2 -182
  12. package/extensions/structured-return/parsers/clang-text.ts +2 -60
  13. package/extensions/structured-return/parsers/dbt-json.ts +2 -135
  14. package/extensions/structured-return/parsers/dotnet-build-text.ts +2 -49
  15. package/extensions/structured-return/parsers/eslint-json.ts +2 -38
  16. package/extensions/structured-return/parsers/go-test-json.ts +2 -138
  17. package/extensions/structured-return/parsers/hadolint-json.ts +2 -60
  18. package/extensions/structured-return/parsers/htmlhint-json.ts +2 -73
  19. package/extensions/structured-return/parsers/isort-text.ts +2 -63
  20. package/extensions/structured-return/parsers/javac-text.ts +2 -82
  21. package/extensions/structured-return/parsers/jsonlint-text.ts +2 -65
  22. package/extensions/structured-return/parsers/junit-xml.ts +2 -325
  23. package/extensions/structured-return/parsers/markdownlint-json.ts +2 -74
  24. package/extensions/structured-return/parsers/minitest-text.ts +2 -107
  25. package/extensions/structured-return/parsers/mocha-json.ts +2 -83
  26. package/extensions/structured-return/parsers/mypy-json.ts +2 -79
  27. package/extensions/structured-return/parsers/node-test-text.ts +2 -92
  28. package/extensions/structured-return/parsers/npm-audit-json.ts +2 -90
  29. package/extensions/structured-return/parsers/prettier-text.ts +2 -66
  30. package/extensions/structured-return/parsers/pylint-json.ts +2 -63
  31. package/extensions/structured-return/parsers/pyright-json.ts +2 -82
  32. package/extensions/structured-return/parsers/rspec-json.ts +2 -75
  33. package/extensions/structured-return/parsers/rubocop-json.ts +2 -75
  34. package/extensions/structured-return/parsers/ruff-json.ts +2 -36
  35. package/extensions/structured-return/parsers/shellcheck-json.ts +2 -60
  36. package/extensions/structured-return/parsers/stylelint-json.ts +2 -75
  37. package/extensions/structured-return/parsers/swiftc-text.ts +2 -52
  38. package/extensions/structured-return/parsers/tail-fallback.ts +2 -19
  39. package/extensions/structured-return/parsers/tidy-text.ts +2 -66
  40. package/extensions/structured-return/parsers/tsc-text.ts +2 -46
  41. package/extensions/structured-return/parsers/unittest-text.ts +2 -125
  42. package/extensions/structured-return/parsers/utils.ts +28 -0
  43. package/extensions/structured-return/parsers/vale-json.ts +2 -79
  44. package/extensions/structured-return/parsers/vitest-json.ts +2 -59
  45. package/extensions/structured-return/storage/log-store.ts +0 -15
  46. package/extensions/structured-return/types.ts +1 -14
  47. package/native/Cargo.lock +193 -0
  48. package/native/Cargo.toml +21 -0
  49. package/native/THIRD-PARTY-LICENSES.txt +3660 -0
  50. package/native/bin/darwin-arm64/build.json +7 -0
  51. package/native/bin/darwin-arm64/structured-return-native +0 -0
  52. package/native/bin/darwin-x64/build.json +7 -0
  53. package/native/bin/darwin-x64/structured-return-native +0 -0
  54. package/native/bin/linux-arm64-musl/build.json +7 -0
  55. package/native/bin/linux-arm64-musl/structured-return-native +0 -0
  56. package/native/bin/linux-x64-musl/build.json +7 -0
  57. package/native/bin/linux-x64-musl/structured-return-native +0 -0
  58. package/native/src/common.rs +118 -0
  59. package/native/src/main.rs +55 -0
  60. package/native/src/parsers/ava_text.rs +125 -0
  61. package/native/src/parsers/bandit_json.rs +120 -0
  62. package/native/src/parsers/black_text.rs +45 -0
  63. package/native/src/parsers/cargo_build.rs +96 -0
  64. package/native/src/parsers/cargo_test.rs +140 -0
  65. package/native/src/parsers/checkstyle_xml.rs +137 -0
  66. package/native/src/parsers/clang_text.rs +39 -0
  67. package/native/src/parsers/compiler_helpers.rs +74 -0
  68. package/native/src/parsers/dbt_json.rs +243 -0
  69. package/native/src/parsers/dotnet_build_text.rs +50 -0
  70. package/native/src/parsers/eslint_json.rs +58 -0
  71. package/native/src/parsers/go_test_json.rs +346 -0
  72. package/native/src/parsers/hadolint_json.rs +37 -0
  73. package/native/src/parsers/htmlhint_json.rs +71 -0
  74. package/native/src/parsers/isort_text.rs +22 -0
  75. package/native/src/parsers/javac_text.rs +49 -0
  76. package/native/src/parsers/json_support.rs +287 -0
  77. package/native/src/parsers/jsonlint_text.rs +50 -0
  78. package/native/src/parsers/junit_xml.rs +430 -0
  79. package/native/src/parsers/markdownlint_json.rs +68 -0
  80. package/native/src/parsers/minitest_text.rs +91 -0
  81. package/native/src/parsers/mocha_json.rs +75 -0
  82. package/native/src/parsers/mod.rs +119 -0
  83. package/native/src/parsers/mypy_json.rs +93 -0
  84. package/native/src/parsers/node_test_text.rs +106 -0
  85. package/native/src/parsers/npm_audit_json.rs +119 -0
  86. package/native/src/parsers/prettier_text.rs +34 -0
  87. package/native/src/parsers/pylint_json.rs +44 -0
  88. package/native/src/parsers/pyright_json.rs +88 -0
  89. package/native/src/parsers/rspec_json.rs +84 -0
  90. package/native/src/parsers/rubocop_json.rs +46 -0
  91. package/native/src/parsers/ruff_json.rs +30 -0
  92. package/native/src/parsers/shellcheck_json.rs +40 -0
  93. package/native/src/parsers/stylelint_json.rs +46 -0
  94. package/native/src/parsers/swiftc_text.rs +38 -0
  95. package/native/src/parsers/tail_fallback.rs +51 -0
  96. package/native/src/parsers/test_helpers.rs +172 -0
  97. package/native/src/parsers/tidy_text.rs +77 -0
  98. package/native/src/parsers/tsc_text.rs +28 -0
  99. package/native/src/parsers/unittest_text.rs +125 -0
  100. package/native/src/parsers/vale_json.rs +66 -0
  101. package/native/src/parsers/vitest_json.rs +71 -0
  102. package/native/src/parsers/xml_support.rs +241 -0
  103. package/native/src/runner.rs +252 -0
  104. package/package.json +20 -6
  105. package/scripts/build-native.mjs +73 -0
  106. package/scripts/native-artifacts.mjs +69 -0
  107. package/skills/structured-return/SKILL.md +103 -249
  108. package/extensions/structured-return/config/project-config.ts +0 -10
  109. package/extensions/structured-return/examples/.pi/machine-readable.json +0 -18
  110. package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +0 -25
@@ -1,326 +1,3 @@
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';
1
+ import { nativeParser } from '../native';
5
2
 
6
- interface JUnitFailureOrError {
7
- message?: string;
8
- type?: string;
9
- '#text'?: string;
10
- }
11
-
12
- interface JUnitTestCase {
13
- name?: string;
14
- classname?: string;
15
- file?: string;
16
- line?: string | number;
17
- failure?: JUnitFailureOrError;
18
- error?: JUnitFailureOrError;
19
- }
20
-
21
- interface JUnitTestSuite {
22
- name?: string;
23
- file?: string;
24
- tests?: string | number;
25
- failures?: string | number;
26
- errors?: string | number;
27
- testcase?: JUnitTestCase[];
28
- testsuite?: JUnitTestSuite[]; // PHPUnit nests testsuites
29
- 'system-out'?: string;
30
- }
31
-
32
- interface JUnitDocument {
33
- testsuites?: { testsuite?: JUnitTestSuite[] };
34
- testsuite?: JUnitTestSuite[];
35
- }
36
-
37
- const xmlParser = new XMLParser({
38
- ignoreAttributes: false,
39
- attributeNamePrefix: '',
40
- isArray: (name) => ['testsuite', 'testcase'].includes(name),
41
- });
42
-
43
- /** Decode numeric XML character references (e.g. 
 → newline) in attribute values. */
44
- function decodeXmlEntities(s: string): string {
45
- return s
46
- .replace(/&#[xX]([0-9a-fA-F]+);/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
47
- .replace(/&#(\d+);/g, (_, dec) => String.fromCharCode(Number(dec)));
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
-
58
- /** Extract Expected/Received/Actual diff lines from a failure body, e.g. Jest assertion output. */
59
- function extractAssertionDiff(text: string): string | undefined {
60
- const diffLines: string[] = [];
61
- for (const line of text.split('\n')) {
62
- const trimmed = line.trim();
63
- if (/^(Expected|Received|Actual)\s*:/.test(trimmed)) diffLines.push(trimmed);
64
- }
65
- return diffLines.length > 0 ? diffLines.join('\n') : undefined;
66
- }
67
-
68
- /** Extract file, line, and message from failure body text.
69
- * Handles:
70
- * - pytest-style: "file.py:line: message"
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
75
- * - .NET-style: "in /path/File.cs:line N"
76
- * - Java/JVM-style: "at [module/]pkg.Class.method(File.java:N)"
77
- * preferring the frame whose class matches `classname`. */
78
- function parseBodyLocation(
79
- text: string,
80
- classname?: string,
81
- ): { file: string; line: number; message?: string } | undefined {
82
- const lines = text
83
- .split('\n')
84
- .map((l) => l.trim())
85
- .filter(Boolean);
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
-
113
- // pytest / Go: "file.ext:line: message"
114
- for (const line of lines) {
115
- const m = line.match(/^([^:\s]+\.\w+):(\d+):\s*(.*)/);
116
- if (m) return { file: m[1], line: Number(m[2]), message: m[3] || undefined };
117
- }
118
-
119
- // .NET: "in /path/File.cs:line N"
120
- for (const line of lines) {
121
- const m = line.match(/\bin ([^\s]+\.(?:cs|fs|vb)):line (\d+)/);
122
- if (m) return { file: path.basename(m[1]), line: Number(m[2]) };
123
- }
124
-
125
- // Java/JVM: "at [module/]pkg.Class.method(File.java:N)"
126
- const javaRe = /^at (?:[\w.$]+\/)?([\w.$]+)\.\w+\(([\w]+\.(?:java|kt|scala|groovy)):(\d+)\)$/;
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();
137
- let firstUserFrame: { file: string; line: number } | undefined;
138
-
139
- for (const line of lines) {
140
- const m = line.match(javaRe);
141
- if (!m) continue;
142
- const [, cls, file, lineNum] = m;
143
- if (simpleClass && cls === simpleClass) return { file, line: Number(lineNum) };
144
- if (!firstUserFrame && !frameworkPrefixes.some((p) => cls.startsWith(p))) {
145
- firstUserFrame = { file, line: Number(lineNum) };
146
- }
147
- }
148
-
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
-
161
- return undefined;
162
- }
163
-
164
- /** Extract panic message and file:line for a specific test from Go's system-out. */
165
- function parsePanicInfo(
166
- systemOut: string,
167
- testName: string,
168
- ): { message?: string; file?: string; line?: number } | undefined {
169
- const lines = systemOut.split('\n');
170
- const panicLine = lines.find((l) => l.trim().startsWith('panic:'));
171
- if (!panicLine) return undefined;
172
- const message = panicLine
173
- .trim()
174
- .replace(/^panic:\s*/, '')
175
- .replace(/\s*\[.*\]$/, '')
176
- .trim();
177
-
178
- // Find the stack frame for this test function, then grab the file:line on the next line
179
- for (let i = 0; i < lines.length - 1; i++) {
180
- if (lines[i].includes(`.${testName}(`)) {
181
- const m = lines[i + 1].trim().match(/^([^:]+\.go):(\d+)/);
182
- if (m) return { message, file: m[1].split('/').pop(), line: Number(m[2]) };
183
- }
184
- }
185
- return { message };
186
- }
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
-
201
- function resolveFile(tc: JUnitTestCase, suite: JUnitTestSuite, cwd: string): string | undefined {
202
- const raw = (tc.file ?? suite.file)?.split('::')[0];
203
- if (raw) return path.relative(cwd, path.resolve(cwd, raw));
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;
222
- }
223
-
224
- const parser: ParserModule = {
225
- id: 'junit-xml',
226
- async parse(ctx) {
227
- const artifactSources = ctx.artifactPaths.length > 0 ? ctx.artifactPaths : [ctx.stdoutPath];
228
-
229
- let totalTests = 0;
230
- let totalFailed = 0;
231
- const failures: ParsedFailure[] = [];
232
-
233
- for (const artifactPath of artifactSources) {
234
- const xml = safeReadFile(artifactPath);
235
- if (!xml.trim()) continue;
236
- const doc = xmlParser.parse(xml) as JUnitDocument;
237
-
238
- const topLevelSuites: JUnitTestSuite[] = doc.testsuites?.testsuite ?? doc.testsuite ?? [];
239
-
240
- // Count tests/failures from top-level only (nested suites report aggregates)
241
- for (const suite of topLevelSuites) {
242
- totalTests += Number(suite.tests ?? 0);
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);
248
-
249
- for (const suite of allSuites) {
250
- for (const tc of suite.testcase ?? []) {
251
- const rawProblem = tc.failure ?? tc.error;
252
- if (!rawProblem) continue;
253
- const problem: JUnitFailureOrError =
254
- typeof rawProblem === 'string' ? { '#text': rawProblem } : rawProblem;
255
-
256
- const bodyLocation = problem['#text']
257
- ? parseBodyLocation(problem['#text'], tc.classname)
258
- : undefined;
259
- const panicInfo =
260
- !bodyLocation && suite['system-out'] && tc.name
261
- ? parsePanicInfo(suite['system-out'], tc.name)
262
- : undefined;
263
- const file =
264
- (tc.file ?? suite.file)
265
- ? resolveFile(tc, suite, ctx.cwd)
266
- : (bodyLocation?.file ?? panicInfo?.file ?? resolveFile(tc, suite, ctx.cwd));
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(':');
279
-
280
- failures.push({
281
- id: id || String(failures.length),
282
- file,
283
- line: Number.isNaN(line) ? undefined : line,
284
- message: (() => {
285
- let raw =
286
- problem.message && problem.message.toLowerCase() !== 'failed'
287
- ? problem.message
288
- : (bodyLocation?.message ??
289
- panicInfo?.message ??
290
- problem.message ??
291
- problem['#text']?.trim().split('\n')[0]);
292
- if (!raw) return undefined;
293
- raw = stripPestTestNamePrefix(raw, tc.name);
294
- const decoded = decodeXmlEntities(raw);
295
- // Append assertion diff lines (Expected/Received/Actual) from the body when not already present.
296
- // Covers Jest-style failures where the diff follows the error type line in #text.
297
- if (
298
- problem['#text'] &&
299
- !decoded.includes('Expected') &&
300
- !decoded.includes('Received') &&
301
- !decoded.includes('Actual')
302
- ) {
303
- const diff = extractAssertionDiff(problem['#text']);
304
- if (diff) return `${decoded}\n${diff}`;
305
- }
306
- return decoded;
307
- })(),
308
- rule: problem.type,
309
- });
310
- }
311
- }
312
- }
313
-
314
- const passed = totalTests - totalFailed;
315
-
316
- return {
317
- tool: 'junit',
318
- status: totalFailed > 0 ? 'fail' : 'pass',
319
- summary: totalFailed > 0 ? `${totalFailed} failed, ${passed} passed` : `${passed} passed`,
320
- failures,
321
- logPath: ctx.logPath,
322
- };
323
- },
324
- };
325
-
326
- export default parser;
3
+ export default nativeParser('junit-xml');
@@ -1,75 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule, ParsedFailure } from '../types';
3
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
5
- interface MarkdownlintItem {
6
- fileName: string;
7
- lineNumber: number;
8
- ruleNames: string[];
9
- ruleDescription: string;
10
- errorDetail?: string | null;
11
- }
12
-
13
- const parser: ParserModule = {
14
- id: 'markdownlint-json',
15
- async parse(ctx) {
16
- const stdout = safeReadFile(ctx.stdoutPath).trim();
17
- if (!stdout) {
18
- return {
19
- tool: 'markdownlint',
20
- status: 'pass',
21
- summary: 'no lint errors',
22
- failures: [],
23
- logPath: ctx.logPath,
24
- };
25
- }
26
-
27
- let items: MarkdownlintItem[];
28
- try {
29
- items = JSON.parse(stdout);
30
- } catch {
31
- return {
32
- tool: 'markdownlint',
33
- status: 'error',
34
- summary: 'failed to parse markdownlint JSON output',
35
- logPath: ctx.logPath,
36
- };
37
- }
38
-
39
- if (!Array.isArray(items) || items.length === 0) {
40
- return {
41
- tool: 'markdownlint',
42
- status: 'pass',
43
- summary: 'no lint errors',
44
- failures: [],
45
- logPath: ctx.logPath,
46
- };
47
- }
48
-
49
- const failures: ParsedFailure[] = items.map((item) => {
50
- const relPath = path.relative(ctx.cwd, item.fileName);
51
- // Use the short MD code (first rule name, e.g. "MD041")
52
- const rule = item.ruleNames[0];
53
- const message = item.errorDetail
54
- ? `${item.ruleDescription}: ${item.errorDetail}`
55
- : item.ruleDescription;
56
- return {
57
- id: `${relPath}:${item.lineNumber}:${rule}`,
58
- file: relPath,
59
- line: item.lineNumber,
60
- message,
61
- rule,
62
- };
63
- });
64
-
65
- return {
66
- tool: 'markdownlint',
67
- status: 'fail',
68
- summary: `${failures.length} lint error${failures.length !== 1 ? 's' : ''}`,
69
- failures,
70
- logPath: ctx.logPath,
71
- };
72
- },
73
- };
74
-
75
- export default parser;
3
+ export default nativeParser('markdownlint-json');
@@ -1,108 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule, ParsedFailure } from '../types';
3
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
5
- /**
6
- * Parses minitest's default text output. No flags or reporters required —
7
- * works with plain `ruby test/my_test.rb` or `bundle exec ruby test/my_test.rb`.
8
- */
9
- const parser: ParserModule = {
10
- id: 'minitest-text',
11
- async parse(ctx) {
12
- const output = safeReadFile(ctx.stdoutPath);
13
-
14
- // "3 runs, 2 assertions, 1 failures, 1 errors, 0 skips"
15
- const summaryMatch = output.match(
16
- /(\d+) runs?, \d+ assertions?, (\d+) failures?, (\d+) errors?, (\d+) skips?/,
17
- );
18
- if (!summaryMatch) {
19
- return {
20
- tool: 'minitest',
21
- status: 'error',
22
- summary: 'no minitest output found',
23
- logPath: ctx.logPath,
24
- };
25
- }
26
-
27
- const totalRuns = parseInt(summaryMatch[1], 10);
28
- const failureCount = parseInt(summaryMatch[2], 10);
29
- const errorCount = parseInt(summaryMatch[3], 10);
30
- const skipCount = parseInt(summaryMatch[4], 10);
31
- const totalFailed = failureCount + errorCount;
32
- const passed = totalRuns - totalFailed - skipCount;
33
-
34
- const failures = parseBlocks(output, ctx.cwd);
35
-
36
- return {
37
- tool: 'minitest',
38
- status: totalFailed > 0 ? 'fail' : 'pass',
39
- summary: totalFailed > 0 ? `${totalFailed} failed, ${passed} passed` : `${passed} passed`,
40
- failures,
41
- logPath: ctx.logPath,
42
- };
43
- },
44
- };
45
-
46
- export default parser;
47
-
48
- function parseBlocks(output: string, cwd: string): ParsedFailure[] {
49
- const failures: ParsedFailure[] = [];
50
- const lines = output.split('\n');
51
- let i = 0;
52
-
53
- while (i < lines.length) {
54
- const headerMatch = lines[i].match(/^\s+\d+\) (Failure|Error):$/);
55
- if (!headerMatch) {
56
- i++;
57
- continue;
58
- }
59
-
60
- const type = headerMatch[1];
61
- i++;
62
-
63
- if (type === 'Failure') {
64
- // "ClassName#method [file:line]:"
65
- const nameMatch = lines[i]?.match(/^(.+?)\s+\[(.+):(\d+)\]:$/);
66
- if (nameMatch) {
67
- const [, id, rawFile, lineStr] = nameMatch;
68
- i++;
69
- // Message lines until blank line
70
- const msgLines: string[] = [];
71
- while (i < lines.length && lines[i].trim() !== '') {
72
- msgLines.push(lines[i].trim());
73
- i++;
74
- }
75
- failures.push({
76
- id,
77
- file: path.relative(cwd, path.resolve(cwd, rawFile)),
78
- line: parseInt(lineStr, 10),
79
- message: msgLines.filter(Boolean).join(' / ') || undefined,
80
- });
81
- }
82
- } else {
83
- // Error — "ClassName#method:"
84
- const nameMatch = lines[i]?.match(/^(.+):$/);
85
- if (nameMatch) {
86
- const id = nameMatch[1];
87
- i++;
88
- // "ExceptionClass: message"
89
- const exceptionLine = lines[i]?.trim() ?? '';
90
- const colonIdx = exceptionLine.indexOf(': ');
91
- const message = colonIdx !== -1 ? exceptionLine.slice(colonIdx + 2) : exceptionLine;
92
- i++;
93
- // First backtrace line: " file.rb:line:in 'method'"
94
- const backtraceMatch = lines[i]?.match(/^\s+(.+\.rb):(\d+):/);
95
- failures.push({
96
- id,
97
- file: backtraceMatch
98
- ? path.relative(cwd, path.resolve(cwd, backtraceMatch[1]))
99
- : undefined,
100
- line: backtraceMatch ? parseInt(backtraceMatch[2], 10) : undefined,
101
- message: message || undefined,
102
- });
103
- }
104
- }
105
- }
106
-
107
- return failures;
108
- }
3
+ export default nativeParser('minitest-text');
@@ -1,84 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule, ParsedFailure } from '../types';
3
- import { extractJsStackLocation, safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
5
- interface MochaErr {
6
- message?: string;
7
- stack?: string;
8
- actual?: string;
9
- expected?: string;
10
- operator?: string;
11
- code?: string;
12
- name?: string;
13
- }
14
-
15
- interface MochaTest {
16
- title: string;
17
- fullTitle: string;
18
- file: string;
19
- err: MochaErr;
20
- }
21
-
22
- interface MochaReport {
23
- stats: { passes: number; failures: number };
24
- failures: MochaTest[];
25
- }
26
-
27
- /** Build a compact failure message. For assertions, include expected/actual. */
28
- function buildMessage(err: MochaErr): string {
29
- if (err.actual !== undefined && err.expected !== undefined) {
30
- return `expected ${err.expected}, got ${err.actual}`;
31
- }
32
- // First line of message, stripped of newlines
33
- const firstLine = (err.message ?? 'test failed').split('\n')[0].trim();
34
- return firstLine;
35
- }
36
-
37
- const parser: ParserModule = {
38
- id: 'mocha-json',
39
- async parse(ctx) {
40
- const stdout = safeReadFile(ctx.stdoutPath).trim();
41
- if (!stdout) {
42
- return { tool: 'mocha', status: 'error', summary: 'no output', logPath: ctx.logPath };
43
- }
44
-
45
- let report: MochaReport;
46
- try {
47
- report = JSON.parse(stdout) as MochaReport;
48
- } catch {
49
- return {
50
- tool: 'mocha',
51
- status: 'error',
52
- summary: 'failed to parse mocha JSON output',
53
- logPath: ctx.logPath,
54
- };
55
- }
56
-
57
- const failures: ParsedFailure[] = report.failures.map((test) => {
58
- const loc = extractJsStackLocation(test.err.stack);
59
- const relFile = loc.file
60
- ? path.relative(ctx.cwd, path.resolve(ctx.cwd, loc.file))
61
- : undefined;
62
- return {
63
- id: test.fullTitle,
64
- file: relFile,
65
- line: loc.line,
66
- message: buildMessage(test.err),
67
- rule: test.err.code ?? test.err.name,
68
- };
69
- });
70
-
71
- const failed = report.stats.failures;
72
- const passed = report.stats.passes;
73
-
74
- return {
75
- tool: 'mocha',
76
- status: failed > 0 ? 'fail' : 'pass',
77
- summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
78
- failures,
79
- logPath: ctx.logPath,
80
- };
81
- },
82
- };
83
-
84
- export default parser;
3
+ export default nativeParser('mocha-json');
@@ -1,80 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule, ParsedFailure } from '../types';
3
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
5
- interface MypyItem {
6
- file: string;
7
- line: number;
8
- column: number;
9
- message: string;
10
- hint: string | null;
11
- code: string | null;
12
- severity: 'error' | 'note';
13
- }
14
-
15
- const parser: ParserModule = {
16
- id: 'mypy-json',
17
- async parse(ctx) {
18
- // mypy --output json writes JSON diagnostics to stderr (stdout gets the human summary).
19
- const stderr = safeReadFile(ctx.stderrPath).trim();
20
- if (!stderr) {
21
- return {
22
- tool: 'mypy',
23
- status: 'pass',
24
- summary: 'no type errors',
25
- failures: [],
26
- logPath: ctx.logPath,
27
- };
28
- }
29
-
30
- const items: MypyItem[] = [];
31
- for (const line of stderr.split('\n')) {
32
- const trimmed = line.trim();
33
- if (!trimmed) continue;
34
- try {
35
- items.push(JSON.parse(trimmed) as MypyItem);
36
- } catch {
37
- // skip non-JSON lines (e.g. summary text on stderr)
38
- }
39
- }
40
-
41
- const errors = items.filter((item) => item.severity === 'error');
42
- // Build a map of notes keyed by normalized relative path:line so lookups
43
- // match regardless of whether mypy emits absolute or relative paths.
44
- const relPathOf = (f: string) => (path.isAbsolute(f) ? path.relative(ctx.cwd, f) : f);
45
- const notesByLocation = new Map<string, string[]>();
46
- for (const item of items) {
47
- if (item.severity === 'note') {
48
- const key = `${relPathOf(item.file)}:${item.line}`;
49
- const notes = notesByLocation.get(key) ?? [];
50
- notes.push(item.message);
51
- notesByLocation.set(key, notes);
52
- }
53
- }
54
-
55
- const failures: ParsedFailure[] = errors.map((item) => {
56
- const relPath = relPathOf(item.file);
57
- const key = `${relPath}:${item.line}`;
58
- const notes = notesByLocation.get(key);
59
- const hint = item.hint ?? (notes ? notes.join('; ') : undefined);
60
- const message = hint ? `${item.message} (${hint})` : item.message;
61
- return {
62
- id: `${relPath}:${item.line}:${item.code ?? 'error'}`,
63
- file: relPath,
64
- line: item.line,
65
- message,
66
- rule: item.code ?? undefined,
67
- };
68
- });
69
-
70
- return {
71
- tool: 'mypy',
72
- status: failures.length > 0 ? 'fail' : 'pass',
73
- summary: failures.length > 0 ? `${failures.length} type errors` : 'no type errors',
74
- failures,
75
- logPath: ctx.logPath,
76
- };
77
- },
78
- };
79
-
80
- export default parser;
3
+ export default nativeParser('mypy-json');