import { spawnSync } from "node:child_process"; export interface ProcessResult { readonly step: string; readonly tool: string; readonly checks: string; readonly verdict: "fail" | "pass"; readonly exitCode: number; readonly output: string; } export const runTool = function runTool( cwd: string, step: string, tool: string, checks: string, args: readonly string[], ): ProcessResult { const result = spawnSync(`${tool} ${args.join(" ")}`.trim(), { cwd, encoding: "utf8", shell: true, }); const launched = result.error === undefined; const output = launched ? `${result.stdout}${result.stderr}`.trim() : String(result.error); const exitCode = launched ? (result.status ?? -1) : -1; return { checks, exitCode, output, step, tool, verdict: exitCode === 0 ? "pass" : "fail" }; };