@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,116 @@
|
|
|
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, stderr);
|
|
14
|
+
fs.writeFileSync(stdoutPath, "");
|
|
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
|
+
});
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { extractJsStackLocation, safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parses AVA's default text output (--no-color).
|
|
7
|
+
* Reads stderrPath — AVA writes all output (results + diagnostics) to stderr.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Summary line: "2 tests failed" or "3 tests passed"
|
|
11
|
+
const SUMMARY_RE = /(\d+) tests? (passed|failed)/g;
|
|
12
|
+
|
|
13
|
+
// Failure header in the results area: "✘ [fail]: <name>"
|
|
14
|
+
const FAIL_MARKER_RE = /^\s*✘\s+\[fail\]:\s+(.+?)(?:\s+Error thrown in test)?$/;
|
|
15
|
+
|
|
16
|
+
const parser: ParserModule = {
|
|
17
|
+
id: "ava-text",
|
|
18
|
+
async parse(ctx) {
|
|
19
|
+
const stderr = safeReadFile(ctx.stderrPath);
|
|
20
|
+
if (!stderr.trim()) {
|
|
21
|
+
return { tool: "ava", status: "error", summary: "no output", logPath: ctx.logPath };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Extract pass/fail counts from summary lines at the end
|
|
25
|
+
let passed = 0;
|
|
26
|
+
let failed = 0;
|
|
27
|
+
let m: RegExpExecArray | null;
|
|
28
|
+
while ((m = SUMMARY_RE.exec(stderr)) !== null) {
|
|
29
|
+
const count = parseInt(m[1], 10);
|
|
30
|
+
if (m[2] === "passed") passed = count;
|
|
31
|
+
else failed = count;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (passed === 0 && failed === 0) {
|
|
35
|
+
return { tool: "ava", status: "error", summary: "could not parse ava output", logPath: ctx.logPath };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const failures = parseFailureBlocks(stderr, ctx.cwd);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
tool: "ava",
|
|
42
|
+
status: failed > 0 ? "fail" : "pass",
|
|
43
|
+
summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
|
|
44
|
+
failures,
|
|
45
|
+
logPath: ctx.logPath,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default parser;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* AVA's failure detail section lives between the first and last ─ separators.
|
|
54
|
+
* Each failure block starts with the test name (matching a name from the ✘ lines),
|
|
55
|
+
* followed by either a file:line (assertion) or "Error thrown in test:" (runtime).
|
|
56
|
+
*
|
|
57
|
+
* Strategy: collect failed test names from ✘ lines, then split the detail section
|
|
58
|
+
* by those names to get per-failure blocks.
|
|
59
|
+
*/
|
|
60
|
+
function parseFailureBlocks(output: string, cwd: string): ParsedFailure[] {
|
|
61
|
+
const lines = output.split("\n");
|
|
62
|
+
|
|
63
|
+
// Collect failed test names from ✘ markers
|
|
64
|
+
const failedNames: string[] = [];
|
|
65
|
+
for (const line of lines) {
|
|
66
|
+
const fm = FAIL_MARKER_RE.exec(line);
|
|
67
|
+
if (fm) failedNames.push(fm[1]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (failedNames.length === 0) return [];
|
|
71
|
+
|
|
72
|
+
// Find the detail section between first and last ─ separators
|
|
73
|
+
const sepIndices: number[] = [];
|
|
74
|
+
for (let i = 0; i < lines.length; i++) {
|
|
75
|
+
if (lines[i].match(/^\s*─\s*$/)) sepIndices.push(i);
|
|
76
|
+
}
|
|
77
|
+
if (sepIndices.length < 2) return [];
|
|
78
|
+
|
|
79
|
+
const detailStart = sepIndices[0] + 1;
|
|
80
|
+
const detailEnd = sepIndices[sepIndices.length - 1];
|
|
81
|
+
const detailLines = lines.slice(detailStart, detailEnd);
|
|
82
|
+
|
|
83
|
+
// Split detail lines into blocks by test name
|
|
84
|
+
const blocks: Array<{ name: string; lines: string[] }> = [];
|
|
85
|
+
let currentBlock: { name: string; lines: string[] } | null = null;
|
|
86
|
+
|
|
87
|
+
for (const line of detailLines) {
|
|
88
|
+
const trimmed = line.trim();
|
|
89
|
+
if (failedNames.includes(trimmed)) {
|
|
90
|
+
if (currentBlock) blocks.push(currentBlock);
|
|
91
|
+
currentBlock = { name: trimmed, lines: [] };
|
|
92
|
+
} else if (currentBlock) {
|
|
93
|
+
currentBlock.lines.push(line);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (currentBlock) blocks.push(currentBlock);
|
|
97
|
+
|
|
98
|
+
// Parse each block
|
|
99
|
+
return blocks.map((block) => parseBlock(block.name, block.lines, cwd));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function parseBlock(name: string, lines: string[], cwd: string): ParsedFailure {
|
|
103
|
+
// Determine type by looking for "Error thrown in test:"
|
|
104
|
+
const isRuntimeError = lines.some((l) => l.trim() === "Error thrown in test:");
|
|
105
|
+
|
|
106
|
+
if (isRuntimeError) {
|
|
107
|
+
return parseRuntimeError(name, lines, cwd);
|
|
108
|
+
}
|
|
109
|
+
return parseAssertionFailure(name, lines, cwd);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function parseAssertionFailure(name: string, lines: string[], cwd: string): ParsedFailure {
|
|
113
|
+
let file: string | undefined;
|
|
114
|
+
let line: number | undefined;
|
|
115
|
+
let actual: string | undefined;
|
|
116
|
+
let expected: string | undefined;
|
|
117
|
+
|
|
118
|
+
for (const l of lines) {
|
|
119
|
+
const trimmed = l.trim();
|
|
120
|
+
|
|
121
|
+
// file:line (standalone, e.g. "test_math.js:8")
|
|
122
|
+
if (!file) {
|
|
123
|
+
const flm = trimmed.match(/^(.+\.[a-z]{1,4}):(\d+)$/);
|
|
124
|
+
if (flm) {
|
|
125
|
+
file = path.relative(cwd, path.resolve(cwd, flm[1]));
|
|
126
|
+
line = parseInt(flm[2], 10);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Diff values: "- 12" (actual), "+ 99" (expected)
|
|
132
|
+
if (trimmed.startsWith("- ") && actual === undefined) {
|
|
133
|
+
actual = trimmed.slice(2);
|
|
134
|
+
} else if (trimmed.startsWith("+ ") && expected === undefined) {
|
|
135
|
+
expected = trimmed.slice(2);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const message = actual !== undefined && expected !== undefined ? `expected ${expected}, got ${actual}` : undefined;
|
|
140
|
+
|
|
141
|
+
return { id: name, file, line, message };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function parseRuntimeError(name: string, lines: string[], cwd: string): ParsedFailure {
|
|
145
|
+
let message: string | undefined;
|
|
146
|
+
|
|
147
|
+
for (const l of lines) {
|
|
148
|
+
const trimmed = l.trim();
|
|
149
|
+
// Extract message from "message: '...'" inside the error object
|
|
150
|
+
if (!message) {
|
|
151
|
+
const msgMatch = trimmed.match(/^message:\s*'(.+)',?$/);
|
|
152
|
+
if (msgMatch) message = msgMatch[1];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Extract file:line from the first user stack frame
|
|
157
|
+
const loc = extractJsStackLocation(lines.join("\n"));
|
|
158
|
+
const file = loc.file ? path.relative(cwd, path.resolve(cwd, loc.file)) : undefined;
|
|
159
|
+
|
|
160
|
+
return { id: name, file, line: loc.line, message };
|
|
161
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
4
|
|
|
5
5
|
interface CargoSpan {
|
|
6
6
|
file_name: string;
|
|
@@ -29,7 +29,7 @@ const parser: ParserModule = {
|
|
|
29
29
|
id: "cargo-build",
|
|
30
30
|
async parse(ctx) {
|
|
31
31
|
// --message-format=json writes NDJSON to stdout; one JSON object per line
|
|
32
|
-
const stdout =
|
|
32
|
+
const stdout = safeReadFile(ctx.stdoutPath);
|
|
33
33
|
const failures: ParsedFailure[] = [];
|
|
34
34
|
|
|
35
35
|
for (const line of stdout.split("\n")) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
4
|
|
|
5
5
|
// Rust 1.73+: thread 'name' (optional-id) panicked at file:line:col:
|
|
6
6
|
// message on following line(s)
|
|
@@ -21,7 +21,7 @@ const parser: ParserModule = {
|
|
|
21
21
|
async parse(ctx) {
|
|
22
22
|
// Use combined log — test binary output goes to stdout, cargo progress to stderr;
|
|
23
23
|
// reading both ensures we catch everything regardless of buffering order.
|
|
24
|
-
const log =
|
|
24
|
+
const log = safeReadFile(ctx.logPath);
|
|
25
25
|
const lines = log.split("\n").map((l) => l.trim());
|
|
26
26
|
|
|
27
27
|
// If compilation failed there will be no "test result:" line
|
|
@@ -0,0 +1,172 @@
|
|
|
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 "./dbt-json";
|
|
6
|
+
import type { RunContext } from "../types";
|
|
7
|
+
|
|
8
|
+
const SAMPLES_DIR = path.resolve(__dirname, "../../../../benchmarks/pipeline-tools/dbt");
|
|
9
|
+
|
|
10
|
+
function makeCtx(stdout: string, cwd = "/project"): RunContext {
|
|
11
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "dbt-test-"));
|
|
12
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
13
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
14
|
+
return {
|
|
15
|
+
command: "dbt run --log-format json",
|
|
16
|
+
argv: ["dbt", "run", "--log-format", "json"],
|
|
17
|
+
cwd,
|
|
18
|
+
artifactPaths: [],
|
|
19
|
+
stdoutPath,
|
|
20
|
+
stderrPath: path.join(dir, "stderr"),
|
|
21
|
+
logPath: path.join(dir, "log"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function loadSample(filename: string): string {
|
|
26
|
+
return fs.readFileSync(path.join(SAMPLES_DIR, filename), "utf8");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("dbt-json parser", () => {
|
|
30
|
+
describe("dbt run success", () => {
|
|
31
|
+
it("3 models pass → status pass, correct summary, no failures", async () => {
|
|
32
|
+
const result = await parser.parse(makeCtx(loadSample("dbt-run-success.jsonl")));
|
|
33
|
+
expect(result.status).toBe("pass");
|
|
34
|
+
expect(result.summary).toBe("3 passed in 34.22s");
|
|
35
|
+
expect(result.failures).toHaveLength(0);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("dbt run failure", () => {
|
|
40
|
+
it("2 errors, 1 skip → status fail, both errors surfaced with node name and path", async () => {
|
|
41
|
+
const result = await parser.parse(makeCtx(loadSample("dbt-run-failure.jsonl")));
|
|
42
|
+
expect(result.status).toBe("fail");
|
|
43
|
+
expect(result.summary).toMatch(/2 failed/);
|
|
44
|
+
expect(result.summary).toMatch(/1 passed/);
|
|
45
|
+
expect(result.summary).toMatch(/1 skipped/);
|
|
46
|
+
expect(result.summary).toMatch(/34\.22s/);
|
|
47
|
+
expect(result.failures).toHaveLength(2);
|
|
48
|
+
|
|
49
|
+
const dbErr = result.failures![0];
|
|
50
|
+
expect(dbErr.id).toBe("mart__core__daily_active_customers");
|
|
51
|
+
expect(dbErr.file).toBe("models/mart/core/mart__core__daily_active_customers.sql");
|
|
52
|
+
expect(dbErr.message).toMatch(/Column customer_id in USING clause not found/);
|
|
53
|
+
|
|
54
|
+
const rtErr = result.failures![1];
|
|
55
|
+
expect(rtErr.id).toBe("mart__core__daily_summary");
|
|
56
|
+
expect(rtErr.file).toBe("models/mart/core/mart__core__daily_summary.sql");
|
|
57
|
+
expect(rtErr.message).toMatch(/Access Denied/);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("dbt test failure", () => {
|
|
62
|
+
it("2 errors → status fail, both errors surfaced", async () => {
|
|
63
|
+
const result = await parser.parse(makeCtx(loadSample("dbt-test-failure.jsonl")));
|
|
64
|
+
expect(result.status).toBe("fail");
|
|
65
|
+
expect(result.summary).toMatch(/2 failed/);
|
|
66
|
+
expect(result.summary).toMatch(/1 passed/);
|
|
67
|
+
expect(result.failures).toHaveLength(2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("uniqueness test failure has result count in message", async () => {
|
|
71
|
+
const result = await parser.parse(makeCtx(loadSample("dbt-test-failure.jsonl")));
|
|
72
|
+
const uniqueTest = result.failures!.find((f) => f.id.includes("unique_"));
|
|
73
|
+
expect(uniqueTest).toBeDefined();
|
|
74
|
+
expect(uniqueTest!.message).toMatch(/Got 3 results/);
|
|
75
|
+
expect(uniqueTest!.file).toBe("models/mart/core/_core__models.yml");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("unit test failure preserves actual/expected diff table", async () => {
|
|
79
|
+
const result = await parser.parse(makeCtx(loadSample("dbt-test-failure.jsonl")));
|
|
80
|
+
const unitTest = result.failures!.find((f) => f.id.includes("unit_test"));
|
|
81
|
+
expect(unitTest).toBeDefined();
|
|
82
|
+
expect(unitTest!.message).toMatch(/actual differs from expected/);
|
|
83
|
+
expect(unitTest!.message).toMatch(/engagement_score/);
|
|
84
|
+
expect(unitTest!.message).toMatch(/85\.5/);
|
|
85
|
+
expect(unitTest!.message).toMatch(/90\.0/);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("warnings are included with [warn] prefix when present", async () => {
|
|
89
|
+
// Inline JSONL with a warning event
|
|
90
|
+
const jsonl = [
|
|
91
|
+
JSON.stringify({
|
|
92
|
+
data: {
|
|
93
|
+
msg: "Got 12 results, configured to warn if != 0",
|
|
94
|
+
node_info: { node_name: "relationships_test", node_path: "models/test.yml", node_status: "warn" },
|
|
95
|
+
},
|
|
96
|
+
info: { name: "RunResultWarning", level: "warn", msg: "Got 12 results" },
|
|
97
|
+
}),
|
|
98
|
+
JSON.stringify({
|
|
99
|
+
data: { elapsed_time: 5.0, num_errors: 0, num_warnings: 1, num_skipped: 0 },
|
|
100
|
+
info: { name: "EndOfRunSummary", level: "info", msg: "Done. PASS=2 WARN=1 ERROR=0 SKIP=0 TOTAL=3" },
|
|
101
|
+
}),
|
|
102
|
+
].join("\n");
|
|
103
|
+
const result = await parser.parse(makeCtx(jsonl));
|
|
104
|
+
expect(result.status).toBe("pass");
|
|
105
|
+
const warning = result.failures!.find((f) => f.id === "relationships_test");
|
|
106
|
+
expect(warning).toBeDefined();
|
|
107
|
+
expect(warning!.message).toMatch(/^\[warn\]/);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("dbt compile success", () => {
|
|
112
|
+
it("3 models compiled, all SQL returned in rawTail", async () => {
|
|
113
|
+
const result = await parser.parse(makeCtx(loadSample("dbt-compile.jsonl")));
|
|
114
|
+
expect(result.status).toBe("pass");
|
|
115
|
+
expect(result.summary).toMatch(/compiled 3 models/);
|
|
116
|
+
expect(result.summary).toMatch(/mart__core__customer_engagement/);
|
|
117
|
+
expect(result.summary).toMatch(/mart__core__daily_summary/);
|
|
118
|
+
expect(result.failures).toHaveLength(0);
|
|
119
|
+
expect(result.rawTail).toBeDefined();
|
|
120
|
+
expect(result.rawTail).toMatch(/WITH user_events AS/);
|
|
121
|
+
expect(result.rawTail).toMatch(/-- mart__core__daily_active_customers/);
|
|
122
|
+
expect(result.rawTail).toMatch(/-- mart__core__daily_summary/);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("dbt compile failure", () => {
|
|
127
|
+
it("no summary + no compiled nodes → status error", async () => {
|
|
128
|
+
// Simulate a compile failure: error-level message, no EndOfRunSummary, no CompiledNode
|
|
129
|
+
const jsonl = [
|
|
130
|
+
JSON.stringify({
|
|
131
|
+
data: {},
|
|
132
|
+
info: { name: "MainReportVersion", level: "info", msg: "Running with dbt=1.8.4" },
|
|
133
|
+
}),
|
|
134
|
+
JSON.stringify({
|
|
135
|
+
data: {},
|
|
136
|
+
info: {
|
|
137
|
+
name: "CompilationError",
|
|
138
|
+
level: "error",
|
|
139
|
+
msg: "Compilation Error in model mart__core__customer_engagement (models/mart/core/mart__core__customer_engagement.sql)\n Model 'ref(\"stg__missing_model\")' was not found",
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
].join("\n");
|
|
143
|
+
|
|
144
|
+
const result = await parser.parse(makeCtx(jsonl));
|
|
145
|
+
expect(result.status).toBe("error");
|
|
146
|
+
expect(result.summary).toBe("1 error");
|
|
147
|
+
expect(result.failures).toHaveLength(1);
|
|
148
|
+
expect(result.failures![0].message).toMatch(/stg__missing_model/);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe("empty / malformed input", () => {
|
|
153
|
+
it("empty stdout → error status, no crash", async () => {
|
|
154
|
+
const result = await parser.parse(makeCtx(""));
|
|
155
|
+
expect(result.status).toBe("error");
|
|
156
|
+
expect(result.failures).toHaveLength(0);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("non-JSON lines are skipped gracefully", async () => {
|
|
160
|
+
const input =
|
|
161
|
+
"some garbage\n" +
|
|
162
|
+
JSON.stringify({
|
|
163
|
+
data: { elapsed_time: 1.0, num_errors: 0, num_warnings: 0, num_skipped: 0 },
|
|
164
|
+
info: { name: "EndOfRunSummary", level: "info", msg: "Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1" },
|
|
165
|
+
}) +
|
|
166
|
+
"\nmore garbage";
|
|
167
|
+
const result = await parser.parse(makeCtx(input));
|
|
168
|
+
expect(result.status).toBe("pass");
|
|
169
|
+
expect(result.summary).toBe("1 passed in 1.00s");
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
2
|
+
import { safeReadFile } from "./utils";
|
|
3
|
+
|
|
4
|
+
interface DbtEvent {
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
info: {
|
|
7
|
+
name: string;
|
|
8
|
+
level: string;
|
|
9
|
+
msg: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface NodeInfo {
|
|
14
|
+
node_name?: string;
|
|
15
|
+
node_path?: string;
|
|
16
|
+
node_status?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Parse `PASS=2 WARN=1 ERROR=1 SKIP=0 TOTAL=4` from EndOfRunSummary msg */
|
|
20
|
+
function parseSummaryCounts(msg: string): Record<string, number> {
|
|
21
|
+
const counts: Record<string, number> = {};
|
|
22
|
+
for (const [, key, val] of msg.matchAll(/(\w+)=(\d+)/g)) {
|
|
23
|
+
counts[key] = Number(val);
|
|
24
|
+
}
|
|
25
|
+
return counts;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const parser: ParserModule = {
|
|
29
|
+
id: "dbt-json",
|
|
30
|
+
async parse(ctx) {
|
|
31
|
+
// dbt --log-format json writes JSONL to stdout
|
|
32
|
+
const raw = safeReadFile(ctx.stdoutPath);
|
|
33
|
+
const events: DbtEvent[] = [];
|
|
34
|
+
for (const line of raw.split("\n")) {
|
|
35
|
+
if (!line.trim().startsWith("{")) continue;
|
|
36
|
+
try {
|
|
37
|
+
events.push(JSON.parse(line) as DbtEvent);
|
|
38
|
+
} catch {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const summary = events.find((e) => e.info.name === "EndOfRunSummary");
|
|
44
|
+
const errors = events.filter((e) => e.info.name === "RunResultError");
|
|
45
|
+
const warnings = events.filter((e) => e.info.name === "RunResultWarning");
|
|
46
|
+
const compiled = events.filter((e) => e.info.name === "CompiledNode");
|
|
47
|
+
|
|
48
|
+
// ---------- compile mode (no EndOfRunSummary, has CompiledNode) ----------
|
|
49
|
+
if (compiled.length > 0 && !summary) {
|
|
50
|
+
const names = compiled.map((n) => ((n.data.node_info ?? {}) as NodeInfo).node_name).filter(Boolean);
|
|
51
|
+
const sqlParts = compiled
|
|
52
|
+
.map((n) => {
|
|
53
|
+
const info = (n.data.node_info ?? {}) as NodeInfo;
|
|
54
|
+
const sql = n.data.compiled as string | undefined;
|
|
55
|
+
return sql ? `-- ${info.node_name ?? "model"}\n${sql}` : undefined;
|
|
56
|
+
})
|
|
57
|
+
.filter(Boolean);
|
|
58
|
+
return {
|
|
59
|
+
tool: "dbt",
|
|
60
|
+
status: "pass",
|
|
61
|
+
summary: `compiled ${compiled.length} model${compiled.length === 1 ? "" : "s"}: ${names.join(", ")}`,
|
|
62
|
+
failures: [],
|
|
63
|
+
rawTail: sqlParts.join("\n\n"),
|
|
64
|
+
logPath: ctx.logPath,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------- compile failure (no summary, no compiled nodes) ----------
|
|
69
|
+
if (!summary && compiled.length === 0) {
|
|
70
|
+
// Look for any error-level messages for context
|
|
71
|
+
const errorMsgs = events.filter((e) => e.info.level === "error");
|
|
72
|
+
const failures: ParsedFailure[] = errorMsgs.map((e, i) => ({
|
|
73
|
+
id: String(i),
|
|
74
|
+
message: e.info.msg,
|
|
75
|
+
}));
|
|
76
|
+
return {
|
|
77
|
+
tool: "dbt",
|
|
78
|
+
status: "error",
|
|
79
|
+
summary: failures.length > 0 ? `${failures.length} error${failures.length === 1 ? "" : "s"}` : "failed",
|
|
80
|
+
failures,
|
|
81
|
+
logPath: ctx.logPath,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---------- run / test mode ----------
|
|
86
|
+
const counts = parseSummaryCounts(summary!.info.msg);
|
|
87
|
+
const elapsed = (summary!.data.elapsed_time as number) ?? 0;
|
|
88
|
+
const numErrors = counts.ERROR ?? (summary!.data.num_errors as number) ?? 0;
|
|
89
|
+
const numWarnings = counts.WARN ?? (summary!.data.num_warnings as number) ?? 0;
|
|
90
|
+
const numSkipped = counts.SKIP ?? (summary!.data.num_skipped as number) ?? 0;
|
|
91
|
+
const numPassed = counts.PASS ?? 0;
|
|
92
|
+
|
|
93
|
+
const failures: ParsedFailure[] = [];
|
|
94
|
+
|
|
95
|
+
for (const err of errors) {
|
|
96
|
+
const nodeInfo = (err.data.node_info ?? {}) as NodeInfo;
|
|
97
|
+
failures.push({
|
|
98
|
+
id: nodeInfo.node_name ?? String(failures.length),
|
|
99
|
+
file: nodeInfo.node_path,
|
|
100
|
+
message: (err.data.msg as string) ?? err.info.msg,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (const warn of warnings) {
|
|
105
|
+
const nodeInfo = (warn.data.node_info ?? {}) as NodeInfo;
|
|
106
|
+
failures.push({
|
|
107
|
+
id: nodeInfo.node_name ?? String(failures.length),
|
|
108
|
+
file: nodeInfo.node_path,
|
|
109
|
+
message: `[warn] ${(warn.data.msg as string) ?? warn.info.msg}`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Build summary string
|
|
114
|
+
const parts: string[] = [];
|
|
115
|
+
if (numErrors > 0) parts.push(`${numErrors} failed`);
|
|
116
|
+
if (numPassed > 0) parts.push(`${numPassed} passed`);
|
|
117
|
+
if (numWarnings > 0) parts.push(`${numWarnings} warning${numWarnings === 1 ? "" : "s"}`);
|
|
118
|
+
if (numSkipped > 0) parts.push(`${numSkipped} skipped`);
|
|
119
|
+
const summaryStr = `${parts.join(", ")} in ${elapsed.toFixed(2)}s`;
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
tool: "dbt",
|
|
123
|
+
status: numErrors > 0 ? "fail" : "pass",
|
|
124
|
+
summary: summaryStr,
|
|
125
|
+
failures,
|
|
126
|
+
logPath: ctx.logPath,
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export default parser;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import type { ParserModule } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
4
|
|
|
5
5
|
const parser: ParserModule = {
|
|
6
6
|
id: "eslint-json",
|
|
7
7
|
async parse(ctx) {
|
|
8
|
-
const stdout =
|
|
8
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
9
9
|
const files = stdout ? JSON.parse(stdout) : [];
|
|
10
10
|
const failures = [] as Array<{ id: string; file?: string; line?: number; message?: string; rule?: string }>;
|
|
11
11
|
for (const file of Array.isArray(files) ? files : []) {
|