fix: harden pgdata backup scheduler recovery
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { scheduleRetryRunObservation, scheduleRunObservation, scheduleRunsScope } from "./src/schedules";
|
||||
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
|
||||
function assertCondition(condition: unknown, message: string, detail: JsonRecord = {}): void {
|
||||
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
|
||||
}
|
||||
|
||||
export function runScheduleCliContract(): JsonRecord {
|
||||
const global = scheduleRunsScope(["runs", "--limit", "50"]);
|
||||
assertCondition(global.scheduleId === null, "global schedule runs must not treat --limit value as schedule id", global);
|
||||
assertCondition(global.limit === 50, "global schedule runs limit should be preserved", global);
|
||||
|
||||
const scoped = scheduleRunsScope(["runs", "unidesk-pgdata-baidu-daily", "--limit", "5"]);
|
||||
assertCondition(scoped.scheduleId === "unidesk-pgdata-baidu-daily", "schedule-specific runs should preserve schedule id", scoped);
|
||||
assertCondition(scoped.limit === 5, "schedule-specific runs limit should be preserved", scoped);
|
||||
|
||||
let numericScheduleRejected = false;
|
||||
try {
|
||||
scheduleRunsScope(["runs", "50"]);
|
||||
} catch (error) {
|
||||
numericScheduleRejected = String((error as Error).message).includes("schedule runs --limit N");
|
||||
}
|
||||
assertCondition(numericScheduleRejected, "numeric positional schedule id should point operators to global --limit syntax");
|
||||
|
||||
const timeoutObservation = scheduleRunObservation(
|
||||
"unidesk-pgdata-baidu-daily",
|
||||
{ body: { run: { id: "schedrun_new" } } },
|
||||
{ ok: false, timedOut: true, timeoutMs: 1 },
|
||||
);
|
||||
assertCondition(timeoutObservation.newRunId === "schedrun_new", "schedule run output must expose newRunId even when wait times out", timeoutObservation);
|
||||
assertCondition(String(timeoutObservation.observeCommand).includes("schedule runs unidesk-pgdata-baidu-daily --limit 20"), "schedule run output must expose observeCommand", timeoutObservation);
|
||||
|
||||
const retryObservation = scheduleRetryRunObservation("schedrun_failed", {
|
||||
body: {
|
||||
originalRunId: "schedrun_failed",
|
||||
scheduleId: "unidesk-pgdata-baidu-daily",
|
||||
newRunId: "schedrun_retry",
|
||||
},
|
||||
});
|
||||
assertCondition(retryObservation.originalRunId === "schedrun_failed", "retry-run output must preserve originalRunId", retryObservation);
|
||||
assertCondition(retryObservation.scheduleId === "unidesk-pgdata-baidu-daily", "retry-run output must expose scheduleId", retryObservation);
|
||||
assertCondition(retryObservation.newRunId === "schedrun_retry", "retry-run output must expose newRunId", retryObservation);
|
||||
assertCondition(String(retryObservation.observeCommand).includes("schedule runs unidesk-pgdata-baidu-daily --limit 20"), "retry-run output must expose observeCommand", retryObservation);
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
checks: [
|
||||
"global schedule runs limit parsing",
|
||||
"schedule-specific runs parsing",
|
||||
"numeric positional guard",
|
||||
"run wait timeout observation",
|
||||
"retry-run observation",
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
process.stdout.write(`${JSON.stringify(runScheduleCliContract(), null, 2)}\n`);
|
||||
}
|
||||
Reference in New Issue
Block a user