|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 6 | +import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/execution/constants' |
6 | 7 |
|
7 | 8 | const { isKnownTool, isSimExecuted } = vi.hoisted(() => ({ |
8 | 9 | isKnownTool: vi.fn(), |
@@ -58,4 +59,82 @@ describe('copilot tool executor fallback', () => { |
58 | 59 | ) |
59 | 60 | expect(result).toEqual({ success: true, output: { emails: [] } }) |
60 | 61 | }) |
| 62 | + |
| 63 | + it('converts function_execute timeout from seconds to milliseconds for copilot calls', async () => { |
| 64 | + isKnownTool.mockReturnValue(false) |
| 65 | + isSimExecuted.mockReturnValue(false) |
| 66 | + executeAppTool.mockResolvedValue({ success: true, output: { result: 'ok' } }) |
| 67 | + |
| 68 | + await executeTool( |
| 69 | + 'function_execute', |
| 70 | + { code: 'return 1', timeout: 7 }, |
| 71 | + { |
| 72 | + userId: 'user-1', |
| 73 | + workflowId: 'workflow-1', |
| 74 | + workspaceId: 'ws-1', |
| 75 | + copilotToolExecution: true, |
| 76 | + } |
| 77 | + ) |
| 78 | + |
| 79 | + expect(executeAppTool).toHaveBeenCalledWith( |
| 80 | + 'function_execute', |
| 81 | + expect.objectContaining({ |
| 82 | + timeout: 7000, |
| 83 | + _context: expect.objectContaining({ |
| 84 | + copilotToolExecution: true, |
| 85 | + }), |
| 86 | + }), |
| 87 | + false |
| 88 | + ) |
| 89 | + }) |
| 90 | + |
| 91 | + it('defaults copilot function_execute timeout to 10 seconds when omitted', async () => { |
| 92 | + isKnownTool.mockReturnValue(false) |
| 93 | + isSimExecuted.mockReturnValue(false) |
| 94 | + executeAppTool.mockResolvedValue({ success: true, output: { result: 'ok' } }) |
| 95 | + |
| 96 | + await executeTool( |
| 97 | + 'function_execute', |
| 98 | + { code: 'return 1' }, |
| 99 | + { |
| 100 | + userId: 'user-1', |
| 101 | + workflowId: 'workflow-1', |
| 102 | + workspaceId: 'ws-1', |
| 103 | + copilotToolExecution: true, |
| 104 | + } |
| 105 | + ) |
| 106 | + |
| 107 | + expect(executeAppTool).toHaveBeenCalledWith( |
| 108 | + 'function_execute', |
| 109 | + expect.objectContaining({ |
| 110 | + timeout: 10_000, |
| 111 | + }), |
| 112 | + false |
| 113 | + ) |
| 114 | + }) |
| 115 | + |
| 116 | + it('does not let copilot function_execute timeout exceed the default execution limit', async () => { |
| 117 | + isKnownTool.mockReturnValue(false) |
| 118 | + isSimExecuted.mockReturnValue(false) |
| 119 | + executeAppTool.mockResolvedValue({ success: true, output: { result: 'ok' } }) |
| 120 | + |
| 121 | + await executeTool( |
| 122 | + 'function_execute', |
| 123 | + { code: 'return 1', timeout: 10_000 }, |
| 124 | + { |
| 125 | + userId: 'user-1', |
| 126 | + workflowId: 'workflow-1', |
| 127 | + workspaceId: 'ws-1', |
| 128 | + copilotToolExecution: true, |
| 129 | + } |
| 130 | + ) |
| 131 | + |
| 132 | + expect(executeAppTool).toHaveBeenCalledWith( |
| 133 | + 'function_execute', |
| 134 | + expect.objectContaining({ |
| 135 | + timeout: DEFAULT_EXECUTION_TIMEOUT_MS, |
| 136 | + }), |
| 137 | + false |
| 138 | + ) |
| 139 | + }) |
61 | 140 | }) |
0 commit comments