@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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
interface HadolintItem {
|
|
6
|
+
code: string;
|
|
7
|
+
column: number;
|
|
8
|
+
file: string;
|
|
9
|
+
level: string;
|
|
10
|
+
line: number;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const parser: ParserModule = {
|
|
15
|
+
id: "hadolint-json",
|
|
16
|
+
async parse(ctx) {
|
|
17
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
18
|
+
if (!stdout || stdout === "[]") {
|
|
19
|
+
return { tool: "hadolint", status: "pass", summary: "no lint errors", failures: [], logPath: ctx.logPath };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let items: HadolintItem[];
|
|
23
|
+
try {
|
|
24
|
+
items = JSON.parse(stdout) as HadolintItem[];
|
|
25
|
+
} catch {
|
|
26
|
+
return {
|
|
27
|
+
tool: "hadolint",
|
|
28
|
+
status: "error",
|
|
29
|
+
summary: "failed to parse hadolint JSON output",
|
|
30
|
+
logPath: ctx.logPath,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const failures: ParsedFailure[] = items.map((item) => {
|
|
35
|
+
const relPath = path.isAbsolute(item.file) ? path.relative(ctx.cwd, item.file) : item.file;
|
|
36
|
+
return {
|
|
37
|
+
id: `${relPath}:${item.line}:${item.code}`,
|
|
38
|
+
file: relPath,
|
|
39
|
+
line: item.line,
|
|
40
|
+
message: item.message,
|
|
41
|
+
rule: item.code,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
tool: "hadolint",
|
|
47
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
48
|
+
summary: failures.length > 0 ? `${failures.length} lint errors` : "no lint errors",
|
|
49
|
+
failures,
|
|
50
|
+
logPath: ctx.logPath,
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default parser;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import { XMLParser } from "fast-xml-parser";
|
|
4
3
|
import type { ParserModule, ParsedFailure } from "../types";
|
|
4
|
+
import { safeReadFile } from "./utils";
|
|
5
5
|
|
|
6
6
|
interface JUnitFailureOrError {
|
|
7
7
|
message?: string;
|
|
@@ -148,7 +148,7 @@ const parser: ParserModule = {
|
|
|
148
148
|
id: "junit-xml",
|
|
149
149
|
async parse(ctx) {
|
|
150
150
|
const artifactPath = ctx.artifactPaths[0] ?? ctx.stdoutPath;
|
|
151
|
-
const xml =
|
|
151
|
+
const xml = safeReadFile(artifactPath);
|
|
152
152
|
const doc = xmlParser.parse(xml) as JUnitDocument;
|
|
153
153
|
|
|
154
154
|
const suites: JUnitTestSuite[] = doc.testsuites?.testsuite ?? doc.testsuite ?? [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Parses minitest's default text output. No flags or reporters required —
|
|
@@ -9,7 +9,7 @@ import type { ParserModule, ParsedFailure } from "../types";
|
|
|
9
9
|
const parser: ParserModule = {
|
|
10
10
|
id: "minitest-text",
|
|
11
11
|
async parse(ctx) {
|
|
12
|
-
const output =
|
|
12
|
+
const output = safeReadFile(ctx.stdoutPath);
|
|
13
13
|
|
|
14
14
|
// "3 runs, 2 assertions, 1 failures, 1 errors, 0 skips"
|
|
15
15
|
const summaryMatch = output.match(/(\d+) runs?, \d+ assertions?, (\d+) failures?, (\d+) errors?, (\d+) skips?/);
|
|
@@ -0,0 +1,108 @@
|
|
|
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 "./mocha-json";
|
|
6
|
+
import type { RunContext } from "../types";
|
|
7
|
+
|
|
8
|
+
function makeCtx(stdout: string, cwd = "/project"): RunContext {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "mocha-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "mocha test_math.js --reporter json",
|
|
14
|
+
argv: ["mocha", "test_math.js", "--reporter", "json"],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("mocha-json parser", () => {
|
|
24
|
+
it("assertion failure → expected/actual in message, file:line from stack", async () => {
|
|
25
|
+
const stdout = JSON.stringify({
|
|
26
|
+
stats: { passes: 1, failures: 1 },
|
|
27
|
+
failures: [
|
|
28
|
+
{
|
|
29
|
+
title: "multiplies two numbers correctly",
|
|
30
|
+
fullTitle: "basic math multiplies two numbers correctly",
|
|
31
|
+
file: "/project/test_math.js",
|
|
32
|
+
err: {
|
|
33
|
+
stack:
|
|
34
|
+
"AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:\n\n12 !== 99\n\n at Context.<anonymous> (test_math.js:9:12)\n at process.processImmediate (node:internal/timers:504:21)",
|
|
35
|
+
message: "Expected values to be strictly equal:\n\n12 !== 99\n",
|
|
36
|
+
actual: "12",
|
|
37
|
+
expected: "99",
|
|
38
|
+
operator: "strictEqual",
|
|
39
|
+
code: "ERR_ASSERTION",
|
|
40
|
+
name: "AssertionError",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
46
|
+
expect(result.status).toBe("fail");
|
|
47
|
+
expect(result.summary).toBe("1 failed, 1 passed");
|
|
48
|
+
expect(result.failures).toHaveLength(1);
|
|
49
|
+
expect(result.failures![0].message).toBe("expected 99, got 12");
|
|
50
|
+
expect(result.failures![0].file).toBe("test_math.js");
|
|
51
|
+
expect(result.failures![0].line).toBe(9);
|
|
52
|
+
expect(result.failures![0].rule).toBe("ERR_ASSERTION");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("runtime error → message from err.message, file:line from stack", async () => {
|
|
56
|
+
const stdout = JSON.stringify({
|
|
57
|
+
stats: { passes: 1, failures: 1 },
|
|
58
|
+
failures: [
|
|
59
|
+
{
|
|
60
|
+
title: "does not divide by zero",
|
|
61
|
+
fullTitle: "basic math does not divide by zero",
|
|
62
|
+
file: "/project/test_math.js",
|
|
63
|
+
err: {
|
|
64
|
+
stack:
|
|
65
|
+
"TypeError: Cannot read properties of null (reading 'value')\n at Context.<anonymous> (test_math.js:13:29)\n at process.processImmediate (node:internal/timers:504:21)",
|
|
66
|
+
message: "Cannot read properties of null (reading 'value')",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
72
|
+
expect(result.failures![0].message).toBe("Cannot read properties of null (reading 'value')");
|
|
73
|
+
expect(result.failures![0].file).toBe("test_math.js");
|
|
74
|
+
expect(result.failures![0].line).toBe(13);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("all passing → status pass", async () => {
|
|
78
|
+
const stdout = JSON.stringify({ stats: { passes: 3, failures: 0 }, failures: [] });
|
|
79
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
80
|
+
expect(result.status).toBe("pass");
|
|
81
|
+
expect(result.summary).toBe("3 passed");
|
|
82
|
+
expect(result.failures).toHaveLength(0);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("empty stdout → status error", async () => {
|
|
86
|
+
const result = await parser.parse(makeCtx(""));
|
|
87
|
+
expect(result.status).toBe("error");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("file paths relativized to cwd", async () => {
|
|
91
|
+
const stdout = JSON.stringify({
|
|
92
|
+
stats: { passes: 0, failures: 1 },
|
|
93
|
+
failures: [
|
|
94
|
+
{
|
|
95
|
+
title: "fails",
|
|
96
|
+
fullTitle: "suite fails",
|
|
97
|
+
file: "/project/test/foo.js",
|
|
98
|
+
err: {
|
|
99
|
+
stack: "Error: oops\n at Context.<anonymous> (/project/test/foo.js:5:10)",
|
|
100
|
+
message: "oops",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
const result = await parser.parse(makeCtx(stdout, "/project"));
|
|
106
|
+
expect(result.failures![0].file).toBe("test/foo.js");
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { extractJsStackLocation, safeReadFile } from "./utils";
|
|
4
|
+
|
|
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 { tool: "mocha", status: "error", summary: "failed to parse mocha JSON output", logPath: ctx.logPath };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const failures: ParsedFailure[] = report.failures.map((test) => {
|
|
53
|
+
const loc = extractJsStackLocation(test.err.stack);
|
|
54
|
+
const relFile = loc.file ? path.relative(ctx.cwd, path.resolve(ctx.cwd, loc.file)) : undefined;
|
|
55
|
+
return {
|
|
56
|
+
id: test.fullTitle,
|
|
57
|
+
file: relFile,
|
|
58
|
+
line: loc.line,
|
|
59
|
+
message: buildMessage(test.err),
|
|
60
|
+
rule: test.err.code ?? test.err.name,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const failed = report.stats.failures;
|
|
65
|
+
const passed = report.stats.passes;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
tool: "mocha",
|
|
69
|
+
status: failed > 0 ? "fail" : "pass",
|
|
70
|
+
summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
|
|
71
|
+
failures,
|
|
72
|
+
logPath: ctx.logPath,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default parser;
|
|
@@ -0,0 +1,101 @@
|
|
|
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 "./mypy-json";
|
|
6
|
+
import type { RunContext } from "../types";
|
|
7
|
+
|
|
8
|
+
function makeCtx(stderr: string, cwd = "/project"): RunContext {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "mypy-test-"));
|
|
10
|
+
const stderrPath = path.join(dir, "stderr");
|
|
11
|
+
fs.writeFileSync(stderrPath, stderr);
|
|
12
|
+
// mypy JSON goes to stderr; stdout is empty
|
|
13
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
14
|
+
fs.writeFileSync(stdoutPath, "");
|
|
15
|
+
return {
|
|
16
|
+
command: "mypy type_check.py --output json",
|
|
17
|
+
argv: ["mypy", "type_check.py", "--output", "json"],
|
|
18
|
+
cwd,
|
|
19
|
+
artifactPaths: [],
|
|
20
|
+
stdoutPath,
|
|
21
|
+
stderrPath,
|
|
22
|
+
logPath: path.join(dir, "log"),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("mypy-json parser", () => {
|
|
27
|
+
it("multiple type errors → correct file, line, message, rule, status fail", async () => {
|
|
28
|
+
const stderr = [
|
|
29
|
+
'{"file": "type_check.py", "line": 5, "column": 14, "message": "Incompatible types in assignment (expression has type \\"int\\", variable has type \\"str\\")", "hint": null, "code": "assignment", "severity": "error"}',
|
|
30
|
+
'{"file": "type_check.py", "line": 6, "column": 17, "message": "Argument 1 to \\"add\\" has incompatible type \\"str\\"; expected \\"int\\"", "hint": null, "code": "arg-type", "severity": "error"}',
|
|
31
|
+
].join("\n");
|
|
32
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
33
|
+
expect(result.status).toBe("fail");
|
|
34
|
+
expect(result.summary).toBe("2 type errors");
|
|
35
|
+
expect(result.failures).toHaveLength(2);
|
|
36
|
+
expect(result.failures![0]).toMatchObject({
|
|
37
|
+
file: "type_check.py",
|
|
38
|
+
line: 5,
|
|
39
|
+
message: 'Incompatible types in assignment (expression has type "int", variable has type "str")',
|
|
40
|
+
rule: "assignment",
|
|
41
|
+
});
|
|
42
|
+
expect(result.failures![1]).toMatchObject({
|
|
43
|
+
file: "type_check.py",
|
|
44
|
+
line: 6,
|
|
45
|
+
message: 'Argument 1 to "add" has incompatible type "str"; expected "int"',
|
|
46
|
+
rule: "arg-type",
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("no errors (empty stderr) → status pass", async () => {
|
|
51
|
+
const result = await parser.parse(makeCtx(""));
|
|
52
|
+
expect(result.status).toBe("pass");
|
|
53
|
+
expect(result.summary).toBe("no type errors");
|
|
54
|
+
expect(result.failures).toHaveLength(0);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("absolute file paths → relativized to cwd", async () => {
|
|
58
|
+
const stderr =
|
|
59
|
+
'{"file": "/project/src/foo.py", "line": 10, "column": 5, "message": "Need type annotation", "hint": null, "code": "var-annotated", "severity": "error"}';
|
|
60
|
+
const result = await parser.parse(makeCtx(stderr, "/project"));
|
|
61
|
+
expect(result.failures![0].file).toBe("src/foo.py");
|
|
62
|
+
expect(result.failures![0].file).not.toContain("/project");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("note severity items are skipped as standalone failures", async () => {
|
|
66
|
+
const stderr = [
|
|
67
|
+
'{"file": "foo.py", "line": 5, "column": 1, "message": "Missing return statement", "hint": null, "code": "return", "severity": "error"}',
|
|
68
|
+
'{"file": "foo.py", "line": 5, "column": 1, "message": "See https://mypy.readthedocs.io/...", "hint": null, "code": null, "severity": "note"}',
|
|
69
|
+
].join("\n");
|
|
70
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
71
|
+
expect(result.failures).toHaveLength(1);
|
|
72
|
+
expect(result.failures![0].rule).toBe("return");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("notes on the same line as an error are appended to the error message", async () => {
|
|
76
|
+
const stderr = [
|
|
77
|
+
'{"file": "foo.py", "line": 5, "column": 1, "message": "Missing return statement", "hint": null, "code": "return", "severity": "error"}',
|
|
78
|
+
'{"file": "foo.py", "line": 5, "column": 1, "message": "Did you forget to return a value?", "hint": null, "code": null, "severity": "note"}',
|
|
79
|
+
].join("\n");
|
|
80
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
81
|
+
expect(result.failures).toHaveLength(1);
|
|
82
|
+
expect(result.failures![0].message).toBe("Missing return statement (Did you forget to return a value?)");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("hint field is included in message when present", async () => {
|
|
86
|
+
const stderr =
|
|
87
|
+
'{"file": "foo.py", "line": 3, "column": 1, "message": "Cannot find module", "hint": "Did you install types-requests?", "code": "import", "severity": "error"}';
|
|
88
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
89
|
+
expect(result.failures![0].message).toBe("Cannot find module (Did you install types-requests?)");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("handles non-JSON lines gracefully (e.g. summary text mixed in)", async () => {
|
|
93
|
+
const stderr = [
|
|
94
|
+
'{"file": "foo.py", "line": 1, "column": 1, "message": "Unused import", "hint": null, "code": "unused-import", "severity": "error"}',
|
|
95
|
+
"Found 1 error in 1 file (checked 1 source file)",
|
|
96
|
+
].join("\n");
|
|
97
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
98
|
+
expect(result.failures).toHaveLength(1);
|
|
99
|
+
expect(result.failures![0].rule).toBe("unused-import");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
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;
|
|
@@ -0,0 +1,120 @@
|
|
|
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 "./pylint-json";
|
|
6
|
+
import type { RunContext } from "../types";
|
|
7
|
+
|
|
8
|
+
function makeCtx(stdout: string, cwd = "/project"): RunContext {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pylint-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "pylint lint_check.py --output-format=json",
|
|
14
|
+
argv: ["pylint", "lint_check.py", "--output-format=json"],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("pylint-json parser", () => {
|
|
24
|
+
it("multiple lint errors → correct file, line, message, rule, status fail", async () => {
|
|
25
|
+
const stdout = JSON.stringify([
|
|
26
|
+
{
|
|
27
|
+
type: "warning",
|
|
28
|
+
module: "lint_check",
|
|
29
|
+
obj: "process_order",
|
|
30
|
+
line: 5,
|
|
31
|
+
column: 4,
|
|
32
|
+
endLine: 5,
|
|
33
|
+
endColumn: 12,
|
|
34
|
+
path: "lint_check.py",
|
|
35
|
+
symbol: "unused-variable",
|
|
36
|
+
message: "Unused variable 'discount'",
|
|
37
|
+
"message-id": "W0612",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "warning",
|
|
41
|
+
module: "lint_check",
|
|
42
|
+
obj: "",
|
|
43
|
+
line: 1,
|
|
44
|
+
column: 0,
|
|
45
|
+
endLine: 1,
|
|
46
|
+
endColumn: 9,
|
|
47
|
+
path: "lint_check.py",
|
|
48
|
+
symbol: "unused-import",
|
|
49
|
+
message: "Unused import os",
|
|
50
|
+
"message-id": "W0611",
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
54
|
+
expect(result.status).toBe("fail");
|
|
55
|
+
expect(result.summary).toBe("2 lint errors");
|
|
56
|
+
expect(result.failures).toHaveLength(2);
|
|
57
|
+
expect(result.failures![0]).toMatchObject({
|
|
58
|
+
file: "lint_check.py",
|
|
59
|
+
line: 5,
|
|
60
|
+
message: "Unused variable 'discount'",
|
|
61
|
+
rule: "W0612(unused-variable)",
|
|
62
|
+
});
|
|
63
|
+
expect(result.failures![1]).toMatchObject({
|
|
64
|
+
file: "lint_check.py",
|
|
65
|
+
line: 1,
|
|
66
|
+
message: "Unused import os",
|
|
67
|
+
rule: "W0611(unused-import)",
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("no errors (empty array) → status pass", async () => {
|
|
72
|
+
const result = await parser.parse(makeCtx("[]"));
|
|
73
|
+
expect(result.status).toBe("pass");
|
|
74
|
+
expect(result.summary).toBe("no lint errors");
|
|
75
|
+
expect(result.failures).toHaveLength(0);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("empty stdout → status pass", async () => {
|
|
79
|
+
const result = await parser.parse(makeCtx(""));
|
|
80
|
+
expect(result.status).toBe("pass");
|
|
81
|
+
expect(result.failures).toHaveLength(0);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("absolute file paths → relativized to cwd", async () => {
|
|
85
|
+
const stdout = JSON.stringify([
|
|
86
|
+
{
|
|
87
|
+
type: "convention",
|
|
88
|
+
module: "foo",
|
|
89
|
+
obj: "",
|
|
90
|
+
line: 1,
|
|
91
|
+
column: 0,
|
|
92
|
+
path: "/project/src/foo.py",
|
|
93
|
+
symbol: "missing-module-docstring",
|
|
94
|
+
message: "Missing module docstring",
|
|
95
|
+
"message-id": "C0114",
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
const result = await parser.parse(makeCtx(stdout, "/project"));
|
|
99
|
+
expect(result.failures![0].file).toBe("src/foo.py");
|
|
100
|
+
expect(result.failures![0].file).not.toContain("/project");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("rule includes both message-id and symbol", async () => {
|
|
104
|
+
const stdout = JSON.stringify([
|
|
105
|
+
{
|
|
106
|
+
type: "convention",
|
|
107
|
+
module: "foo",
|
|
108
|
+
obj: "",
|
|
109
|
+
line: 1,
|
|
110
|
+
column: 0,
|
|
111
|
+
path: "foo.py",
|
|
112
|
+
symbol: "line-too-long",
|
|
113
|
+
message: "Line too long (120/100)",
|
|
114
|
+
"message-id": "C0301",
|
|
115
|
+
},
|
|
116
|
+
]);
|
|
117
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
118
|
+
expect(result.failures![0].rule).toBe("C0301(line-too-long)");
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
interface PylintItem {
|
|
6
|
+
type: string;
|
|
7
|
+
module: string;
|
|
8
|
+
obj: string;
|
|
9
|
+
line: number;
|
|
10
|
+
column: number;
|
|
11
|
+
path: string;
|
|
12
|
+
symbol: string;
|
|
13
|
+
message: string;
|
|
14
|
+
"message-id": string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parser: ParserModule = {
|
|
18
|
+
id: "pylint-json",
|
|
19
|
+
async parse(ctx) {
|
|
20
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
21
|
+
if (!stdout || stdout === "[]") {
|
|
22
|
+
return {
|
|
23
|
+
tool: "pylint",
|
|
24
|
+
status: "pass",
|
|
25
|
+
summary: "no lint errors",
|
|
26
|
+
failures: [],
|
|
27
|
+
logPath: ctx.logPath,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let items: PylintItem[];
|
|
32
|
+
try {
|
|
33
|
+
items = JSON.parse(stdout) as PylintItem[];
|
|
34
|
+
} catch {
|
|
35
|
+
return {
|
|
36
|
+
tool: "pylint",
|
|
37
|
+
status: "error",
|
|
38
|
+
summary: "failed to parse pylint JSON output",
|
|
39
|
+
logPath: ctx.logPath,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const failures: ParsedFailure[] = items.map((item) => {
|
|
44
|
+
const relPath = path.isAbsolute(item.path) ? path.relative(ctx.cwd, item.path) : item.path;
|
|
45
|
+
return {
|
|
46
|
+
id: `${relPath}:${item.line}:${item["message-id"]}`,
|
|
47
|
+
file: relPath,
|
|
48
|
+
line: item.line,
|
|
49
|
+
message: item.message,
|
|
50
|
+
rule: `${item["message-id"]}(${item.symbol})`,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
tool: "pylint",
|
|
56
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
57
|
+
summary: failures.length > 0 ? `${failures.length} lint errors` : "no lint errors",
|
|
58
|
+
failures,
|
|
59
|
+
logPath: ctx.logPath,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default parser;
|
|
@@ -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 RSpecException {
|
|
6
6
|
class: string;
|
|
@@ -40,7 +40,7 @@ function firstParagraph(message: string): string {
|
|
|
40
40
|
const parser: ParserModule = {
|
|
41
41
|
id: "rspec-json",
|
|
42
42
|
async parse(ctx) {
|
|
43
|
-
const stdout =
|
|
43
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
44
44
|
const report = stdout ? (JSON.parse(stdout) as RSpecReport) : null;
|
|
45
45
|
if (!report) {
|
|
46
46
|
return {
|