@robhowley/pi-structured-return 1.9.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +2 -1
  2. package/extensions/structured-return/config/project-config.ts +10 -0
  3. package/extensions/structured-return/config/registry.ts +306 -0
  4. package/extensions/structured-return/examples/.pi/machine-readable.json +18 -0
  5. package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +25 -0
  6. package/extensions/structured-return/{src/index.ts → index.ts} +94 -69
  7. package/extensions/structured-return/{src/parsers → parsers}/ava-text.ts +23 -15
  8. package/extensions/structured-return/{src/parsers → parsers}/bandit-json.ts +17 -15
  9. package/extensions/structured-return/{src/parsers → parsers}/black-text.ts +18 -18
  10. package/extensions/structured-return/{src/parsers → parsers}/cargo-build.ts +19 -14
  11. package/extensions/structured-return/{src/parsers → parsers}/cargo-test.ts +20 -19
  12. package/extensions/structured-return/parsers/checkstyle-xml.ts +183 -0
  13. package/extensions/structured-return/{src/parsers → parsers}/clang-text.ts +15 -13
  14. package/extensions/structured-return/{src/parsers → parsers}/dbt-json.ts +28 -23
  15. package/extensions/structured-return/{src/parsers → parsers}/dotnet-build-text.ts +10 -8
  16. package/extensions/structured-return/{src/parsers → parsers}/eslint-json.ts +15 -9
  17. package/extensions/structured-return/{src/parsers → parsers}/go-test-json.ts +23 -21
  18. package/extensions/structured-return/{src/parsers → parsers}/hadolint-json.ts +18 -12
  19. package/extensions/structured-return/{src/parsers → parsers}/htmlhint-json.ts +15 -13
  20. package/extensions/structured-return/{src/parsers → parsers}/isort-text.ts +18 -18
  21. package/extensions/structured-return/{src/parsers → parsers}/javac-text.ts +14 -12
  22. package/extensions/structured-return/{src/parsers → parsers}/jsonlint-text.ts +16 -14
  23. package/extensions/structured-return/{src/parsers → parsers}/junit-xml.ts +61 -43
  24. package/extensions/structured-return/{src/parsers → parsers}/markdownlint-json.ts +19 -17
  25. package/extensions/structured-return/{src/parsers → parsers}/minitest-text.ts +24 -15
  26. package/extensions/structured-return/{src/parsers → parsers}/mocha-json.ts +17 -10
  27. package/extensions/structured-return/{src/parsers → parsers}/mypy-json.ts +16 -16
  28. package/extensions/structured-return/{src/parsers → parsers}/node-test-text.ts +17 -14
  29. package/extensions/structured-return/{src/parsers → parsers}/npm-audit-json.ts +19 -16
  30. package/extensions/structured-return/{src/parsers → parsers}/prettier-text.ts +21 -17
  31. package/extensions/structured-return/{src/parsers → parsers}/pylint-json.ts +17 -17
  32. package/extensions/structured-return/{src/parsers → parsers}/pyright-json.ts +20 -18
  33. package/extensions/structured-return/{src/parsers → parsers}/rspec-json.ts +14 -14
  34. package/extensions/structured-return/{src/parsers → parsers}/rubocop-json.ts +22 -11
  35. package/extensions/structured-return/{src/parsers → parsers}/ruff-json.ts +7 -7
  36. package/extensions/structured-return/{src/parsers → parsers}/shellcheck-json.ts +14 -14
  37. package/extensions/structured-return/{src/parsers → parsers}/stylelint-json.ts +21 -13
  38. package/extensions/structured-return/{src/parsers → parsers}/swiftc-text.ts +16 -10
  39. package/extensions/structured-return/parsers/tail-fallback.ts +20 -0
  40. package/extensions/structured-return/{src/parsers → parsers}/tidy-text.ts +13 -13
  41. package/extensions/structured-return/{src/parsers → parsers}/tsc-text.ts +11 -11
  42. package/extensions/structured-return/{src/parsers → parsers}/unittest-text.ts +24 -14
  43. package/extensions/structured-return/{src/parsers → parsers}/utils.ts +9 -6
  44. package/extensions/structured-return/{src/parsers → parsers}/vale-json.ts +18 -18
  45. package/extensions/structured-return/{src/parsers → parsers}/vitest-json.ts +14 -14
  46. package/extensions/structured-return/{src/storage → storage}/log-store.ts +5 -5
  47. package/extensions/structured-return/{src/storage → storage}/session-stats.ts +11 -11
  48. package/extensions/structured-return/{src/types.ts → types.ts} +4 -2
  49. package/package.json +29 -44
  50. package/skills/structured-return/SKILL.md +7 -0
  51. package/LICENSE +0 -21
  52. package/extensions/structured-return/src/config/project-config.ts +0 -10
  53. package/extensions/structured-return/src/config/registry.test.ts +0 -171
  54. package/extensions/structured-return/src/config/registry.ts +0 -282
  55. package/extensions/structured-return/src/index.test.ts +0 -220
  56. package/extensions/structured-return/src/parsers/ava-text.test.ts +0 -116
  57. package/extensions/structured-return/src/parsers/bandit-json.test.ts +0 -90
  58. package/extensions/structured-return/src/parsers/black-text.test.ts +0 -67
  59. package/extensions/structured-return/src/parsers/cargo-build.test.ts +0 -170
  60. package/extensions/structured-return/src/parsers/cargo-test.test.ts +0 -191
  61. package/extensions/structured-return/src/parsers/clang-text.test.ts +0 -61
  62. package/extensions/structured-return/src/parsers/dbt-json.test.ts +0 -172
  63. package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +0 -85
  64. package/extensions/structured-return/src/parsers/eslint-json.test.ts +0 -60
  65. package/extensions/structured-return/src/parsers/go-test-json.test.ts +0 -119
  66. package/extensions/structured-return/src/parsers/hadolint-json.test.ts +0 -73
  67. package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +0 -72
  68. package/extensions/structured-return/src/parsers/isort-text.test.ts +0 -58
  69. package/extensions/structured-return/src/parsers/javac-text.test.ts +0 -75
  70. package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +0 -52
  71. package/extensions/structured-return/src/parsers/junit-xml.test.ts +0 -627
  72. package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +0 -76
  73. package/extensions/structured-return/src/parsers/minitest-text.test.ts +0 -110
  74. package/extensions/structured-return/src/parsers/mocha-json.test.ts +0 -108
  75. package/extensions/structured-return/src/parsers/mypy-json.test.ts +0 -101
  76. package/extensions/structured-return/src/parsers/node-test-text.test.ts +0 -117
  77. package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +0 -83
  78. package/extensions/structured-return/src/parsers/prettier-text.test.ts +0 -76
  79. package/extensions/structured-return/src/parsers/pylint-json.test.ts +0 -120
  80. package/extensions/structured-return/src/parsers/pyright-json.test.ts +0 -112
  81. package/extensions/structured-return/src/parsers/rspec-json.test.ts +0 -126
  82. package/extensions/structured-return/src/parsers/rubocop-json.test.ts +0 -118
  83. package/extensions/structured-return/src/parsers/ruff-json.test.ts +0 -57
  84. package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +0 -110
  85. package/extensions/structured-return/src/parsers/stylelint-json.test.ts +0 -120
  86. package/extensions/structured-return/src/parsers/swiftc-text.test.ts +0 -73
  87. package/extensions/structured-return/src/parsers/tail-fallback.test.ts +0 -41
  88. package/extensions/structured-return/src/parsers/tail-fallback.ts +0 -20
  89. package/extensions/structured-return/src/parsers/tidy-text.test.ts +0 -74
  90. package/extensions/structured-return/src/parsers/tsc-text.test.ts +0 -81
  91. package/extensions/structured-return/src/parsers/unittest-text.test.ts +0 -126
  92. package/extensions/structured-return/src/parsers/vale-json.test.ts +0 -84
  93. package/extensions/structured-return/src/parsers/vitest-json.test.ts +0 -118
  94. package/extensions/structured-return/src/storage/session-stats.test.ts +0 -156
  95. package/extensions/structured-return/tsconfig.json +0 -11
  96. package/extensions/structured-return/vitest.config.ts +0 -9
  97. /package/extensions/structured-return/{src/ui → ui}/widget.ts +0 -0
@@ -1,282 +0,0 @@
1
- import path from "node:path";
2
- import type { ParserModule, ParserRegistration } from "../types";
3
- import ruffJson from "../parsers/ruff-json";
4
- import eslintJson from "../parsers/eslint-json";
5
- import vitestJson from "../parsers/vitest-json";
6
- import rspecJson from "../parsers/rspec-json";
7
- import minitestText from "../parsers/minitest-text";
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";
12
- import mypyJson from "../parsers/mypy-json";
13
- import tscText from "../parsers/tsc-text";
14
- import pylintJson from "../parsers/pylint-json";
15
- import shellcheckJson from "../parsers/shellcheck-json";
16
- import rubocopJson from "../parsers/rubocop-json";
17
- import swiftcText from "../parsers/swiftc-text";
18
- import hadolintJson from "../parsers/hadolint-json";
19
- import stylelintJson from "../parsers/stylelint-json";
20
- import mochaJson from "../parsers/mocha-json";
21
- import unittestText from "../parsers/unittest-text";
22
- import goTestJson from "../parsers/go-test-json";
23
- import avaText from "../parsers/ava-text";
24
- import pyrightJson from "../parsers/pyright-json";
25
- import banditJson from "../parsers/bandit-json";
26
- import javacText from "../parsers/javac-text";
27
- import dotnetBuildText from "../parsers/dotnet-build-text";
28
- import clangText from "../parsers/clang-text";
29
- import nodeTestText from "../parsers/node-test-text";
30
- import blackText from "../parsers/black-text";
31
- import markdownlintJson from "../parsers/markdownlint-json";
32
- import prettierText from "../parsers/prettier-text";
33
- import valeJson from "../parsers/vale-json";
34
- import tidyText from "../parsers/tidy-text";
35
- import jsonlintText from "../parsers/jsonlint-text";
36
- import npmAuditJson from "../parsers/npm-audit-json";
37
- import isortText from "../parsers/isort-text";
38
- import htmlhintJson from "../parsers/htmlhint-json";
39
- import tailFallback from "../parsers/tail-fallback";
40
-
41
- const builtIns: Record<string, ParserModule> = {
42
- "ruff-json": ruffJson,
43
- "eslint-json": eslintJson,
44
- "vitest-json": vitestJson,
45
- "rspec-json": rspecJson,
46
- "minitest-text": minitestText,
47
- "junit-xml": junitXml,
48
- "cargo-build": cargoBuild,
49
- "cargo-test": cargoTest,
50
- "dbt-json": dbtJson,
51
- "mypy-json": mypyJson,
52
- "tsc-text": tscText,
53
- "pylint-json": pylintJson,
54
- "shellcheck-json": shellcheckJson,
55
- "rubocop-json": rubocopJson,
56
- "swiftc-text": swiftcText,
57
- "hadolint-json": hadolintJson,
58
- "stylelint-json": stylelintJson,
59
- "mocha-json": mochaJson,
60
- "unittest-text": unittestText,
61
- "go-test-json": goTestJson,
62
- "ava-text": avaText,
63
- "pyright-json": pyrightJson,
64
- "bandit-json": banditJson,
65
- "javac-text": javacText,
66
- "dotnet-build-text": dotnetBuildText,
67
- "clang-text": clangText,
68
- "node-test-text": nodeTestText,
69
- "black-text": blackText,
70
- "markdownlint-json": markdownlintJson,
71
- "prettier-text": prettierText,
72
- "vale-json": valeJson,
73
- "tidy-text": tidyText,
74
- "jsonlint-text": jsonlintText,
75
- "npm-audit-json": npmAuditJson,
76
- "isort-text": isortText,
77
- "htmlhint-json": htmlhintJson,
78
- "tail-fallback": tailFallback,
79
- };
80
-
81
- /**
82
- * Check whether argv contains `--flag=value` (joined) or `--flag value` (adjacent).
83
- * Avoids false positives from bare `value` tokens appearing elsewhere in argv.
84
- */
85
- function hasFlag(argv: string[], flag: string, value: string): boolean {
86
- if (argv.includes(`${flag}=${value}`)) return true;
87
- for (let i = 0; i < argv.length - 1; i++) {
88
- if (argv[i] === flag && argv[i + 1] === value) return true;
89
- }
90
- return false;
91
- }
92
-
93
- /** Built-in detection patterns — fire when no explicit parseAs or project registration matched. */
94
- const AUTO_DETECT: Array<{ parserId: string; detect: (argv: string[]) => boolean }> = [
95
- {
96
- parserId: "eslint-json",
97
- detect: (argv) => argv.includes("eslint") && hasFlag(argv, "-f", "json"),
98
- },
99
- {
100
- parserId: "ruff-json",
101
- detect: (argv) => argv.includes("ruff") && hasFlag(argv, "--output-format", "json"),
102
- },
103
- {
104
- parserId: "vitest-json",
105
- detect: (argv) => argv.includes("vitest") && hasFlag(argv, "--reporter", "json"),
106
- },
107
- {
108
- parserId: "rspec-json",
109
- detect: (argv) => argv.includes("rspec") && hasFlag(argv, "--format", "json"),
110
- },
111
- {
112
- parserId: "junit-xml",
113
- detect: (argv) =>
114
- argv.some((a) => a.startsWith("--junitxml") || a.startsWith("--junit-xml") || a === "--format=junit"),
115
- },
116
- {
117
- parserId: "cargo-build",
118
- detect: (argv) => argv.includes("cargo") && argv.includes("build") && hasFlag(argv, "--message-format", "json"),
119
- },
120
- {
121
- parserId: "cargo-test",
122
- detect: (argv) => argv.includes("cargo") && argv.includes("test"),
123
- },
124
- {
125
- parserId: "dbt-json",
126
- detect: (argv) =>
127
- argv.includes("dbt") &&
128
- (argv.includes("run") || argv.includes("test") || argv.includes("compile")) &&
129
- hasFlag(argv, "--log-format", "json"),
130
- },
131
- {
132
- parserId: "mypy-json",
133
- detect: (argv) => argv.includes("mypy") && hasFlag(argv, "--output", "json"),
134
- },
135
- {
136
- parserId: "tsc-text",
137
- detect: (argv) => argv.includes("tsc") && hasFlag(argv, "--pretty", "false"),
138
- },
139
- {
140
- parserId: "pylint-json",
141
- detect: (argv) => argv.includes("pylint") && hasFlag(argv, "--output-format", "json"),
142
- },
143
- {
144
- parserId: "shellcheck-json",
145
- detect: (argv) => argv.includes("shellcheck") && hasFlag(argv, "--format", "json"),
146
- },
147
- {
148
- parserId: "rubocop-json",
149
- detect: (argv) => argv.includes("rubocop") && hasFlag(argv, "--format", "json"),
150
- },
151
- {
152
- parserId: "swiftc-text",
153
- detect: (argv) => argv.includes("swiftc") && argv.includes("-typecheck"),
154
- },
155
- {
156
- parserId: "hadolint-json",
157
- detect: (argv) => argv.includes("hadolint") && hasFlag(argv, "--format", "json"),
158
- },
159
- {
160
- parserId: "stylelint-json",
161
- detect: (argv) => argv.includes("stylelint") && hasFlag(argv, "--formatter", "json"),
162
- },
163
- {
164
- parserId: "mocha-json",
165
- detect: (argv) => argv.includes("mocha") && hasFlag(argv, "--reporter", "json"),
166
- },
167
- {
168
- parserId: "unittest-text",
169
- detect: (argv) =>
170
- argv.includes("unittest") || (argv.includes("python3") && argv.includes("-m") && argv.includes("unittest")),
171
- },
172
- {
173
- parserId: "go-test-json",
174
- detect: (argv) => argv.includes("go") && argv.includes("test") && argv.includes("-json"),
175
- },
176
- {
177
- parserId: "ava-text",
178
- detect: (argv) => argv.includes("ava"),
179
- },
180
- {
181
- parserId: "pyright-json",
182
- detect: (argv) => argv.includes("pyright") && argv.includes("--outputjson"),
183
- },
184
- {
185
- parserId: "bandit-json",
186
- detect: (argv) => argv.includes("bandit") && hasFlag(argv, "-f", "json"),
187
- },
188
- {
189
- parserId: "javac-text",
190
- detect: (argv) => argv.includes("javac") && !argv.includes("-version"),
191
- },
192
- {
193
- parserId: "dotnet-build-text",
194
- detect: (argv) => argv.includes("dotnet") && argv.includes("build"),
195
- },
196
- {
197
- parserId: "node-test-text",
198
- detect: (argv) => argv.includes("node") && argv.includes("--test"),
199
- },
200
- {
201
- parserId: "black-text",
202
- detect: (argv) => argv.includes("black") && argv.includes("--check"),
203
- },
204
- {
205
- parserId: "markdownlint-json",
206
- detect: (argv) => argv.includes("markdownlint") && argv.includes("--json"),
207
- },
208
- {
209
- parserId: "prettier-text",
210
- detect: (argv) => argv.includes("prettier") && argv.includes("--check"),
211
- },
212
- {
213
- parserId: "tidy-text",
214
- detect: (argv) => argv.includes("tidy"),
215
- },
216
- {
217
- parserId: "jsonlint-text",
218
- detect: (argv) => argv.includes("jsonlint"),
219
- },
220
- {
221
- parserId: "htmlhint-json",
222
- detect: (argv) => argv.includes("htmlhint") && hasFlag(argv, "--format", "json"),
223
- },
224
- {
225
- parserId: "isort-text",
226
- detect: (argv) => argv.includes("isort") && argv.includes("--check"),
227
- },
228
- {
229
- parserId: "npm-audit-json",
230
- detect: (argv) => argv.includes("npm") && argv.includes("audit") && argv.includes("--json"),
231
- },
232
- {
233
- parserId: "vale-json",
234
- detect: (argv) => argv.includes("vale") && hasFlag(argv, "--output", "JSON"),
235
- },
236
- {
237
- parserId: "clang-text",
238
- detect: (argv) =>
239
- (argv.includes("gcc") || argv.includes("g++") || argv.includes("clang") || argv.includes("clang++")) &&
240
- (argv.includes("-c") || argv.includes("-o")),
241
- },
242
- ];
243
-
244
- export function listParsers(): { id: string; autoDetect: boolean }[] {
245
- const builtInIds = Object.keys(builtIns).filter((id) => id !== "tail-fallback");
246
- const autoDetectIds = new Set(AUTO_DETECT.map((d) => d.parserId));
247
- return builtInIds.map((id) => ({ id, autoDetect: autoDetectIds.has(id) }));
248
- }
249
-
250
- export async function resolveParser(opts: {
251
- cwd: string;
252
- parseAs?: string;
253
- argv: string[];
254
- registrations: ParserRegistration[];
255
- }): Promise<ParserModule> {
256
- if (opts.parseAs && builtIns[opts.parseAs]) return builtIns[opts.parseAs];
257
-
258
- const matched = opts.registrations.find((reg) => matches(reg, opts.argv));
259
- if (matched?.parseAs && builtIns[matched.parseAs]) return builtIns[matched.parseAs];
260
- if (matched?.module) {
261
- const modulePath = path.resolve(opts.cwd, ".pi", matched.module);
262
- const loaded = await import(modulePath);
263
- return loaded.default ?? loaded;
264
- }
265
-
266
- const autoMatched = AUTO_DETECT.find((d) => d.detect(opts.argv));
267
- if (autoMatched) return builtIns[autoMatched.parserId];
268
-
269
- return builtIns["tail-fallback"];
270
- }
271
-
272
- function matches(reg: ParserRegistration, argv: string[]): boolean {
273
- if (reg.match?.argvIncludes?.length) {
274
- const ok = reg.match.argvIncludes.every((token) => argv.includes(token));
275
- if (!ok) return false;
276
- }
277
- if (reg.match?.regex) {
278
- const text = argv.join(" ");
279
- if (!new RegExp(reg.match.regex).test(text)) return false;
280
- }
281
- return Boolean(reg.match?.argvIncludes?.length || reg.match?.regex);
282
- }
@@ -1,220 +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 { stripCdPrefix, formatResult, finalizeResult, expandArtifactPaths } from "./index";
6
-
7
- describe("stripCdPrefix", () => {
8
- it("strips cd /path && prefix", () => {
9
- expect(stripCdPrefix("cd /some/path && npx eslint . -f json")).toBe("npx eslint . -f json");
10
- });
11
-
12
- it("leaves commands without cd unchanged", () => {
13
- expect(stripCdPrefix("npx eslint . -f json")).toBe("npx eslint . -f json");
14
- });
15
-
16
- it("handles paths with no trailing space variations", () => {
17
- expect(stripCdPrefix("cd /a/b/c &&npx eslint .")).toBe("npx eslint .");
18
- });
19
- });
20
-
21
- describe("formatResult", () => {
22
- it("includes cwd when set", () => {
23
- const result = formatResult({
24
- tool: "eslint",
25
- exitCode: 1,
26
- status: "fail",
27
- summary: "1 lint errors",
28
- cwd: "/project",
29
- failures: [],
30
- });
31
- expect(result).toContain("cwd: /project");
32
- });
33
-
34
- it("omits cwd line when not set", () => {
35
- const result = formatResult({
36
- tool: "eslint",
37
- exitCode: 0,
38
- status: "pass",
39
- summary: "no lint errors",
40
- });
41
- expect(result).not.toContain("cwd:");
42
- });
43
-
44
- it("renders relative paths in failure lines", () => {
45
- const result = formatResult({
46
- tool: "eslint",
47
- exitCode: 1,
48
- status: "fail",
49
- summary: "1 lint errors",
50
- cwd: "/project",
51
- failures: [
52
- { id: "src/foo.ts:10:rule", file: "src/foo.ts", line: 10, message: "Unexpected any.", rule: "no-explicit-any" },
53
- ],
54
- });
55
- expect(result).toContain("src/foo.ts:10");
56
- expect(result).not.toContain("/project/src/foo.ts");
57
- });
58
- });
59
-
60
- describe("finalizeResult", () => {
61
- it("status error with exit code 0 flips to pass", () => {
62
- const result = finalizeResult(
63
- {
64
- tool: "unknown",
65
- status: "error",
66
- summary: "no parser matched; returning tail + log path",
67
- logPath: "/log",
68
- },
69
- 0,
70
- "/log",
71
- "/project"
72
- );
73
- expect(result.status).toBe("pass");
74
- expect(result.summary).toBe("command completed; no parser matched");
75
- });
76
-
77
- it("status error with non-zero exit code stays error", () => {
78
- const result = finalizeResult(
79
- {
80
- tool: "unknown",
81
- status: "error",
82
- summary: "no parser matched; returning tail + log path",
83
- logPath: "/log",
84
- },
85
- 1,
86
- "/log",
87
- "/project"
88
- );
89
- expect(result.status).toBe("error");
90
- });
91
-
92
- it("attaches cwd to result", () => {
93
- const result = finalizeResult(
94
- { tool: "eslint", status: "pass", summary: "no lint errors", logPath: "/log" },
95
- 0,
96
- "/log",
97
- "/project"
98
- );
99
- expect(result.cwd).toBe("/project");
100
- });
101
-
102
- it("appends rawTail when parser reports failures but extracts no details", () => {
103
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "finalize-test-"));
104
- const logPath = path.join(dir, "combined.log");
105
- fs.writeFileSync(logPath, "line1\nline2\nFAIL: something broke\n");
106
- const result = finalizeResult(
107
- { tool: "ava", status: "fail", summary: "2 failed, 1 passed", failures: [] },
108
- 1,
109
- logPath,
110
- "/project"
111
- );
112
- expect(result.rawTail).toContain("FAIL: something broke");
113
- });
114
-
115
- it("does not overwrite rawTail when parser already set it", () => {
116
- const result = finalizeResult(
117
- { tool: "dbt", status: "fail", summary: "1 error", failures: [], rawTail: "SELECT * FROM ..." },
118
- 1,
119
- "/nonexistent/log",
120
- "/project"
121
- );
122
- expect(result.rawTail).toBe("SELECT * FROM ...");
123
- });
124
- });
125
-
126
- describe("expandArtifactPaths", () => {
127
- it("expands glob patterns to matching files (sorted)", () => {
128
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "expand-glob-"));
129
- fs.writeFileSync(path.join(dir, "TEST-Bar.xml"), "<bar/>");
130
- fs.writeFileSync(path.join(dir, "TEST-Foo.xml"), "<foo/>");
131
- fs.writeFileSync(path.join(dir, "other.txt"), "ignore");
132
-
133
- const result = expandArtifactPaths(["TEST-*.xml"], dir);
134
- expect(result).toEqual([path.join(dir, "TEST-Bar.xml"), path.join(dir, "TEST-Foo.xml")]);
135
- });
136
-
137
- it("keeps unmatched patterns as-is (parser handles missing files)", () => {
138
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "expand-nomatch-"));
139
- const result = expandArtifactPaths(["reports/TEST-*.xml"], dir);
140
- expect(result).toEqual([path.join(dir, "reports/TEST-*.xml")]);
141
- });
142
-
143
- it("resolves relative paths against cwd", () => {
144
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "expand-rel-"));
145
- const sub = path.join(dir, "build");
146
- fs.mkdirSync(sub);
147
- fs.writeFileSync(path.join(sub, "report.xml"), "<ok/>");
148
-
149
- const result = expandArtifactPaths(["build/report.xml"], dir);
150
- expect(result).toEqual([path.join(dir, "build/report.xml")]);
151
- });
152
-
153
- it("passes through absolute paths unchanged", () => {
154
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "expand-abs-"));
155
- fs.writeFileSync(path.join(dir, "report.xml"), "<ok/>");
156
-
157
- const abs = path.join(dir, "report.xml");
158
- const result = expandArtifactPaths([abs], "/some/other/cwd");
159
- expect(result).toEqual([abs]);
160
- });
161
-
162
- it("handles multiple patterns, some with globs and some without", () => {
163
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "expand-multi-"));
164
- fs.writeFileSync(path.join(dir, "TEST-A.xml"), "a");
165
- fs.writeFileSync(path.join(dir, "TEST-B.xml"), "b");
166
- fs.writeFileSync(path.join(dir, "coverage.xml"), "c");
167
-
168
- const result = expandArtifactPaths(["TEST-*.xml", "coverage.xml"], dir);
169
- expect(result).toEqual([
170
- path.join(dir, "TEST-A.xml"),
171
- path.join(dir, "TEST-B.xml"),
172
- path.join(dir, "coverage.xml"),
173
- ]);
174
- });
175
-
176
- it("expands globs with * in directory positions (multi-module Gradle)", () => {
177
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), "expand-dirglob-"));
178
- const modA = path.join(dir, "moduleA", "build", "test-results", "test");
179
- const modB = path.join(dir, "moduleB", "build", "test-results", "test");
180
- fs.mkdirSync(modA, { recursive: true });
181
- fs.mkdirSync(modB, { recursive: true });
182
- fs.writeFileSync(path.join(modA, "TEST-FooTest.xml"), "<foo/>");
183
- fs.writeFileSync(path.join(modB, "TEST-BarTest.xml"), "<bar/>");
184
-
185
- const result = expandArtifactPaths(["*/build/test-results/test/TEST-*.xml"], dir);
186
- expect(result).toEqual([path.join(modA, "TEST-FooTest.xml"), path.join(modB, "TEST-BarTest.xml")]);
187
- });
188
-
189
- it("returns empty array for empty input", () => {
190
- expect(expandArtifactPaths([], "/any")).toEqual([]);
191
- });
192
- });
193
-
194
- describe("formatResult safety net", () => {
195
- it("surfaces log path and rawTail when failures detected but no details parsed", () => {
196
- const result = formatResult({
197
- tool: "ava",
198
- exitCode: 1,
199
- status: "fail",
200
- summary: "2 failed, 1 passed",
201
- failures: [],
202
- logPath: "/tmp/ava-run.log",
203
- rawTail: "FAIL: test_multiply\nexpected 99, got 12",
204
- });
205
- expect(result).toContain("log: /tmp/ava-run.log");
206
- expect(result).toContain("expected 99, got 12");
207
- });
208
-
209
- it("does not surface log path when failures have details", () => {
210
- const result = formatResult({
211
- tool: "ava",
212
- exitCode: 1,
213
- status: "fail",
214
- summary: "1 failed",
215
- failures: [{ id: "test1", file: "test.js", line: 5, message: "boom" }],
216
- logPath: "/tmp/ava-run.log",
217
- });
218
- expect(result).not.toContain("log:");
219
- });
220
- });
@@ -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
- });