mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-12 02:28:05 +00:00
fix: align request_user_input other answers across clients
This commit is contained in:
@@ -18,6 +18,22 @@ function fixture() {
|
||||
return { permissions, request, respond, handlers, send, state: () => state };
|
||||
}
|
||||
describe('shared request arbitration', () => {
|
||||
it.each([{ notes: [] }, { notes: ['user_note: custom answer'] }])('preserves isOther and canonical other answers (%j) without claiming a winner', async ({ notes }) => {
|
||||
const f = fixture();
|
||||
const request = { ...f.request, params: { ...f.request.params, isBlocking: true,
|
||||
questions: f.request.params.questions.map(question => ({ ...question, isOther: true })) } };
|
||||
f.permissions.receive(request);
|
||||
const [id, pending] = Object.entries(f.state().requests ?? {})[0]!;
|
||||
expect(pending.arguments).toEqual(request.params);
|
||||
const answers = { choice: { answers: ['None of the above', ...notes] } };
|
||||
await f.handlers.get('permission')!({ id, approved: true, answers });
|
||||
await vi.waitFor(() => expect(f.respond).toHaveBeenCalledWith(1, { answers }));
|
||||
expect(f.state().completedRequests).toBeUndefined();
|
||||
f.permissions.resolved('thread', request.id);
|
||||
expect(f.state().completedRequests?.[id]).toMatchObject({ status: 'resolved' });
|
||||
expect(f.state().completedRequests?.[id]).not.toHaveProperty('answers');
|
||||
});
|
||||
|
||||
it('withdrawal on disconnect is canceled, not a claim that a native answer won', () => {
|
||||
const f = fixture(); f.permissions.receive(f.request); f.permissions.close();
|
||||
expect(Object.values(f.state().completedRequests ?? {})[0]?.status).toBe('canceled');
|
||||
|
||||
@@ -25,13 +25,14 @@ describe('registerAppServerPermissionHandlers', () => {
|
||||
expect(id).toBe('tool-123');
|
||||
expect(input).toEqual({
|
||||
itemId: 'tool-123',
|
||||
questions: [{ id: 'approve_nav', question: 'Approve app tool call?' }]
|
||||
isBlocking: true,
|
||||
questions: [{ id: 'approve_nav', question: 'Approve app tool call?', isOther: true }]
|
||||
});
|
||||
return {
|
||||
decision: 'accept',
|
||||
answers: {
|
||||
approve_nav: {
|
||||
answers: ['Allow']
|
||||
answers: ['None of the above', 'user_note: custom answer']
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -48,12 +49,13 @@ describe('registerAppServerPermissionHandlers', () => {
|
||||
|
||||
await expect(handler?.({
|
||||
itemId: 'tool-123',
|
||||
questions: [{ id: 'approve_nav', question: 'Approve app tool call?' }]
|
||||
isBlocking: true,
|
||||
questions: [{ id: 'approve_nav', question: 'Approve app tool call?', isOther: true }]
|
||||
})).resolves.toEqual({
|
||||
decision: 'accept',
|
||||
answers: {
|
||||
approve_nav: {
|
||||
answers: ['Allow']
|
||||
answers: ['None of the above', 'user_note: custom answer']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user