takt/src/__tests__/actionDispatcher.test.ts
nrs 4e58c86643
github-issue-256-takt-list-instruct (#267)
* fix: OpenCode SDKサーバー起動タイムアウトを30秒に延長

* takt: github-issue-256-takt-list-instruct

* refactor: 会話後アクションフローを共通化
2026-02-13 22:08:28 +09:00

40 lines
1.2 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
import { dispatchConversationAction } from '../features/interactive/actionDispatcher.js';
describe('dispatchConversationAction', () => {
it('should dispatch to matching handler with full result payload', async () => {
const execute = vi.fn().mockResolvedValue('executed');
const saveTask = vi.fn().mockResolvedValue('saved');
const cancel = vi.fn().mockResolvedValue('cancelled');
const result = await dispatchConversationAction(
{ action: 'save_task', task: 'refine branch docs' },
{
execute,
save_task: saveTask,
cancel,
},
);
expect(result).toBe('saved');
expect(saveTask).toHaveBeenCalledWith({ action: 'save_task', task: 'refine branch docs' });
expect(execute).not.toHaveBeenCalled();
expect(cancel).not.toHaveBeenCalled();
});
it('should support synchronous handlers', async () => {
const result = await dispatchConversationAction(
{ action: 'cancel', task: '' },
{
execute: () => true,
save_task: () => true,
cancel: () => false,
},
);
expect(result).toBe(false);
});
});