fix(codex): handle remote request_user_input approvals (#382)

This commit is contained in:
iRonMan
2026-04-07 12:04:52 +08:00
committed by GitHub
parent 3ef7b8c7cd
commit 56925f8b98
5 changed files with 237 additions and 19 deletions
@@ -0,0 +1,80 @@
import { describe, expect, it, vi } from 'vitest';
import { registerAppServerPermissionHandlers } from './appServerPermissionAdapter';
type UserInputHandler = NonNullable<Parameters<typeof registerAppServerPermissionHandlers>[0]['onUserInputRequest']>;
function createClient() {
const handlers = new Map<string, (params: unknown) => Promise<unknown> | unknown>();
return {
client: {
registerRequestHandler(method: string, handler: (params: unknown) => Promise<unknown> | unknown) {
handlers.set(method, handler);
}
},
handlers
};
}
describe('registerAppServerPermissionHandlers', () => {
it('forwards request_user_input answers through the callback', async () => {
const { client, handlers } = createClient();
const permissionHandler = {
handleToolCall: vi.fn()
};
const onUserInputRequest: UserInputHandler = async ({ id, input }) => {
expect(id).toBe('tool-123');
expect(input).toEqual({
itemId: 'tool-123',
questions: [{ id: 'approve_nav', question: 'Approve app tool call?' }]
});
return {
decision: 'accept',
answers: {
approve_nav: {
answers: ['Allow']
}
}
};
};
registerAppServerPermissionHandlers({
client: client as never,
permissionHandler: permissionHandler as never,
onUserInputRequest: vi.fn(onUserInputRequest)
});
const handler = handlers.get('item/tool/requestUserInput');
expect(handler).toBeTypeOf('function');
await expect(handler?.({
itemId: 'tool-123',
questions: [{ id: 'approve_nav', question: 'Approve app tool call?' }]
})).resolves.toEqual({
decision: 'accept',
answers: {
approve_nav: {
answers: ['Allow']
}
}
});
});
it('cancels request_user_input when no callback is registered', async () => {
const { client, handlers } = createClient();
const permissionHandler = {
handleToolCall: vi.fn()
};
registerAppServerPermissionHandlers({
client: client as never,
permissionHandler: permissionHandler as never
});
const handler = handlers.get('item/tool/requestUserInput');
expect(handler).toBeTypeOf('function');
await expect(handler?.({ itemId: 'tool-123' })).resolves.toEqual({
decision: 'cancel'
});
});
});