@robhowley/pi-structured-return 1.4.0 → 1.5.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 +79 -75
- package/extensions/structured-return/src/config/registry.test.ts +171 -0
- package/extensions/structured-return/src/config/registry.ts +91 -14
- package/extensions/structured-return/src/index.test.ts +54 -0
- package/extensions/structured-return/src/index.ts +20 -9
- package/extensions/structured-return/src/parsers/ava-text.test.ts +116 -0
- package/extensions/structured-return/src/parsers/ava-text.ts +161 -0
- package/extensions/structured-return/src/parsers/cargo-build.ts +2 -2
- package/extensions/structured-return/src/parsers/cargo-test.ts +2 -2
- package/extensions/structured-return/src/parsers/dbt-json.ts +2 -2
- package/extensions/structured-return/src/parsers/eslint-json.ts +2 -2
- package/extensions/structured-return/src/parsers/go-test-json.test.ts +119 -0
- package/extensions/structured-return/src/parsers/go-test-json.ts +137 -0
- package/extensions/structured-return/src/parsers/hadolint-json.test.ts +73 -0
- package/extensions/structured-return/src/parsers/hadolint-json.ts +55 -0
- package/extensions/structured-return/src/parsers/junit-xml.ts +2 -2
- package/extensions/structured-return/src/parsers/minitest-text.ts +2 -2
- package/extensions/structured-return/src/parsers/mocha-json.test.ts +108 -0
- package/extensions/structured-return/src/parsers/mocha-json.ts +77 -0
- package/extensions/structured-return/src/parsers/mypy-json.test.ts +101 -0
- package/extensions/structured-return/src/parsers/mypy-json.ts +80 -0
- package/extensions/structured-return/src/parsers/pylint-json.test.ts +120 -0
- package/extensions/structured-return/src/parsers/pylint-json.ts +64 -0
- package/extensions/structured-return/src/parsers/rspec-json.ts +2 -2
- package/extensions/structured-return/src/parsers/rubocop-json.test.ts +118 -0
- package/extensions/structured-return/src/parsers/rubocop-json.ts +65 -0
- package/extensions/structured-return/src/parsers/ruff-json.ts +2 -2
- package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +110 -0
- package/extensions/structured-return/src/parsers/shellcheck-json.ts +61 -0
- package/extensions/structured-return/src/parsers/stylelint-json.test.ts +120 -0
- package/extensions/structured-return/src/parsers/stylelint-json.ts +68 -0
- package/extensions/structured-return/src/parsers/swiftc-text.test.ts +73 -0
- package/extensions/structured-return/src/parsers/swiftc-text.ts +47 -0
- package/extensions/structured-return/src/parsers/tail-fallback.ts +2 -2
- package/extensions/structured-return/src/parsers/tsc-text.test.ts +81 -0
- package/extensions/structured-return/src/parsers/tsc-text.ts +47 -0
- package/extensions/structured-return/src/parsers/unittest-text.test.ts +126 -0
- package/extensions/structured-return/src/parsers/unittest-text.ts +116 -0
- package/extensions/structured-return/src/parsers/utils.ts +43 -0
- package/extensions/structured-return/src/parsers/vitest-json.ts +2 -2
- package/package.json +1 -1
- package/skills/structured-return/SKILL.md +39 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import type { ParserModule } from "../types";
|
|
2
|
+
import { safeReadFile } from "./utils";
|
|
3
3
|
|
|
4
4
|
const parser: ParserModule = {
|
|
5
5
|
id: "tail-fallback",
|
|
6
6
|
async parse(ctx) {
|
|
7
|
-
const log =
|
|
7
|
+
const log = safeReadFile(ctx.logPath);
|
|
8
8
|
const lines = log.split(/\r?\n/);
|
|
9
9
|
const tail = lines.slice(-200).join("\n");
|
|
10
10
|
return {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { describe, it, expect } from "vitest";
|
|
5
|
+
import parser from "./tsc-text";
|
|
6
|
+
import type { RunContext } from "../types";
|
|
7
|
+
|
|
8
|
+
function makeCtx(stdout: string, cwd = "/project"): RunContext {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "tsc-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "tsc --noEmit --pretty false",
|
|
14
|
+
argv: ["tsc", "--noEmit", "--pretty", "false"],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("tsc-text parser", () => {
|
|
24
|
+
it("multiple type errors → correct file, line, message, rule, status fail", async () => {
|
|
25
|
+
const stdout = [
|
|
26
|
+
"type_check.ts(5,7): error TS2322: Type 'number' is not assignable to type 'string'.",
|
|
27
|
+
"type_check.ts(6,27): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.",
|
|
28
|
+
].join("\n");
|
|
29
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
30
|
+
expect(result.status).toBe("fail");
|
|
31
|
+
expect(result.summary).toBe("2 type errors");
|
|
32
|
+
expect(result.failures).toHaveLength(2);
|
|
33
|
+
expect(result.failures![0]).toMatchObject({
|
|
34
|
+
file: "type_check.ts",
|
|
35
|
+
line: 5,
|
|
36
|
+
message: "Type 'number' is not assignable to type 'string'.",
|
|
37
|
+
rule: "TS2322",
|
|
38
|
+
});
|
|
39
|
+
expect(result.failures![1]).toMatchObject({
|
|
40
|
+
file: "type_check.ts",
|
|
41
|
+
line: 6,
|
|
42
|
+
message: "Argument of type 'string' is not assignable to parameter of type 'number'.",
|
|
43
|
+
rule: "TS2345",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("no errors (empty stdout) → status pass", async () => {
|
|
48
|
+
const result = await parser.parse(makeCtx(""));
|
|
49
|
+
expect(result.status).toBe("pass");
|
|
50
|
+
expect(result.summary).toBe("no type errors");
|
|
51
|
+
expect(result.failures).toHaveLength(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("absolute file paths → relativized to cwd", async () => {
|
|
55
|
+
const stdout = "/project/src/foo.ts(10,5): error TS2304: Cannot find name 'bar'.";
|
|
56
|
+
const result = await parser.parse(makeCtx(stdout, "/project"));
|
|
57
|
+
expect(result.failures![0].file).toBe("src/foo.ts");
|
|
58
|
+
expect(result.failures![0].file).not.toContain("/project");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("errors across multiple files", async () => {
|
|
62
|
+
const stdout = [
|
|
63
|
+
"src/a.ts(1,1): error TS2304: Cannot find name 'foo'.",
|
|
64
|
+
"src/b.ts(5,3): error TS2551: Property 'baz' does not exist on type 'Bar'.",
|
|
65
|
+
].join("\n");
|
|
66
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
67
|
+
expect(result.failures).toHaveLength(2);
|
|
68
|
+
expect(result.failures![0].file).toBe("src/a.ts");
|
|
69
|
+
expect(result.failures![1].file).toBe("src/b.ts");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("skips non-error lines (e.g. Found N errors)", async () => {
|
|
73
|
+
const stdout = [
|
|
74
|
+
"type_check.ts(5,7): error TS2322: Type 'number' is not assignable to type 'string'.",
|
|
75
|
+
"",
|
|
76
|
+
"Found 1 error in type_check.ts:5",
|
|
77
|
+
].join("\n");
|
|
78
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
79
|
+
expect(result.failures).toHaveLength(1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
// tsc --pretty false format: file(line,col): error TSXXXX: message
|
|
6
|
+
const TSC_LINE = /^(.+?)\((\d+),(\d+)\):\s+error\s+(TS\d+):\s+(.+)$/;
|
|
7
|
+
|
|
8
|
+
const parser: ParserModule = {
|
|
9
|
+
id: "tsc-text",
|
|
10
|
+
async parse(ctx) {
|
|
11
|
+
const raw = safeReadFile(ctx.stdoutPath).trim();
|
|
12
|
+
if (!raw) {
|
|
13
|
+
return {
|
|
14
|
+
tool: "tsc",
|
|
15
|
+
status: "pass",
|
|
16
|
+
summary: "no type errors",
|
|
17
|
+
failures: [],
|
|
18
|
+
logPath: ctx.logPath,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const failures: ParsedFailure[] = [];
|
|
23
|
+
for (const line of raw.split("\n")) {
|
|
24
|
+
const m = line.match(TSC_LINE);
|
|
25
|
+
if (!m) continue;
|
|
26
|
+
const [, file, lineNum, , code, message] = m;
|
|
27
|
+
const relPath = path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file;
|
|
28
|
+
failures.push({
|
|
29
|
+
id: `${relPath}:${lineNum}:${code}`,
|
|
30
|
+
file: relPath,
|
|
31
|
+
line: Number(lineNum),
|
|
32
|
+
message,
|
|
33
|
+
rule: code,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
tool: "tsc",
|
|
39
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
40
|
+
summary: failures.length > 0 ? `${failures.length} type errors` : "no type errors",
|
|
41
|
+
failures,
|
|
42
|
+
logPath: ctx.logPath,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default parser;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { describe, it, expect } from "vitest";
|
|
5
|
+
import parser from "./unittest-text";
|
|
6
|
+
import type { RunContext } from "../types";
|
|
7
|
+
|
|
8
|
+
function makeCtx(stderr: string, cwd = "/project"): RunContext {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "unittest-test-"));
|
|
10
|
+
const stderrPath = path.join(dir, "stderr");
|
|
11
|
+
fs.writeFileSync(stderrPath, stderr);
|
|
12
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
13
|
+
fs.writeFileSync(stdoutPath, "");
|
|
14
|
+
return {
|
|
15
|
+
command: "python3 -m unittest test_math.py",
|
|
16
|
+
argv: ["python3", "-m", "unittest", "test_math.py"],
|
|
17
|
+
cwd,
|
|
18
|
+
artifactPaths: [],
|
|
19
|
+
stdoutPath,
|
|
20
|
+
stderrPath,
|
|
21
|
+
logPath: path.join(dir, "log"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const REAL_FAILURE_OUTPUT = `.EF
|
|
26
|
+
======================================================================
|
|
27
|
+
ERROR: test_does_not_divide_by_zero (test_math.TestMath.test_does_not_divide_by_zero)
|
|
28
|
+
----------------------------------------------------------------------
|
|
29
|
+
Traceback (most recent call last):
|
|
30
|
+
File "/project/test_math.py", line 12, in test_does_not_divide_by_zero
|
|
31
|
+
result = 1 / 0
|
|
32
|
+
~~^~~
|
|
33
|
+
ZeroDivisionError: division by zero
|
|
34
|
+
|
|
35
|
+
======================================================================
|
|
36
|
+
FAIL: test_multiplies_two_numbers_correctly (test_math.TestMath.test_multiplies_two_numbers_correctly)
|
|
37
|
+
----------------------------------------------------------------------
|
|
38
|
+
Traceback (most recent call last):
|
|
39
|
+
File "/project/test_math.py", line 9, in test_multiplies_two_numbers_correctly
|
|
40
|
+
self.assertEqual(3 * 4, 99)
|
|
41
|
+
~~~~~~~~~~~~~~~~^^^^^^^^^^^
|
|
42
|
+
AssertionError: 12 != 99
|
|
43
|
+
|
|
44
|
+
----------------------------------------------------------------------
|
|
45
|
+
Ran 3 tests in 0.001s
|
|
46
|
+
|
|
47
|
+
FAILED (failures=1, errors=1)`;
|
|
48
|
+
|
|
49
|
+
describe("unittest-text parser", () => {
|
|
50
|
+
it("real output → assertion failure with expected/actual, runtime error with message", async () => {
|
|
51
|
+
const result = await parser.parse(makeCtx(REAL_FAILURE_OUTPUT));
|
|
52
|
+
expect(result.status).toBe("fail");
|
|
53
|
+
expect(result.summary).toBe("2 failed, 1 passed");
|
|
54
|
+
expect(result.failures).toHaveLength(2);
|
|
55
|
+
|
|
56
|
+
// ERROR block
|
|
57
|
+
const err = result.failures!.find((f) => f.rule === "error")!;
|
|
58
|
+
expect(err.file).toBe("test_math.py");
|
|
59
|
+
expect(err.line).toBe(12);
|
|
60
|
+
expect(err.message).toBe("ZeroDivisionError: division by zero");
|
|
61
|
+
|
|
62
|
+
// FAIL block
|
|
63
|
+
const fail = result.failures!.find((f) => f.rule === "assertion")!;
|
|
64
|
+
expect(fail.file).toBe("test_math.py");
|
|
65
|
+
expect(fail.line).toBe(9);
|
|
66
|
+
expect(fail.message).toBe("12 != 99");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("all passing → status pass", async () => {
|
|
70
|
+
const stderr = `...
|
|
71
|
+
----------------------------------------------------------------------
|
|
72
|
+
Ran 3 tests in 0.001s
|
|
73
|
+
|
|
74
|
+
OK`;
|
|
75
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
76
|
+
expect(result.status).toBe("pass");
|
|
77
|
+
expect(result.summary).toBe("3 passed");
|
|
78
|
+
expect(result.failures).toHaveLength(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("empty stderr → status pass", async () => {
|
|
82
|
+
const result = await parser.parse(makeCtx(""));
|
|
83
|
+
expect(result.status).toBe("pass");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("file paths relativized to cwd", async () => {
|
|
87
|
+
const result = await parser.parse(makeCtx(REAL_FAILURE_OUTPUT, "/project"));
|
|
88
|
+
for (const f of result.failures!) {
|
|
89
|
+
expect(f.file).not.toContain("/project/");
|
|
90
|
+
expect(f.file).toBe("test_math.py");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("skipped tests are not counted as passed", async () => {
|
|
95
|
+
const stderr = `.sF
|
|
96
|
+
======================================================================
|
|
97
|
+
FAIL: test_fail (test_math.TestMath.test_fail)
|
|
98
|
+
----------------------------------------------------------------------
|
|
99
|
+
Traceback (most recent call last):
|
|
100
|
+
File "/project/test_math.py", line 8, in test_fail
|
|
101
|
+
self.assertEqual(1, 2)
|
|
102
|
+
~~~~~~~~~~~~~~~~^^^^^^
|
|
103
|
+
AssertionError: 1 != 2
|
|
104
|
+
|
|
105
|
+
----------------------------------------------------------------------
|
|
106
|
+
Ran 3 tests in 0.001s
|
|
107
|
+
|
|
108
|
+
FAILED (failures=1, skipped=1)`;
|
|
109
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
110
|
+
expect(result.status).toBe("fail");
|
|
111
|
+
// 3 total - 1 failed - 1 skipped = 1 passed (not 2)
|
|
112
|
+
expect(result.summary).toBe("1 failed, 1 passed");
|
|
113
|
+
expect(result.failures).toHaveLength(1);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("all passing with skips → correct passed count", async () => {
|
|
117
|
+
const stderr = `.s
|
|
118
|
+
----------------------------------------------------------------------
|
|
119
|
+
Ran 2 tests in 0.001s
|
|
120
|
+
|
|
121
|
+
OK (skipped=1)`;
|
|
122
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
123
|
+
expect(result.status).toBe("pass");
|
|
124
|
+
expect(result.summary).toBe("1 passed");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
// unittest output blocks are separated by ======
|
|
6
|
+
// Each block starts with ERROR: or FAIL: line
|
|
7
|
+
// Then a Traceback with file:line, and the final line is the error/assertion message
|
|
8
|
+
|
|
9
|
+
const BLOCK_HEADER = /(ERROR|FAIL):\s+(\S+)\s+\(([^)]+)\)/;
|
|
10
|
+
const FILE_LINE = /File\s+"([^"]+)",\s+line\s+(\d+)/;
|
|
11
|
+
|
|
12
|
+
const parser: ParserModule = {
|
|
13
|
+
id: "unittest-text",
|
|
14
|
+
async parse(ctx) {
|
|
15
|
+
// Python unittest writes all output (results, tracebacks, summary) to stderr.
|
|
16
|
+
const stderr = safeReadFile(ctx.stderrPath).trim();
|
|
17
|
+
if (!stderr) {
|
|
18
|
+
return { tool: "unittest", status: "pass", summary: "no output", failures: [], logPath: ctx.logPath };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Parse the summary line: "Ran N tests in Xs" and "FAILED (failures=N, errors=N)" or "OK"
|
|
22
|
+
const ranMatch = stderr.match(/Ran\s+(\d+)\s+test/);
|
|
23
|
+
const totalTests = ranMatch ? Number(ranMatch[1]) : 0;
|
|
24
|
+
// Parse skipped count from "FAILED (failures=N, skipped=N)" or "OK (skipped=N)"
|
|
25
|
+
const skippedMatch = stderr.match(/skipped=(\d+)/);
|
|
26
|
+
const skipped = skippedMatch ? Number(skippedMatch[1]) : 0;
|
|
27
|
+
const isOk = stderr.includes("\nOK");
|
|
28
|
+
|
|
29
|
+
if (isOk) {
|
|
30
|
+
const passed = totalTests - skipped;
|
|
31
|
+
return {
|
|
32
|
+
tool: "unittest",
|
|
33
|
+
status: "pass",
|
|
34
|
+
summary: `${passed} passed`,
|
|
35
|
+
failures: [],
|
|
36
|
+
logPath: ctx.logPath,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Split into blocks by the ====== separator
|
|
41
|
+
const blocks = stderr.split(/={50,}/);
|
|
42
|
+
const failures: ParsedFailure[] = [];
|
|
43
|
+
|
|
44
|
+
for (const block of blocks) {
|
|
45
|
+
const headerMatch = block.match(BLOCK_HEADER);
|
|
46
|
+
if (!headerMatch) continue;
|
|
47
|
+
|
|
48
|
+
const [, kind, testName] = headerMatch;
|
|
49
|
+
const lines = block.split("\n");
|
|
50
|
+
|
|
51
|
+
// Find the last File "..." line in the traceback (the user code, not framework)
|
|
52
|
+
let file: string | undefined;
|
|
53
|
+
let line: number | undefined;
|
|
54
|
+
for (const l of lines) {
|
|
55
|
+
const fm = l.match(FILE_LINE);
|
|
56
|
+
if (fm) {
|
|
57
|
+
file = fm[1];
|
|
58
|
+
line = Number(fm[2]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The error message is the last non-empty line of the traceback block.
|
|
63
|
+
// Stop at dashed separators (------) that come AFTER the traceback,
|
|
64
|
+
// summary lines ("Ran N tests"), or FAILED/OK lines.
|
|
65
|
+
const traceLines: string[] = [];
|
|
66
|
+
let pastHeader = false;
|
|
67
|
+
for (const l of lines) {
|
|
68
|
+
const trimmed = l.trim();
|
|
69
|
+
if (!pastHeader) {
|
|
70
|
+
// Skip until we're past the initial header + first dashed separator
|
|
71
|
+
if (/^-{10,}/.test(trimmed)) {
|
|
72
|
+
pastHeader = true;
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
// Stop at the next dashed separator (before summary) or summary lines
|
|
77
|
+
if (/^-{10,}/.test(trimmed)) break;
|
|
78
|
+
if (/^Ran\s+\d+\s+test/.test(trimmed)) break;
|
|
79
|
+
if (/^(FAILED|OK)/.test(trimmed)) break;
|
|
80
|
+
traceLines.push(trimmed);
|
|
81
|
+
}
|
|
82
|
+
const nonEmpty = traceLines.filter(Boolean);
|
|
83
|
+
const errorLine = nonEmpty[nonEmpty.length - 1] ?? "test failed";
|
|
84
|
+
|
|
85
|
+
// For assertions, extract expected/actual from "AssertionError: X != Y"
|
|
86
|
+
let message = errorLine;
|
|
87
|
+
const assertMatch = errorLine.match(/AssertionError:\s*(.+)/);
|
|
88
|
+
if (assertMatch) {
|
|
89
|
+
message = assertMatch[1];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const relFile = file ? (path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file) : undefined;
|
|
93
|
+
|
|
94
|
+
failures.push({
|
|
95
|
+
id: `${testName}`,
|
|
96
|
+
file: relFile,
|
|
97
|
+
line,
|
|
98
|
+
message,
|
|
99
|
+
rule: kind === "ERROR" ? "error" : "assertion",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const failed = failures.length;
|
|
104
|
+
const passed = totalTests - failed - skipped;
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
tool: "unittest",
|
|
108
|
+
status: failed > 0 ? "fail" : "pass",
|
|
109
|
+
summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
|
|
110
|
+
failures,
|
|
111
|
+
logPath: ctx.logPath,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default parser;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Safely read a file, returning empty string if it doesn't exist.
|
|
5
|
+
* Handles the case where a command was killed before writing output.
|
|
6
|
+
*/
|
|
7
|
+
export function safeReadFile(filePath: string): string {
|
|
8
|
+
try {
|
|
9
|
+
return fs.readFileSync(filePath, "utf8");
|
|
10
|
+
} catch (err: unknown) {
|
|
11
|
+
if (err instanceof Error && "code" in err && err.code === "ENOENT") return "";
|
|
12
|
+
throw err;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Extract the first user-code file:line from a JS/TS stack trace string.
|
|
18
|
+
* Skips node_modules and Node.js internal frames.
|
|
19
|
+
*
|
|
20
|
+
* Handles both formats:
|
|
21
|
+
* at functionName (file.ts:10:5)
|
|
22
|
+
* at file.ts:10:5
|
|
23
|
+
*/
|
|
24
|
+
export function extractJsStackLocation(stack: string | undefined): { file?: string; line?: number } {
|
|
25
|
+
if (!stack) return {};
|
|
26
|
+
for (const line of stack.split("\n")) {
|
|
27
|
+
// "at name (file:line:col)"
|
|
28
|
+
const withParens = line.match(/at\s+\S+\s+\(([^)]+\.(?:[jt]sx?|mjs|cjs)):(\d+):\d+\)/);
|
|
29
|
+
if (withParens && isUserFrame(withParens[1])) {
|
|
30
|
+
return { file: withParens[1], line: Number(withParens[2]) };
|
|
31
|
+
}
|
|
32
|
+
// "at file:line:col" (no parens)
|
|
33
|
+
const bare = line.match(/at\s+([^\s(]+\.(?:[jt]sx?|mjs|cjs)):(\d+):\d+/);
|
|
34
|
+
if (bare && isUserFrame(bare[1])) {
|
|
35
|
+
return { file: bare[1], line: Number(bare[2]) };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isUserFrame(filePath: string): boolean {
|
|
42
|
+
return !filePath.includes("node_modules") && !filePath.includes("node:");
|
|
43
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import type { ParserModule } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
4
|
|
|
5
5
|
interface VitestAssertionResult {
|
|
6
6
|
fullName: string;
|
|
@@ -23,7 +23,7 @@ interface VitestReport {
|
|
|
23
23
|
const parser: ParserModule = {
|
|
24
24
|
id: "vitest-json",
|
|
25
25
|
async parse(ctx) {
|
|
26
|
-
const stdout =
|
|
26
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
27
27
|
const report = stdout ? (JSON.parse(stdout) as VitestReport) : null;
|
|
28
28
|
if (!report) {
|
|
29
29
|
return {
|
package/package.json
CHANGED
|
@@ -33,6 +33,45 @@ Prefer better output at the source.
|
|
|
33
33
|
### ruff format
|
|
34
34
|
- `ruff format --check .` (no structured_return — json output not supported)
|
|
35
35
|
|
|
36
|
+
### mypy
|
|
37
|
+
- `structured_return({ command: "mypy [any mypy args] --output json", parseAs: "mypy-json" })` — `--output json` is built into mypy (1.0+); outputs NDJSON to stderr with file, line, column, message, error code, and severity; notes are folded into their parent error's message
|
|
38
|
+
|
|
39
|
+
### tsc
|
|
40
|
+
- `structured_return({ command: "tsc --noEmit --pretty false [any tsc args]", parseAs: "tsc-text" })` — `--pretty false` suppresses source snippets and ANSI codes; parser extracts file, line, TS error code, and message from the compact `file(line,col): error TSXXXX: message` format
|
|
41
|
+
|
|
42
|
+
### pylint
|
|
43
|
+
- `structured_return({ command: "pylint [any pylint args] --output-format=json", parseAs: "pylint-json" })` — `--output-format=json` is built into pylint; rule includes both message-id and symbol name (e.g. `W0612(unused-variable)`)
|
|
44
|
+
|
|
45
|
+
### shellcheck
|
|
46
|
+
- `structured_return({ command: "shellcheck [any shellcheck args] --format=json", parseAs: "shellcheck-json" })` — `--format=json` is built into shellcheck; strips source snippets, caret indicators, "Did you mean" suggestions, and wiki URLs
|
|
47
|
+
|
|
48
|
+
### rubocop
|
|
49
|
+
- `structured_return({ command: "rubocop [any rubocop args] --format json", parseAs: "rubocop-json" })` — `--format json` is built into rubocop; cop name prefix stripped from messages; source snippets and caret indicators removed
|
|
50
|
+
|
|
51
|
+
### flake8
|
|
52
|
+
- `flake8 [any flake8 args]` (no structured_return — default output is already compact `file:line:col: CODE message`; no JSON without a plugin; use `bash` directly)
|
|
53
|
+
|
|
54
|
+
### swiftc
|
|
55
|
+
- `structured_return({ command: "swiftc -typecheck [any swiftc args]", parseAs: "swiftc-text" })` — parses `file:line:col: error: message` from stderr; source annotations and duplicate error lines deduplicated; warnings filtered out
|
|
56
|
+
|
|
57
|
+
### hadolint
|
|
58
|
+
- `structured_return({ command: "hadolint [any hadolint args] --format json", parseAs: "hadolint-json" })` — `--format json` is built into hadolint; strips ANSI color codes and level labels from text output
|
|
59
|
+
|
|
60
|
+
### stylelint
|
|
61
|
+
- `structured_return({ command: "stylelint [any stylelint args] --formatter json", parseAs: "stylelint-json" })` — `--formatter json` is built into stylelint; rule name suffix stripped from message text; requires a `.stylelintrc` config
|
|
62
|
+
|
|
63
|
+
### ava
|
|
64
|
+
- `structured_return({ command: "npx ava [any ava args] --no-color", parseAs: "ava-text" })` — parses default text output from stderr; assertion failures extract expected/actual from diff lines and file:line; runtime errors extract message and file:line from stack trace
|
|
65
|
+
|
|
66
|
+
### mocha
|
|
67
|
+
- `structured_return({ command: "mocha [any mocha args] --reporter json", parseAs: "mocha-json" })` — `--reporter json` is built into mocha; assertion failures surface explicit expected/actual values; runtime errors surface message and file:line from stack trace
|
|
68
|
+
|
|
69
|
+
### Python unittest
|
|
70
|
+
- `structured_return({ command: "python3 -m unittest [any unittest args]", parseAs: "unittest-text" })` — no special flags needed; parses the default verbose traceback output from stderr; assertion messages extracted from `AssertionError` lines; file:line from traceback frames
|
|
71
|
+
|
|
72
|
+
### go test
|
|
73
|
+
- `structured_return({ command: "go test -json [any go test args]", parseAs: "go-test-json" })` — `-json` is built into `go test`; NDJSON output; assertion failures extract file:line and message from `t.Error`/`t.Errorf` output; panics extract message and user-code file:line from stack trace; 97% reduction vs raw NDJSON
|
|
74
|
+
|
|
36
75
|
### vitest
|
|
37
76
|
- `structured_return({ command: "vitest run [any vitest args] --reporter=json", parseAs: "vitest-json" })` — file paths, filters, etc. go in `[any vitest args]`
|
|
38
77
|
|