@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.
Files changed (72) hide show
  1. package/README.md +108 -74
  2. package/extensions/structured-return/src/config/registry.test.ts +171 -0
  3. package/extensions/structured-return/src/config/registry.ts +183 -14
  4. package/extensions/structured-return/src/index.test.ts +54 -0
  5. package/extensions/structured-return/src/index.ts +20 -9
  6. package/extensions/structured-return/src/parsers/ava-text.test.ts +116 -0
  7. package/extensions/structured-return/src/parsers/ava-text.ts +161 -0
  8. package/extensions/structured-return/src/parsers/bandit-json.test.ts +90 -0
  9. package/extensions/structured-return/src/parsers/bandit-json.ts +78 -0
  10. package/extensions/structured-return/src/parsers/black-text.test.ts +67 -0
  11. package/extensions/structured-return/src/parsers/black-text.ts +74 -0
  12. package/extensions/structured-return/src/parsers/cargo-build.ts +2 -2
  13. package/extensions/structured-return/src/parsers/cargo-test.ts +2 -2
  14. package/extensions/structured-return/src/parsers/clang-text.test.ts +61 -0
  15. package/extensions/structured-return/src/parsers/clang-text.ts +59 -0
  16. package/extensions/structured-return/src/parsers/dbt-json.ts +2 -2
  17. package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +85 -0
  18. package/extensions/structured-return/src/parsers/dotnet-build-text.ts +48 -0
  19. package/extensions/structured-return/src/parsers/eslint-json.ts +2 -2
  20. package/extensions/structured-return/src/parsers/go-test-json.test.ts +119 -0
  21. package/extensions/structured-return/src/parsers/go-test-json.ts +137 -0
  22. package/extensions/structured-return/src/parsers/hadolint-json.test.ts +73 -0
  23. package/extensions/structured-return/src/parsers/hadolint-json.ts +55 -0
  24. package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +72 -0
  25. package/extensions/structured-return/src/parsers/htmlhint-json.ts +72 -0
  26. package/extensions/structured-return/src/parsers/isort-text.test.ts +58 -0
  27. package/extensions/structured-return/src/parsers/isort-text.ts +64 -0
  28. package/extensions/structured-return/src/parsers/javac-text.test.ts +75 -0
  29. package/extensions/structured-return/src/parsers/javac-text.ts +81 -0
  30. package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +52 -0
  31. package/extensions/structured-return/src/parsers/jsonlint-text.ts +64 -0
  32. package/extensions/structured-return/src/parsers/junit-xml.ts +2 -2
  33. package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +76 -0
  34. package/extensions/structured-return/src/parsers/markdownlint-json.ts +73 -0
  35. package/extensions/structured-return/src/parsers/minitest-text.ts +2 -2
  36. package/extensions/structured-return/src/parsers/mocha-json.test.ts +108 -0
  37. package/extensions/structured-return/src/parsers/mocha-json.ts +77 -0
  38. package/extensions/structured-return/src/parsers/mypy-json.test.ts +101 -0
  39. package/extensions/structured-return/src/parsers/mypy-json.ts +80 -0
  40. package/extensions/structured-return/src/parsers/node-test-text.test.ts +117 -0
  41. package/extensions/structured-return/src/parsers/node-test-text.ts +90 -0
  42. package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +83 -0
  43. package/extensions/structured-return/src/parsers/npm-audit-json.ts +88 -0
  44. package/extensions/structured-return/src/parsers/prettier-text.test.ts +76 -0
  45. package/extensions/structured-return/src/parsers/prettier-text.ts +63 -0
  46. package/extensions/structured-return/src/parsers/pylint-json.test.ts +120 -0
  47. package/extensions/structured-return/src/parsers/pylint-json.ts +64 -0
  48. package/extensions/structured-return/src/parsers/pyright-json.test.ts +112 -0
  49. package/extensions/structured-return/src/parsers/pyright-json.ts +81 -0
  50. package/extensions/structured-return/src/parsers/rspec-json.ts +2 -2
  51. package/extensions/structured-return/src/parsers/rubocop-json.test.ts +118 -0
  52. package/extensions/structured-return/src/parsers/rubocop-json.ts +65 -0
  53. package/extensions/structured-return/src/parsers/ruff-json.ts +2 -2
  54. package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +110 -0
  55. package/extensions/structured-return/src/parsers/shellcheck-json.ts +61 -0
  56. package/extensions/structured-return/src/parsers/stylelint-json.test.ts +120 -0
  57. package/extensions/structured-return/src/parsers/stylelint-json.ts +68 -0
  58. package/extensions/structured-return/src/parsers/swiftc-text.test.ts +73 -0
  59. package/extensions/structured-return/src/parsers/swiftc-text.ts +47 -0
  60. package/extensions/structured-return/src/parsers/tail-fallback.ts +2 -2
  61. package/extensions/structured-return/src/parsers/tidy-text.test.ts +74 -0
  62. package/extensions/structured-return/src/parsers/tidy-text.ts +67 -0
  63. package/extensions/structured-return/src/parsers/tsc-text.test.ts +81 -0
  64. package/extensions/structured-return/src/parsers/tsc-text.ts +47 -0
  65. package/extensions/structured-return/src/parsers/unittest-text.test.ts +126 -0
  66. package/extensions/structured-return/src/parsers/unittest-text.ts +116 -0
  67. package/extensions/structured-return/src/parsers/utils.ts +43 -0
  68. package/extensions/structured-return/src/parsers/vale-json.test.ts +84 -0
  69. package/extensions/structured-return/src/parsers/vale-json.ts +80 -0
  70. package/extensions/structured-return/src/parsers/vitest-json.ts +2 -2
  71. package/package.json +1 -1
  72. package/skills/structured-return/SKILL.md +93 -2
@@ -0,0 +1,90 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ // Summary lines: ℹ pass 1, ℹ fail 2
6
+ const SUMMARY_PASS = /^ℹ pass (\d+)/m;
7
+ const SUMMARY_FAIL = /^ℹ fail (\d+)/m;
8
+
9
+ // Failing test header: test at file:line:col
10
+ const TEST_AT_LINE = /^test at (.+?):(\d+):\d+/;
11
+
12
+ const parser: ParserModule = {
13
+ id: "node-test-text",
14
+ async parse(ctx) {
15
+ const combined = safeReadFile(ctx.stdoutPath) + safeReadFile(ctx.stderrPath);
16
+ if (!combined.trim()) {
17
+ return {
18
+ tool: "node:test",
19
+ status: "pass",
20
+ summary: "no tests found",
21
+ failures: [],
22
+ logPath: ctx.logPath,
23
+ };
24
+ }
25
+
26
+ const passMatch = combined.match(SUMMARY_PASS);
27
+ const failMatch = combined.match(SUMMARY_FAIL);
28
+ const passed = passMatch ? parseInt(passMatch[1], 10) : 0;
29
+ const failed = failMatch ? parseInt(failMatch[1], 10) : 0;
30
+
31
+ // Parse the "failing tests:" section
32
+ const failingSection = combined.split("✖ failing tests:")[1] ?? "";
33
+ const failures: ParsedFailure[] = [];
34
+
35
+ if (failingSection) {
36
+ // Split into per-test blocks by "test at" lines
37
+ const blocks = failingSection.split(/(?=^test at )/m).filter((b) => b.trim());
38
+
39
+ for (const block of blocks) {
40
+ const atMatch = block.match(TEST_AT_LINE);
41
+ const nameMatch = block.match(/^✖ (.+?) \(/m);
42
+
43
+ let file: string | undefined;
44
+ let line: number | undefined;
45
+ if (atMatch) {
46
+ file = path.relative(ctx.cwd, atMatch[1]);
47
+ line = parseInt(atMatch[2], 10);
48
+ }
49
+
50
+ const name = nameMatch ? nameMatch[1] : "unknown test";
51
+
52
+ // Extract meaningful error message — try specific patterns first, then generic
53
+ let message = name;
54
+ const strictMatch = block.match(/Expected values to be strictly equal:\s*\n\s*\n\s*(.+)/);
55
+ const falsyMatch = block.match(/The expression evaluated to a falsy value:\s*\n\s*\n\s*(.+)/);
56
+ if (strictMatch) {
57
+ message = `Expected values to be strictly equal: ${strictMatch[1].trim()}`;
58
+ } else if (falsyMatch) {
59
+ message = `The expression evaluated to a falsy value: ${falsyMatch[1].trim()}`;
60
+ } else {
61
+ // Match any Error type (AssertionError, TypeError, ReferenceError, etc.)
62
+ const errorMatch = block.match(/^\s+(\w*Error\b.*?)$/m);
63
+ if (errorMatch) message = errorMatch[1].replace(/\s*\[ERR_\w+\]:\s*/, ": ").replace(/^\w+Error: /, "");
64
+ }
65
+
66
+ failures.push({
67
+ id: `${file}:${line}`,
68
+ file,
69
+ line,
70
+ message,
71
+ });
72
+ }
73
+ }
74
+
75
+ const parts: string[] = [];
76
+ if (failed > 0) parts.push(`${failed} failed`);
77
+ if (passed > 0) parts.push(`${passed} passed`);
78
+ const summary = parts.join(", ") || "tests completed";
79
+
80
+ return {
81
+ tool: "node:test",
82
+ status: failed > 0 ? "fail" : "pass",
83
+ summary,
84
+ failures,
85
+ logPath: ctx.logPath,
86
+ };
87
+ },
88
+ };
89
+
90
+ export default parser;
@@ -0,0 +1,83 @@
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 "./npm-audit-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(), "npm-audit-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ fs.writeFileSync(stdoutPath, stdout);
12
+ return {
13
+ command: "npm audit --json",
14
+ argv: ["npm", "audit", "--json"],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath,
18
+ stderrPath: path.join(dir, "stderr"),
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("npm-audit-json parser", () => {
24
+ it("vulnerabilities with advisories → extracts package name, severity, advisory titles", async () => {
25
+ const stdout = JSON.stringify({
26
+ auditReportVersion: 2,
27
+ vulnerabilities: {
28
+ lodash: {
29
+ name: "lodash",
30
+ severity: "high",
31
+ isDirect: true,
32
+ via: [
33
+ { title: "Command Injection in lodash", severity: "high", url: "https://example.com" },
34
+ { title: "ReDoS in lodash", severity: "moderate", url: "https://example.com" },
35
+ ],
36
+ fixAvailable: true,
37
+ },
38
+ },
39
+ metadata: { vulnerabilities: { info: 0, low: 0, moderate: 0, high: 1, critical: 0, total: 1 } },
40
+ });
41
+ const result = await parser.parse(makeCtx(stdout));
42
+ expect(result.status).toBe("fail");
43
+ expect(result.summary).toBe("1 vulnerability (1 high)");
44
+ expect(result.failures).toHaveLength(1);
45
+ expect(result.failures![0].file).toBe("lodash");
46
+ expect(result.failures![0].rule).toBe("high");
47
+ expect(result.failures![0].message).toContain("Command Injection");
48
+ expect(result.failures![0].message).toContain("ReDoS");
49
+ // No URLs in output
50
+ expect(result.failures![0].message).not.toContain("https://");
51
+ });
52
+
53
+ it("no vulnerabilities → status pass", async () => {
54
+ const stdout = JSON.stringify({
55
+ auditReportVersion: 2,
56
+ vulnerabilities: {},
57
+ metadata: { vulnerabilities: { info: 0, low: 0, moderate: 0, high: 0, critical: 0, total: 0 } },
58
+ });
59
+ const result = await parser.parse(makeCtx(stdout));
60
+ expect(result.status).toBe("pass");
61
+ expect(result.summary).toBe("no vulnerabilities found");
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("multiple severities → correct summary breakdown", async () => {
72
+ const stdout = JSON.stringify({
73
+ vulnerabilities: {
74
+ "pkg-a": { name: "pkg-a", severity: "critical", isDirect: true, via: [{ title: "RCE" }] },
75
+ "pkg-b": { name: "pkg-b", severity: "low", isDirect: false, via: [{ title: "Info leak" }] },
76
+ },
77
+ metadata: { vulnerabilities: { info: 0, low: 1, moderate: 0, high: 0, critical: 1, total: 2 } },
78
+ });
79
+ const result = await parser.parse(makeCtx(stdout));
80
+ expect(result.summary).toBe("2 vulnerabilities (1 critical, 1 low)");
81
+ expect(result.failures).toHaveLength(2);
82
+ });
83
+ });
@@ -0,0 +1,88 @@
1
+ import type { ParserModule, ParsedFailure } from "../types";
2
+ import { safeReadFile } from "./utils";
3
+
4
+ interface NpmAuditVia {
5
+ title?: string;
6
+ severity?: string;
7
+ url?: string;
8
+ name?: string;
9
+ }
10
+
11
+ interface NpmAuditVuln {
12
+ name: string;
13
+ severity: string;
14
+ isDirect: boolean;
15
+ via: Array<NpmAuditVia | string>;
16
+ fixAvailable?: boolean | { name: string; version: string };
17
+ }
18
+
19
+ interface NpmAuditReport {
20
+ vulnerabilities?: Record<string, NpmAuditVuln>;
21
+ metadata?: {
22
+ vulnerabilities?: Record<string, number>;
23
+ };
24
+ }
25
+
26
+ const parser: ParserModule = {
27
+ id: "npm-audit-json",
28
+ async parse(ctx) {
29
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
30
+ if (!stdout) {
31
+ return {
32
+ tool: "npm audit",
33
+ status: "pass",
34
+ summary: "no vulnerabilities found",
35
+ failures: [],
36
+ logPath: ctx.logPath,
37
+ };
38
+ }
39
+
40
+ let report: NpmAuditReport;
41
+ try {
42
+ report = JSON.parse(stdout);
43
+ } catch {
44
+ return {
45
+ tool: "npm audit",
46
+ status: "error",
47
+ summary: "failed to parse npm audit JSON output",
48
+ logPath: ctx.logPath,
49
+ };
50
+ }
51
+
52
+ const vulns = report.vulnerabilities ?? {};
53
+ const failures: ParsedFailure[] = [];
54
+
55
+ for (const [pkg, vuln] of Object.entries(vulns)) {
56
+ // Extract advisory titles from 'via' (skip string refs to other packages)
57
+ const titles = vuln.via.filter((v): v is NpmAuditVia => typeof v !== "string" && !!v.title).map((v) => v.title!);
58
+ const message = titles.length > 0 ? titles.join("; ") : `${vuln.severity} severity vulnerability`;
59
+ failures.push({
60
+ id: pkg,
61
+ file: pkg,
62
+ message,
63
+ rule: vuln.severity,
64
+ });
65
+ }
66
+
67
+ // Build severity summary from metadata
68
+ const meta = report.metadata?.vulnerabilities ?? {};
69
+ const sevParts = ["critical", "high", "moderate", "low", "info"]
70
+ .filter((s) => meta[s])
71
+ .map((s) => `${meta[s]} ${s}`);
72
+ const total = meta.total ?? failures.length;
73
+ const summary =
74
+ total > 0
75
+ ? `${total} vulnerabilit${total !== 1 ? "ies" : "y"} (${sevParts.join(", ")})`
76
+ : "no vulnerabilities found";
77
+
78
+ return {
79
+ tool: "npm audit",
80
+ status: total > 0 ? "fail" : "pass",
81
+ summary,
82
+ failures,
83
+ logPath: ctx.logPath,
84
+ };
85
+ },
86
+ };
87
+
88
+ export default parser;
@@ -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 "./prettier-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(), "prettier-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: "prettier --check .",
16
+ argv: ["prettier", "--check", "."],
17
+ cwd,
18
+ artifactPaths: [],
19
+ stdoutPath,
20
+ stderrPath,
21
+ logPath: path.join(dir, "log"),
22
+ };
23
+ }
24
+
25
+ describe("prettier-text parser", () => {
26
+ it("files needing formatting → strips preamble/footer, lists files", async () => {
27
+ const cwd = "/project";
28
+ const stdout = `Checking formatting...
29
+ [warn] /project/src/app.ts
30
+ [warn] /project/src/utils.ts
31
+ [warn] Code style issues found in 2 files. Run Prettier with --write to fix.`;
32
+ const result = await parser.parse(makeCtx(stdout, "", cwd));
33
+ expect(result.status).toBe("fail");
34
+ expect(result.summary).toBe("2 files have formatting issues");
35
+ expect(result.failures).toHaveLength(2);
36
+ expect(result.failures![0].file).toBe("src/app.ts");
37
+ expect(result.failures![1].file).toBe("src/utils.ts");
38
+ });
39
+
40
+ it("all formatted → status pass", async () => {
41
+ const stdout = `Checking formatting...
42
+ All matched files use Prettier code style!`;
43
+ const result = await parser.parse(makeCtx(stdout));
44
+ expect(result.status).toBe("pass");
45
+ expect(result.summary).toBe("all files formatted");
46
+ expect(result.failures).toHaveLength(0);
47
+ });
48
+
49
+ it("single file → singular grammar", async () => {
50
+ const stdout = `Checking formatting...
51
+ [warn] /project/bad.ts
52
+ [warn] Code style issues found in the above file. Run Prettier with --write to fix.`;
53
+ const result = await parser.parse(makeCtx(stdout));
54
+ expect(result.status).toBe("fail");
55
+ expect(result.summary).toBe("1 file has formatting issues");
56
+ });
57
+
58
+ it("extensionless files (Dockerfile, Makefile) → not dropped", async () => {
59
+ const cwd = "/project";
60
+ const stdout = `Checking formatting...
61
+ [warn] /project/Dockerfile
62
+ [warn] /project/src/app.ts
63
+ [warn] Code style issues found in 2 files. Run Prettier with --write to fix.`;
64
+ const result = await parser.parse(makeCtx(stdout, "", cwd));
65
+ expect(result.status).toBe("fail");
66
+ expect(result.failures).toHaveLength(2);
67
+ expect(result.failures![0].file).toBe("Dockerfile");
68
+ expect(result.failures![1].file).toBe("src/app.ts");
69
+ });
70
+
71
+ it("empty output → no crash, status pass", async () => {
72
+ const result = await parser.parse(makeCtx(""));
73
+ expect(result.status).toBe("pass");
74
+ expect(result.failures).toHaveLength(0);
75
+ });
76
+ });
@@ -0,0 +1,63 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ // [warn] /path/to/file — but not summary lines like "[warn] Code style issues..."
6
+ const WARN_LINE = /^\[warn\] (.+)$/;
7
+ const SUMMARY_PREFIX = /^Code style issues|^Run Prettier/;
8
+
9
+ const parser: ParserModule = {
10
+ id: "prettier-text",
11
+ async parse(ctx) {
12
+ const combined = (safeReadFile(ctx.stdoutPath) + "\n" + safeReadFile(ctx.stderrPath)).trim();
13
+ if (!combined) {
14
+ return {
15
+ tool: "prettier",
16
+ status: "pass",
17
+ summary: "all files formatted",
18
+ failures: [],
19
+ logPath: ctx.logPath,
20
+ };
21
+ }
22
+
23
+ const lines = combined.split("\n");
24
+ const failures: ParsedFailure[] = [];
25
+
26
+ for (const line of lines) {
27
+ const warnMatch = line.match(WARN_LINE);
28
+ if (warnMatch && !SUMMARY_PREFIX.test(warnMatch[1])) {
29
+ const relPath = path.relative(ctx.cwd, warnMatch[1]);
30
+ failures.push({
31
+ id: relPath,
32
+ file: relPath,
33
+ message: "needs formatting",
34
+ });
35
+ }
36
+ }
37
+
38
+ // All done, no warnings
39
+ if (failures.length === 0 && combined.includes("All matched files use Prettier code style")) {
40
+ return {
41
+ tool: "prettier",
42
+ status: "pass",
43
+ summary: "all files formatted",
44
+ failures: [],
45
+ logPath: ctx.logPath,
46
+ };
47
+ }
48
+
49
+ const n = failures.length;
50
+ const summary =
51
+ n > 0 ? (n === 1 ? "1 file has formatting issues" : `${n} files have formatting issues`) : "all files formatted";
52
+
53
+ return {
54
+ tool: "prettier",
55
+ status: n > 0 ? "fail" : "pass",
56
+ summary,
57
+ failures,
58
+ logPath: ctx.logPath,
59
+ };
60
+ },
61
+ };
62
+
63
+ export default parser;
@@ -0,0 +1,120 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { describe, it, expect } from "vitest";
5
+ import parser from "./pylint-json";
6
+ import type { RunContext } from "../types";
7
+
8
+ function makeCtx(stdout: string, cwd = "/project"): RunContext {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pylint-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ fs.writeFileSync(stdoutPath, stdout);
12
+ return {
13
+ command: "pylint lint_check.py --output-format=json",
14
+ argv: ["pylint", "lint_check.py", "--output-format=json"],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath,
18
+ stderrPath: path.join(dir, "stderr"),
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("pylint-json parser", () => {
24
+ it("multiple lint errors → correct file, line, message, rule, status fail", async () => {
25
+ const stdout = JSON.stringify([
26
+ {
27
+ type: "warning",
28
+ module: "lint_check",
29
+ obj: "process_order",
30
+ line: 5,
31
+ column: 4,
32
+ endLine: 5,
33
+ endColumn: 12,
34
+ path: "lint_check.py",
35
+ symbol: "unused-variable",
36
+ message: "Unused variable 'discount'",
37
+ "message-id": "W0612",
38
+ },
39
+ {
40
+ type: "warning",
41
+ module: "lint_check",
42
+ obj: "",
43
+ line: 1,
44
+ column: 0,
45
+ endLine: 1,
46
+ endColumn: 9,
47
+ path: "lint_check.py",
48
+ symbol: "unused-import",
49
+ message: "Unused import os",
50
+ "message-id": "W0611",
51
+ },
52
+ ]);
53
+ const result = await parser.parse(makeCtx(stdout));
54
+ expect(result.status).toBe("fail");
55
+ expect(result.summary).toBe("2 lint errors");
56
+ expect(result.failures).toHaveLength(2);
57
+ expect(result.failures![0]).toMatchObject({
58
+ file: "lint_check.py",
59
+ line: 5,
60
+ message: "Unused variable 'discount'",
61
+ rule: "W0612(unused-variable)",
62
+ });
63
+ expect(result.failures![1]).toMatchObject({
64
+ file: "lint_check.py",
65
+ line: 1,
66
+ message: "Unused import os",
67
+ rule: "W0611(unused-import)",
68
+ });
69
+ });
70
+
71
+ it("no errors (empty array) → status pass", async () => {
72
+ const result = await parser.parse(makeCtx("[]"));
73
+ expect(result.status).toBe("pass");
74
+ expect(result.summary).toBe("no lint errors");
75
+ expect(result.failures).toHaveLength(0);
76
+ });
77
+
78
+ it("empty stdout → status pass", async () => {
79
+ const result = await parser.parse(makeCtx(""));
80
+ expect(result.status).toBe("pass");
81
+ expect(result.failures).toHaveLength(0);
82
+ });
83
+
84
+ it("absolute file paths → relativized to cwd", async () => {
85
+ const stdout = JSON.stringify([
86
+ {
87
+ type: "convention",
88
+ module: "foo",
89
+ obj: "",
90
+ line: 1,
91
+ column: 0,
92
+ path: "/project/src/foo.py",
93
+ symbol: "missing-module-docstring",
94
+ message: "Missing module docstring",
95
+ "message-id": "C0114",
96
+ },
97
+ ]);
98
+ const result = await parser.parse(makeCtx(stdout, "/project"));
99
+ expect(result.failures![0].file).toBe("src/foo.py");
100
+ expect(result.failures![0].file).not.toContain("/project");
101
+ });
102
+
103
+ it("rule includes both message-id and symbol", async () => {
104
+ const stdout = JSON.stringify([
105
+ {
106
+ type: "convention",
107
+ module: "foo",
108
+ obj: "",
109
+ line: 1,
110
+ column: 0,
111
+ path: "foo.py",
112
+ symbol: "line-too-long",
113
+ message: "Line too long (120/100)",
114
+ "message-id": "C0301",
115
+ },
116
+ ]);
117
+ const result = await parser.parse(makeCtx(stdout));
118
+ expect(result.failures![0].rule).toBe("C0301(line-too-long)");
119
+ });
120
+ });
@@ -0,0 +1,64 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ interface PylintItem {
6
+ type: string;
7
+ module: string;
8
+ obj: string;
9
+ line: number;
10
+ column: number;
11
+ path: string;
12
+ symbol: string;
13
+ message: string;
14
+ "message-id": string;
15
+ }
16
+
17
+ const parser: ParserModule = {
18
+ id: "pylint-json",
19
+ async parse(ctx) {
20
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
21
+ if (!stdout || stdout === "[]") {
22
+ return {
23
+ tool: "pylint",
24
+ status: "pass",
25
+ summary: "no lint errors",
26
+ failures: [],
27
+ logPath: ctx.logPath,
28
+ };
29
+ }
30
+
31
+ let items: PylintItem[];
32
+ try {
33
+ items = JSON.parse(stdout) as PylintItem[];
34
+ } catch {
35
+ return {
36
+ tool: "pylint",
37
+ status: "error",
38
+ summary: "failed to parse pylint JSON output",
39
+ logPath: ctx.logPath,
40
+ };
41
+ }
42
+
43
+ const failures: ParsedFailure[] = items.map((item) => {
44
+ const relPath = path.isAbsolute(item.path) ? path.relative(ctx.cwd, item.path) : item.path;
45
+ return {
46
+ id: `${relPath}:${item.line}:${item["message-id"]}`,
47
+ file: relPath,
48
+ line: item.line,
49
+ message: item.message,
50
+ rule: `${item["message-id"]}(${item.symbol})`,
51
+ };
52
+ });
53
+
54
+ return {
55
+ tool: "pylint",
56
+ status: failures.length > 0 ? "fail" : "pass",
57
+ summary: failures.length > 0 ? `${failures.length} lint errors` : "no lint errors",
58
+ failures,
59
+ logPath: ctx.logPath,
60
+ };
61
+ },
62
+ };
63
+
64
+ export default parser;