fix: 修正 Monitor status 就绪退出语义
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { rootPath } from "./config";
|
||||
import { readYamlRecord } from "./platform-infra-ops-library";
|
||||
import { monitorResetScript, monitorStatusScript, runPlatformDbCommand } from "./platform-db";
|
||||
import { monitorResetScript, monitorStatusScript, monitorStatusSucceeded, runPlatformDbCommand } from "./platform-db";
|
||||
|
||||
const configPath = "config/platform-db/postgres-nc01.yaml";
|
||||
const parsed = readYamlRecord<Record<string, any>>(rootPath(configPath), "postgres-host-cluster");
|
||||
@@ -57,4 +57,14 @@ describe("platform-db Monitor 专属空库入口", () => {
|
||||
expect(reset).toContain('[ "$rows" != "0" ]');
|
||||
expect(reset).toContain('\"siblingDatabasesUnchanged\":true');
|
||||
});
|
||||
|
||||
test("status ready=true 且远端退出 0 时成功", () => {
|
||||
expect(monitorStatusSucceeded(0, { ok: true, ready: true, schemaReady: true, empty: true, businessRows: 0 })).toBe(true);
|
||||
});
|
||||
|
||||
test("status ready=false 时失败,即使远端误返回退出 0", () => {
|
||||
expect(monitorStatusSucceeded(0, { ok: false, ready: false, schemaReady: true, empty: false, businessRows: 1 })).toBe(false);
|
||||
expect(monitorStatusSucceeded(0, { ok: true, ready: false, schemaReady: false, empty: false, businessRows: null })).toBe(false);
|
||||
expect(monitorStatusSucceeded(1, { ok: false, ready: false })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -372,8 +372,11 @@ async function monitorCommand(config: UniDeskConfig, action: string, options: Pl
|
||||
const script = action === "status" ? monitorStatusScript(pg, target) : monitorResetScript(pg, target);
|
||||
const capture = await runSshCommandCapture(config, pg.node.route, ["sh"], script);
|
||||
const parsed = parseJsonOutput(capture.stdout);
|
||||
const commandOk = action === "status"
|
||||
? monitorStatusSucceeded(capture.exitCode, parsed)
|
||||
: capture.exitCode === 0 && parsed?.ok === true;
|
||||
return {
|
||||
ok: capture.exitCode === 0 && parsed?.ok === true,
|
||||
ok: commandOk,
|
||||
...base,
|
||||
mutation: action === "reset",
|
||||
...(action === "reset" ? { confirmed: true } : {}),
|
||||
@@ -382,6 +385,10 @@ async function monitorCommand(config: UniDeskConfig, action: string, options: Pl
|
||||
};
|
||||
}
|
||||
|
||||
export function monitorStatusSucceeded(exitCode: number, parsed: Record<string, unknown> | null): boolean {
|
||||
return exitCode === 0 && parsed?.ok === true && parsed.ready === true;
|
||||
}
|
||||
|
||||
function unsupported(args: string[]): Record<string, unknown> {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -1105,7 +1112,8 @@ fi
|
||||
empty=false
|
||||
ready=false
|
||||
if [ "$schema_ready" = true ] && [ "$business_rows" = "0" ]; then empty=true; ready=true; fi
|
||||
printf '{"ok":true,"databaseExists":%s,"schemaReady":%s,"empty":%s,"ready":%s,"databaseOid":"%s","schemaVersion":"%s","businessRows":%s,"siblingDatabaseOids":"%s"}\n' "$([ -n "$database_oid" ] && printf true || printf false)" "$schema_ready" "$empty" "$ready" "$database_oid" "$schema_version_observed" "$([ -n "$business_rows" ] && printf '%s' "$business_rows" || printf null)" "$sibling_oids"
|
||||
printf '{"ok":%s,"databaseExists":%s,"schemaReady":%s,"empty":%s,"ready":%s,"databaseOid":"%s","schemaVersion":"%s","businessRows":%s,"siblingDatabaseOids":"%s"}\n' "$ready" "$([ -n "$database_oid" ] && printf true || printf false)" "$schema_ready" "$empty" "$ready" "$database_oid" "$schema_version_observed" "$([ -n "$business_rows" ] && printf '%s' "$business_rows" || printf null)" "$sibling_oids"
|
||||
if [ "$ready" != true ]; then exit 1; fi
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user