File size: 2,499 Bytes
3144483 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | // Cron protocol schema tests cover runtime validation for cron protocol payloads.
import { describe, expect, it } from "vitest";
import {
CronJobStateSchema,
CronPacingSchema,
CronUpdateParamsSchema,
} from "../../packages/gateway-protocol/src/schema.js";
type SchemaLike = {
description?: string;
properties?: Record<string, unknown>;
deprecated?: boolean;
};
describe("cron protocol schema", () => {
it("marks the legacy lastStatus alias deprecated", () => {
const properties = (CronJobStateSchema as SchemaLike).properties ?? {};
const lastStatus = properties.lastStatus as SchemaLike | undefined;
if (!lastStatus) {
throw new Error("expected legacy lastStatus schema alias");
}
expect(lastStatus.deprecated).toBe(true);
});
it("exposes failure-notification delivery state", () => {
const properties = (CronJobStateSchema as SchemaLike).properties ?? {};
expect(properties.lastFailureNotificationDelivered).toBeDefined();
expect(properties.lastFailureNotificationDeliveryStatus).toBeDefined();
expect(properties.lastFailureNotificationDeliveryError).toBeDefined();
});
it("reports stream identity without accepting it in state patches", () => {
const stateProperties = (CronJobStateSchema as SchemaLike).properties ?? {};
expect(stateProperties.streamSourceIdentity).toBeDefined();
const updateProperties = (CronUpdateParamsSchema as SchemaLike).properties ?? {};
const patchProperties = (updateProperties.patch as SchemaLike | undefined)?.properties ?? {};
const patchStateProperties =
(patchProperties.state as SchemaLike | undefined)?.properties ?? {};
expect(patchStateProperties.streamSourceIdentity).toBeUndefined();
});
it("reports schedule activation without accepting it in state patches", () => {
const stateProperties = (CronJobStateSchema as SchemaLike).properties ?? {};
expect(stateProperties.scheduleActivatedAtMs).toBeDefined();
const updateProperties = (CronUpdateParamsSchema as SchemaLike).properties ?? {};
const patchProperties = (updateProperties.patch as SchemaLike | undefined)?.properties ?? {};
const patchState = patchProperties.state as SchemaLike | undefined;
expect(patchState?.properties?.scheduleActivatedAtMs).toBeUndefined();
});
it("documents that pacing requires at least one bound", () => {
expect((CronPacingSchema as SchemaLike).description).toContain(
"at least one of min or max is required",
);
});
});
|