25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import { ForbiddenException } from "@nestjs/common";
|
|
import { KillSwitchService } from "./kill-switch.service";
|
|
|
|
describe("KillSwitchService", () => {
|
|
const prisma = { orchestrationKillSwitch: { findUnique: jest.fn() } };
|
|
const service = new KillSwitchService(prisma as never);
|
|
|
|
beforeEach(() => jest.resetAllMocks());
|
|
|
|
it.each([
|
|
["FREEZE_NEW_WORK", "CREATE_TASK"],
|
|
["STOP_AGENTS", "RUN_AGENT"],
|
|
["DISABLE_MUTATIONS", "MUTATE_PRODUCTION"],
|
|
["EMERGENCY_HALT", "OBSERVE"],
|
|
])("blocks %s at its policy boundary", async (level, action) => {
|
|
prisma.orchestrationKillSwitch.findUnique.mockResolvedValue({ scope: "GLOBAL", level, active: true });
|
|
await expect(service.assertAllowed(action as never)).rejects.toThrow(ForbiddenException);
|
|
});
|
|
|
|
it("allows observation while production mutations are disabled", async () => {
|
|
prisma.orchestrationKillSwitch.findUnique.mockResolvedValue({ scope: "GLOBAL", level: "DISABLE_MUTATIONS", active: true });
|
|
await expect(service.assertAllowed("OBSERVE")).resolves.toBeUndefined();
|
|
});
|
|
});
|