Merge pull request #1795 from pikasTech/fix/decision-ssh-json-recovery
修复 Decision CLI 长正文导致的 JSON 截断
This commit is contained in:
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
|
||||
import { resolve } from "node:path";
|
||||
import { type UniDeskConfig, repoRoot } from "./config";
|
||||
import { runCommand } from "./command";
|
||||
import { resolveCliChildJsonCommandResult } from "./cli-child-json-recovery";
|
||||
import { coreInternalFetch } from "./microservices";
|
||||
import { capture, compactCapture, parseJsonOutput, shQuote } from "./platform-infra-ops-library";
|
||||
|
||||
@@ -659,11 +660,24 @@ console.log(output);
|
||||
stderrTail: result.stderr.slice(-1000),
|
||||
};
|
||||
}
|
||||
const jsonLine = result.stdout.trim().split("\n").reverse().find((line) => line.trim().startsWith("{"));
|
||||
if (jsonLine === undefined) {
|
||||
return { ok: false, status: 502, error: "NC01 decision-center k8s proxy returned no JSON", stdoutTail: result.stdout.slice(-1000), stderrTail: result.stderr.slice(-1000) };
|
||||
}
|
||||
return JSON.parse(jsonLine) as unknown;
|
||||
const resolved = resolveCliChildJsonCommandResult({
|
||||
result,
|
||||
requestedStdoutType: "NC01 decision-center k8s proxy JSON",
|
||||
acceptParsed: (value) => typeof value.ok === "boolean" && typeof value.status === "number",
|
||||
});
|
||||
if (resolved.parsed !== null) return resolved.parsed;
|
||||
return {
|
||||
ok: false,
|
||||
status: 502,
|
||||
error: "NC01 decision-center k8s proxy returned unparseable JSON",
|
||||
transport: {
|
||||
exitCode: result.exitCode,
|
||||
timedOut: result.timedOut,
|
||||
stdoutBytes: Buffer.byteLength(result.stdout),
|
||||
stderrBytes: Buffer.byteLength(result.stderr),
|
||||
},
|
||||
diagnostics: resolved.diagnostics,
|
||||
};
|
||||
}
|
||||
|
||||
async function decisionProxyAsync(
|
||||
|
||||
Reference in New Issue
Block a user