@robhowley/pi-structured-return 1.10.1 → 2.0.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/LICENSE +21 -0
- package/README.md +33 -83
- package/extensions/structured-return/config/registry.ts +4 -30
- package/extensions/structured-return/index.ts +105 -76
- package/extensions/structured-return/native.ts +223 -0
- package/extensions/structured-return/parsers/ava-text.ts +2 -168
- package/extensions/structured-return/parsers/bandit-json.ts +2 -79
- package/extensions/structured-return/parsers/black-text.ts +2 -73
- package/extensions/structured-return/parsers/cargo-build.ts +2 -78
- package/extensions/structured-return/parsers/cargo-test.ts +2 -135
- package/extensions/structured-return/parsers/checkstyle-xml.ts +2 -182
- package/extensions/structured-return/parsers/clang-text.ts +2 -60
- package/extensions/structured-return/parsers/dbt-json.ts +2 -135
- package/extensions/structured-return/parsers/dotnet-build-text.ts +2 -49
- package/extensions/structured-return/parsers/eslint-json.ts +2 -38
- package/extensions/structured-return/parsers/go-test-json.ts +2 -138
- package/extensions/structured-return/parsers/hadolint-json.ts +2 -60
- package/extensions/structured-return/parsers/htmlhint-json.ts +2 -73
- package/extensions/structured-return/parsers/isort-text.ts +2 -63
- package/extensions/structured-return/parsers/javac-text.ts +2 -82
- package/extensions/structured-return/parsers/jsonlint-text.ts +2 -65
- package/extensions/structured-return/parsers/junit-xml.ts +2 -325
- package/extensions/structured-return/parsers/markdownlint-json.ts +2 -74
- package/extensions/structured-return/parsers/minitest-text.ts +2 -107
- package/extensions/structured-return/parsers/mocha-json.ts +2 -83
- package/extensions/structured-return/parsers/mypy-json.ts +2 -79
- package/extensions/structured-return/parsers/node-test-text.ts +2 -92
- package/extensions/structured-return/parsers/npm-audit-json.ts +2 -90
- package/extensions/structured-return/parsers/prettier-text.ts +2 -66
- package/extensions/structured-return/parsers/pylint-json.ts +2 -63
- package/extensions/structured-return/parsers/pyright-json.ts +2 -82
- package/extensions/structured-return/parsers/rspec-json.ts +2 -75
- package/extensions/structured-return/parsers/rubocop-json.ts +2 -75
- package/extensions/structured-return/parsers/ruff-json.ts +2 -36
- package/extensions/structured-return/parsers/shellcheck-json.ts +2 -60
- package/extensions/structured-return/parsers/stylelint-json.ts +2 -75
- package/extensions/structured-return/parsers/swiftc-text.ts +2 -52
- package/extensions/structured-return/parsers/tail-fallback.ts +2 -19
- package/extensions/structured-return/parsers/tidy-text.ts +2 -66
- package/extensions/structured-return/parsers/tsc-text.ts +2 -46
- package/extensions/structured-return/parsers/unittest-text.ts +2 -125
- package/extensions/structured-return/parsers/utils.ts +28 -0
- package/extensions/structured-return/parsers/vale-json.ts +2 -79
- package/extensions/structured-return/parsers/vitest-json.ts +2 -59
- package/extensions/structured-return/storage/log-store.ts +0 -15
- package/extensions/structured-return/types.ts +1 -14
- package/native/Cargo.lock +193 -0
- package/native/Cargo.toml +21 -0
- package/native/THIRD-PARTY-LICENSES.txt +3660 -0
- package/native/bin/darwin-arm64/build.json +7 -0
- package/native/bin/darwin-arm64/structured-return-native +0 -0
- package/native/bin/darwin-x64/build.json +7 -0
- package/native/bin/darwin-x64/structured-return-native +0 -0
- package/native/bin/linux-arm64-musl/build.json +7 -0
- package/native/bin/linux-arm64-musl/structured-return-native +0 -0
- package/native/bin/linux-x64-musl/build.json +7 -0
- package/native/bin/linux-x64-musl/structured-return-native +0 -0
- package/native/src/common.rs +118 -0
- package/native/src/main.rs +55 -0
- package/native/src/parsers/ava_text.rs +125 -0
- package/native/src/parsers/bandit_json.rs +120 -0
- package/native/src/parsers/black_text.rs +45 -0
- package/native/src/parsers/cargo_build.rs +96 -0
- package/native/src/parsers/cargo_test.rs +140 -0
- package/native/src/parsers/checkstyle_xml.rs +137 -0
- package/native/src/parsers/clang_text.rs +39 -0
- package/native/src/parsers/compiler_helpers.rs +74 -0
- package/native/src/parsers/dbt_json.rs +243 -0
- package/native/src/parsers/dotnet_build_text.rs +50 -0
- package/native/src/parsers/eslint_json.rs +58 -0
- package/native/src/parsers/go_test_json.rs +346 -0
- package/native/src/parsers/hadolint_json.rs +37 -0
- package/native/src/parsers/htmlhint_json.rs +71 -0
- package/native/src/parsers/isort_text.rs +22 -0
- package/native/src/parsers/javac_text.rs +49 -0
- package/native/src/parsers/json_support.rs +287 -0
- package/native/src/parsers/jsonlint_text.rs +50 -0
- package/native/src/parsers/junit_xml.rs +430 -0
- package/native/src/parsers/markdownlint_json.rs +68 -0
- package/native/src/parsers/minitest_text.rs +91 -0
- package/native/src/parsers/mocha_json.rs +75 -0
- package/native/src/parsers/mod.rs +119 -0
- package/native/src/parsers/mypy_json.rs +93 -0
- package/native/src/parsers/node_test_text.rs +106 -0
- package/native/src/parsers/npm_audit_json.rs +119 -0
- package/native/src/parsers/prettier_text.rs +34 -0
- package/native/src/parsers/pylint_json.rs +44 -0
- package/native/src/parsers/pyright_json.rs +88 -0
- package/native/src/parsers/rspec_json.rs +84 -0
- package/native/src/parsers/rubocop_json.rs +46 -0
- package/native/src/parsers/ruff_json.rs +30 -0
- package/native/src/parsers/shellcheck_json.rs +40 -0
- package/native/src/parsers/stylelint_json.rs +46 -0
- package/native/src/parsers/swiftc_text.rs +38 -0
- package/native/src/parsers/tail_fallback.rs +51 -0
- package/native/src/parsers/test_helpers.rs +172 -0
- package/native/src/parsers/tidy_text.rs +77 -0
- package/native/src/parsers/tsc_text.rs +28 -0
- package/native/src/parsers/unittest_text.rs +125 -0
- package/native/src/parsers/vale_json.rs +66 -0
- package/native/src/parsers/vitest_json.rs +71 -0
- package/native/src/parsers/xml_support.rs +241 -0
- package/native/src/runner.rs +252 -0
- package/package.json +20 -6
- package/scripts/build-native.mjs +73 -0
- package/scripts/native-artifacts.mjs +69 -0
- package/skills/structured-return/SKILL.md +103 -249
- package/extensions/structured-return/config/project-config.ts +0 -10
- package/extensions/structured-return/examples/.pi/machine-readable.json +0 -18
- package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +0 -25
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import type { ParserModule, RunContext } from './types';
|
|
6
|
+
|
|
7
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
8
|
+
const version: string = JSON.parse(
|
|
9
|
+
fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'),
|
|
10
|
+
).version;
|
|
11
|
+
const protocol = 1;
|
|
12
|
+
|
|
13
|
+
export function nativeExecutable(): string {
|
|
14
|
+
if (process.env.STRUCTURED_RETURN_NATIVE) return process.env.STRUCTURED_RETURN_NATIVE;
|
|
15
|
+
const key = `${process.platform}-${process.arch}${process.platform === 'linux' ? '-musl' : ''}`;
|
|
16
|
+
if (!['darwin-x64', 'darwin-arm64', 'linux-x64-musl', 'linux-arm64-musl'].includes(key)) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Structured Return does not support ${process.platform}-${process.arch}. Supported: macOS and Linux, x64/arm64.`,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const installed = path.join(packageRoot, 'native/bin', key, 'structured-return-native');
|
|
22
|
+
if (fs.existsSync(installed)) return installed;
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Structured Return native helper is missing for ${key}. Reinstall the published npm package. Source checkouts must run npm run build:native (Rust 1.88.0). No TypeScript fallback is available.`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function killTree(pid: number): void {
|
|
29
|
+
try {
|
|
30
|
+
process.kill(-pid, 'SIGKILL');
|
|
31
|
+
} catch {
|
|
32
|
+
/* Process group already exited. */
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One short-lived helper per operation. Validate its handshake before sending work. */
|
|
37
|
+
export function callNative<T>(request: object, signal?: AbortSignal, isRun = false): Promise<T> {
|
|
38
|
+
if (signal?.aborted)
|
|
39
|
+
return Promise.reject(new Error('Structured Return was cancelled before starting.'));
|
|
40
|
+
const executable = nativeExecutable();
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const child = spawn(executable, [], { stdio: ['pipe', 'pipe', 'pipe'], detached: true });
|
|
43
|
+
let chunks: Buffer[] = [];
|
|
44
|
+
let pendingBytes = 0;
|
|
45
|
+
let stderr = '';
|
|
46
|
+
let value: T | undefined;
|
|
47
|
+
let failure: Error | undefined;
|
|
48
|
+
let commandPid: number | undefined;
|
|
49
|
+
let ready = false;
|
|
50
|
+
let killTimer: ReturnType<typeof setTimeout> | undefined;
|
|
51
|
+
let responseTimer: ReturnType<typeof setTimeout> | undefined;
|
|
52
|
+
const stop = (error: Error) => {
|
|
53
|
+
failure ??= error;
|
|
54
|
+
if (commandPid) killTree(commandPid);
|
|
55
|
+
if (child.pid) killTree(child.pid);
|
|
56
|
+
};
|
|
57
|
+
const handshakeTimer = setTimeout(
|
|
58
|
+
() =>
|
|
59
|
+
stop(
|
|
60
|
+
new Error('Structured Return native helper handshake timed out. Reinstall the package.'),
|
|
61
|
+
),
|
|
62
|
+
5000,
|
|
63
|
+
);
|
|
64
|
+
const abort = () => {
|
|
65
|
+
if (!ready || !isRun) stop(new Error('Structured Return was cancelled.'));
|
|
66
|
+
else {
|
|
67
|
+
child.stdin.write('cancel\n');
|
|
68
|
+
killTimer = setTimeout(
|
|
69
|
+
() => stop(new Error('Structured Return native helper did not complete cancellation.')),
|
|
70
|
+
2000,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const cleanup = () => {
|
|
75
|
+
clearTimeout(handshakeTimer);
|
|
76
|
+
if (killTimer) clearTimeout(killTimer);
|
|
77
|
+
if (responseTimer) clearTimeout(responseTimer);
|
|
78
|
+
signal?.removeEventListener('abort', abort);
|
|
79
|
+
child.stdin.destroy();
|
|
80
|
+
};
|
|
81
|
+
child.stdout.on('data', (chunk: Buffer) => {
|
|
82
|
+
if (failure) return;
|
|
83
|
+
let start = 0;
|
|
84
|
+
while (start < chunk.length) {
|
|
85
|
+
const newline = chunk.indexOf(10, start);
|
|
86
|
+
const end = newline < 0 ? chunk.length : newline + 1;
|
|
87
|
+
if (pendingBytes + end - start > 16 * 1024 * 1024) {
|
|
88
|
+
stop(new Error('Structured Return native protocol response exceeds 16 MiB.'));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
chunks.push(chunk.subarray(start, end));
|
|
92
|
+
pendingBytes += end - start;
|
|
93
|
+
start = end;
|
|
94
|
+
if (newline < 0) return;
|
|
95
|
+
const line = Buffer.concat(chunks, pendingBytes).subarray(0, -1).toString('utf8');
|
|
96
|
+
chunks = [];
|
|
97
|
+
pendingBytes = 0;
|
|
98
|
+
try {
|
|
99
|
+
const message = JSON.parse(line);
|
|
100
|
+
if (message.protocol !== protocol || message.version !== version) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`native protocol/version mismatch (expected ${protocol}/${version}). Reinstall the package.`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (!ready) {
|
|
106
|
+
if (message.event !== 'ready') throw new Error('expected native ready handshake');
|
|
107
|
+
ready = true;
|
|
108
|
+
clearTimeout(handshakeTimer);
|
|
109
|
+
child.stdin.write(JSON.stringify({ ...request, protocol, version }) + '\n');
|
|
110
|
+
if (!isRun) {
|
|
111
|
+
child.stdin.end();
|
|
112
|
+
responseTimer = setTimeout(
|
|
113
|
+
() => stop(new Error('Structured Return native parser timed out.')),
|
|
114
|
+
30000,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
} else if (
|
|
118
|
+
message.event === 'started' &&
|
|
119
|
+
isRun &&
|
|
120
|
+
!commandPid &&
|
|
121
|
+
Number.isSafeInteger(message.pid) &&
|
|
122
|
+
message.pid > 1
|
|
123
|
+
) {
|
|
124
|
+
commandPid = message.pid;
|
|
125
|
+
} else if ('result' in message && value === undefined) {
|
|
126
|
+
const result = message.result;
|
|
127
|
+
if (
|
|
128
|
+
!result ||
|
|
129
|
+
typeof result !== 'object' ||
|
|
130
|
+
(isRun ? !validRun(result) : !validParsed(result))
|
|
131
|
+
)
|
|
132
|
+
throw new Error('invalid native result');
|
|
133
|
+
value = result as T;
|
|
134
|
+
if (responseTimer) clearTimeout(responseTimer);
|
|
135
|
+
responseTimer = setTimeout(
|
|
136
|
+
() =>
|
|
137
|
+
stop(new Error('Structured Return native helper did not exit after its result.')),
|
|
138
|
+
5000,
|
|
139
|
+
);
|
|
140
|
+
} else throw new Error('unexpected native protocol message');
|
|
141
|
+
} catch (error) {
|
|
142
|
+
stop(new Error(`Structured Return native protocol error: ${(error as Error).message}`));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
child.stderr.setEncoding('utf8').on('data', (chunk: string) => {
|
|
148
|
+
stderr = (stderr + chunk).slice(-16384);
|
|
149
|
+
});
|
|
150
|
+
child.on('error', (error) => {
|
|
151
|
+
cleanup();
|
|
152
|
+
reject(
|
|
153
|
+
new Error(
|
|
154
|
+
`Structured Return could not start native helper ${executable}: ${error.message}. Reinstall the package or rebuild from source.`,
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
child.stdin.on('error', (error: NodeJS.ErrnoException) => {
|
|
159
|
+
if (error.code !== 'EPIPE') stop(error);
|
|
160
|
+
});
|
|
161
|
+
child.on('close', (code) => {
|
|
162
|
+
cleanup();
|
|
163
|
+
if (
|
|
164
|
+
code !== 0 ||
|
|
165
|
+
failure ||
|
|
166
|
+
value === undefined ||
|
|
167
|
+
Buffer.concat(chunks, pendingBytes).toString('utf8').trim()
|
|
168
|
+
) {
|
|
169
|
+
if (commandPid) killTree(commandPid);
|
|
170
|
+
reject(
|
|
171
|
+
failure ??
|
|
172
|
+
new Error(
|
|
173
|
+
`Structured Return native helper exited ${code}: ${stderr.trim() || 'missing or incomplete protocol response'}`,
|
|
174
|
+
),
|
|
175
|
+
);
|
|
176
|
+
} else resolve(value);
|
|
177
|
+
});
|
|
178
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
179
|
+
if (signal?.aborted) abort();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function validParsed(result: Record<string, unknown>): boolean {
|
|
184
|
+
return (
|
|
185
|
+
typeof result.tool === 'string' &&
|
|
186
|
+
['pass', 'fail', 'error'].includes(String(result.status)) &&
|
|
187
|
+
typeof result.summary === 'string' &&
|
|
188
|
+
(result.failures === undefined || Array.isArray(result.failures))
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
function validRun(result: Record<string, unknown>): boolean {
|
|
192
|
+
return (
|
|
193
|
+
['stdoutPath', 'stderrPath', 'logPath'].every((key) => typeof result[key] === 'string') &&
|
|
194
|
+
Number.isSafeInteger(result.exitCode) &&
|
|
195
|
+
Number.isSafeInteger(result.rawBytes) &&
|
|
196
|
+
Number(result.rawBytes) >= 0 &&
|
|
197
|
+
typeof result.cancelled === 'boolean'
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function nativeParser(id: string): ParserModule {
|
|
202
|
+
return {
|
|
203
|
+
id,
|
|
204
|
+
parse: ({ signal, ...context }: RunContext) => callNative({ parser: id, context }, signal),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
export type NativeRun = {
|
|
208
|
+
stdoutPath: string;
|
|
209
|
+
stderrPath: string;
|
|
210
|
+
logPath: string;
|
|
211
|
+
exitCode: number;
|
|
212
|
+
rawBytes: number;
|
|
213
|
+
cancelled: boolean;
|
|
214
|
+
};
|
|
215
|
+
export function runNative(
|
|
216
|
+
command: string,
|
|
217
|
+
cwd: string,
|
|
218
|
+
runDir: string,
|
|
219
|
+
runId: string,
|
|
220
|
+
signal?: AbortSignal,
|
|
221
|
+
): Promise<NativeRun> {
|
|
222
|
+
return callNative({ op: 'run', command, cwd, runDir, runId }, signal, true);
|
|
223
|
+
}
|
|
@@ -1,169 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
-
import { extractJsStackLocation, safeReadFile } from './utils';
|
|
1
|
+
import { nativeParser } from '../native';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
* Parses AVA's default text output (--no-color).
|
|
7
|
-
* Reads stdoutPath — AVA writes all output (results + diagnostics) to stdout.
|
|
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.stdoutPath);
|
|
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 {
|
|
36
|
-
tool: 'ava',
|
|
37
|
-
status: 'error',
|
|
38
|
-
summary: 'could not parse ava output',
|
|
39
|
-
logPath: ctx.logPath,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const failures = parseFailureBlocks(stderr, ctx.cwd);
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
tool: 'ava',
|
|
47
|
-
status: failed > 0 ? 'fail' : 'pass',
|
|
48
|
-
summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
|
|
49
|
-
failures,
|
|
50
|
-
logPath: ctx.logPath,
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export default parser;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* AVA's failure detail section lives between the first and last ─ separators.
|
|
59
|
-
* Each failure block starts with the test name (matching a name from the ✘ lines),
|
|
60
|
-
* followed by either a file:line (assertion) or "Error thrown in test:" (runtime).
|
|
61
|
-
*
|
|
62
|
-
* Strategy: collect failed test names from ✘ lines, then split the detail section
|
|
63
|
-
* by those names to get per-failure blocks.
|
|
64
|
-
*/
|
|
65
|
-
function parseFailureBlocks(output: string, cwd: string): ParsedFailure[] {
|
|
66
|
-
const lines = output.split('\n');
|
|
67
|
-
|
|
68
|
-
// Collect failed test names from ✘ markers
|
|
69
|
-
const failedNames: string[] = [];
|
|
70
|
-
for (const line of lines) {
|
|
71
|
-
const fm = FAIL_MARKER_RE.exec(line);
|
|
72
|
-
if (fm) failedNames.push(fm[1]);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (failedNames.length === 0) return [];
|
|
76
|
-
|
|
77
|
-
// Find the detail section between first and last ─ separators
|
|
78
|
-
const sepIndices: number[] = [];
|
|
79
|
-
for (let i = 0; i < lines.length; i++) {
|
|
80
|
-
if (lines[i].match(/^\s*─\s*$/)) sepIndices.push(i);
|
|
81
|
-
}
|
|
82
|
-
if (sepIndices.length < 2) return [];
|
|
83
|
-
|
|
84
|
-
const detailStart = sepIndices[0] + 1;
|
|
85
|
-
const detailEnd = sepIndices[sepIndices.length - 1];
|
|
86
|
-
const detailLines = lines.slice(detailStart, detailEnd);
|
|
87
|
-
|
|
88
|
-
// Split detail lines into blocks by test name
|
|
89
|
-
const blocks: Array<{ name: string; lines: string[] }> = [];
|
|
90
|
-
let currentBlock: { name: string; lines: string[] } | null = null;
|
|
91
|
-
|
|
92
|
-
for (const line of detailLines) {
|
|
93
|
-
const trimmed = line.trim();
|
|
94
|
-
if (failedNames.includes(trimmed)) {
|
|
95
|
-
if (currentBlock) blocks.push(currentBlock);
|
|
96
|
-
currentBlock = { name: trimmed, lines: [] };
|
|
97
|
-
} else if (currentBlock) {
|
|
98
|
-
currentBlock.lines.push(line);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (currentBlock) blocks.push(currentBlock);
|
|
102
|
-
|
|
103
|
-
// Parse each block
|
|
104
|
-
return blocks.map((block) => parseBlock(block.name, block.lines, cwd));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function parseBlock(name: string, lines: string[], cwd: string): ParsedFailure {
|
|
108
|
-
// Determine type by looking for "Error thrown in test:"
|
|
109
|
-
const isRuntimeError = lines.some((l) => l.trim() === 'Error thrown in test:');
|
|
110
|
-
|
|
111
|
-
if (isRuntimeError) {
|
|
112
|
-
return parseRuntimeError(name, lines, cwd);
|
|
113
|
-
}
|
|
114
|
-
return parseAssertionFailure(name, lines, cwd);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function parseAssertionFailure(name: string, lines: string[], cwd: string): ParsedFailure {
|
|
118
|
-
let file: string | undefined;
|
|
119
|
-
let line: number | undefined;
|
|
120
|
-
let actual: string | undefined;
|
|
121
|
-
let expected: string | undefined;
|
|
122
|
-
|
|
123
|
-
for (const l of lines) {
|
|
124
|
-
const trimmed = l.trim();
|
|
125
|
-
|
|
126
|
-
// file:line (standalone, e.g. "test_math.js:8")
|
|
127
|
-
if (!file) {
|
|
128
|
-
const flm = trimmed.match(/^(.+\.[a-z]{1,4}):(\d+)$/);
|
|
129
|
-
if (flm) {
|
|
130
|
-
file = path.relative(cwd, path.resolve(cwd, flm[1]));
|
|
131
|
-
line = parseInt(flm[2], 10);
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Diff values: "- 12" (actual), "+ 99" (expected)
|
|
137
|
-
if (trimmed.startsWith('- ') && actual === undefined) {
|
|
138
|
-
actual = trimmed.slice(2);
|
|
139
|
-
} else if (trimmed.startsWith('+ ') && expected === undefined) {
|
|
140
|
-
expected = trimmed.slice(2);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const message =
|
|
145
|
-
actual !== undefined && expected !== undefined
|
|
146
|
-
? `expected ${expected}, got ${actual}`
|
|
147
|
-
: undefined;
|
|
148
|
-
|
|
149
|
-
return { id: name, file, line, message };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function parseRuntimeError(name: string, lines: string[], cwd: string): ParsedFailure {
|
|
153
|
-
let message: string | undefined;
|
|
154
|
-
|
|
155
|
-
for (const l of lines) {
|
|
156
|
-
const trimmed = l.trim();
|
|
157
|
-
// Extract message from "message: '...'" inside the error object
|
|
158
|
-
if (!message) {
|
|
159
|
-
const msgMatch = trimmed.match(/^message:\s*'(.+)',?$/);
|
|
160
|
-
if (msgMatch) message = msgMatch[1];
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Extract file:line from the first user stack frame
|
|
165
|
-
const loc = extractJsStackLocation(lines.join('\n'));
|
|
166
|
-
const file = loc.file ? path.relative(cwd, path.resolve(cwd, loc.file)) : undefined;
|
|
167
|
-
|
|
168
|
-
return { id: name, file, line: loc.line, message };
|
|
169
|
-
}
|
|
3
|
+
export default nativeParser('ava-text');
|
|
@@ -1,80 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
-
import { safeReadFile } from './utils';
|
|
1
|
+
import { nativeParser } from '../native';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
filename: string;
|
|
7
|
-
line_number: number;
|
|
8
|
-
issue_text: string;
|
|
9
|
-
issue_severity: string;
|
|
10
|
-
test_id: string;
|
|
11
|
-
test_name: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface BanditOutput {
|
|
15
|
-
results?: BanditResult[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const parser: ParserModule = {
|
|
19
|
-
id: 'bandit-json',
|
|
20
|
-
async parse(ctx) {
|
|
21
|
-
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
22
|
-
if (!stdout) {
|
|
23
|
-
return {
|
|
24
|
-
tool: 'bandit',
|
|
25
|
-
status: 'pass',
|
|
26
|
-
summary: 'no security issues',
|
|
27
|
-
failures: [],
|
|
28
|
-
logPath: ctx.logPath,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let output: BanditOutput;
|
|
33
|
-
try {
|
|
34
|
-
output = JSON.parse(stdout);
|
|
35
|
-
} catch {
|
|
36
|
-
return {
|
|
37
|
-
tool: 'bandit',
|
|
38
|
-
status: 'error',
|
|
39
|
-
summary: 'failed to parse bandit JSON output',
|
|
40
|
-
logPath: ctx.logPath,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const results = output.results ?? [];
|
|
45
|
-
const failures: ParsedFailure[] = results.map((r) => {
|
|
46
|
-
const relPath = path.relative(ctx.cwd, r.filename);
|
|
47
|
-
return {
|
|
48
|
-
id: `${relPath}:${r.line_number}:${r.test_id}`,
|
|
49
|
-
file: relPath,
|
|
50
|
-
line: r.line_number,
|
|
51
|
-
message: r.issue_text,
|
|
52
|
-
rule: `${r.test_id}:${r.test_name}`,
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const bySeverity: Record<string, number> = {};
|
|
57
|
-
for (const r of results) {
|
|
58
|
-
const sev = r.issue_severity.toLowerCase();
|
|
59
|
-
bySeverity[sev] = (bySeverity[sev] ?? 0) + 1;
|
|
60
|
-
}
|
|
61
|
-
const sevParts = ['high', 'medium', 'low']
|
|
62
|
-
.filter((s) => bySeverity[s])
|
|
63
|
-
.map((s) => `${bySeverity[s]} ${s}`);
|
|
64
|
-
|
|
65
|
-
const summary =
|
|
66
|
-
results.length > 0
|
|
67
|
-
? `${results.length} issue${results.length !== 1 ? 's' : ''} (${sevParts.join(', ')})`
|
|
68
|
-
: 'no security issues';
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
tool: 'bandit',
|
|
72
|
-
status: failures.length > 0 ? 'fail' : 'pass',
|
|
73
|
-
summary,
|
|
74
|
-
failures,
|
|
75
|
-
logPath: ctx.logPath,
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export default parser;
|
|
3
|
+
export default nativeParser('bandit-json');
|
|
@@ -1,74 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
-
import { safeReadFile } from './utils';
|
|
1
|
+
import { nativeParser } from '../native';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
const ERROR_FORMAT = /^error: cannot format (.+?): (.+)$/;
|
|
7
|
-
|
|
8
|
-
const parser: ParserModule = {
|
|
9
|
-
id: 'black-text',
|
|
10
|
-
async parse(ctx) {
|
|
11
|
-
const combined = (safeReadFile(ctx.stdoutPath) + '\n' + safeReadFile(ctx.stderrPath)).trim();
|
|
12
|
-
if (!combined) {
|
|
13
|
-
return {
|
|
14
|
-
tool: 'black',
|
|
15
|
-
status: 'pass',
|
|
16
|
-
summary: 'all files formatted',
|
|
17
|
-
failures: [],
|
|
18
|
-
logPath: ctx.logPath,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const lines = combined.split('\n');
|
|
23
|
-
const failures: ParsedFailure[] = [];
|
|
24
|
-
for (const line of lines) {
|
|
25
|
-
const reformatMatch = line.match(REFORMAT_LINE);
|
|
26
|
-
if (reformatMatch) {
|
|
27
|
-
const relPath = path.relative(ctx.cwd, reformatMatch[1]);
|
|
28
|
-
failures.push({
|
|
29
|
-
id: relPath,
|
|
30
|
-
file: relPath,
|
|
31
|
-
message: 'would reformat',
|
|
32
|
-
});
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const errorMatch = line.match(ERROR_FORMAT);
|
|
37
|
-
if (errorMatch) {
|
|
38
|
-
const relPath = path.relative(ctx.cwd, errorMatch[1]);
|
|
39
|
-
failures.push({
|
|
40
|
-
id: relPath,
|
|
41
|
-
file: relPath,
|
|
42
|
-
message: errorMatch[2],
|
|
43
|
-
});
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// If "All done!" and no reformats needed
|
|
49
|
-
if (failures.length === 0 && combined.includes('All done!')) {
|
|
50
|
-
return {
|
|
51
|
-
tool: 'black',
|
|
52
|
-
status: 'pass',
|
|
53
|
-
summary: 'all files formatted',
|
|
54
|
-
failures: [],
|
|
55
|
-
logPath: ctx.logPath,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const summary =
|
|
60
|
-
failures.length > 0
|
|
61
|
-
? `${failures.length} file${failures.length !== 1 ? 's' : ''} would be reformatted`
|
|
62
|
-
: 'all files formatted';
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
tool: 'black',
|
|
66
|
-
status: failures.length > 0 ? 'fail' : 'pass',
|
|
67
|
-
summary,
|
|
68
|
-
failures,
|
|
69
|
-
logPath: ctx.logPath,
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export default parser;
|
|
3
|
+
export default nativeParser('black-text');
|
|
@@ -1,79 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
-
import { safeReadFile } from './utils';
|
|
1
|
+
import { nativeParser } from '../native';
|
|
4
2
|
|
|
5
|
-
|
|
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 = safeReadFile(ctx.stdoutPath);
|
|
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
|
|
50
|
-
? path.relative(ctx.cwd, path.resolve(ctx.cwd, primarySpan.file_name))
|
|
51
|
-
: undefined;
|
|
52
|
-
const lineNum = primarySpan?.line_start;
|
|
53
|
-
const label = primarySpan?.label ?? undefined;
|
|
54
|
-
const code = msg.code?.code;
|
|
55
|
-
|
|
56
|
-
failures.push({
|
|
57
|
-
id: [file, lineNum, code].filter(Boolean).join(':'),
|
|
58
|
-
file,
|
|
59
|
-
line: lineNum,
|
|
60
|
-
// Surface the primary span label (e.g. "expected `i32`, found `&str`") as a second line
|
|
61
|
-
message: label ? `${msg.message}\n${label}` : msg.message,
|
|
62
|
-
rule: code,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
tool: 'cargo',
|
|
68
|
-
status: failures.length > 0 ? 'fail' : 'pass',
|
|
69
|
-
summary:
|
|
70
|
-
failures.length > 0
|
|
71
|
-
? `${failures.length} error${failures.length === 1 ? '' : 's'}`
|
|
72
|
-
: 'build succeeded',
|
|
73
|
-
failures,
|
|
74
|
-
logPath: ctx.logPath,
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export default parser;
|
|
3
|
+
export default nativeParser('cargo-build');
|