feat: add session-scoped workflow approval gate commands

This commit is contained in:
William Valentin
2026-02-18 10:35:42 -08:00
parent 1508bcf9cb
commit f34a974210
13 changed files with 369 additions and 6 deletions
+45 -1
View File
@@ -1,6 +1,6 @@
import { describe, it, expect, vi } from 'vitest';
import { createContextCommand, createElevateCommand, createModelCommand, createQueueCommand, createResearchCommand, createTransferCommand } from './index.js';
import { createApproveCommand, createApprovalsCommand, createContextCommand, createDenyCommand, createElevateCommand, createModelCommand, createQueueCommand, createResearchCommand, createTransferCommand } from './index.js';
describe('builtin /model command', () => {
it('passes through the full argument string', async () => {
@@ -197,3 +197,47 @@ describe('builtin /transfer command', () => {
expect(result).toEqual({ handled: true, text: 'Transfer command is not available in this session.' });
});
});
describe('builtin approval commands', () => {
it('calls getApprovals for /approvals', async () => {
const cmd = createApprovalsCommand();
const getApprovals = vi.fn(() => '1 pending');
const result = await cmd.execute([], {
channel: 'test',
senderId: 'user',
sessionId: 's1',
rawInput: '/approvals',
services: { getApprovals },
});
expect(getApprovals).toHaveBeenCalledOnce();
expect(result).toEqual({ handled: true, text: '1 pending' });
});
it('passes raw input to approvePending for /approve', async () => {
const cmd = createApproveCommand();
const approvePending = vi.fn(() => 'approved');
const result = await cmd.execute(['abc-123'], {
channel: 'test',
senderId: 'user',
sessionId: 's1',
rawInput: '/approve abc-123',
services: { approvePending },
});
expect(approvePending).toHaveBeenCalledWith('abc-123');
expect(result).toEqual({ handled: true, text: 'approved' });
});
it('passes raw input to denyPending for /deny', async () => {
const cmd = createDenyCommand();
const denyPending = vi.fn(() => 'denied');
const result = await cmd.execute(['abc-123', 'too', 'risky'], {
channel: 'test',
senderId: 'user',
sessionId: 's1',
rawInput: '/deny abc-123 too risky',
services: { denyPending },
});
expect(denyPending).toHaveBeenCalledWith('abc-123 too risky');
expect(result).toEqual({ handled: true, text: 'denied' });
});
});