fix(housekeeping): isolate executable command schemas
This commit is contained in:
1 parent
00618fb2a3
commit
7895188b56
5 files changed
+431
-67
No files matched your search
@@ -1,10 +1,58 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { anyCapability, ok } from "../contracts";
|
||||
import { housekeepingCommandRegistryReady } from "./bootstrap";
|
||||
import { registerHousekeepingCommand } from "./registry";
|
||||
import {
|
||||
defineHousekeepingCommands,
|
||||
housekeepingCommandRegistryReady,
|
||||
registerHousekeepingCommands,
|
||||
} from "./bootstrap";
|
||||
import {
|
||||
type HousekeepingCommand,
|
||||
registerHousekeepingCommand,
|
||||
} from "./registry";
|
||||
|
||||
describe("housekeeping command bootstrap", () => {
|
||||
it("preserves heterogeneous concrete input and output types", () => {
|
||||
const stringCommand: HousekeepingCommand<
|
||||
{ value: string },
|
||||
{ length: number }
|
||||
> = {
|
||||
id: "system.bootstrap.string-shape",
|
||||
owner: "system",
|
||||
risk: "safe",
|
||||
capability: anyCapability("admin.settings.view"),
|
||||
input: z.object({ value: z.string() }),
|
||||
requiresReason: false,
|
||||
rateLimit: { attempts: 1, windowMs: 1_000 },
|
||||
execute: async (context, input) =>
|
||||
ok({ length: input.value.length }, context.correlationId),
|
||||
};
|
||||
const numberCommand: HousekeepingCommand<
|
||||
{ count: number },
|
||||
{ doubled: number }
|
||||
> = {
|
||||
id: "system.bootstrap.number-shape",
|
||||
owner: "system",
|
||||
risk: "safe",
|
||||
capability: anyCapability("admin.settings.view"),
|
||||
input: z.object({ count: z.number().int() }),
|
||||
requiresReason: false,
|
||||
rateLimit: { attempts: 2, windowMs: 2_000 },
|
||||
execute: async (context, input) =>
|
||||
ok({ doubled: input.count * 2 }, context.correlationId),
|
||||
};
|
||||
|
||||
const commands = defineHousekeepingCommands(stringCommand, numberCommand);
|
||||
const stringInput: z.input<(typeof commands)[0]["input"]> = {
|
||||
value: "typed",
|
||||
};
|
||||
const numberInput: z.input<(typeof commands)[1]["input"]> = { count: 4 };
|
||||
expect(commands[0].input.parse(stringInput)).toEqual({ value: "typed" });
|
||||
expect(commands[1].input.parse(numberInput)).toEqual({ count: 4 });
|
||||
expect(() => registerHousekeepingCommands(commands)).toThrow(
|
||||
"command registry is sealed",
|
||||
);
|
||||
});
|
||||
it("registers the complete current list and seals during module initialization", () => {
|
||||
expect(housekeepingCommandRegistryReady).toBe(true);
|
||||
expect(() =>
|
||||
|
||||
Reference in new issue
Block a user