feat: add approval checkpoints backend

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David Kaya
2026-03-24 19:48:58 +01:00
co-authored by Copilot
parent e7dfb66038
commit 2aa8d73b2d
28 changed files with 1471 additions and 23 deletions
+67
View File
@@ -0,0 +1,67 @@
import { describe, expect, test } from 'bun:test';
import {
approvalPolicyRequiresCheckpoint,
normalizeApprovalPolicy,
normalizePendingApproval,
} from '@shared/domain/approval';
describe('approval helpers', () => {
test('normalizes duplicate checkpoint rules into stable agent-scoped policy entries', () => {
expect(normalizeApprovalPolicy({
rules: [
{ kind: 'tool-call', agentIds: ['agent-1', ' agent-1 ', 'agent-2'] },
{ kind: 'tool-call', agentIds: ['agent-2', 'agent-3'] },
{ kind: 'final-response', agentIds: [] },
],
})).toEqual({
rules: [
{ kind: 'tool-call', agentIds: ['agent-1', 'agent-2', 'agent-3'] },
{ kind: 'final-response' },
],
});
});
test('matches approval requirements for all-agent and agent-specific rules', () => {
const policy = normalizeApprovalPolicy({
rules: [
{ kind: 'tool-call', agentIds: ['agent-1'] },
{ kind: 'final-response', agentIds: [] },
],
});
expect(approvalPolicyRequiresCheckpoint(policy, 'tool-call', 'agent-1')).toBe(true);
expect(approvalPolicyRequiresCheckpoint(policy, 'tool-call', 'agent-2')).toBe(false);
expect(approvalPolicyRequiresCheckpoint(policy, 'final-response', 'agent-2')).toBe(true);
});
test('normalizes pending approvals with optional message previews', () => {
expect(normalizePendingApproval({
id: 'approval-1',
kind: 'final-response',
status: 'pending',
requestedAt: '2026-03-24T10:00:00.000Z',
title: 'Approve final response',
messages: [
{
id: 'msg-1',
authorName: 'Primary Agent',
content: 'Draft answer',
},
],
})).toEqual({
id: 'approval-1',
kind: 'final-response',
status: 'pending',
requestedAt: '2026-03-24T10:00:00.000Z',
title: 'Approve final response',
messages: [
{
id: 'msg-1',
authorName: 'Primary Agent',
content: 'Draft answer',
},
],
});
});
});