fix: support ts backend core cli probes

This commit is contained in:
Codex
2026-05-18 16:20:11 +00:00
parent 803a695d0a
commit 29dab8fab2
6 changed files with 95 additions and 20 deletions
+25 -4
View File
@@ -22,9 +22,30 @@ async function readJson(url: string, init?: RequestInit): Promise<unknown> {
}
}
function coreFetchCommand(path: string, init?: { method?: string; body?: unknown }): string[] {
const method = init?.method ?? "GET";
const url = `http://127.0.0.1:8080${path}`;
const body = init?.body === undefined ? "" : JSON.stringify(init.body);
const script = [
"set -euo pipefail",
"if command -v backend-core >/dev/null 2>&1; then",
` exec backend-core --fetch-json ${shellQuote(url)} --method ${shellQuote(method)}${body.length > 0 ? ` --body-json ${shellQuote(body)}` : ""}`,
"fi",
`url=${shellQuote(url)}`,
`method=${shellQuote(method)}`,
`body=${shellQuote(body)}`,
"export url method body",
"bun -e 'const url=process.env.url; const method=process.env.method; const body=process.env.body; fetch(url,{method,body:body?body:undefined,headers:body?{\"content-type\":\"application/json\"}:undefined}).then(async r=>{const text=await r.text(); console.log(JSON.stringify({ok:r.ok,status:r.status,body:text?JSON.parse(text):null})); process.exit(r.ok?0:1);}).catch(e=>{console.error(e); process.exit(1);})'",
].join("\n");
return ["docker", "exec", "unidesk-backend-core", "sh", "-lc", script];
}
function shellQuote(value: string): string {
return `'${value.replace(/'/g, `'\\''`)}'`;
}
function coreInternalFetch(path: string, init?: { method?: string; body?: unknown }): unknown {
const command = ["docker", "exec", "unidesk-backend-core", "backend-core", "--fetch-json", `http://127.0.0.1:8080${path}`, "--method", init?.method ?? "GET"];
if (init?.body !== undefined) command.push("--body-json", JSON.stringify(init.body));
const command = coreFetchCommand(path, init);
const result = runCommand(command, repoRoot);
if (result.exitCode !== 0) {
return { ok: false, exitCode: result.exitCode, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
@@ -37,7 +58,7 @@ function coreInternalFetch(path: string, init?: { method?: string; body?: unknow
}
function coreDockerStatusSummary(): unknown {
const result = runCommand(["docker", "exec", "unidesk-backend-core", "backend-core", "--fetch-json", "http://127.0.0.1:8080/api/nodes/docker-status"], repoRoot);
const result = runCommand(coreFetchCommand("/api/nodes/docker-status"), repoRoot);
if (result.exitCode !== 0) {
return { ok: false, exitCode: result.exitCode, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
}
@@ -67,7 +88,7 @@ function coreDockerStatusSummary(): unknown {
}
function coreSystemStatusSummary(): unknown {
const result = runCommand(["docker", "exec", "unidesk-backend-core", "backend-core", "--fetch-json", "http://127.0.0.1:8080/api/nodes/system-status?limit=24"], repoRoot);
const result = runCommand(coreFetchCommand("/api/nodes/system-status?limit=24"), repoRoot);
if (result.exitCode !== 0) {
return { ok: false, exitCode: result.exitCode, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
}