@robhowley/pi-structured-return 1.5.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 +34 -4
- package/extensions/structured-return/src/config/registry.ts +92 -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/clang-text.test.ts +61 -0
- package/extensions/structured-return/src/parsers/clang-text.ts +59 -0
- 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/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/markdownlint-json.test.ts +76 -0
- package/extensions/structured-return/src/parsers/markdownlint-json.ts +73 -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/pyright-json.test.ts +112 -0
- package/extensions/structured-return/src/parsers/pyright-json.ts +81 -0
- 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/vale-json.test.ts +84 -0
- package/extensions/structured-return/src/parsers/vale-json.ts +80 -0
- package/package.json +1 -1
- package/skills/structured-return/SKILL.md +58 -6
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ Benchmark: 3 tests — 1 passing, 1 assertion failure, 1 unexpected error.
|
|
|
60
60
|
|---|---|---|---|---|
|
|
61
61
|
| `go-test-json` | 1819 | 48 | **97%** | NDJSON event stream with stack traces; file:line + expected/actual preserved |
|
|
62
62
|
| `junit-xml` (maven) | 1063 | 86 | **92%** | build lifecycle noise with surefire stack traces per failure |
|
|
63
|
+
| `node-test-text` | 629 | 64 | **90%** | strips full stack traces, assertion internals, timing; preserves expected/actual |
|
|
63
64
|
| `ava-text` | 483 | 56 | **88%** | source snippets, diffs, full stack traces stripped; expected/actual preserved |
|
|
64
65
|
| `junit-xml` (go) | 400 | 58 | **86%** | verbose output with full stack trace per failure |
|
|
65
66
|
| `junit-xml` (dotnet) | 487 | 107 | **78%** | build header and VSTest output with per-failure stack traces |
|
|
@@ -79,6 +80,7 @@ Benchmark: 1 file, 1–2 violations. Reduction is a conservative lower bound —
|
|
|
79
80
|
|
|
80
81
|
| Parser | Raw | Structured | Reduction | Notes |
|
|
81
82
|
|---|---|---|---|---|
|
|
83
|
+
| `dotnet-build-text` | 383 | 53 | **86%** | strips restore/timing noise, deduplicates repeated error lines, absolute paths relativized |
|
|
82
84
|
| `cargo-build` | 225 | 77 | **66%** | rustc error annotations with code spans and help text per error |
|
|
83
85
|
| `swiftc-text` | 161 | 58 | **64%** | source annotations with backtick markers deduplicated |
|
|
84
86
|
| `ruff-json` | 107 | 52 | **51%** | source context + help text per error |
|
|
@@ -88,9 +90,21 @@ Benchmark: 1 file, 1–2 violations. Reduction is a conservative lower bound —
|
|
|
88
90
|
| `stylelint-json` | 70 | 51 | **27%** | strips summary footer and fix hint |
|
|
89
91
|
| `pylint-json` | 141 | 120 | **15%** | strips header, score line, separator; scales with error count |
|
|
90
92
|
| `hadolint-json` | 178 | 156 | **12%** | strips ANSI color codes and level labels; measured vs colored output |
|
|
93
|
+
| `prettier-text` | 38 | 33 | **13%** | strips preamble, [warn] prefixes, footer hint; scales with file count |
|
|
91
94
|
| `eslint-json` | 64 | 59 | **8%** | already compact formatter |
|
|
95
|
+
| `jsonlint-text` | 148 | 28 | **81%** | strips stack trace, source pointer line; preserves line number and expecting message |
|
|
96
|
+
| `npm-audit-json` | 158 | 50 | **68%** | strips advisory URLs, fix instructions, CVSS vectors; advisory titles joined per package |
|
|
97
|
+
| `isort-text` | 143 | 29 | **80%** | strips diff hunks, absolute paths, timestamps; lists files with unsorted imports |
|
|
98
|
+
| `htmlhint-json` | 174 | 92 | **47%** | strips ANSI codes, source evidence, rule descriptions, URLs |
|
|
99
|
+
| `tidy-text` | 233 | 51 | **78%** | strips remediation advice, accessibility tips, HTML output, Info lines |
|
|
100
|
+
| `bandit-json` | 402 | 99 | **75%** | strips source snippets, CWE URLs, run metrics, confidence labels |
|
|
101
|
+
| `markdownlint-json` | 199 | 117 | **41%** | strips context quotes, URLs, fix info, error ranges |
|
|
102
|
+
| `vale-json` | 141 | 79 | **44%** | strips ANSI codes, Action/Span/Description fields, column-aligned formatting |
|
|
103
|
+
| `pyright-json` | 100 | 59 | **41%** | strips version, timing, absolute paths; detail lines collapsed |
|
|
104
|
+
| `clang-text` | 109 | 77 | **29%** | strips source snippets, caret indicators, line numbers from gutter |
|
|
105
|
+
| `javac-text` | 79 | 66 | **16%** | strips source snippets, caret indicators; folds symbol/location into message |
|
|
92
106
|
| `mypy-json` | 75 | 72 | **4%** | mypy text is already compact; notes folded into parent errors |
|
|
93
|
-
| `
|
|
107
|
+
| `black-text` | 155 | 31 | **80%** | strips diff hunks, emoji, timestamps; lists files needing reformatting |
|
|
94
108
|
|
|
95
109
|
### Pipeline tools
|
|
96
110
|
|
|
@@ -107,13 +121,29 @@ The numbers below use 3–4 model toy examples; real projects run hundreds of mo
|
|
|
107
121
|
|
|
108
122
|
At 12 models, run failures hit 85% reduction. An 18-model DAG success: 1,645 → 20 tokens (99%).
|
|
109
123
|
|
|
124
|
+
### Already compact — use `bash` directly
|
|
125
|
+
|
|
126
|
+
Evaluated for structured parsing but raw output is already compact enough that a parser adds no reduction (or goes negative). Use `bash` instead of `structured_return` for these tools.
|
|
127
|
+
|
|
128
|
+
| Tool | Raw tokens | Format | Why no parser |
|
|
129
|
+
|---|---|---|---|
|
|
130
|
+
| `go build` | 85 | `file:line:col: message` | one line per error, no decoration |
|
|
131
|
+
| `flake8` | 75 | `file:line:col: CODE message` | no JSON without a plugin; text is already one line per violation |
|
|
132
|
+
| `yamllint` | 72 | `file:line:col level message (rule)` | filename printed once; one line per issue |
|
|
133
|
+
| `golangci-lint` | 59 | `file:line:col: message (linter)` | text output already minimal; JSON includes massive linter report |
|
|
134
|
+
| `go vet` | ~60 | `file:line:col: message` | same format as go build |
|
|
135
|
+
| `vulture` | 58 | `file:line: message (confidence%)` | single line per finding |
|
|
136
|
+
| `pydocstyle` | 48 | `file:line context + CODE: message` | two lines per issue; structured format would repeat file paths |
|
|
137
|
+
|
|
110
138
|
## Built-in parsers
|
|
111
139
|
|
|
112
|
-
**Test runners:** `junit-xml` (pytest, Gradle, Maven, Jest, Go, .NET — anything that emits JUnit XML), `vitest-json`, `rspec-json`, `minitest-text`, `cargo-test`, `go-test-json`, `mocha-json`, `ava-text`, `unittest-text`
|
|
140
|
+
**Test runners:** `junit-xml` (pytest, Gradle, Maven, Jest, Go, .NET — anything that emits JUnit XML), `vitest-json`, `rspec-json`, `minitest-text`, `cargo-test`, `go-test-json`, `mocha-json`, `ava-text`, `unittest-text`, `node-test-text`
|
|
141
|
+
|
|
142
|
+
**Linters & type checkers:** `ruff-json`, `eslint-json`, `mypy-json`, `pyright-json`, `tsc-text`, `pylint-json`, `shellcheck-json`, `rubocop-json`, `swiftc-text`, `hadolint-json`, `stylelint-json`, `black-text`, `markdownlint-json`, `prettier-text`, `vale-json`, `tidy-text`, `jsonlint-text`, `isort-text`, `htmlhint-json`
|
|
113
143
|
|
|
114
|
-
**
|
|
144
|
+
**Build tools:** `cargo-build`, `javac-text`, `dotnet-build-text`, `clang-text`
|
|
115
145
|
|
|
116
|
-
**
|
|
146
|
+
**Security & audit:** `bandit-json`, `npm-audit-json`
|
|
117
147
|
|
|
118
148
|
**Pipeline tools:** `dbt-json` (run, test, compile)
|
|
119
149
|
|
|
@@ -21,6 +21,21 @@ import mochaJson from "../parsers/mocha-json";
|
|
|
21
21
|
import unittestText from "../parsers/unittest-text";
|
|
22
22
|
import goTestJson from "../parsers/go-test-json";
|
|
23
23
|
import avaText from "../parsers/ava-text";
|
|
24
|
+
import pyrightJson from "../parsers/pyright-json";
|
|
25
|
+
import banditJson from "../parsers/bandit-json";
|
|
26
|
+
import javacText from "../parsers/javac-text";
|
|
27
|
+
import dotnetBuildText from "../parsers/dotnet-build-text";
|
|
28
|
+
import clangText from "../parsers/clang-text";
|
|
29
|
+
import nodeTestText from "../parsers/node-test-text";
|
|
30
|
+
import blackText from "../parsers/black-text";
|
|
31
|
+
import markdownlintJson from "../parsers/markdownlint-json";
|
|
32
|
+
import prettierText from "../parsers/prettier-text";
|
|
33
|
+
import valeJson from "../parsers/vale-json";
|
|
34
|
+
import tidyText from "../parsers/tidy-text";
|
|
35
|
+
import jsonlintText from "../parsers/jsonlint-text";
|
|
36
|
+
import npmAuditJson from "../parsers/npm-audit-json";
|
|
37
|
+
import isortText from "../parsers/isort-text";
|
|
38
|
+
import htmlhintJson from "../parsers/htmlhint-json";
|
|
24
39
|
import tailFallback from "../parsers/tail-fallback";
|
|
25
40
|
|
|
26
41
|
const builtIns: Record<string, ParserModule> = {
|
|
@@ -45,6 +60,21 @@ const builtIns: Record<string, ParserModule> = {
|
|
|
45
60
|
"unittest-text": unittestText,
|
|
46
61
|
"go-test-json": goTestJson,
|
|
47
62
|
"ava-text": avaText,
|
|
63
|
+
"pyright-json": pyrightJson,
|
|
64
|
+
"bandit-json": banditJson,
|
|
65
|
+
"javac-text": javacText,
|
|
66
|
+
"dotnet-build-text": dotnetBuildText,
|
|
67
|
+
"clang-text": clangText,
|
|
68
|
+
"node-test-text": nodeTestText,
|
|
69
|
+
"black-text": blackText,
|
|
70
|
+
"markdownlint-json": markdownlintJson,
|
|
71
|
+
"prettier-text": prettierText,
|
|
72
|
+
"vale-json": valeJson,
|
|
73
|
+
"tidy-text": tidyText,
|
|
74
|
+
"jsonlint-text": jsonlintText,
|
|
75
|
+
"npm-audit-json": npmAuditJson,
|
|
76
|
+
"isort-text": isortText,
|
|
77
|
+
"htmlhint-json": htmlhintJson,
|
|
48
78
|
"tail-fallback": tailFallback,
|
|
49
79
|
};
|
|
50
80
|
|
|
@@ -147,6 +177,68 @@ const AUTO_DETECT: Array<{ parserId: string; detect: (argv: string[]) => boolean
|
|
|
147
177
|
parserId: "ava-text",
|
|
148
178
|
detect: (argv) => argv.includes("ava"),
|
|
149
179
|
},
|
|
180
|
+
{
|
|
181
|
+
parserId: "pyright-json",
|
|
182
|
+
detect: (argv) => argv.includes("pyright") && argv.includes("--outputjson"),
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
parserId: "bandit-json",
|
|
186
|
+
detect: (argv) => argv.includes("bandit") && hasFlag(argv, "-f", "json"),
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
parserId: "javac-text",
|
|
190
|
+
detect: (argv) => argv.includes("javac") && !argv.includes("-version"),
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
parserId: "dotnet-build-text",
|
|
194
|
+
detect: (argv) => argv.includes("dotnet") && argv.includes("build"),
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
parserId: "node-test-text",
|
|
198
|
+
detect: (argv) => argv.includes("node") && argv.includes("--test"),
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
parserId: "black-text",
|
|
202
|
+
detect: (argv) => argv.includes("black") && argv.includes("--check"),
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
parserId: "markdownlint-json",
|
|
206
|
+
detect: (argv) => argv.includes("markdownlint") && argv.includes("--json"),
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
parserId: "prettier-text",
|
|
210
|
+
detect: (argv) => argv.includes("prettier") && argv.includes("--check"),
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
parserId: "tidy-text",
|
|
214
|
+
detect: (argv) => argv.includes("tidy"),
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
parserId: "jsonlint-text",
|
|
218
|
+
detect: (argv) => argv.includes("jsonlint"),
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
parserId: "htmlhint-json",
|
|
222
|
+
detect: (argv) => argv.includes("htmlhint") && hasFlag(argv, "--format", "json"),
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
parserId: "isort-text",
|
|
226
|
+
detect: (argv) => argv.includes("isort") && argv.includes("--check"),
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
parserId: "npm-audit-json",
|
|
230
|
+
detect: (argv) => argv.includes("npm") && argv.includes("audit") && argv.includes("--json"),
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
parserId: "vale-json",
|
|
234
|
+
detect: (argv) => argv.includes("vale") && hasFlag(argv, "--output", "JSON"),
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
parserId: "clang-text",
|
|
238
|
+
detect: (argv) =>
|
|
239
|
+
(argv.includes("gcc") || argv.includes("g++") || argv.includes("clang") || argv.includes("clang++")) &&
|
|
240
|
+
(argv.includes("-c") || argv.includes("-o")),
|
|
241
|
+
},
|
|
150
242
|
];
|
|
151
243
|
|
|
152
244
|
export function listParsers(): { id: string; autoDetect: boolean }[] {
|
|
@@ -0,0 +1,90 @@
|
|
|
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 "./bandit-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(), "bandit-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "bandit -f json .",
|
|
14
|
+
argv: ["bandit", "-f", "json", "."],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("bandit-json parser", () => {
|
|
24
|
+
it("multiple issues → correct severity summary, relative paths, rule includes test_id and test_name", async () => {
|
|
25
|
+
const cwd = "/project";
|
|
26
|
+
const stdout = JSON.stringify({
|
|
27
|
+
results: [
|
|
28
|
+
{
|
|
29
|
+
filename: "/project/src/app.py",
|
|
30
|
+
line_number: 1,
|
|
31
|
+
issue_text: "Consider possible security implications associated with the subprocess module.",
|
|
32
|
+
issue_severity: "LOW",
|
|
33
|
+
issue_confidence: "HIGH",
|
|
34
|
+
test_id: "B404",
|
|
35
|
+
test_name: "blacklist",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
filename: "/project/src/app.py",
|
|
39
|
+
line_number: 4,
|
|
40
|
+
issue_text: "subprocess call with shell=True identified, security issue.",
|
|
41
|
+
issue_severity: "HIGH",
|
|
42
|
+
issue_confidence: "HIGH",
|
|
43
|
+
test_id: "B602",
|
|
44
|
+
test_name: "subprocess_popen_with_shell_equals_true",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
const result = await parser.parse(makeCtx(stdout, cwd));
|
|
49
|
+
expect(result.status).toBe("fail");
|
|
50
|
+
expect(result.summary).toBe("2 issues (1 high, 1 low)");
|
|
51
|
+
expect(result.failures).toHaveLength(2);
|
|
52
|
+
expect(result.failures![0].file).toBe("src/app.py");
|
|
53
|
+
expect(result.failures![0].rule).toBe("B404:blacklist");
|
|
54
|
+
expect(result.failures![1].rule).toBe("B602:subprocess_popen_with_shell_equals_true");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("no issues → status pass, empty failures", async () => {
|
|
58
|
+
const stdout = JSON.stringify({ results: [] });
|
|
59
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
60
|
+
expect(result.status).toBe("pass");
|
|
61
|
+
expect(result.summary).toBe("no security issues");
|
|
62
|
+
expect(result.failures).toHaveLength(0);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("empty stdout → no crash, status pass", async () => {
|
|
66
|
+
const result = await parser.parse(makeCtx(""));
|
|
67
|
+
expect(result.status).toBe("pass");
|
|
68
|
+
expect(result.failures).toHaveLength(0);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("single high severity issue → singular 'issue' in summary", async () => {
|
|
72
|
+
const stdout = JSON.stringify({
|
|
73
|
+
results: [
|
|
74
|
+
{
|
|
75
|
+
filename: "/project/danger.py",
|
|
76
|
+
line_number: 10,
|
|
77
|
+
issue_text: "Possible hardcoded password.",
|
|
78
|
+
issue_severity: "HIGH",
|
|
79
|
+
issue_confidence: "MEDIUM",
|
|
80
|
+
test_id: "B105",
|
|
81
|
+
test_name: "hardcoded_password_string",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
86
|
+
expect(result.status).toBe("fail");
|
|
87
|
+
expect(result.summary).toBe("1 issue (1 high)");
|
|
88
|
+
expect(result.failures).toHaveLength(1);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
interface BanditResult {
|
|
6
|
+
filename: string;
|
|
7
|
+
line_number: number;
|
|
8
|
+
issue_text: string;
|
|
9
|
+
issue_severity: string;
|
|
10
|
+
test_id: string;
|
|
11
|
+
test_name: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface BanditOutput {
|
|
15
|
+
results?: BanditResult[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const parser: ParserModule = {
|
|
19
|
+
id: "bandit-json",
|
|
20
|
+
async parse(ctx) {
|
|
21
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
22
|
+
if (!stdout) {
|
|
23
|
+
return {
|
|
24
|
+
tool: "bandit",
|
|
25
|
+
status: "pass",
|
|
26
|
+
summary: "no security issues",
|
|
27
|
+
failures: [],
|
|
28
|
+
logPath: ctx.logPath,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let output: BanditOutput;
|
|
33
|
+
try {
|
|
34
|
+
output = JSON.parse(stdout);
|
|
35
|
+
} catch {
|
|
36
|
+
return {
|
|
37
|
+
tool: "bandit",
|
|
38
|
+
status: "error",
|
|
39
|
+
summary: "failed to parse bandit JSON output",
|
|
40
|
+
logPath: ctx.logPath,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const results = output.results ?? [];
|
|
45
|
+
const failures: ParsedFailure[] = results.map((r) => {
|
|
46
|
+
const relPath = path.relative(ctx.cwd, r.filename);
|
|
47
|
+
return {
|
|
48
|
+
id: `${relPath}:${r.line_number}:${r.test_id}`,
|
|
49
|
+
file: relPath,
|
|
50
|
+
line: r.line_number,
|
|
51
|
+
message: r.issue_text,
|
|
52
|
+
rule: `${r.test_id}:${r.test_name}`,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const bySeverity: Record<string, number> = {};
|
|
57
|
+
for (const r of results) {
|
|
58
|
+
const sev = r.issue_severity.toLowerCase();
|
|
59
|
+
bySeverity[sev] = (bySeverity[sev] ?? 0) + 1;
|
|
60
|
+
}
|
|
61
|
+
const sevParts = ["high", "medium", "low"].filter((s) => bySeverity[s]).map((s) => `${bySeverity[s]} ${s}`);
|
|
62
|
+
|
|
63
|
+
const summary =
|
|
64
|
+
results.length > 0
|
|
65
|
+
? `${results.length} issue${results.length !== 1 ? "s" : ""} (${sevParts.join(", ")})`
|
|
66
|
+
: "no security issues";
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
tool: "bandit",
|
|
70
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
71
|
+
summary,
|
|
72
|
+
failures,
|
|
73
|
+
logPath: ctx.logPath,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default parser;
|
|
@@ -0,0 +1,67 @@
|
|
|
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 "./black-text";
|
|
6
|
+
import type { RunContext } from "../types";
|
|
7
|
+
|
|
8
|
+
function makeCtx(stdout: string, stderr = "", cwd = "/project"): RunContext {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "black-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
const stderrPath = path.join(dir, "stderr");
|
|
12
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
13
|
+
fs.writeFileSync(stderrPath, stderr);
|
|
14
|
+
return {
|
|
15
|
+
command: "black --check .",
|
|
16
|
+
argv: ["black", "--check", "."],
|
|
17
|
+
cwd,
|
|
18
|
+
artifactPaths: [],
|
|
19
|
+
stdoutPath,
|
|
20
|
+
stderrPath,
|
|
21
|
+
logPath: path.join(dir, "log"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("black-text parser", () => {
|
|
26
|
+
it("files needing reformat → strips emoji, lists files, status fail", async () => {
|
|
27
|
+
const cwd = "/project";
|
|
28
|
+
const stderr = `would reformat /project/src/app.py
|
|
29
|
+
would reformat /project/src/utils.py
|
|
30
|
+
|
|
31
|
+
Oh no! 💥 💔 💥
|
|
32
|
+
2 files would be reformatted.`;
|
|
33
|
+
const result = await parser.parse(makeCtx("", stderr, cwd));
|
|
34
|
+
expect(result.status).toBe("fail");
|
|
35
|
+
expect(result.summary).toBe("2 files would be reformatted");
|
|
36
|
+
expect(result.failures).toHaveLength(2);
|
|
37
|
+
expect(result.failures![0].file).toBe("src/app.py");
|
|
38
|
+
expect(result.failures![1].file).toBe("src/utils.py");
|
|
39
|
+
expect(result.failures![0].message).toBe("would reformat");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("all formatted → status pass", async () => {
|
|
43
|
+
const stderr = `All done! ✨ 🍰 ✨
|
|
44
|
+
3 files would be left unchanged.`;
|
|
45
|
+
const result = await parser.parse(makeCtx("", stderr));
|
|
46
|
+
expect(result.status).toBe("pass");
|
|
47
|
+
expect(result.summary).toBe("all files formatted");
|
|
48
|
+
expect(result.failures).toHaveLength(0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("format errors → captured with message", async () => {
|
|
52
|
+
const stderr = `error: cannot format /project/bad.py: Cannot parse: 1:0:
|
|
53
|
+
Oh no! 💥 💔 💥
|
|
54
|
+
1 file would fail to reformat.`;
|
|
55
|
+
const result = await parser.parse(makeCtx("", stderr));
|
|
56
|
+
expect(result.status).toBe("fail");
|
|
57
|
+
expect(result.failures).toHaveLength(1);
|
|
58
|
+
expect(result.failures![0].file).toBe("bad.py");
|
|
59
|
+
expect(result.failures![0].message).toContain("Cannot parse");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("empty output → no crash, status pass", async () => {
|
|
63
|
+
const result = await parser.parse(makeCtx(""));
|
|
64
|
+
expect(result.status).toBe("pass");
|
|
65
|
+
expect(result.failures).toHaveLength(0);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -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;
|
|
@@ -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;
|