mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-03 18:38:35 +02:00
fix: queue session approvals
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import {
|
||||
dequeuePendingApprovalState,
|
||||
enqueuePendingApprovalState,
|
||||
listPendingApprovals,
|
||||
approvalPolicyRequiresCheckpoint,
|
||||
normalizePendingApprovalState,
|
||||
normalizeApprovalPolicy,
|
||||
normalizePendingApproval,
|
||||
} from '@shared/domain/approval';
|
||||
@@ -64,4 +68,94 @@ describe('approval helpers', () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test('normalizes legacy active approval plus queued approvals into a stable pending state', () => {
|
||||
expect(normalizePendingApprovalState({
|
||||
pendingApproval: {
|
||||
id: 'approval-1',
|
||||
kind: 'tool-call',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-24T10:00:00.000Z',
|
||||
title: 'Approve tool access',
|
||||
},
|
||||
pendingApprovalQueue: [
|
||||
{
|
||||
id: 'approval-1',
|
||||
kind: 'tool-call',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-24T10:00:00.000Z',
|
||||
title: 'Approve tool access',
|
||||
},
|
||||
{
|
||||
id: 'approval-2',
|
||||
kind: 'final-response',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-24T10:01:00.000Z',
|
||||
title: 'Approve final response',
|
||||
},
|
||||
{
|
||||
id: 'approval-3',
|
||||
kind: 'tool-call',
|
||||
status: 'approved',
|
||||
requestedAt: '2026-03-24T10:02:00.000Z',
|
||||
resolvedAt: '2026-03-24T10:03:00.000Z',
|
||||
title: 'Already resolved',
|
||||
},
|
||||
],
|
||||
})).toEqual({
|
||||
pendingApproval: {
|
||||
id: 'approval-1',
|
||||
kind: 'tool-call',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-24T10:00:00.000Z',
|
||||
title: 'Approve tool access',
|
||||
},
|
||||
pendingApprovalQueue: [
|
||||
{
|
||||
id: 'approval-2',
|
||||
kind: 'final-response',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-24T10:01:00.000Z',
|
||||
title: 'Approve final response',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test('enqueues and dequeues pending approvals while keeping the first approval active', () => {
|
||||
const state = enqueuePendingApprovalState(
|
||||
{
|
||||
pendingApproval: {
|
||||
id: 'approval-1',
|
||||
kind: 'tool-call',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-24T10:00:00.000Z',
|
||||
title: 'Approve tool access',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'approval-2',
|
||||
kind: 'final-response',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-24T10:01:00.000Z',
|
||||
title: 'Approve final response',
|
||||
},
|
||||
);
|
||||
|
||||
expect(listPendingApprovals(state).map((approval) => approval.id)).toEqual([
|
||||
'approval-1',
|
||||
'approval-2',
|
||||
]);
|
||||
|
||||
expect(dequeuePendingApprovalState(state, 'approval-1')).toEqual({
|
||||
pendingApproval: {
|
||||
id: 'approval-2',
|
||||
kind: 'final-response',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-24T10:01:00.000Z',
|
||||
title: 'Approve final response',
|
||||
},
|
||||
pendingApprovalQueue: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -129,6 +129,15 @@ describe('session library helpers', () => {
|
||||
requestedAt: '2026-03-23T00:01:00.000Z',
|
||||
title: 'Approve tool access',
|
||||
},
|
||||
pendingApprovalQueue: [
|
||||
{
|
||||
id: 'approval-2',
|
||||
kind: 'final-response',
|
||||
status: 'pending',
|
||||
requestedAt: '2026-03-23T00:02:00.000Z',
|
||||
title: 'Approve final response',
|
||||
},
|
||||
],
|
||||
messages: [
|
||||
{
|
||||
id: 'msg-1',
|
||||
@@ -157,6 +166,7 @@ describe('session library helpers', () => {
|
||||
});
|
||||
expect(session.messages[0]?.pending).toBe(false);
|
||||
expect(session.pendingApproval).toBeUndefined();
|
||||
expect(session.pendingApprovalQueue).toBeUndefined();
|
||||
expect(session.runs).toEqual([]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user