@robhowley/pi-structured-return 1.4.0 → 1.6.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 +108 -74
- package/extensions/structured-return/src/config/registry.test.ts +171 -0
- package/extensions/structured-return/src/config/registry.ts +183 -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/bandit-json.test.ts +90 -0
- package/extensions/structured-return/src/parsers/bandit-json.ts +78 -0
- package/extensions/structured-return/src/parsers/black-text.test.ts +67 -0
- package/extensions/structured-return/src/parsers/black-text.ts +74 -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/clang-text.test.ts +61 -0
- package/extensions/structured-return/src/parsers/clang-text.ts +59 -0
- package/extensions/structured-return/src/parsers/dbt-json.ts +2 -2
- package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +85 -0
- package/extensions/structured-return/src/parsers/dotnet-build-text.ts +48 -0
- 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/htmlhint-json.test.ts +72 -0
- package/extensions/structured-return/src/parsers/htmlhint-json.ts +72 -0
- package/extensions/structured-return/src/parsers/isort-text.test.ts +58 -0
- package/extensions/structured-return/src/parsers/isort-text.ts +64 -0
- package/extensions/structured-return/src/parsers/javac-text.test.ts +75 -0
- package/extensions/structured-return/src/parsers/javac-text.ts +81 -0
- package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +52 -0
- package/extensions/structured-return/src/parsers/jsonlint-text.ts +64 -0
- package/extensions/structured-return/src/parsers/junit-xml.ts +2 -2
- package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +76 -0
- package/extensions/structured-return/src/parsers/markdownlint-json.ts +73 -0
- 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/node-test-text.test.ts +117 -0
- package/extensions/structured-return/src/parsers/node-test-text.ts +90 -0
- package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +83 -0
- package/extensions/structured-return/src/parsers/npm-audit-json.ts +88 -0
- package/extensions/structured-return/src/parsers/prettier-text.test.ts +76 -0
- package/extensions/structured-return/src/parsers/prettier-text.ts +63 -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/pyright-json.test.ts +112 -0
- package/extensions/structured-return/src/parsers/pyright-json.ts +81 -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/tidy-text.test.ts +74 -0
- package/extensions/structured-return/src/parsers/tidy-text.ts +67 -0
- 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/vale-json.test.ts +84 -0
- package/extensions/structured-return/src/parsers/vale-json.ts +80 -0
- package/extensions/structured-return/src/parsers/vitest-json.ts +2 -2
- package/package.json +1 -1
- package/skills/structured-return/SKILL.md +93 -2
|
@@ -0,0 +1,76 @@
|
|
|
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 "./markdownlint-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(), "markdownlint-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "markdownlint --json .",
|
|
14
|
+
argv: ["markdownlint", "--json", "."],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("markdownlint-json parser", () => {
|
|
24
|
+
it("multiple issues → correct relative paths, rule codes, descriptions", async () => {
|
|
25
|
+
const cwd = "/project";
|
|
26
|
+
const stdout = JSON.stringify([
|
|
27
|
+
{
|
|
28
|
+
fileName: "/project/docs/README.md",
|
|
29
|
+
lineNumber: 1,
|
|
30
|
+
ruleNames: ["MD041", "first-line-heading"],
|
|
31
|
+
ruleDescription: "First line in a file should be a top-level heading",
|
|
32
|
+
errorDetail: null,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
fileName: "/project/docs/README.md",
|
|
36
|
+
lineNumber: 3,
|
|
37
|
+
ruleNames: ["MD009", "no-trailing-spaces"],
|
|
38
|
+
ruleDescription: "Trailing spaces",
|
|
39
|
+
errorDetail: "Expected: 0 or 2; Actual: 3",
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
const result = await parser.parse(makeCtx(stdout, cwd));
|
|
43
|
+
expect(result.status).toBe("fail");
|
|
44
|
+
expect(result.summary).toBe("2 lint errors");
|
|
45
|
+
expect(result.failures).toHaveLength(2);
|
|
46
|
+
expect(result.failures![0].file).toBe("docs/README.md");
|
|
47
|
+
expect(result.failures![0].rule).toBe("MD041");
|
|
48
|
+
expect(result.failures![1].message).toContain("Expected: 0 or 2; Actual: 3");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("no issues → status pass", async () => {
|
|
52
|
+
const result = await parser.parse(makeCtx(JSON.stringify([])));
|
|
53
|
+
expect(result.status).toBe("pass");
|
|
54
|
+
expect(result.failures).toHaveLength(0);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("empty stdout → no crash, status pass", async () => {
|
|
58
|
+
const result = await parser.parse(makeCtx(""));
|
|
59
|
+
expect(result.status).toBe("pass");
|
|
60
|
+
expect(result.failures).toHaveLength(0);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("single issue → singular 'error' in summary", async () => {
|
|
64
|
+
const stdout = JSON.stringify([
|
|
65
|
+
{
|
|
66
|
+
fileName: "/project/README.md",
|
|
67
|
+
lineNumber: 5,
|
|
68
|
+
ruleNames: ["MD032", "blanks-around-lists"],
|
|
69
|
+
ruleDescription: "Lists should be surrounded by blank lines",
|
|
70
|
+
errorDetail: null,
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
74
|
+
expect(result.summary).toBe("1 lint error");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
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 ? `${item.ruleDescription}: ${item.errorDetail}` : item.ruleDescription;
|
|
54
|
+
return {
|
|
55
|
+
id: `${relPath}:${item.lineNumber}:${rule}`,
|
|
56
|
+
file: relPath,
|
|
57
|
+
line: item.lineNumber,
|
|
58
|
+
message,
|
|
59
|
+
rule,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
tool: "markdownlint",
|
|
65
|
+
status: "fail",
|
|
66
|
+
summary: `${failures.length} lint error${failures.length !== 1 ? "s" : ""}`,
|
|
67
|
+
failures,
|
|
68
|
+
logPath: ctx.logPath,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
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, 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,117 @@
|
|
|
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 "./node-test-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(), "node-test-text-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
const stderrPath = path.join(dir, "stderr");
|
|
12
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
13
|
+
fs.writeFileSync(stderrPath, "");
|
|
14
|
+
return {
|
|
15
|
+
command: "node --test",
|
|
16
|
+
argv: ["node", "--test"],
|
|
17
|
+
cwd,
|
|
18
|
+
artifactPaths: [],
|
|
19
|
+
stdoutPath,
|
|
20
|
+
stderrPath,
|
|
21
|
+
logPath: path.join(dir, "log"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("node-test-text parser", () => {
|
|
26
|
+
it("mixed pass/fail → correct summary, file:line, and assertion messages", async () => {
|
|
27
|
+
const cwd = "/project";
|
|
28
|
+
const stdout = `▶ math
|
|
29
|
+
✔ adds two numbers correctly (0.329ms)
|
|
30
|
+
✖ multiplies two numbers correctly (0.466ms)
|
|
31
|
+
✖ does not divide by zero (5.098ms)
|
|
32
|
+
✖ math (6.373ms)
|
|
33
|
+
ℹ tests 3
|
|
34
|
+
ℹ suites 1
|
|
35
|
+
ℹ pass 1
|
|
36
|
+
ℹ fail 2
|
|
37
|
+
ℹ cancelled 0
|
|
38
|
+
ℹ skipped 0
|
|
39
|
+
ℹ todo 0
|
|
40
|
+
ℹ duration_ms 68.049
|
|
41
|
+
|
|
42
|
+
✖ failing tests:
|
|
43
|
+
|
|
44
|
+
test at /project/src/test_math.mjs:9:3
|
|
45
|
+
✖ multiplies two numbers correctly (0.466ms)
|
|
46
|
+
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
|
|
47
|
+
|
|
48
|
+
12 !== 99
|
|
49
|
+
|
|
50
|
+
at TestContext.<anonymous> (file:///project/src/test_math.mjs:10:12)
|
|
51
|
+
at Test.runInAsyncScope (node:async_hooks:226:14)
|
|
52
|
+
|
|
53
|
+
test at /project/src/test_math.mjs:13:3
|
|
54
|
+
✖ does not divide by zero (5.098ms)
|
|
55
|
+
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
|
|
56
|
+
|
|
57
|
+
assert.ok(isFinite(result))
|
|
58
|
+
|
|
59
|
+
at TestContext.<anonymous> (file:///project/src/test_math.mjs:15:12)`;
|
|
60
|
+
const result = await parser.parse(makeCtx(stdout, cwd));
|
|
61
|
+
expect(result.status).toBe("fail");
|
|
62
|
+
expect(result.summary).toBe("2 failed, 1 passed");
|
|
63
|
+
expect(result.failures).toHaveLength(2);
|
|
64
|
+
expect(result.failures![0].file).toBe("src/test_math.mjs");
|
|
65
|
+
expect(result.failures![0].line).toBe(9);
|
|
66
|
+
expect(result.failures![0].message).toContain("12 !== 99");
|
|
67
|
+
expect(result.failures![1].message).toContain("assert.ok(isFinite(result))");
|
|
68
|
+
// No stack traces in output
|
|
69
|
+
expect(result.failures![0].message).not.toContain("at Test");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("all passing → status pass, no failures", async () => {
|
|
73
|
+
const stdout = `▶ math
|
|
74
|
+
✔ adds correctly (0.2ms)
|
|
75
|
+
✔ math (1ms)
|
|
76
|
+
ℹ tests 1
|
|
77
|
+
ℹ suites 1
|
|
78
|
+
ℹ pass 1
|
|
79
|
+
ℹ fail 0
|
|
80
|
+
ℹ duration_ms 50.0`;
|
|
81
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
82
|
+
expect(result.status).toBe("pass");
|
|
83
|
+
expect(result.summary).toBe("1 passed");
|
|
84
|
+
expect(result.failures).toHaveLength(0);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("non-assertion error (TypeError) → captures error message", async () => {
|
|
88
|
+
const cwd = "/project";
|
|
89
|
+
const stdout = `▶ suite
|
|
90
|
+
✖ throws type error (1ms)
|
|
91
|
+
✖ suite (2ms)
|
|
92
|
+
ℹ tests 1
|
|
93
|
+
ℹ suites 1
|
|
94
|
+
ℹ pass 0
|
|
95
|
+
ℹ fail 1
|
|
96
|
+
ℹ duration_ms 50.0
|
|
97
|
+
|
|
98
|
+
✖ failing tests:
|
|
99
|
+
|
|
100
|
+
test at /project/src/test.mjs:5:3
|
|
101
|
+
✖ throws type error (1ms)
|
|
102
|
+
TypeError: Cannot read properties of null (reading 'foo')
|
|
103
|
+
at TestContext.<anonymous> (file:///project/src/test.mjs:6:10)
|
|
104
|
+
at Test.runInAsyncScope (node:async_hooks:226:14)`;
|
|
105
|
+
const result = await parser.parse(makeCtx(stdout, cwd));
|
|
106
|
+
expect(result.status).toBe("fail");
|
|
107
|
+
expect(result.failures).toHaveLength(1);
|
|
108
|
+
expect(result.failures![0].message).toContain("Cannot read properties of null");
|
|
109
|
+
expect(result.failures![0].message).not.toContain("at Test");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("empty stdout → no crash, status pass", async () => {
|
|
113
|
+
const result = await parser.parse(makeCtx(""));
|
|
114
|
+
expect(result.status).toBe("pass");
|
|
115
|
+
expect(result.failures).toHaveLength(0);
|
|
116
|
+
});
|
|
117
|
+
});
|