fix(housekeeping): harden command dispatch boundaries

This commit is contained in:
Simo committed 2026-08-27 19:32:19 +02:00
1 parent 796d009c07
commit 00618fb2a3
8 files changed
+608 -30

No files matched your search

@@ -123,6 +123,37 @@ describe("housekeeping command registry", () => {
expect(() => registerHousekeepingCommand(invalid)).toThrow();
});
it("keeps registered validation unchanged after original shape and child mutation", () => {
const child = z.string().min(3);
const input = z.object({ value: child, guard: child });
registerHousekeepingCommand({
...command("people.registry.deep-validation"),
input,
execute: async (context, value) =>
ok({ id: value.value.length }, context.correlationId),
} as HousekeepingCommand<{ value: string; guard: string }, { id: number }>);
const registered = getHousekeepingCommand(
"people.registry.deep-validation",
);
if (!registered) throw new Error("registered command missing");
(input.def as { shape: { value: z.ZodType } }).shape.value = z.number();
const minCheck = (child.def as { checks: unknown[] }).checks[0] as {
_zod: { def: { minimum: number } };
};
minCheck._zod.def.minimum = 0;
expect(input.safeParse({ value: 4, guard: "a" }).success).toBe(true);
expect(
registered.input.safeParse({ value: "abcd", guard: "ab" }).success,
).toBe(false);
expect(
registered.input.safeParse({ value: "abcd", guard: "abcd" }).success,
).toBe(true);
expect(
registered.input.safeParse({ value: 4, guard: "abcd" }).success,
).toBe(false);
});
it("seals the global registry after deterministic bootstrap", () => {
sealHousekeepingCommandRegistry();