fix(mac): keep pnpm health output json-safe

This commit is contained in:
Peter Steinberger
2025-12-07 15:09:26 +00:00
parent 4e2fb38d62
commit f878e5e635
3 changed files with 21 additions and 4 deletions

View File

@@ -99,10 +99,13 @@ final class HealthStore: ObservableObject {
return
}
var env = ProcessInfo.processInfo.environment
env["PATH"] = CommandResolver.preferredPaths().joined(separator: ":")
let response = await ShellRunner.run(
command: CommandResolver.clawdisCommand(subcommand: "health", extraArgs: ["--json"]),
cwd: nil,
env: nil,
cwd: CommandResolver.projectRootPath(),
env: env,
timeout: 15)
guard response.ok, let data = response.payload, !data.isEmpty else {

View File

@@ -250,7 +250,8 @@ enum CommandResolver {
}
}
if let pnpm = self.findExecutable(named: "pnpm") {
return [pnpm, "clawdis", subcommand] + extraArgs
// Use --silent to avoid pnpm lifecycle banners that would corrupt JSON outputs.
return [pnpm, "--silent", "clawdis", subcommand] + extraArgs
}
return ["clawdis", subcommand] + extraArgs
}

View File

@@ -54,7 +54,20 @@ import Testing
let cmd = CommandResolver.clawdisCommand(subcommand: "rpc")
#expect(cmd.prefix(3).elementsEqual([pnpmPath.path, "clawdis", "rpc"]))
#expect(cmd.prefix(4).elementsEqual([pnpmPath.path, "--silent", "clawdis", "rpc"]))
}
@Test func pnpmKeepsExtraArgsAfterSubcommand() async throws {
let tmp = try makeTempDir()
CommandResolver.setProjectRoot(tmp.path)
let pnpmPath = tmp.appendingPathComponent("node_modules/.bin/pnpm")
try makeExec(at: pnpmPath)
let cmd = CommandResolver.clawdisCommand(subcommand: "health", extraArgs: ["--json", "--timeout", "5"])
#expect(cmd.prefix(5).elementsEqual([pnpmPath.path, "--silent", "clawdis", "health", "--json"]))
#expect(cmd.suffix(2).elementsEqual(["--timeout", "5"]))
}
@Test func preferredPathsStartWithProjectNodeBins() async throws {