@robhowley/pi-structured-return 1.2.2 → 1.4.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 +29 -2
- package/extensions/structured-return/src/config/registry.ts +24 -0
- package/extensions/structured-return/src/parsers/cargo-build.test.ts +170 -0
- package/extensions/structured-return/src/parsers/cargo-build.ts +74 -0
- package/extensions/structured-return/src/parsers/cargo-test.test.ts +191 -0
- package/extensions/structured-return/src/parsers/cargo-test.ts +135 -0
- package/extensions/structured-return/src/parsers/dbt-json.test.ts +172 -0
- package/extensions/structured-return/src/parsers/dbt-json.ts +131 -0
- package/package.json +1 -1
- package/skills/structured-return/SKILL.md +12 -0
package/README.md
CHANGED
|
@@ -6,12 +6,15 @@ Cross-platform Pi package that combines:
|
|
|
6
6
|
- a `structured-return` skill for choosing compact / machine-readable command forms
|
|
7
7
|
- a `structured-return` extension that captures output, stores artifacts, applies parsers, and falls back to tail + log path
|
|
8
8
|
|
|
9
|
+
Tens of thousands of tokens per session saved by filtering noise from test suites, linters, build tools, and data pipelines
|
|
10
|
+
so LLMs spend tokens on signal, not boilerplate.
|
|
11
|
+
|
|
9
12
|
## Token reduction
|
|
10
13
|
|
|
11
14
|
Tool output is designed for humans: source diffs, line annotations, timing breakdowns, absolute paths repeated on every line. Useful on a terminal. Expensive in a model context, especially on failure when output is most verbose and the model needs to act fast.
|
|
12
15
|
|
|
13
|
-
Test runners: 3 tests, 1 passing, 1 assertion failure, 1 unexpected error.
|
|
14
|
-
Linters: 1 unused variable warning in a single file.
|
|
16
|
+
- Test runners: 3 tests, 1 passing, 1 assertion failure, 1 unexpected error.
|
|
17
|
+
- Linters: 1 unused variable warning in a single file.
|
|
15
18
|
|
|
16
19
|
| Parser | Raw (tokens) | Structured (tokens) | Reduction | Notes |
|
|
17
20
|
|---|---|---|---|---|
|
|
@@ -19,21 +22,45 @@ Linters: 1 unused variable warning in a single file.
|
|
|
19
22
|
| `junit-xml` (go) | 400 | 58 | **86%** | verbose output with full stack trace per failure |
|
|
20
23
|
| `junit-xml` (dotnet) | 487 | 107 | **78%** | build header and VSTest output with per-failure stack traces |
|
|
21
24
|
| `vitest-json` | 348 | 75 | **78%** | source diff with inline arrows and ANSI color codes per failure |
|
|
25
|
+
| `cargo-test` | 285 | 68 | **76%** | cargo progress + test binary output with panic traces per failure |
|
|
22
26
|
| `junit-xml` (pytest) | 289 | 71 | **75%** | verbose output with source snippets and summary footer |
|
|
23
27
|
| `rspec-json` | 212 | 55 | **74%** | default output with backtrace |
|
|
24
28
|
| `junit-xml` (gradle) | 263 | 81 | **69%** | gradle console output with build lifecycle noise |
|
|
25
29
|
| `junit-xml` (jest) | 309 | 99 | **68%** | source annotations with deep jest-circus stack traces per failure |
|
|
30
|
+
| `cargo-build` | 225 | 77 | **66%** | rustc error annotations with code spans and help text per error |
|
|
26
31
|
| `minitest-text` | 168 | 59 | **65%** | default output with backtrace |
|
|
27
32
|
| `ruff-json` | 107 | 52 | **51%** | source context + help text per error |
|
|
28
33
|
| `eslint-json` | 64 | 59 | **8%** | already compact formatter |
|
|
29
34
|
|
|
30
35
|
Tokens counted with `cl100k_base` (tiktoken). Linter output is more compact than test runner output to begin with, so the baseline reduction is lower. The numbers above are measured against a single file with a single error — a conservative lower bound. Both ruff and eslint repeat absolute file paths per error in their raw output, so reduction grows as violations spread across more files.
|
|
31
36
|
|
|
37
|
+
### Pipeline tools
|
|
38
|
+
|
|
39
|
+
dbt output is the noisiest tool in this repo relative to useful signal. Every run prints version info, adapter registration, project stats, concurrency settings, and per-node start/finish lines — all before any result.
|
|
40
|
+
|
|
41
|
+
The numbers below use 3–4 model toy examples; real projects run hundreds of models where the noise scales linearly and reduction compounds.
|
|
42
|
+
|
|
43
|
+
- dbt run: 4 models, 1 passing, 1 DB error, 1 permissions error, 1 DAG skip.
|
|
44
|
+
- dbt test: 3 tests, 1 passing, 1 uniqueness failure, 1 unit test diff.
|
|
45
|
+
- dbt compile: 3 models compiled to SQL.
|
|
46
|
+
|
|
47
|
+
| Parser | Raw (tokens) | Structured (tokens) | Reduction | Notes |
|
|
48
|
+
|---|---|---|---|---|
|
|
49
|
+
| `dbt-json` (run, success) | 428 | 20 | **95%** | version, adapter, concurrency, per-model start/finish — all noise on success |
|
|
50
|
+
| `dbt-json` (run, failure) | 618 | 198 | **68%** | error messages, model paths, compiled code paths preserved |
|
|
51
|
+
| `dbt-json` (test) | 720 | 274 | **62%** | unit test diff tables preserved verbatim; preamble stripped |
|
|
52
|
+
| `dbt-json` (compile) | 775 | 683 | **12%** | compiled SQL is the signal and returned verbatim |
|
|
53
|
+
|
|
54
|
+
At 12 models, run failures hit 85% reduction. An 18-model DAG success: 1,645 → 20 tokens (99%).
|
|
55
|
+
|
|
32
56
|
## Built-in parsers
|
|
33
57
|
- `junit-xml` (JUnit XML — covers pytest `--junitxml`, Gradle, Maven, Jest with `jest-junit`, Go with `go-junit-report`, and any other tool that emits the JUnit XML schema)
|
|
34
58
|
- `vitest-json`
|
|
35
59
|
- `rspec-json`
|
|
36
60
|
- `minitest-text` (parses default minitest output — no flags or reporters needed)
|
|
61
|
+
- `dbt-json` (`dbt run/test/compile --log-format json` — errors, warnings, and unit test diffs from JSONL; compiled SQL returned for compile; success runs reduced to a one-line summary)
|
|
62
|
+
- `cargo-build` (`cargo build --message-format=json` — errors with file, line, error code, and primary span label; warnings filtered out)
|
|
63
|
+
- `cargo-test` (`cargo test` — assertion left/right values, panic messages, and file:line per failure; detects compilation failures and directs to `cargo build --message-format=json`)
|
|
37
64
|
- `ruff-json` (`ruff check` only — `ruff format` has no json support)
|
|
38
65
|
- `eslint-json`
|
|
39
66
|
|
|
@@ -6,6 +6,9 @@ import vitestJson from "../parsers/vitest-json";
|
|
|
6
6
|
import rspecJson from "../parsers/rspec-json";
|
|
7
7
|
import minitestText from "../parsers/minitest-text";
|
|
8
8
|
import junitXml from "../parsers/junit-xml";
|
|
9
|
+
import cargoBuild from "../parsers/cargo-build";
|
|
10
|
+
import cargoTest from "../parsers/cargo-test";
|
|
11
|
+
import dbtJson from "../parsers/dbt-json";
|
|
9
12
|
import tailFallback from "../parsers/tail-fallback";
|
|
10
13
|
|
|
11
14
|
const builtIns: Record<string, ParserModule> = {
|
|
@@ -15,6 +18,9 @@ const builtIns: Record<string, ParserModule> = {
|
|
|
15
18
|
"rspec-json": rspecJson,
|
|
16
19
|
"minitest-text": minitestText,
|
|
17
20
|
"junit-xml": junitXml,
|
|
21
|
+
"cargo-build": cargoBuild,
|
|
22
|
+
"cargo-test": cargoTest,
|
|
23
|
+
"dbt-json": dbtJson,
|
|
18
24
|
"tail-fallback": tailFallback,
|
|
19
25
|
};
|
|
20
26
|
|
|
@@ -46,6 +52,24 @@ const AUTO_DETECT: Array<{ parserId: string; detect: (argv: string[]) => boolean
|
|
|
46
52
|
detect: (argv) =>
|
|
47
53
|
argv.some((a) => a.startsWith("--junitxml") || a.startsWith("--junit-xml") || a === "--format=junit"),
|
|
48
54
|
},
|
|
55
|
+
{
|
|
56
|
+
parserId: "cargo-build",
|
|
57
|
+
detect: (argv) =>
|
|
58
|
+
argv.includes("cargo") &&
|
|
59
|
+
argv.includes("build") &&
|
|
60
|
+
argv.some((a) => a.startsWith("--message-format=json") || a === "json"),
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
parserId: "cargo-test",
|
|
64
|
+
detect: (argv) => argv.includes("cargo") && argv.includes("test"),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
parserId: "dbt-json",
|
|
68
|
+
detect: (argv) =>
|
|
69
|
+
argv.includes("dbt") &&
|
|
70
|
+
(argv.includes("run") || argv.includes("test") || argv.includes("compile")) &&
|
|
71
|
+
argv.some((a) => a === "--log-format" || a === "json" || a === "--log-format=json"),
|
|
72
|
+
},
|
|
49
73
|
];
|
|
50
74
|
|
|
51
75
|
export function listParsers(): { id: string; autoDetect: boolean }[] {
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
4
|
+
|
|
5
|
+
interface CargoSpan {
|
|
6
|
+
file_name: string;
|
|
7
|
+
line_start: number;
|
|
8
|
+
is_primary: boolean;
|
|
9
|
+
label: string | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface CargoCode {
|
|
13
|
+
code: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface CargoMessage {
|
|
17
|
+
message: string;
|
|
18
|
+
level: string;
|
|
19
|
+
code: CargoCode | null;
|
|
20
|
+
spans: CargoSpan[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface CargoCompilerMessage {
|
|
24
|
+
reason: "compiler-message";
|
|
25
|
+
message: CargoMessage;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const parser: ParserModule = {
|
|
29
|
+
id: "cargo-build",
|
|
30
|
+
async parse(ctx) {
|
|
31
|
+
// --message-format=json writes NDJSON to stdout; one JSON object per line
|
|
32
|
+
const stdout = fs.readFileSync(ctx.stdoutPath, "utf8");
|
|
33
|
+
const failures: ParsedFailure[] = [];
|
|
34
|
+
|
|
35
|
+
for (const line of stdout.split("\n")) {
|
|
36
|
+
if (!line.trim().startsWith("{")) continue;
|
|
37
|
+
let obj: Partial<CargoCompilerMessage>;
|
|
38
|
+
try {
|
|
39
|
+
obj = JSON.parse(line);
|
|
40
|
+
} catch {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (obj.reason !== "compiler-message") continue;
|
|
45
|
+
const msg = obj.message;
|
|
46
|
+
if (!msg || msg.level !== "error") continue;
|
|
47
|
+
|
|
48
|
+
const primarySpan = msg.spans?.find((s) => s.is_primary);
|
|
49
|
+
const file = primarySpan ? path.relative(ctx.cwd, path.resolve(ctx.cwd, primarySpan.file_name)) : undefined;
|
|
50
|
+
const lineNum = primarySpan?.line_start;
|
|
51
|
+
const label = primarySpan?.label ?? undefined;
|
|
52
|
+
const code = msg.code?.code;
|
|
53
|
+
|
|
54
|
+
failures.push({
|
|
55
|
+
id: [file, lineNum, code].filter(Boolean).join(":"),
|
|
56
|
+
file,
|
|
57
|
+
line: lineNum,
|
|
58
|
+
// Surface the primary span label (e.g. "expected `i32`, found `&str`") as a second line
|
|
59
|
+
message: label ? `${msg.message}\n${label}` : msg.message,
|
|
60
|
+
rule: code,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
tool: "cargo",
|
|
66
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
67
|
+
summary: failures.length > 0 ? `${failures.length} error${failures.length === 1 ? "" : "s"}` : "build succeeded",
|
|
68
|
+
failures,
|
|
69
|
+
logPath: ctx.logPath,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default parser;
|
|
@@ -0,0 +1,191 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
4
|
+
|
|
5
|
+
// Rust 1.73+: thread 'name' (optional-id) panicked at file:line:col:
|
|
6
|
+
// message on following line(s)
|
|
7
|
+
const PANIC_NEW = /^thread '.+?' (?:\(\d+\) )?panicked at (.+?):(\d+):\d+:?$/;
|
|
8
|
+
|
|
9
|
+
// Pre-1.73: thread 'name' panicked at 'message', file:line:col
|
|
10
|
+
// Message may span multiple lines — use dotall flag
|
|
11
|
+
const PANIC_OLD = /thread '.+?' panicked at '(.*)', (.+?):(\d+):\d+/s;
|
|
12
|
+
|
|
13
|
+
// test result: FAILED. 1 passed; 2 failed; ...
|
|
14
|
+
const TEST_RESULT_RE = /^test result: \w+\. (\d+) passed; (\d+) failed/;
|
|
15
|
+
|
|
16
|
+
// ---- test::name stdout ----
|
|
17
|
+
const BLOCK_HEADER_RE = /^---- (.+) stdout ----$/;
|
|
18
|
+
|
|
19
|
+
const parser: ParserModule = {
|
|
20
|
+
id: "cargo-test",
|
|
21
|
+
async parse(ctx) {
|
|
22
|
+
// Use combined log — test binary output goes to stdout, cargo progress to stderr;
|
|
23
|
+
// reading both ensures we catch everything regardless of buffering order.
|
|
24
|
+
const log = fs.readFileSync(ctx.logPath, "utf8");
|
|
25
|
+
const lines = log.split("\n").map((l) => l.trim());
|
|
26
|
+
|
|
27
|
+
// If compilation failed there will be no "test result:" line
|
|
28
|
+
const hasTestResult = lines.some((l) => TEST_RESULT_RE.test(l));
|
|
29
|
+
if (!hasTestResult) {
|
|
30
|
+
return {
|
|
31
|
+
tool: "cargo",
|
|
32
|
+
status: "error",
|
|
33
|
+
summary: "compilation failed — run `cargo build --message-format=json` for structured errors",
|
|
34
|
+
failures: [],
|
|
35
|
+
logPath: ctx.logPath,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let passed = 0;
|
|
40
|
+
let failed = 0;
|
|
41
|
+
for (const line of lines) {
|
|
42
|
+
const m = TEST_RESULT_RE.exec(line);
|
|
43
|
+
if (m) {
|
|
44
|
+
passed = Number(m[1]);
|
|
45
|
+
failed = Number(m[2]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Split into per-test failure blocks delimited by "---- test::name stdout ----" headers
|
|
50
|
+
const blocks: Array<{ name: string; lines: string[] }> = [];
|
|
51
|
+
let current: { name: string; lines: string[] } | null = null;
|
|
52
|
+
|
|
53
|
+
for (const line of lines) {
|
|
54
|
+
const headerMatch = BLOCK_HEADER_RE.exec(line);
|
|
55
|
+
if (headerMatch) {
|
|
56
|
+
if (current) blocks.push(current);
|
|
57
|
+
current = { name: headerMatch[1], lines: [] };
|
|
58
|
+
} else if (current) {
|
|
59
|
+
current.lines.push(line);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (current) blocks.push(current);
|
|
63
|
+
|
|
64
|
+
const failures: ParsedFailure[] = blocks.map(({ name, lines: blockLines }) =>
|
|
65
|
+
parseFailureBlock(name, blockLines, ctx.cwd)
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
tool: "cargo",
|
|
70
|
+
status: failed > 0 ? "fail" : "pass",
|
|
71
|
+
summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
|
|
72
|
+
failures,
|
|
73
|
+
logPath: ctx.logPath,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function parseFailureBlock(testName: string, lines: string[], cwd: string): ParsedFailure {
|
|
79
|
+
let file: string | undefined;
|
|
80
|
+
let lineNum: number | undefined;
|
|
81
|
+
let message: string | undefined;
|
|
82
|
+
|
|
83
|
+
// Try new format (1.73+) line by line first
|
|
84
|
+
for (let i = 0; i < lines.length; i++) {
|
|
85
|
+
const line = lines[i];
|
|
86
|
+
const newMatch = PANIC_NEW.exec(line);
|
|
87
|
+
if (newMatch) {
|
|
88
|
+
file = path.relative(cwd, path.resolve(cwd, newMatch[1]));
|
|
89
|
+
lineNum = Number(newMatch[2]);
|
|
90
|
+
// Collect message lines that follow until blank line or note:/error:
|
|
91
|
+
const msgLines: string[] = [];
|
|
92
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
93
|
+
const next = lines[j];
|
|
94
|
+
if (next === "" || next.startsWith("note:") || next.startsWith("error:")) break;
|
|
95
|
+
msgLines.push(next);
|
|
96
|
+
}
|
|
97
|
+
message = formatMessage(msgLines);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Fall back to pre-1.73 format; join block so dotall regex handles multi-line messages
|
|
103
|
+
if (!file) {
|
|
104
|
+
const blockText = lines.join("\n");
|
|
105
|
+
const oldMatch = PANIC_OLD.exec(blockText);
|
|
106
|
+
if (oldMatch) {
|
|
107
|
+
// Collapse internal newlines in message to a single space
|
|
108
|
+
message = oldMatch[1].replace(/\s+/g, " ").trim();
|
|
109
|
+
file = path.relative(cwd, path.resolve(cwd, oldMatch[2]));
|
|
110
|
+
lineNum = Number(oldMatch[3]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const id = [file, lineNum, testName].filter(Boolean).join(":");
|
|
115
|
+
return {
|
|
116
|
+
id: id || testName,
|
|
117
|
+
file,
|
|
118
|
+
line: lineNum,
|
|
119
|
+
message: message ?? testName,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Compact assertion left/right onto one line; otherwise join with "; " */
|
|
124
|
+
function formatMessage(msgLines: string[]): string {
|
|
125
|
+
if (msgLines.length === 0) return "";
|
|
126
|
+
const main = msgLines[0];
|
|
127
|
+
const leftLine = msgLines.find((l) => l.trimStart().startsWith("left:"));
|
|
128
|
+
const rightLine = msgLines.find((l) => l.trimStart().startsWith("right:"));
|
|
129
|
+
if (leftLine && rightLine) {
|
|
130
|
+
return `${main}\n${leftLine.trim()}, ${rightLine.trim()}`;
|
|
131
|
+
}
|
|
132
|
+
return msgLines.filter(Boolean).join("; ");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export default parser;
|
|
@@ -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 fs from "node:fs";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
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 = fs.readFileSync(ctx.stdoutPath, "utf8");
|
|
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;
|
package/package.json
CHANGED
|
@@ -45,6 +45,18 @@ Prefer better output at the source.
|
|
|
45
45
|
### minitest
|
|
46
46
|
- `structured_return({ command: "ruby [any minitest args]", parseAs: "minitest-text" })` — no format flags needed; works with plain ruby invocation
|
|
47
47
|
|
|
48
|
+
### dbt (run, test, compile)
|
|
49
|
+
- `structured_return({ command: "dbt run [any dbt args] --log-format json", parseAs: "dbt-json" })` — `--log-format json` required; model selectors, flags, etc. go in `[any dbt args]`
|
|
50
|
+
- `structured_return({ command: "dbt test [any dbt args] --log-format json", parseAs: "dbt-json" })` — same parser handles run and test; unit test diffs preserved verbatim
|
|
51
|
+
- `structured_return({ command: "dbt compile [any dbt args] --log-format json", parseAs: "dbt-json" })` — returns compiled SQL; preamble stripped
|
|
52
|
+
|
|
53
|
+
### cargo build
|
|
54
|
+
- `structured_return({ command: "cargo build --message-format=json", parseAs: "cargo-build" })` — `--message-format=json` is built into cargo; errors include file, line, error code (E0308 etc.), and primary span label (expected X, found Y); warnings are filtered out
|
|
55
|
+
|
|
56
|
+
### cargo test
|
|
57
|
+
- `structured_return({ command: "cargo test", parseAs: "cargo-test" })` — no extra flags needed; assertion failures surface left/right values and file:line; panics surface the message and file:line; if compilation fails, the summary says so and tells the model to run `cargo build --message-format=json` for structured errors
|
|
58
|
+
- `structured_return({ command: "cargo test [filter]", parseAs: "cargo-test" })` — filter by test name substring, module path, or `--test integration_test_name`
|
|
59
|
+
|
|
48
60
|
### junit-xml
|
|
49
61
|
|
|
50
62
|
JUnit XML is the de facto standard output format across the JVM ecosystem and many others — Maven, Gradle, pytest (`--junitxml`), Go (`go-junit-report`), .NET (`--logger trx` with conversion), Jest (`jest-junit`), and more. If a tool can emit JUnit XML, `junit-xml` covers it without a custom parser.
|