@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,74 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
const REFORMAT_LINE = /^would reformat (.+)$/;
|
|
6
|
+
const ERROR_FORMAT = /^error: cannot format (.+?): (.+)$/;
|
|
7
|
+
|
|
8
|
+
const parser: ParserModule = {
|
|
9
|
+
id: "black-text",
|
|
10
|
+
async parse(ctx) {
|
|
11
|
+
const combined = (safeReadFile(ctx.stdoutPath) + "\n" + safeReadFile(ctx.stderrPath)).trim();
|
|
12
|
+
if (!combined) {
|
|
13
|
+
return {
|
|
14
|
+
tool: "black",
|
|
15
|
+
status: "pass",
|
|
16
|
+
summary: "all files formatted",
|
|
17
|
+
failures: [],
|
|
18
|
+
logPath: ctx.logPath,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const lines = combined.split("\n");
|
|
23
|
+
const failures: ParsedFailure[] = [];
|
|
24
|
+
for (const line of lines) {
|
|
25
|
+
const reformatMatch = line.match(REFORMAT_LINE);
|
|
26
|
+
if (reformatMatch) {
|
|
27
|
+
const relPath = path.relative(ctx.cwd, reformatMatch[1]);
|
|
28
|
+
failures.push({
|
|
29
|
+
id: relPath,
|
|
30
|
+
file: relPath,
|
|
31
|
+
message: "would reformat",
|
|
32
|
+
});
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const errorMatch = line.match(ERROR_FORMAT);
|
|
37
|
+
if (errorMatch) {
|
|
38
|
+
const relPath = path.relative(ctx.cwd, errorMatch[1]);
|
|
39
|
+
failures.push({
|
|
40
|
+
id: relPath,
|
|
41
|
+
file: relPath,
|
|
42
|
+
message: errorMatch[2],
|
|
43
|
+
});
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If "All done!" and no reformats needed
|
|
49
|
+
if (failures.length === 0 && combined.includes("All done!")) {
|
|
50
|
+
return {
|
|
51
|
+
tool: "black",
|
|
52
|
+
status: "pass",
|
|
53
|
+
summary: "all files formatted",
|
|
54
|
+
failures: [],
|
|
55
|
+
logPath: ctx.logPath,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const summary =
|
|
60
|
+
failures.length > 0
|
|
61
|
+
? `${failures.length} file${failures.length !== 1 ? "s" : ""} would be reformatted`
|
|
62
|
+
: "all files formatted";
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
tool: "black",
|
|
66
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
67
|
+
summary,
|
|
68
|
+
failures,
|
|
69
|
+
logPath: ctx.logPath,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
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
|
interface CargoSpan {
|
|
6
6
|
file_name: string;
|
|
@@ -29,7 +29,7 @@ const parser: ParserModule = {
|
|
|
29
29
|
id: "cargo-build",
|
|
30
30
|
async parse(ctx) {
|
|
31
31
|
// --message-format=json writes NDJSON to stdout; one JSON object per line
|
|
32
|
-
const stdout =
|
|
32
|
+
const stdout = safeReadFile(ctx.stdoutPath);
|
|
33
33
|
const failures: ParsedFailure[] = [];
|
|
34
34
|
|
|
35
35
|
for (const line of stdout.split("\n")) {
|
|
@@ -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
|
// Rust 1.73+: thread 'name' (optional-id) panicked at file:line:col:
|
|
6
6
|
// message on following line(s)
|
|
@@ -21,7 +21,7 @@ const parser: ParserModule = {
|
|
|
21
21
|
async parse(ctx) {
|
|
22
22
|
// Use combined log — test binary output goes to stdout, cargo progress to stderr;
|
|
23
23
|
// reading both ensures we catch everything regardless of buffering order.
|
|
24
|
-
const log =
|
|
24
|
+
const log = safeReadFile(ctx.logPath);
|
|
25
25
|
const lines = log.split("\n").map((l) => l.trim());
|
|
26
26
|
|
|
27
27
|
// If compilation failed there will be no "test result:" line
|
|
@@ -0,0 +1,61 @@
|
|
|
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 "./clang-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(), "clang-test-"));
|
|
10
|
+
const stderrPath = path.join(dir, "stderr");
|
|
11
|
+
fs.writeFileSync(stderrPath, stderr);
|
|
12
|
+
return {
|
|
13
|
+
command: "gcc -c src/main.c",
|
|
14
|
+
argv: ["gcc", "-c", "src/main.c"],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath: path.join(dir, "stdout"),
|
|
18
|
+
stderrPath,
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("clang-text parser", () => {
|
|
24
|
+
it("two errors with source snippets → strips snippets, extracts file:line and message", async () => {
|
|
25
|
+
const cwd = "/project";
|
|
26
|
+
const stderr = `/project/src/main.c:4:9: error: incompatible pointer to integer conversion initializing 'int' with an expression of type 'char[6]' [-Wint-conversion]
|
|
27
|
+
4 | int x = "hello";
|
|
28
|
+
| ^ ~~~~~~~
|
|
29
|
+
/project/src/main.c:5:20: error: use of undeclared identifier 'undeclared_var'
|
|
30
|
+
5 | printf("%d\\n", undeclared_var);
|
|
31
|
+
| ^
|
|
32
|
+
2 errors generated.`;
|
|
33
|
+
const result = await parser.parse(makeCtx(stderr, cwd));
|
|
34
|
+
expect(result.status).toBe("fail");
|
|
35
|
+
expect(result.summary).toBe("2 errors generated.");
|
|
36
|
+
expect(result.failures).toHaveLength(2);
|
|
37
|
+
expect(result.failures![0].file).toBe("src/main.c");
|
|
38
|
+
expect(result.failures![0].line).toBe(4);
|
|
39
|
+
expect(result.failures![0].rule).toBe("-Wint-conversion");
|
|
40
|
+
expect(result.failures![1].file).toBe("src/main.c");
|
|
41
|
+
expect(result.failures![1].line).toBe(5);
|
|
42
|
+
expect(result.failures![1].rule).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("fatal error → captured as failure", async () => {
|
|
46
|
+
const stderr = `/project/src/main.c:1:10: fatal error: 'nonexistent.h' file not found
|
|
47
|
+
1 | #include <nonexistent.h>
|
|
48
|
+
| ^~~~~~~~~~~~~~~
|
|
49
|
+
1 error generated.`;
|
|
50
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
51
|
+
expect(result.status).toBe("fail");
|
|
52
|
+
expect(result.failures).toHaveLength(1);
|
|
53
|
+
expect(result.failures![0].message).toContain("nonexistent.h");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("empty stderr → no crash, status pass", async () => {
|
|
57
|
+
const result = await parser.parse(makeCtx(""));
|
|
58
|
+
expect(result.status).toBe("pass");
|
|
59
|
+
expect(result.failures).toHaveLength(0);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
// Clang/GCC error format: file:line:col: error: message [-Wflag]
|
|
6
|
+
const ERROR_LINE = /^(.+?):(\d+):\d+: (error|fatal error): (.+?)(\s+\[-.+\])?$/;
|
|
7
|
+
const SUMMARY_LINE = /^(\d+) errors? generated/;
|
|
8
|
+
|
|
9
|
+
const parser: ParserModule = {
|
|
10
|
+
id: "clang-text",
|
|
11
|
+
async parse(ctx) {
|
|
12
|
+
const stderr = safeReadFile(ctx.stderrPath).trim();
|
|
13
|
+
if (!stderr) {
|
|
14
|
+
return {
|
|
15
|
+
tool: "clang",
|
|
16
|
+
status: "pass",
|
|
17
|
+
summary: "compilation successful",
|
|
18
|
+
failures: [],
|
|
19
|
+
logPath: ctx.logPath,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const lines = stderr.split("\n");
|
|
24
|
+
const failures: ParsedFailure[] = [];
|
|
25
|
+
let summaryLine = "";
|
|
26
|
+
|
|
27
|
+
for (const line of lines) {
|
|
28
|
+
const errorMatch = line.match(ERROR_LINE);
|
|
29
|
+
if (errorMatch) {
|
|
30
|
+
const [, filePath, lineNum, , message, flag] = errorMatch;
|
|
31
|
+
const relPath = path.relative(ctx.cwd, filePath);
|
|
32
|
+
failures.push({
|
|
33
|
+
id: `${relPath}:${lineNum}`,
|
|
34
|
+
file: relPath,
|
|
35
|
+
line: parseInt(lineNum, 10),
|
|
36
|
+
message,
|
|
37
|
+
rule: flag?.trim().replace(/^\[/, "").replace(/\]$/, ""),
|
|
38
|
+
});
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const sumMatch = line.match(SUMMARY_LINE);
|
|
42
|
+
if (sumMatch) summaryLine = line;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const summary =
|
|
46
|
+
summaryLine ||
|
|
47
|
+
(failures.length > 0 ? `${failures.length} error${failures.length !== 1 ? "s" : ""}` : "compilation successful");
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
tool: "clang",
|
|
51
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
52
|
+
summary,
|
|
53
|
+
failures,
|
|
54
|
+
logPath: ctx.logPath,
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default parser;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import type { ParserModule, ParsedFailure } from "../types";
|
|
2
|
+
import { safeReadFile } from "./utils";
|
|
3
3
|
|
|
4
4
|
interface DbtEvent {
|
|
5
5
|
data: Record<string, unknown>;
|
|
@@ -29,7 +29,7 @@ const parser: ParserModule = {
|
|
|
29
29
|
id: "dbt-json",
|
|
30
30
|
async parse(ctx) {
|
|
31
31
|
// dbt --log-format json writes JSONL to stdout
|
|
32
|
-
const raw =
|
|
32
|
+
const raw = safeReadFile(ctx.stdoutPath);
|
|
33
33
|
const events: DbtEvent[] = [];
|
|
34
34
|
for (const line of raw.split("\n")) {
|
|
35
35
|
if (!line.trim().startsWith("{")) continue;
|
|
@@ -0,0 +1,85 @@
|
|
|
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 "./dotnet-build-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(), "dotnet-build-test-"));
|
|
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: "dotnet build",
|
|
16
|
+
argv: ["dotnet", "build"],
|
|
17
|
+
cwd,
|
|
18
|
+
artifactPaths: [],
|
|
19
|
+
stdoutPath,
|
|
20
|
+
stderrPath,
|
|
21
|
+
logPath: path.join(dir, "log"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("dotnet-build-text parser", () => {
|
|
26
|
+
it("duplicated errors → deduplicated, relative paths, rule code extracted", async () => {
|
|
27
|
+
const cwd = "/project";
|
|
28
|
+
const stdout = ` Determining projects to restore...
|
|
29
|
+
All projects are up-to-date for restore.
|
|
30
|
+
/project/src/App.cs(7,25): error CS0029: Cannot implicitly convert type 'int' to 'string' [/project/src/App.csproj]
|
|
31
|
+
/project/src/App.cs(8,16): error CS0029: Cannot implicitly convert type 'string' to 'int' [/project/src/App.csproj]
|
|
32
|
+
|
|
33
|
+
Build FAILED.
|
|
34
|
+
|
|
35
|
+
/project/src/App.cs(7,25): error CS0029: Cannot implicitly convert type 'int' to 'string' [/project/src/App.csproj]
|
|
36
|
+
/project/src/App.cs(8,16): error CS0029: Cannot implicitly convert type 'string' to 'int' [/project/src/App.csproj]
|
|
37
|
+
0 Warning(s)
|
|
38
|
+
2 Error(s)
|
|
39
|
+
|
|
40
|
+
Time Elapsed 00:00:01.58`;
|
|
41
|
+
const result = await parser.parse(makeCtx(stdout, cwd));
|
|
42
|
+
expect(result.status).toBe("fail");
|
|
43
|
+
expect(result.summary).toBe("2 errors");
|
|
44
|
+
expect(result.failures).toHaveLength(2); // deduplicated from 4 lines
|
|
45
|
+
expect(result.failures![0].file).toBe("src/App.cs");
|
|
46
|
+
expect(result.failures![0].line).toBe(7);
|
|
47
|
+
expect(result.failures![0].rule).toBe("CS0029");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("no errors → status pass", async () => {
|
|
51
|
+
const stdout = ` Determining projects to restore...
|
|
52
|
+
All projects are up-to-date for restore.
|
|
53
|
+
App -> /project/bin/Debug/net10.0/App.dll
|
|
54
|
+
|
|
55
|
+
Build succeeded.
|
|
56
|
+
0 Warning(s)
|
|
57
|
+
0 Error(s)
|
|
58
|
+
|
|
59
|
+
Time Elapsed 00:00:01.00`;
|
|
60
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
61
|
+
expect(result.status).toBe("pass");
|
|
62
|
+
expect(result.summary).toBe("build succeeded");
|
|
63
|
+
expect(result.failures).toHaveLength(0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("empty stdout → no crash, status pass", async () => {
|
|
67
|
+
const result = await parser.parse(makeCtx(""));
|
|
68
|
+
expect(result.status).toBe("pass");
|
|
69
|
+
expect(result.failures).toHaveLength(0);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("single error → singular 'error' in summary", async () => {
|
|
73
|
+
const stdout = `/project/a.cs(1,1): error CS0246: The type or namespace name 'Foo' could not be found [/project/a.csproj]
|
|
74
|
+
|
|
75
|
+
Build FAILED.
|
|
76
|
+
|
|
77
|
+
/project/a.cs(1,1): error CS0246: The type or namespace name 'Foo' could not be found [/project/a.csproj]
|
|
78
|
+
0 Warning(s)
|
|
79
|
+
1 Error(s)`;
|
|
80
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
81
|
+
expect(result.status).toBe("fail");
|
|
82
|
+
expect(result.summary).toBe("1 error");
|
|
83
|
+
expect(result.failures).toHaveLength(1);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
// MSBuild error format: file(line,col): error CODE: message [project]
|
|
6
|
+
const ERROR_LINE = /^(.+?)\((\d+),\d+\): error (\w+): (.+?)(?:\s+\[.+\])?$/;
|
|
7
|
+
|
|
8
|
+
const parser: ParserModule = {
|
|
9
|
+
id: "dotnet-build-text",
|
|
10
|
+
async parse(ctx) {
|
|
11
|
+
const combined = safeReadFile(ctx.stdoutPath) + safeReadFile(ctx.stderrPath);
|
|
12
|
+
const lines = combined.split("\n");
|
|
13
|
+
|
|
14
|
+
// Deduplicate — MSBuild prints errors twice (inline + summary)
|
|
15
|
+
const seen = new Set<string>();
|
|
16
|
+
const failures: ParsedFailure[] = [];
|
|
17
|
+
|
|
18
|
+
for (const line of lines) {
|
|
19
|
+
const match = line.trim().match(ERROR_LINE);
|
|
20
|
+
if (!match) continue;
|
|
21
|
+
const [, filePath, lineNum, code, message] = match;
|
|
22
|
+
const relPath = path.relative(ctx.cwd, filePath);
|
|
23
|
+
const key = `${relPath}:${lineNum}:${code}`;
|
|
24
|
+
if (seen.has(key)) continue;
|
|
25
|
+
seen.add(key);
|
|
26
|
+
failures.push({
|
|
27
|
+
id: key,
|
|
28
|
+
file: relPath,
|
|
29
|
+
line: parseInt(lineNum, 10),
|
|
30
|
+
message,
|
|
31
|
+
rule: code,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const summary =
|
|
36
|
+
failures.length > 0 ? `${failures.length} error${failures.length !== 1 ? "s" : ""}` : "build succeeded";
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
tool: "dotnet build",
|
|
40
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
41
|
+
summary,
|
|
42
|
+
failures,
|
|
43
|
+
logPath: ctx.logPath,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default parser;
|
|
@@ -1,11 +1,11 @@
|
|
|
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
|
const parser: ParserModule = {
|
|
6
6
|
id: "eslint-json",
|
|
7
7
|
async parse(ctx) {
|
|
8
|
-
const stdout =
|
|
8
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
9
9
|
const files = stdout ? JSON.parse(stdout) : [];
|
|
10
10
|
const failures = [] as Array<{ id: string; file?: string; line?: number; message?: string; rule?: string }>;
|
|
11
11
|
for (const file of Array.isArray(files) ? files : []) {
|
|
@@ -0,0 +1,119 @@
|
|
|
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 "./go-test-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(), "gotest-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "go test -json ./...",
|
|
14
|
+
argv: ["go", "test", "-json", "./..."],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function ndjson(...events: object[]): string {
|
|
24
|
+
return events.map((e) => JSON.stringify(e)).join("\n");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("go-test-json parser", () => {
|
|
28
|
+
it("assertion failure → file:line and message from t.Errorf output", async () => {
|
|
29
|
+
const stdout = ndjson(
|
|
30
|
+
{ Action: "run", Package: "math-test", Test: "TestAdd" },
|
|
31
|
+
{ Action: "output", Package: "math-test", Test: "TestAdd", Output: "=== RUN TestAdd\n" },
|
|
32
|
+
{ Action: "output", Package: "math-test", Test: "TestAdd", Output: "--- PASS: TestAdd (0.00s)\n" },
|
|
33
|
+
{ Action: "pass", Package: "math-test", Test: "TestAdd" },
|
|
34
|
+
{ Action: "run", Package: "math-test", Test: "TestMultiply" },
|
|
35
|
+
{ Action: "output", Package: "math-test", Test: "TestMultiply", Output: "=== RUN TestMultiply\n" },
|
|
36
|
+
{
|
|
37
|
+
Action: "output",
|
|
38
|
+
Package: "math-test",
|
|
39
|
+
Test: "TestMultiply",
|
|
40
|
+
Output: " math_test.go:14: expected 99, got 12\n",
|
|
41
|
+
},
|
|
42
|
+
{ Action: "output", Package: "math-test", Test: "TestMultiply", Output: "--- FAIL: TestMultiply (0.00s)\n" },
|
|
43
|
+
{ Action: "fail", Package: "math-test", Test: "TestMultiply" },
|
|
44
|
+
{ Action: "fail", Package: "math-test", Elapsed: 0.1 }
|
|
45
|
+
);
|
|
46
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
47
|
+
expect(result.status).toBe("fail");
|
|
48
|
+
expect(result.summary).toBe("1 failed, 1 passed");
|
|
49
|
+
expect(result.failures).toHaveLength(1);
|
|
50
|
+
expect(result.failures![0]).toMatchObject({
|
|
51
|
+
file: "math_test.go",
|
|
52
|
+
line: 14,
|
|
53
|
+
message: "expected 99, got 12",
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("panic → message and user-code file:line from stack trace", async () => {
|
|
58
|
+
const stdout = ndjson(
|
|
59
|
+
{ Action: "run", Package: "math-test", Test: "TestDoesNotPanic" },
|
|
60
|
+
{ Action: "output", Package: "math-test", Test: "TestDoesNotPanic", Output: "=== RUN TestDoesNotPanic\n" },
|
|
61
|
+
{
|
|
62
|
+
Action: "output",
|
|
63
|
+
Package: "math-test",
|
|
64
|
+
Test: "TestDoesNotPanic",
|
|
65
|
+
Output: "--- FAIL: TestDoesNotPanic (0.00s)\n",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
Action: "output",
|
|
69
|
+
Package: "math-test",
|
|
70
|
+
Test: "TestDoesNotPanic",
|
|
71
|
+
Output: "panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]\n",
|
|
72
|
+
},
|
|
73
|
+
{ Action: "output", Package: "math-test", Test: "TestDoesNotPanic", Output: "goroutine 23 [running]:\n" },
|
|
74
|
+
{
|
|
75
|
+
Action: "output",
|
|
76
|
+
Package: "math-test",
|
|
77
|
+
Test: "TestDoesNotPanic",
|
|
78
|
+
Output: "testing.tRunner.func1.2({0x1003f2be0, 0x10043cec0})\n",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
Action: "output",
|
|
82
|
+
Package: "math-test",
|
|
83
|
+
Test: "TestDoesNotPanic",
|
|
84
|
+
Output: "\t/usr/local/go/src/testing/testing.go:1974 +0x1a0\n",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
Action: "output",
|
|
88
|
+
Package: "math-test",
|
|
89
|
+
Test: "TestDoesNotPanic",
|
|
90
|
+
Output: "math-test.TestDoesNotPanic(0x123)\n",
|
|
91
|
+
},
|
|
92
|
+
{ Action: "output", Package: "math-test", Test: "TestDoesNotPanic", Output: "\t/project/math_test.go:20 +0x4\n" },
|
|
93
|
+
{ Action: "fail", Package: "math-test", Test: "TestDoesNotPanic" },
|
|
94
|
+
{ Action: "fail", Package: "math-test", Elapsed: 0.1 }
|
|
95
|
+
);
|
|
96
|
+
const result = await parser.parse(makeCtx(stdout, "/project"));
|
|
97
|
+
expect(result.failures).toHaveLength(1);
|
|
98
|
+
expect(result.failures![0].message).toBe("runtime error: invalid memory address or nil pointer dereference");
|
|
99
|
+
expect(result.failures![0].file).toBe("math_test.go");
|
|
100
|
+
expect(result.failures![0].line).toBe(20);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("all passing → status pass", async () => {
|
|
104
|
+
const stdout = ndjson(
|
|
105
|
+
{ Action: "run", Package: "math-test", Test: "TestAdd" },
|
|
106
|
+
{ Action: "pass", Package: "math-test", Test: "TestAdd" },
|
|
107
|
+
{ Action: "pass", Package: "math-test", Elapsed: 0.1 }
|
|
108
|
+
);
|
|
109
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
110
|
+
expect(result.status).toBe("pass");
|
|
111
|
+
expect(result.summary).toBe("1 passed");
|
|
112
|
+
expect(result.failures).toHaveLength(0);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("empty stdout → status error", async () => {
|
|
116
|
+
const result = await parser.parse(makeCtx(""));
|
|
117
|
+
expect(result.status).toBe("error");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
4
|
+
|
|
5
|
+
interface GoTestEvent {
|
|
6
|
+
Action: string;
|
|
7
|
+
Package?: string;
|
|
8
|
+
Test?: string;
|
|
9
|
+
Output?: string;
|
|
10
|
+
Elapsed?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Extract file:line and message from a Go t.Error/t.Errorf output line. */
|
|
14
|
+
function parseTestOutput(output: string): { file?: string; line?: number; message?: string } | undefined {
|
|
15
|
+
// Format: " file.go:line: message"
|
|
16
|
+
const m = output.match(/^\s+(\S+\.go):(\d+):\s+(.+)/);
|
|
17
|
+
if (m) return { file: m[1], line: Number(m[2]), message: m[3].trim() };
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Extract panic message and user-code file:line from a stack trace. */
|
|
22
|
+
function parsePanic(
|
|
23
|
+
outputs: string[],
|
|
24
|
+
testName: string
|
|
25
|
+
): { message?: string; file?: string; line?: number } | undefined {
|
|
26
|
+
const panicLine = outputs.find((o) => o.trim().startsWith("panic:"));
|
|
27
|
+
if (!panicLine) return undefined;
|
|
28
|
+
const message = panicLine
|
|
29
|
+
.trim()
|
|
30
|
+
.replace(/^panic:\s*/, "")
|
|
31
|
+
.replace(/\s*\[.*\]$/, "")
|
|
32
|
+
.trim();
|
|
33
|
+
|
|
34
|
+
// Find the user code frame: "module.TestName(..." followed by "\tfile.go:line"
|
|
35
|
+
for (let i = 0; i < outputs.length - 1; i++) {
|
|
36
|
+
if (outputs[i].includes(`.${testName}(`)) {
|
|
37
|
+
const m = outputs[i + 1].match(/\t([^\t]+\.go):(\d+)/);
|
|
38
|
+
if (m) return { message, file: m[1], line: Number(m[2]) };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { message };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const parser: ParserModule = {
|
|
45
|
+
id: "go-test-json",
|
|
46
|
+
async parse(ctx) {
|
|
47
|
+
const stdout = fs.readFileSync(ctx.stdoutPath, "utf8").trim();
|
|
48
|
+
if (!stdout) {
|
|
49
|
+
return { tool: "go test", status: "error", summary: "no output", logPath: ctx.logPath };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const events: GoTestEvent[] = [];
|
|
53
|
+
for (const line of stdout.split("\n")) {
|
|
54
|
+
if (!line.trim()) continue;
|
|
55
|
+
try {
|
|
56
|
+
events.push(JSON.parse(line) as GoTestEvent);
|
|
57
|
+
} catch {
|
|
58
|
+
// skip non-JSON lines
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Collect outputs per test
|
|
63
|
+
const testOutputs = new Map<string, string[]>();
|
|
64
|
+
let passed = 0;
|
|
65
|
+
let failed = 0;
|
|
66
|
+
|
|
67
|
+
for (const e of events) {
|
|
68
|
+
if (!e.Test) continue;
|
|
69
|
+
if (e.Action === "output") {
|
|
70
|
+
const outputs = testOutputs.get(e.Test) ?? [];
|
|
71
|
+
outputs.push(e.Output ?? "");
|
|
72
|
+
testOutputs.set(e.Test, outputs);
|
|
73
|
+
} else if (e.Action === "pass") {
|
|
74
|
+
passed++;
|
|
75
|
+
} else if (e.Action === "fail") {
|
|
76
|
+
failed++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const failures: ParsedFailure[] = [];
|
|
81
|
+
for (const e of events) {
|
|
82
|
+
if (e.Action !== "fail" || !e.Test) continue;
|
|
83
|
+
const outputs = testOutputs.get(e.Test) ?? [];
|
|
84
|
+
|
|
85
|
+
// Try parsing as a t.Error/t.Errorf output first
|
|
86
|
+
let found = false;
|
|
87
|
+
for (const o of outputs) {
|
|
88
|
+
const parsed = parseTestOutput(o);
|
|
89
|
+
if (parsed) {
|
|
90
|
+
const relFile = parsed.file
|
|
91
|
+
? path.isAbsolute(parsed.file)
|
|
92
|
+
? path.relative(ctx.cwd, parsed.file)
|
|
93
|
+
: parsed.file
|
|
94
|
+
: undefined;
|
|
95
|
+
failures.push({
|
|
96
|
+
id: e.Test,
|
|
97
|
+
file: relFile,
|
|
98
|
+
line: parsed.line,
|
|
99
|
+
message: parsed.message,
|
|
100
|
+
});
|
|
101
|
+
found = true;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!found) {
|
|
107
|
+
// Try parsing as a panic
|
|
108
|
+
const panic = parsePanic(outputs, e.Test);
|
|
109
|
+
if (panic) {
|
|
110
|
+
const relFile = panic.file
|
|
111
|
+
? path.isAbsolute(panic.file)
|
|
112
|
+
? path.relative(ctx.cwd, panic.file)
|
|
113
|
+
: panic.file
|
|
114
|
+
: undefined;
|
|
115
|
+
failures.push({
|
|
116
|
+
id: e.Test,
|
|
117
|
+
file: relFile,
|
|
118
|
+
line: panic.line,
|
|
119
|
+
message: panic.message ?? "panic",
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
failures.push({ id: e.Test, message: "test failed" });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
tool: "go test",
|
|
129
|
+
status: failed > 0 ? "fail" : "pass",
|
|
130
|
+
summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
|
|
131
|
+
failures,
|
|
132
|
+
logPath: ctx.logPath,
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export default parser;
|