Checkpoint recovered orchestration core with tested fail-closed boundaries

This commit is contained in:
devops committed 2026-10-23 08:01:08 +00:00
1 parent c7f1d25e98
commit 0952a482fb
18 files changed
+1918 -129

No files matched your search

@@ -1,24 +1,45 @@
import { ForbiddenException } from "@nestjs/common";
import { KillSwitchService } from "./kill-switch.service";
import { ForbiddenException } from '@nestjs/common';
import { KillSwitchService } from './kill-switch.service';
describe("KillSwitchService", () => {
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);
['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();
it('freezes new claims while allowing an already running agent to finish', async () => {
prisma.orchestrationKillSwitch.findUnique.mockResolvedValue({scope:'GLOBAL',level:'FREEZE_NEW_WORK',active:true});
await expect(service.assertAllowed('CLAIM_TASK' as never)).rejects.toThrow(ForbiddenException);
await expect(service.assertAllowed('RUN_AGENT')).resolves.toBeUndefined();
});
it('fails closed when an active persisted kill level is unknown', async () => {
prisma.orchestrationKillSwitch.findUnique.mockResolvedValue({scope:'GLOBAL',level:'CORRUPT_LEVEL',active:true});
await expect(service.assertAllowed('RUN_AGENT')).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();
});
});