@robhowley/pi-structured-return 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -52
- package/extensions/structured-return/src/config/registry.test.ts +171 -0
- package/extensions/structured-return/src/config/registry.ts +99 -13
- package/extensions/structured-return/src/index.test.ts +54 -0
- package/extensions/structured-return/src/index.ts +20 -9
- package/extensions/structured-return/src/parsers/ava-text.test.ts +116 -0
- package/extensions/structured-return/src/parsers/ava-text.ts +161 -0
- package/extensions/structured-return/src/parsers/cargo-build.ts +2 -2
- package/extensions/structured-return/src/parsers/cargo-test.ts +2 -2
- package/extensions/structured-return/src/parsers/dbt-json.test.ts +172 -0
- package/extensions/structured-return/src/parsers/dbt-json.ts +131 -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/junit-xml.ts +2 -2
- package/extensions/structured-return/src/parsers/minitest-text.ts +2 -2
- package/extensions/structured-return/src/parsers/mocha-json.test.ts +108 -0
- package/extensions/structured-return/src/parsers/mocha-json.ts +77 -0
- package/extensions/structured-return/src/parsers/mypy-json.test.ts +101 -0
- package/extensions/structured-return/src/parsers/mypy-json.ts +80 -0
- package/extensions/structured-return/src/parsers/pylint-json.test.ts +120 -0
- package/extensions/structured-return/src/parsers/pylint-json.ts +64 -0
- package/extensions/structured-return/src/parsers/rspec-json.ts +2 -2
- package/extensions/structured-return/src/parsers/rubocop-json.test.ts +118 -0
- package/extensions/structured-return/src/parsers/rubocop-json.ts +65 -0
- package/extensions/structured-return/src/parsers/ruff-json.ts +2 -2
- package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +110 -0
- package/extensions/structured-return/src/parsers/shellcheck-json.ts +61 -0
- package/extensions/structured-return/src/parsers/stylelint-json.test.ts +120 -0
- package/extensions/structured-return/src/parsers/stylelint-json.ts +68 -0
- package/extensions/structured-return/src/parsers/swiftc-text.test.ts +73 -0
- package/extensions/structured-return/src/parsers/swiftc-text.ts +47 -0
- package/extensions/structured-return/src/parsers/tail-fallback.ts +2 -2
- package/extensions/structured-return/src/parsers/tsc-text.test.ts +81 -0
- package/extensions/structured-return/src/parsers/tsc-text.ts +47 -0
- package/extensions/structured-return/src/parsers/unittest-text.test.ts +126 -0
- package/extensions/structured-return/src/parsers/unittest-text.ts +116 -0
- package/extensions/structured-return/src/parsers/utils.ts +43 -0
- package/extensions/structured-return/src/parsers/vitest-json.ts +2 -2
- package/package.json +1 -1
- package/skills/structured-return/SKILL.md +44 -0
|
@@ -0,0 +1,110 @@
|
|
|
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 "./shellcheck-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(), "shellcheck-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "shellcheck lint_check.sh --format=json",
|
|
14
|
+
argv: ["shellcheck", "lint_check.sh", "--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("shellcheck-json parser", () => {
|
|
24
|
+
it("multiple lint errors → correct file, line, message, rule, status fail", async () => {
|
|
25
|
+
const stdout = JSON.stringify([
|
|
26
|
+
{
|
|
27
|
+
file: "lint_check.sh",
|
|
28
|
+
line: 4,
|
|
29
|
+
endLine: 4,
|
|
30
|
+
column: 6,
|
|
31
|
+
endColumn: 15,
|
|
32
|
+
level: "info",
|
|
33
|
+
code: 2086,
|
|
34
|
+
message: "Double quote to prevent globbing and word splitting.",
|
|
35
|
+
fix: null,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
file: "lint_check.sh",
|
|
39
|
+
line: 6,
|
|
40
|
+
endLine: 6,
|
|
41
|
+
column: 10,
|
|
42
|
+
endColumn: 21,
|
|
43
|
+
level: "error",
|
|
44
|
+
code: 2045,
|
|
45
|
+
message: "Iterating over ls output is fragile. Use globs.",
|
|
46
|
+
fix: null,
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
50
|
+
expect(result.status).toBe("fail");
|
|
51
|
+
expect(result.summary).toBe("2 lint errors");
|
|
52
|
+
expect(result.failures).toHaveLength(2);
|
|
53
|
+
expect(result.failures![0]).toMatchObject({
|
|
54
|
+
file: "lint_check.sh",
|
|
55
|
+
line: 4,
|
|
56
|
+
message: "Double quote to prevent globbing and word splitting.",
|
|
57
|
+
rule: "SC2086",
|
|
58
|
+
});
|
|
59
|
+
expect(result.failures![1]).toMatchObject({
|
|
60
|
+
file: "lint_check.sh",
|
|
61
|
+
line: 6,
|
|
62
|
+
message: "Iterating over ls output is fragile. Use globs.",
|
|
63
|
+
rule: "SC2045",
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("no errors (empty array) → status pass", async () => {
|
|
68
|
+
const result = await parser.parse(makeCtx("[]"));
|
|
69
|
+
expect(result.status).toBe("pass");
|
|
70
|
+
expect(result.summary).toBe("no lint errors");
|
|
71
|
+
expect(result.failures).toHaveLength(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("empty stdout → status pass", async () => {
|
|
75
|
+
const result = await parser.parse(makeCtx(""));
|
|
76
|
+
expect(result.status).toBe("pass");
|
|
77
|
+
expect(result.failures).toHaveLength(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("absolute file paths → relativized to cwd", async () => {
|
|
81
|
+
const stdout = JSON.stringify([
|
|
82
|
+
{
|
|
83
|
+
file: "/project/scripts/deploy.sh",
|
|
84
|
+
line: 10,
|
|
85
|
+
column: 5,
|
|
86
|
+
level: "warning",
|
|
87
|
+
code: 2034,
|
|
88
|
+
message: "foo appears unused.",
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
const result = await parser.parse(makeCtx(stdout, "/project"));
|
|
92
|
+
expect(result.failures![0].file).toBe("scripts/deploy.sh");
|
|
93
|
+
expect(result.failures![0].file).not.toContain("/project");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("rule code is prefixed with SC", async () => {
|
|
97
|
+
const stdout = JSON.stringify([
|
|
98
|
+
{
|
|
99
|
+
file: "test.sh",
|
|
100
|
+
line: 1,
|
|
101
|
+
column: 1,
|
|
102
|
+
level: "info",
|
|
103
|
+
code: 2035,
|
|
104
|
+
message: "Use ./*glob* or -- *glob* so names with dashes won't become options.",
|
|
105
|
+
},
|
|
106
|
+
]);
|
|
107
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
108
|
+
expect(result.failures![0].rule).toBe("SC2035");
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
interface ShellCheckItem {
|
|
6
|
+
file: string;
|
|
7
|
+
line: number;
|
|
8
|
+
column: number;
|
|
9
|
+
level: string;
|
|
10
|
+
code: number;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const parser: ParserModule = {
|
|
15
|
+
id: "shellcheck-json",
|
|
16
|
+
async parse(ctx) {
|
|
17
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
18
|
+
if (!stdout || stdout === "[]") {
|
|
19
|
+
return {
|
|
20
|
+
tool: "shellcheck",
|
|
21
|
+
status: "pass",
|
|
22
|
+
summary: "no lint errors",
|
|
23
|
+
failures: [],
|
|
24
|
+
logPath: ctx.logPath,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let items: ShellCheckItem[];
|
|
29
|
+
try {
|
|
30
|
+
items = JSON.parse(stdout) as ShellCheckItem[];
|
|
31
|
+
} catch {
|
|
32
|
+
return {
|
|
33
|
+
tool: "shellcheck",
|
|
34
|
+
status: "error",
|
|
35
|
+
summary: "failed to parse shellcheck JSON output",
|
|
36
|
+
logPath: ctx.logPath,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const failures: ParsedFailure[] = items.map((item) => {
|
|
41
|
+
const relPath = path.isAbsolute(item.file) ? path.relative(ctx.cwd, item.file) : item.file;
|
|
42
|
+
return {
|
|
43
|
+
id: `${relPath}:${item.line}:SC${item.code}`,
|
|
44
|
+
file: relPath,
|
|
45
|
+
line: item.line,
|
|
46
|
+
message: item.message,
|
|
47
|
+
rule: `SC${item.code}`,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
tool: "shellcheck",
|
|
53
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
54
|
+
summary: failures.length > 0 ? `${failures.length} lint errors` : "no lint errors",
|
|
55
|
+
failures,
|
|
56
|
+
logPath: ctx.logPath,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
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 "./stylelint-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(), "stylelint-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "stylelint lint_check.css --formatter json",
|
|
14
|
+
argv: ["stylelint", "lint_check.css", "--formatter", "json"],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("stylelint-json parser", () => {
|
|
24
|
+
it("multiple warnings → correct file, line, message, rule", async () => {
|
|
25
|
+
const stdout = JSON.stringify([
|
|
26
|
+
{
|
|
27
|
+
source: "/project/lint_check.css",
|
|
28
|
+
warnings: [
|
|
29
|
+
{
|
|
30
|
+
line: 2,
|
|
31
|
+
column: 3,
|
|
32
|
+
rule: "declaration-block-no-duplicate-properties",
|
|
33
|
+
severity: "error",
|
|
34
|
+
text: 'Unexpected duplicate "color" (declaration-block-no-duplicate-properties)',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
line: 4,
|
|
38
|
+
column: 19,
|
|
39
|
+
rule: "declaration-no-important",
|
|
40
|
+
severity: "error",
|
|
41
|
+
text: "Unexpected !important (declaration-no-important)",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
deprecations: [],
|
|
45
|
+
invalidOptionWarnings: [],
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
const result = await parser.parse(makeCtx(stdout, "/project"));
|
|
49
|
+
expect(result.status).toBe("fail");
|
|
50
|
+
expect(result.summary).toBe("2 lint errors");
|
|
51
|
+
expect(result.failures![0]).toMatchObject({
|
|
52
|
+
file: "lint_check.css",
|
|
53
|
+
line: 2,
|
|
54
|
+
message: 'Unexpected duplicate "color"',
|
|
55
|
+
rule: "declaration-block-no-duplicate-properties",
|
|
56
|
+
});
|
|
57
|
+
expect(result.failures![1]).toMatchObject({ message: "Unexpected !important", rule: "declaration-no-important" });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("no warnings → status pass", async () => {
|
|
61
|
+
const stdout = JSON.stringify([{ source: "clean.css", warnings: [], deprecations: [], invalidOptionWarnings: [] }]);
|
|
62
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
63
|
+
expect(result.status).toBe("pass");
|
|
64
|
+
expect(result.failures).toHaveLength(0);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("empty stdout → status pass", async () => {
|
|
68
|
+
const result = await parser.parse(makeCtx(""));
|
|
69
|
+
expect(result.status).toBe("pass");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("strips rule name suffix from message text", async () => {
|
|
73
|
+
const stdout = JSON.stringify([
|
|
74
|
+
{
|
|
75
|
+
source: "foo.css",
|
|
76
|
+
warnings: [
|
|
77
|
+
{
|
|
78
|
+
line: 1,
|
|
79
|
+
column: 1,
|
|
80
|
+
rule: "color-no-invalid-hex",
|
|
81
|
+
severity: "error",
|
|
82
|
+
text: 'Unexpected invalid hex color "#FG" (color-no-invalid-hex)',
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
88
|
+
expect(result.failures![0].message).toBe('Unexpected invalid hex color "#FG"');
|
|
89
|
+
expect(result.failures![0].rule).toBe("color-no-invalid-hex");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("does not strip trailing parens when they are part of the message, not the rule", async () => {
|
|
93
|
+
const stdout = JSON.stringify([
|
|
94
|
+
{
|
|
95
|
+
source: "foo.css",
|
|
96
|
+
warnings: [
|
|
97
|
+
{
|
|
98
|
+
line: 3,
|
|
99
|
+
column: 10,
|
|
100
|
+
rule: "function-no-unknown",
|
|
101
|
+
severity: "error",
|
|
102
|
+
text: 'Unexpected unknown function "clamp(10px, 5vw, 50px)" (function-no-unknown)',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
line: 7,
|
|
106
|
+
column: 15,
|
|
107
|
+
rule: "value-no-vendor-prefix",
|
|
108
|
+
severity: "error",
|
|
109
|
+
text: "Unexpected value with parentheses calc(100% - 10px)",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
]);
|
|
114
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
115
|
+
// First warning: has the standard "(rule-name)" suffix — should be stripped
|
|
116
|
+
expect(result.failures![0].message).toBe('Unexpected unknown function "clamp(10px, 5vw, 50px)"');
|
|
117
|
+
// Second warning: trailing parens are CSS value, not rule suffix — must NOT be stripped
|
|
118
|
+
expect(result.failures![1].message).toBe("Unexpected value with parentheses calc(100% - 10px)");
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
interface StylelintWarning {
|
|
6
|
+
line: number;
|
|
7
|
+
column: number;
|
|
8
|
+
rule: string;
|
|
9
|
+
severity: string;
|
|
10
|
+
text: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface StylelintResult {
|
|
14
|
+
source: string;
|
|
15
|
+
warnings: StylelintWarning[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const parser: ParserModule = {
|
|
19
|
+
id: "stylelint-json",
|
|
20
|
+
async parse(ctx) {
|
|
21
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
22
|
+
if (!stdout || stdout === "[]") {
|
|
23
|
+
return { tool: "stylelint", status: "pass", summary: "no lint errors", failures: [], logPath: ctx.logPath };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let results: StylelintResult[];
|
|
27
|
+
try {
|
|
28
|
+
results = JSON.parse(stdout) as StylelintResult[];
|
|
29
|
+
} catch {
|
|
30
|
+
return {
|
|
31
|
+
tool: "stylelint",
|
|
32
|
+
status: "error",
|
|
33
|
+
summary: "failed to parse stylelint JSON output",
|
|
34
|
+
logPath: ctx.logPath,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const failures: ParsedFailure[] = [];
|
|
39
|
+
for (const result of results) {
|
|
40
|
+
const relPath = path.isAbsolute(result.source) ? path.relative(ctx.cwd, result.source) : result.source;
|
|
41
|
+
for (const w of result.warnings) {
|
|
42
|
+
// Strip the trailing " (rule-name)" from text, but only if the
|
|
43
|
+
// parenthesized content matches the actual rule name. Avoids
|
|
44
|
+
// over-stripping when the message itself ends with parens
|
|
45
|
+
// (e.g. CSS values like "calc(100% - 10px)").
|
|
46
|
+
const suffix = ` (${w.rule})`;
|
|
47
|
+
const msg = w.text.endsWith(suffix) ? w.text.slice(0, -suffix.length) : w.text;
|
|
48
|
+
failures.push({
|
|
49
|
+
id: `${relPath}:${w.line}:${w.rule}`,
|
|
50
|
+
file: relPath,
|
|
51
|
+
line: w.line,
|
|
52
|
+
message: msg,
|
|
53
|
+
rule: w.rule,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
tool: "stylelint",
|
|
60
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
61
|
+
summary: failures.length > 0 ? `${failures.length} lint errors` : "no lint errors",
|
|
62
|
+
failures,
|
|
63
|
+
logPath: ctx.logPath,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default parser;
|
|
@@ -0,0 +1,73 @@
|
|
|
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 "./swiftc-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(), "swiftc-test-"));
|
|
10
|
+
const stderrPath = path.join(dir, "stderr");
|
|
11
|
+
fs.writeFileSync(stderrPath, stderr);
|
|
12
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
13
|
+
fs.writeFileSync(stdoutPath, "");
|
|
14
|
+
return {
|
|
15
|
+
command: "swiftc -typecheck type_check.swift",
|
|
16
|
+
argv: ["swiftc", "-typecheck", "type_check.swift"],
|
|
17
|
+
cwd,
|
|
18
|
+
artifactPaths: [],
|
|
19
|
+
stdoutPath,
|
|
20
|
+
stderrPath,
|
|
21
|
+
logPath: path.join(dir, "log"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("swiftc-text parser", () => {
|
|
26
|
+
it("multiple errors with source annotations → deduplicated, correct file/line/message", async () => {
|
|
27
|
+
const stderr = [
|
|
28
|
+
"type_check.swift:5:22: error: cannot convert value of type 'Int' to specified type 'String'",
|
|
29
|
+
"3 | }",
|
|
30
|
+
"4 | ",
|
|
31
|
+
"5 | let result: String = add(1, 2)",
|
|
32
|
+
" | `- error: cannot convert value of type 'Int' to specified type 'String'",
|
|
33
|
+
'6 | let total: Int = add("hello", 3)',
|
|
34
|
+
"",
|
|
35
|
+
"type_check.swift:6:22: error: cannot convert value of type 'String' to expected argument type 'Int'",
|
|
36
|
+
"5 | let result: String = add(1, 2)",
|
|
37
|
+
'6 | let total: Int = add("hello", 3)',
|
|
38
|
+
" | `- error: cannot convert value of type 'String' to expected argument type 'Int'",
|
|
39
|
+
].join("\n");
|
|
40
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
41
|
+
expect(result.status).toBe("fail");
|
|
42
|
+
expect(result.summary).toBe("2 errors");
|
|
43
|
+
expect(result.failures).toHaveLength(2);
|
|
44
|
+
expect(result.failures![0]).toMatchObject({
|
|
45
|
+
file: "type_check.swift",
|
|
46
|
+
line: 5,
|
|
47
|
+
message: "cannot convert value of type 'Int' to specified type 'String'",
|
|
48
|
+
});
|
|
49
|
+
expect(result.failures![1]).toMatchObject({ file: "type_check.swift", line: 6 });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("empty stderr → status pass", async () => {
|
|
53
|
+
const result = await parser.parse(makeCtx(""));
|
|
54
|
+
expect(result.status).toBe("pass");
|
|
55
|
+
expect(result.failures).toHaveLength(0);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("absolute paths → relativized", async () => {
|
|
59
|
+
const stderr = "/project/Sources/main.swift:10:5: error: use of unresolved identifier 'foo'";
|
|
60
|
+
const result = await parser.parse(makeCtx(stderr, "/project"));
|
|
61
|
+
expect(result.failures![0].file).toBe("Sources/main.swift");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("warnings are skipped", async () => {
|
|
65
|
+
const stderr = [
|
|
66
|
+
"foo.swift:1:1: warning: expression of type 'Int' is unused",
|
|
67
|
+
"foo.swift:2:1: error: cannot find 'bar' in scope",
|
|
68
|
+
].join("\n");
|
|
69
|
+
const result = await parser.parse(makeCtx(stderr));
|
|
70
|
+
expect(result.failures).toHaveLength(1);
|
|
71
|
+
expect(result.failures![0].message).toBe("cannot find 'bar' in scope");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
// swiftc format: file:line:col: error: message (or warning:, note:)
|
|
6
|
+
const SWIFT_LINE = /^(.+?):(\d+):\d+:\s+(error|warning):\s+(.+)$/;
|
|
7
|
+
|
|
8
|
+
const parser: ParserModule = {
|
|
9
|
+
id: "swiftc-text",
|
|
10
|
+
async parse(ctx) {
|
|
11
|
+
// swiftc writes diagnostics (errors, warnings, notes) to stderr.
|
|
12
|
+
const stderr = safeReadFile(ctx.stderrPath).trim();
|
|
13
|
+
if (!stderr) {
|
|
14
|
+
return { tool: "swiftc", status: "pass", summary: "no errors", failures: [], logPath: ctx.logPath };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const failures: ParsedFailure[] = [];
|
|
18
|
+
const seen = new Set<string>();
|
|
19
|
+
for (const line of stderr.split("\n")) {
|
|
20
|
+
const m = line.match(SWIFT_LINE);
|
|
21
|
+
if (!m) continue;
|
|
22
|
+
const [, file, lineNum, severity, message] = m;
|
|
23
|
+
if (severity !== "error") continue; // skip warnings for now
|
|
24
|
+
const relPath = path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file;
|
|
25
|
+
// Deduplicate: swiftc repeats the same error in source annotation lines
|
|
26
|
+
const id = `${relPath}:${lineNum}:${message}`;
|
|
27
|
+
if (seen.has(id)) continue;
|
|
28
|
+
seen.add(id);
|
|
29
|
+
failures.push({
|
|
30
|
+
id,
|
|
31
|
+
file: relPath,
|
|
32
|
+
line: Number(lineNum),
|
|
33
|
+
message,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
tool: "swiftc",
|
|
39
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
40
|
+
summary: failures.length > 0 ? `${failures.length} errors` : "no errors",
|
|
41
|
+
failures,
|
|
42
|
+
logPath: ctx.logPath,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default parser;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import type { ParserModule } from "../types";
|
|
2
|
+
import { safeReadFile } from "./utils";
|
|
3
3
|
|
|
4
4
|
const parser: ParserModule = {
|
|
5
5
|
id: "tail-fallback",
|
|
6
6
|
async parse(ctx) {
|
|
7
|
-
const log =
|
|
7
|
+
const log = safeReadFile(ctx.logPath);
|
|
8
8
|
const lines = log.split(/\r?\n/);
|
|
9
9
|
const tail = lines.slice(-200).join("\n");
|
|
10
10
|
return {
|
|
@@ -0,0 +1,81 @@
|
|
|
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 "./tsc-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(), "tsc-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "tsc --noEmit --pretty false",
|
|
14
|
+
argv: ["tsc", "--noEmit", "--pretty", "false"],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("tsc-text parser", () => {
|
|
24
|
+
it("multiple type errors → correct file, line, message, rule, status fail", async () => {
|
|
25
|
+
const stdout = [
|
|
26
|
+
"type_check.ts(5,7): error TS2322: Type 'number' is not assignable to type 'string'.",
|
|
27
|
+
"type_check.ts(6,27): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.",
|
|
28
|
+
].join("\n");
|
|
29
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
30
|
+
expect(result.status).toBe("fail");
|
|
31
|
+
expect(result.summary).toBe("2 type errors");
|
|
32
|
+
expect(result.failures).toHaveLength(2);
|
|
33
|
+
expect(result.failures![0]).toMatchObject({
|
|
34
|
+
file: "type_check.ts",
|
|
35
|
+
line: 5,
|
|
36
|
+
message: "Type 'number' is not assignable to type 'string'.",
|
|
37
|
+
rule: "TS2322",
|
|
38
|
+
});
|
|
39
|
+
expect(result.failures![1]).toMatchObject({
|
|
40
|
+
file: "type_check.ts",
|
|
41
|
+
line: 6,
|
|
42
|
+
message: "Argument of type 'string' is not assignable to parameter of type 'number'.",
|
|
43
|
+
rule: "TS2345",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("no errors (empty stdout) → status pass", async () => {
|
|
48
|
+
const result = await parser.parse(makeCtx(""));
|
|
49
|
+
expect(result.status).toBe("pass");
|
|
50
|
+
expect(result.summary).toBe("no type errors");
|
|
51
|
+
expect(result.failures).toHaveLength(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("absolute file paths → relativized to cwd", async () => {
|
|
55
|
+
const stdout = "/project/src/foo.ts(10,5): error TS2304: Cannot find name 'bar'.";
|
|
56
|
+
const result = await parser.parse(makeCtx(stdout, "/project"));
|
|
57
|
+
expect(result.failures![0].file).toBe("src/foo.ts");
|
|
58
|
+
expect(result.failures![0].file).not.toContain("/project");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("errors across multiple files", async () => {
|
|
62
|
+
const stdout = [
|
|
63
|
+
"src/a.ts(1,1): error TS2304: Cannot find name 'foo'.",
|
|
64
|
+
"src/b.ts(5,3): error TS2551: Property 'baz' does not exist on type 'Bar'.",
|
|
65
|
+
].join("\n");
|
|
66
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
67
|
+
expect(result.failures).toHaveLength(2);
|
|
68
|
+
expect(result.failures![0].file).toBe("src/a.ts");
|
|
69
|
+
expect(result.failures![1].file).toBe("src/b.ts");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("skips non-error lines (e.g. Found N errors)", async () => {
|
|
73
|
+
const stdout = [
|
|
74
|
+
"type_check.ts(5,7): error TS2322: Type 'number' is not assignable to type 'string'.",
|
|
75
|
+
"",
|
|
76
|
+
"Found 1 error in type_check.ts:5",
|
|
77
|
+
].join("\n");
|
|
78
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
79
|
+
expect(result.failures).toHaveLength(1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
// tsc --pretty false format: file(line,col): error TSXXXX: message
|
|
6
|
+
const TSC_LINE = /^(.+?)\((\d+),(\d+)\):\s+error\s+(TS\d+):\s+(.+)$/;
|
|
7
|
+
|
|
8
|
+
const parser: ParserModule = {
|
|
9
|
+
id: "tsc-text",
|
|
10
|
+
async parse(ctx) {
|
|
11
|
+
const raw = safeReadFile(ctx.stdoutPath).trim();
|
|
12
|
+
if (!raw) {
|
|
13
|
+
return {
|
|
14
|
+
tool: "tsc",
|
|
15
|
+
status: "pass",
|
|
16
|
+
summary: "no type errors",
|
|
17
|
+
failures: [],
|
|
18
|
+
logPath: ctx.logPath,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const failures: ParsedFailure[] = [];
|
|
23
|
+
for (const line of raw.split("\n")) {
|
|
24
|
+
const m = line.match(TSC_LINE);
|
|
25
|
+
if (!m) continue;
|
|
26
|
+
const [, file, lineNum, , code, message] = m;
|
|
27
|
+
const relPath = path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file;
|
|
28
|
+
failures.push({
|
|
29
|
+
id: `${relPath}:${lineNum}:${code}`,
|
|
30
|
+
file: relPath,
|
|
31
|
+
line: Number(lineNum),
|
|
32
|
+
message,
|
|
33
|
+
rule: code,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
tool: "tsc",
|
|
39
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
40
|
+
summary: failures.length > 0 ? `${failures.length} type errors` : "no type errors",
|
|
41
|
+
failures,
|
|
42
|
+
logPath: ctx.logPath,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default parser;
|