@robhowley/pi-structured-return 1.8.0 → 1.10.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 +84 -73
- package/extensions/structured-return/config/project-config.ts +10 -0
- package/extensions/structured-return/config/registry.ts +306 -0
- package/extensions/structured-return/examples/.pi/machine-readable.json +18 -0
- package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +25 -0
- package/extensions/structured-return/{src/index.ts → index.ts} +94 -69
- package/extensions/structured-return/{src/parsers → parsers}/ava-text.ts +23 -15
- package/extensions/structured-return/{src/parsers → parsers}/bandit-json.ts +17 -15
- package/extensions/structured-return/{src/parsers → parsers}/black-text.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/cargo-build.ts +19 -14
- package/extensions/structured-return/{src/parsers → parsers}/cargo-test.ts +20 -19
- package/extensions/structured-return/parsers/checkstyle-xml.ts +183 -0
- package/extensions/structured-return/{src/parsers → parsers}/clang-text.ts +15 -13
- package/extensions/structured-return/{src/parsers → parsers}/dbt-json.ts +28 -23
- package/extensions/structured-return/{src/parsers → parsers}/dotnet-build-text.ts +10 -8
- package/extensions/structured-return/{src/parsers → parsers}/eslint-json.ts +15 -9
- package/extensions/structured-return/{src/parsers → parsers}/go-test-json.ts +23 -21
- package/extensions/structured-return/{src/parsers → parsers}/hadolint-json.ts +18 -12
- package/extensions/structured-return/{src/parsers → parsers}/htmlhint-json.ts +15 -13
- package/extensions/structured-return/{src/parsers → parsers}/isort-text.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/javac-text.ts +14 -12
- package/extensions/structured-return/{src/parsers → parsers}/jsonlint-text.ts +16 -14
- package/extensions/structured-return/{src/parsers → parsers}/junit-xml.ts +149 -50
- package/extensions/structured-return/{src/parsers → parsers}/markdownlint-json.ts +19 -17
- package/extensions/structured-return/{src/parsers → parsers}/minitest-text.ts +24 -15
- package/extensions/structured-return/{src/parsers → parsers}/mocha-json.ts +17 -10
- package/extensions/structured-return/{src/parsers → parsers}/mypy-json.ts +16 -16
- package/extensions/structured-return/{src/parsers → parsers}/node-test-text.ts +17 -14
- package/extensions/structured-return/{src/parsers → parsers}/npm-audit-json.ts +19 -16
- package/extensions/structured-return/{src/parsers → parsers}/prettier-text.ts +21 -17
- package/extensions/structured-return/{src/parsers → parsers}/pylint-json.ts +17 -17
- package/extensions/structured-return/{src/parsers → parsers}/pyright-json.ts +20 -18
- package/extensions/structured-return/{src/parsers → parsers}/rspec-json.ts +14 -14
- package/extensions/structured-return/{src/parsers → parsers}/rubocop-json.ts +22 -11
- package/extensions/structured-return/{src/parsers → parsers}/ruff-json.ts +7 -7
- package/extensions/structured-return/{src/parsers → parsers}/shellcheck-json.ts +14 -14
- package/extensions/structured-return/{src/parsers → parsers}/stylelint-json.ts +21 -13
- package/extensions/structured-return/{src/parsers → parsers}/swiftc-text.ts +16 -10
- package/extensions/structured-return/parsers/tail-fallback.ts +20 -0
- package/extensions/structured-return/{src/parsers → parsers}/tidy-text.ts +13 -13
- package/extensions/structured-return/{src/parsers → parsers}/tsc-text.ts +11 -11
- package/extensions/structured-return/{src/parsers → parsers}/unittest-text.ts +24 -14
- package/extensions/structured-return/{src/parsers → parsers}/utils.ts +9 -6
- package/extensions/structured-return/{src/parsers → parsers}/vale-json.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/vitest-json.ts +14 -14
- package/extensions/structured-return/{src/storage → storage}/log-store.ts +5 -5
- package/extensions/structured-return/{src/storage → storage}/session-stats.ts +11 -11
- package/extensions/structured-return/{src/types.ts → types.ts} +4 -2
- package/package.json +27 -43
- package/skills/structured-return/SKILL.md +62 -1
- package/LICENSE +0 -21
- package/extensions/structured-return/src/config/project-config.ts +0 -10
- package/extensions/structured-return/src/config/registry.test.ts +0 -171
- package/extensions/structured-return/src/config/registry.ts +0 -282
- package/extensions/structured-return/src/index.test.ts +0 -220
- package/extensions/structured-return/src/parsers/ava-text.test.ts +0 -116
- package/extensions/structured-return/src/parsers/bandit-json.test.ts +0 -90
- package/extensions/structured-return/src/parsers/black-text.test.ts +0 -67
- package/extensions/structured-return/src/parsers/cargo-build.test.ts +0 -170
- package/extensions/structured-return/src/parsers/cargo-test.test.ts +0 -191
- package/extensions/structured-return/src/parsers/clang-text.test.ts +0 -61
- package/extensions/structured-return/src/parsers/dbt-json.test.ts +0 -172
- package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +0 -85
- package/extensions/structured-return/src/parsers/eslint-json.test.ts +0 -60
- package/extensions/structured-return/src/parsers/go-test-json.test.ts +0 -119
- package/extensions/structured-return/src/parsers/hadolint-json.test.ts +0 -73
- package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +0 -72
- package/extensions/structured-return/src/parsers/isort-text.test.ts +0 -58
- package/extensions/structured-return/src/parsers/javac-text.test.ts +0 -75
- package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +0 -52
- package/extensions/structured-return/src/parsers/junit-xml.test.ts +0 -410
- package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +0 -76
- package/extensions/structured-return/src/parsers/minitest-text.test.ts +0 -110
- package/extensions/structured-return/src/parsers/mocha-json.test.ts +0 -108
- package/extensions/structured-return/src/parsers/mypy-json.test.ts +0 -101
- package/extensions/structured-return/src/parsers/node-test-text.test.ts +0 -117
- package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +0 -83
- package/extensions/structured-return/src/parsers/prettier-text.test.ts +0 -76
- package/extensions/structured-return/src/parsers/pylint-json.test.ts +0 -120
- package/extensions/structured-return/src/parsers/pyright-json.test.ts +0 -112
- package/extensions/structured-return/src/parsers/rspec-json.test.ts +0 -126
- package/extensions/structured-return/src/parsers/rubocop-json.test.ts +0 -118
- package/extensions/structured-return/src/parsers/ruff-json.test.ts +0 -57
- package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +0 -110
- package/extensions/structured-return/src/parsers/stylelint-json.test.ts +0 -120
- package/extensions/structured-return/src/parsers/swiftc-text.test.ts +0 -73
- package/extensions/structured-return/src/parsers/tail-fallback.test.ts +0 -41
- package/extensions/structured-return/src/parsers/tail-fallback.ts +0 -20
- package/extensions/structured-return/src/parsers/tidy-text.test.ts +0 -74
- package/extensions/structured-return/src/parsers/tsc-text.test.ts +0 -81
- package/extensions/structured-return/src/parsers/unittest-text.test.ts +0 -126
- package/extensions/structured-return/src/parsers/vale-json.test.ts +0 -84
- package/extensions/structured-return/src/parsers/vitest-json.test.ts +0 -118
- package/extensions/structured-return/src/storage/session-stats.test.ts +0 -156
- package/extensions/structured-return/tsconfig.json +0 -11
- package/extensions/structured-return/vitest.config.ts +0 -9
- /package/extensions/structured-return/{src/ui → ui}/widget.ts +0 -0
|
@@ -1,116 +0,0 @@
|
|
|
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 "./ava-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(), "ava-test-"));
|
|
10
|
-
const stderrPath = path.join(dir, "stderr");
|
|
11
|
-
const stdoutPath = path.join(dir, "stdout");
|
|
12
|
-
const logPath = path.join(dir, "log");
|
|
13
|
-
fs.writeFileSync(stderrPath, "");
|
|
14
|
-
fs.writeFileSync(stdoutPath, stderr);
|
|
15
|
-
fs.writeFileSync(logPath, stderr);
|
|
16
|
-
return {
|
|
17
|
-
command: "npx ava test_math.js --no-color",
|
|
18
|
-
argv: ["npx", "ava", "test_math.js", "--no-color"],
|
|
19
|
-
cwd,
|
|
20
|
-
artifactPaths: [],
|
|
21
|
-
stdoutPath,
|
|
22
|
-
stderrPath,
|
|
23
|
-
logPath,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const FAILURE_OUTPUT = `
|
|
28
|
-
✔ adds two numbers correctly
|
|
29
|
-
✘ [fail]: multiplies two numbers correctly
|
|
30
|
-
✘ [fail]: does not divide by zero Error thrown in test
|
|
31
|
-
─
|
|
32
|
-
|
|
33
|
-
multiplies two numbers correctly
|
|
34
|
-
|
|
35
|
-
test_math.js:8
|
|
36
|
-
|
|
37
|
-
7: test('multiplies two numbers correctly', t => {
|
|
38
|
-
8: t.is(3 * 4, 99);
|
|
39
|
-
9: });
|
|
40
|
-
|
|
41
|
-
Difference (- actual, + expected):
|
|
42
|
-
|
|
43
|
-
- 12
|
|
44
|
-
+ 99
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
does not divide by zero
|
|
49
|
-
|
|
50
|
-
Error thrown in test:
|
|
51
|
-
|
|
52
|
-
TypeError {
|
|
53
|
-
message: 'Cannot read properties of null (reading \\'value\\')',
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
TypeError: Cannot read properties of null (reading 'value')
|
|
57
|
-
at /project/benchmarks/test-runners/ava/test_math.js:12:29
|
|
58
|
-
at Test.callFn (file:///project/node_modules/ava/lib/test.js:525:26)
|
|
59
|
-
at Test.run (file:///project/node_modules/ava/lib/test.js:534:33)
|
|
60
|
-
|
|
61
|
-
─
|
|
62
|
-
|
|
63
|
-
2 tests failed
|
|
64
|
-
1 test passed
|
|
65
|
-
`;
|
|
66
|
-
|
|
67
|
-
const SUCCESS_OUTPUT = `
|
|
68
|
-
✔ adds two numbers correctly
|
|
69
|
-
─
|
|
70
|
-
|
|
71
|
-
1 test passed
|
|
72
|
-
`;
|
|
73
|
-
|
|
74
|
-
describe("ava-text parser", () => {
|
|
75
|
-
it("parses assertion failure with expected/actual and file:line", async () => {
|
|
76
|
-
const result = await parser.parse(makeCtx(FAILURE_OUTPUT));
|
|
77
|
-
expect(result.status).toBe("fail");
|
|
78
|
-
expect(result.summary).toBe("2 failed, 1 passed");
|
|
79
|
-
expect(result.failures).toHaveLength(2);
|
|
80
|
-
|
|
81
|
-
const assertion = result.failures![0];
|
|
82
|
-
expect(assertion.id).toBe("multiplies two numbers correctly");
|
|
83
|
-
expect(assertion.file).toBe("test_math.js");
|
|
84
|
-
expect(assertion.line).toBe(8);
|
|
85
|
-
expect(assertion.message).toBe("expected 99, got 12");
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("parses runtime error with message and file:line from stack", async () => {
|
|
89
|
-
const result = await parser.parse(makeCtx(FAILURE_OUTPUT));
|
|
90
|
-
const runtime = result.failures![1];
|
|
91
|
-
expect(runtime.id).toBe("does not divide by zero");
|
|
92
|
-
expect(runtime.file).toBe("benchmarks/test-runners/ava/test_math.js");
|
|
93
|
-
expect(runtime.line).toBe(12);
|
|
94
|
-
expect(runtime.message).toBe("Cannot read properties of null (reading \\'value\\')");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("all passing → status pass", async () => {
|
|
98
|
-
const result = await parser.parse(makeCtx(SUCCESS_OUTPUT));
|
|
99
|
-
expect(result.status).toBe("pass");
|
|
100
|
-
expect(result.summary).toBe("1 passed");
|
|
101
|
-
expect(result.failures).toHaveLength(0);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("empty stderr → status error", async () => {
|
|
105
|
-
const result = await parser.parse(makeCtx(""));
|
|
106
|
-
expect(result.status).toBe("error");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("file paths are relative to cwd", async () => {
|
|
110
|
-
const result = await parser.parse(makeCtx(FAILURE_OUTPUT));
|
|
111
|
-
const runtime = result.failures![1];
|
|
112
|
-
// absolute /project/benchmarks/... becomes relative to /project
|
|
113
|
-
expect(runtime.file).not.toMatch(/^\//);
|
|
114
|
-
expect(runtime.file).toBe("benchmarks/test-runners/ava/test_math.js");
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,170 +0,0 @@
|
|
|
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 "./cargo-build";
|
|
6
|
-
import type { RunContext } from "../types";
|
|
7
|
-
|
|
8
|
-
function makeCtx(stdoutContent: string, cwd = "/project"): RunContext {
|
|
9
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "cargo-build-test-"));
|
|
10
|
-
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
-
const stderrPath = path.join(dir, "stderr");
|
|
12
|
-
const logPath = path.join(dir, "combined.log");
|
|
13
|
-
fs.writeFileSync(stdoutPath, stdoutContent);
|
|
14
|
-
fs.writeFileSync(stderrPath, "");
|
|
15
|
-
fs.writeFileSync(logPath, stdoutContent);
|
|
16
|
-
return {
|
|
17
|
-
command: "cargo build --message-format=json",
|
|
18
|
-
argv: ["cargo", "build", "--message-format=json"],
|
|
19
|
-
cwd,
|
|
20
|
-
artifactPaths: [],
|
|
21
|
-
stdoutPath,
|
|
22
|
-
stderrPath,
|
|
23
|
-
logPath,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Build a minimal compiler-message NDJSON line */
|
|
28
|
-
function compilerMessage(opts: {
|
|
29
|
-
level: string;
|
|
30
|
-
message: string;
|
|
31
|
-
code?: string;
|
|
32
|
-
file?: string;
|
|
33
|
-
line?: number;
|
|
34
|
-
label?: string;
|
|
35
|
-
}): string {
|
|
36
|
-
const span = opts.file
|
|
37
|
-
? [
|
|
38
|
-
{
|
|
39
|
-
file_name: opts.file,
|
|
40
|
-
line_start: opts.line ?? 1,
|
|
41
|
-
is_primary: true,
|
|
42
|
-
label: opts.label ?? null,
|
|
43
|
-
},
|
|
44
|
-
]
|
|
45
|
-
: [];
|
|
46
|
-
return JSON.stringify({
|
|
47
|
-
reason: "compiler-message",
|
|
48
|
-
message: {
|
|
49
|
-
message: opts.message,
|
|
50
|
-
level: opts.level,
|
|
51
|
-
code: opts.code ? { code: opts.code } : null,
|
|
52
|
-
spans: span,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const BUILD_FINISHED_OK = JSON.stringify({ reason: "build-finished", success: true });
|
|
58
|
-
const BUILD_FINISHED_ERR = JSON.stringify({ reason: "build-finished", success: false });
|
|
59
|
-
|
|
60
|
-
describe("cargo-build parser", () => {
|
|
61
|
-
it("two errors → status fail, correct count and details", async () => {
|
|
62
|
-
const stdout = [
|
|
63
|
-
compilerMessage({
|
|
64
|
-
level: "error",
|
|
65
|
-
message: "mismatched types",
|
|
66
|
-
code: "E0308",
|
|
67
|
-
file: "src/main.rs",
|
|
68
|
-
line: 6,
|
|
69
|
-
label: "expected `i32`, found `&str`",
|
|
70
|
-
}),
|
|
71
|
-
compilerMessage({
|
|
72
|
-
level: "error",
|
|
73
|
-
message: "cannot find value `missing_var` in this scope",
|
|
74
|
-
code: "E0425",
|
|
75
|
-
file: "src/main.rs",
|
|
76
|
-
line: 7,
|
|
77
|
-
label: "not found in this scope",
|
|
78
|
-
}),
|
|
79
|
-
BUILD_FINISHED_ERR,
|
|
80
|
-
].join("\n");
|
|
81
|
-
|
|
82
|
-
const result = await parser.parse(makeCtx(stdout));
|
|
83
|
-
expect(result.status).toBe("fail");
|
|
84
|
-
expect(result.summary).toBe("2 errors");
|
|
85
|
-
expect(result.failures).toHaveLength(2);
|
|
86
|
-
|
|
87
|
-
const first = result.failures![0];
|
|
88
|
-
expect(first.file).toBe("src/main.rs");
|
|
89
|
-
expect(first.line).toBe(6);
|
|
90
|
-
expect(first.rule).toBe("E0308");
|
|
91
|
-
expect(first.message).toBe("mismatched types\nexpected `i32`, found `&str`");
|
|
92
|
-
|
|
93
|
-
const second = result.failures![1];
|
|
94
|
-
expect(second.file).toBe("src/main.rs");
|
|
95
|
-
expect(second.line).toBe(7);
|
|
96
|
-
expect(second.rule).toBe("E0425");
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("single error, no code → message only, no rule", async () => {
|
|
100
|
-
const stdout = [
|
|
101
|
-
compilerMessage({ level: "error", message: "something went wrong", file: "src/lib.rs", line: 3 }),
|
|
102
|
-
BUILD_FINISHED_ERR,
|
|
103
|
-
].join("\n");
|
|
104
|
-
|
|
105
|
-
const result = await parser.parse(makeCtx(stdout));
|
|
106
|
-
expect(result.status).toBe("fail");
|
|
107
|
-
expect(result.summary).toBe("1 error");
|
|
108
|
-
expect(result.failures![0].rule).toBeUndefined();
|
|
109
|
-
expect(result.failures![0].message).toBe("something went wrong");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("warnings are ignored, only errors count", async () => {
|
|
113
|
-
const stdout = [
|
|
114
|
-
compilerMessage({ level: "warning", message: "unused variable", file: "src/lib.rs", line: 1 }),
|
|
115
|
-
BUILD_FINISHED_OK,
|
|
116
|
-
].join("\n");
|
|
117
|
-
|
|
118
|
-
const result = await parser.parse(makeCtx(stdout));
|
|
119
|
-
expect(result.status).toBe("pass");
|
|
120
|
-
expect(result.summary).toBe("build succeeded");
|
|
121
|
-
expect(result.failures).toHaveLength(0);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("no errors → build succeeded", async () => {
|
|
125
|
-
const stdout = [BUILD_FINISHED_OK].join("\n");
|
|
126
|
-
const result = await parser.parse(makeCtx(stdout));
|
|
127
|
-
expect(result.status).toBe("pass");
|
|
128
|
-
expect(result.summary).toBe("build succeeded");
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("non-JSON lines mixed in (e.g. cargo human-readable stderr leaked) are skipped", async () => {
|
|
132
|
-
const stdout = [
|
|
133
|
-
" Compiling myapp v0.1.0",
|
|
134
|
-
compilerMessage({ level: "error", message: "broken", file: "src/lib.rs", line: 5 }),
|
|
135
|
-
"error: could not compile",
|
|
136
|
-
BUILD_FINISHED_ERR,
|
|
137
|
-
].join("\n");
|
|
138
|
-
|
|
139
|
-
const result = await parser.parse(makeCtx(stdout));
|
|
140
|
-
expect(result.status).toBe("fail");
|
|
141
|
-
expect(result.failures).toHaveLength(1);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("file path made relative to cwd", async () => {
|
|
145
|
-
const cwd = "/project";
|
|
146
|
-
const stdout = [
|
|
147
|
-
compilerMessage({ level: "error", message: "oops", file: "src/lib.rs", line: 1 }),
|
|
148
|
-
BUILD_FINISHED_ERR,
|
|
149
|
-
].join("\n");
|
|
150
|
-
|
|
151
|
-
const result = await parser.parse(makeCtx(stdout, cwd));
|
|
152
|
-
expect(result.failures![0].file).toBe("src/lib.rs");
|
|
153
|
-
expect(result.failures![0].file).not.toContain("/project");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("failure-note level messages are skipped", async () => {
|
|
157
|
-
const stdout = [
|
|
158
|
-
compilerMessage({
|
|
159
|
-
level: "failure-note",
|
|
160
|
-
message: "Some errors have detailed explanations: E0308.",
|
|
161
|
-
}),
|
|
162
|
-
compilerMessage({ level: "error", message: "mismatched types", code: "E0308", file: "src/main.rs", line: 2 }),
|
|
163
|
-
BUILD_FINISHED_ERR,
|
|
164
|
-
].join("\n");
|
|
165
|
-
|
|
166
|
-
const result = await parser.parse(makeCtx(stdout));
|
|
167
|
-
expect(result.failures).toHaveLength(1);
|
|
168
|
-
expect(result.failures![0].rule).toBe("E0308");
|
|
169
|
-
});
|
|
170
|
-
});
|
|
@@ -1,191 +0,0 @@
|
|
|
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 "./cargo-test";
|
|
6
|
-
import type { RunContext } from "../types";
|
|
7
|
-
|
|
8
|
-
function makeCtx(logContent: string, cwd = "/project"): RunContext {
|
|
9
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "cargo-test-test-"));
|
|
10
|
-
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
-
const stderrPath = path.join(dir, "stderr");
|
|
12
|
-
const logPath = path.join(dir, "combined.log");
|
|
13
|
-
fs.writeFileSync(stdoutPath, logContent);
|
|
14
|
-
fs.writeFileSync(stderrPath, "");
|
|
15
|
-
fs.writeFileSync(logPath, logContent);
|
|
16
|
-
return {
|
|
17
|
-
command: "cargo test",
|
|
18
|
-
argv: ["cargo", "test"],
|
|
19
|
-
cwd,
|
|
20
|
-
artifactPaths: [],
|
|
21
|
-
stdoutPath,
|
|
22
|
-
stderrPath,
|
|
23
|
-
logPath,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Realistic cargo test output with Rust 1.73+ panic format
|
|
28
|
-
const REAL_OUTPUT_NEW_FORMAT = ` Compiling math v0.1.0 (/project)
|
|
29
|
-
Finished \`test\` profile [unoptimized + debuginfo] target(s) in 1.23s
|
|
30
|
-
Running unittests src/lib.rs (target/debug/deps/math-abc123)
|
|
31
|
-
|
|
32
|
-
running 3 tests
|
|
33
|
-
test tests::adds_two_numbers_correctly ... ok
|
|
34
|
-
test tests::multiplies_two_numbers_correctly ... FAILED
|
|
35
|
-
test tests::does_not_panic ... FAILED
|
|
36
|
-
|
|
37
|
-
failures:
|
|
38
|
-
|
|
39
|
-
---- tests::multiplies_two_numbers_correctly stdout ----
|
|
40
|
-
|
|
41
|
-
thread 'tests::multiplies_two_numbers_correctly' (12345) panicked at src/lib.rs:20:9:
|
|
42
|
-
assertion \`left == right\` failed
|
|
43
|
-
left: 12
|
|
44
|
-
right: 99
|
|
45
|
-
|
|
46
|
-
---- tests::does_not_panic stdout ----
|
|
47
|
-
|
|
48
|
-
thread 'tests::does_not_panic' (12346) panicked at src/lib.rs:26:18:
|
|
49
|
-
index out of bounds: the len is 0 but the index is 0
|
|
50
|
-
note: run with \`RUST_BACKTRACE=1\` environment variable to display a backtrace
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
failures:
|
|
54
|
-
tests::does_not_panic
|
|
55
|
-
tests::multiplies_two_numbers_correctly
|
|
56
|
-
|
|
57
|
-
test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
|
58
|
-
|
|
59
|
-
error: test failed, to rerun pass \`--lib\`
|
|
60
|
-
`;
|
|
61
|
-
|
|
62
|
-
// Pre-1.73 panic format
|
|
63
|
-
const OLD_FORMAT_PANIC = `running 2 tests
|
|
64
|
-
test tests::foo ... FAILED
|
|
65
|
-
test tests::bar ... ok
|
|
66
|
-
|
|
67
|
-
failures:
|
|
68
|
-
|
|
69
|
-
---- tests::foo stdout ----
|
|
70
|
-
thread 'tests::foo' panicked at 'assertion failed: \`(left == right)\`
|
|
71
|
-
left: \`5\`,
|
|
72
|
-
right: \`10\`', src/lib.rs:8:5
|
|
73
|
-
|
|
74
|
-
failures:
|
|
75
|
-
tests::foo
|
|
76
|
-
|
|
77
|
-
test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
|
-
const ALL_PASSING = `running 2 tests
|
|
81
|
-
test tests::a ... ok
|
|
82
|
-
test tests::b ... ok
|
|
83
|
-
|
|
84
|
-
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
const COMPILE_ERROR = ` Compiling math v0.1.0 (/project)
|
|
88
|
-
error[E0308]: mismatched types
|
|
89
|
-
--> src/lib.rs:5:20
|
|
90
|
-
|
|
|
91
|
-
5 | let x: i32 = "oops";
|
|
92
|
-
| ^^^^^^ expected \`i32\`, found \`&str\`
|
|
93
|
-
|
|
94
|
-
error: could not compile \`math\` due to 1 previous error
|
|
95
|
-
`;
|
|
96
|
-
|
|
97
|
-
describe("cargo-test parser", () => {
|
|
98
|
-
describe("Rust 1.73+ panic format", () => {
|
|
99
|
-
it("2 failed, 1 passed → correct summary and failure details", async () => {
|
|
100
|
-
const result = await parser.parse(makeCtx(REAL_OUTPUT_NEW_FORMAT));
|
|
101
|
-
expect(result.status).toBe("fail");
|
|
102
|
-
expect(result.summary).toBe("2 failed, 1 passed");
|
|
103
|
-
expect(result.failures).toHaveLength(2);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("assertion failure has file, line, and compact left/right message", async () => {
|
|
107
|
-
const result = await parser.parse(makeCtx(REAL_OUTPUT_NEW_FORMAT));
|
|
108
|
-
const f = result.failures!.find((f) => f.id.includes("20"));
|
|
109
|
-
expect(f).toBeDefined();
|
|
110
|
-
expect(f!.file).toBe("src/lib.rs");
|
|
111
|
-
expect(f!.line).toBe(20);
|
|
112
|
-
expect(f!.message).toMatch(/assertion .* failed/);
|
|
113
|
-
expect(f!.message).toMatch(/left: 12/);
|
|
114
|
-
expect(f!.message).toMatch(/right: 99/);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("runtime panic has file, line, and error message", async () => {
|
|
118
|
-
const result = await parser.parse(makeCtx(REAL_OUTPUT_NEW_FORMAT));
|
|
119
|
-
const f = result.failures!.find((f) => f.id.includes("26"));
|
|
120
|
-
expect(f).toBeDefined();
|
|
121
|
-
expect(f!.file).toBe("src/lib.rs");
|
|
122
|
-
expect(f!.line).toBe(26);
|
|
123
|
-
expect(f!.message).toMatch(/index out of bounds/);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("file paths are relative", async () => {
|
|
127
|
-
const result = await parser.parse(makeCtx(REAL_OUTPUT_NEW_FORMAT, "/project"));
|
|
128
|
-
for (const f of result.failures!) {
|
|
129
|
-
expect(f.file).not.toMatch(/^\/project/);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe("pre-1.73 panic format", () => {
|
|
135
|
-
it("parses old-style panicked at 'message', file:line format", async () => {
|
|
136
|
-
const result = await parser.parse(makeCtx(OLD_FORMAT_PANIC));
|
|
137
|
-
expect(result.status).toBe("fail");
|
|
138
|
-
expect(result.summary).toBe("1 failed, 1 passed");
|
|
139
|
-
expect(result.failures).toHaveLength(1);
|
|
140
|
-
const f = result.failures![0];
|
|
141
|
-
expect(f.file).toBe("src/lib.rs");
|
|
142
|
-
expect(f.line).toBe(8);
|
|
143
|
-
expect(f.message).toMatch(/assertion failed/);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe("all passing", () => {
|
|
148
|
-
it("all tests pass → status pass, empty failures", async () => {
|
|
149
|
-
const result = await parser.parse(makeCtx(ALL_PASSING));
|
|
150
|
-
expect(result.status).toBe("pass");
|
|
151
|
-
expect(result.summary).toBe("2 passed");
|
|
152
|
-
expect(result.failures).toHaveLength(0);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe("compilation failure", () => {
|
|
157
|
-
it("no test result line → status error with guidance message", async () => {
|
|
158
|
-
const result = await parser.parse(makeCtx(COMPILE_ERROR));
|
|
159
|
-
expect(result.status).toBe("error");
|
|
160
|
-
expect(result.summary).toMatch(/compilation failed/);
|
|
161
|
-
expect(result.summary).toMatch(/cargo build --message-format=json/);
|
|
162
|
-
expect(result.failures).toHaveLength(0);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe("single failing test", () => {
|
|
167
|
-
it("single test failure parsed correctly", async () => {
|
|
168
|
-
const log = `running 1 test
|
|
169
|
-
test tests::only_one ... FAILED
|
|
170
|
-
|
|
171
|
-
failures:
|
|
172
|
-
|
|
173
|
-
---- tests::only_one stdout ----
|
|
174
|
-
|
|
175
|
-
thread 'tests::only_one' panicked at src/lib.rs:5:3:
|
|
176
|
-
explicit panic
|
|
177
|
-
|
|
178
|
-
failures:
|
|
179
|
-
tests::only_one
|
|
180
|
-
|
|
181
|
-
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
|
|
182
|
-
`;
|
|
183
|
-
const result = await parser.parse(makeCtx(log));
|
|
184
|
-
expect(result.status).toBe("fail");
|
|
185
|
-
expect(result.summary).toBe("1 failed, 0 passed");
|
|
186
|
-
expect(result.failures).toHaveLength(1);
|
|
187
|
-
expect(result.failures![0].line).toBe(5);
|
|
188
|
-
expect(result.failures![0].message).toBe("explicit panic");
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
});
|