|
1 | 1 | import * as analytics from '@codebuff/common/analytics' |
2 | 2 | import db from '@codebuff/common/db' |
3 | 3 | import { TEST_USER_ID } from '@codebuff/common/old-constants' |
4 | | -import { TEST_AGENT_RUNTIME_IMPL } from '@codebuff/common/testing/impl/agent-runtime' |
| 4 | +import { |
| 5 | + TEST_AGENT_RUNTIME_IMPL, |
| 6 | + TEST_AGENT_RUNTIME_SCOPED_IMPL, |
| 7 | +} from '@codebuff/common/testing/impl/agent-runtime' |
5 | 8 | import { |
6 | 9 | clearMockedModules, |
7 | 10 | mockModule, |
@@ -29,17 +32,20 @@ import { mockFileContext, MockWebSocket } from './test-utils' |
29 | 32 | import type { getAgentTemplate } from '../templates/agent-registry' |
30 | 33 | import type { AgentTemplate } from '../templates/types' |
31 | 34 | import type { StepGenerator } from '@codebuff/common/types/agent-template' |
32 | | -import type { AgentRuntimeDeps } from '@codebuff/common/types/contracts/agent-runtime' |
| 35 | +import type { |
| 36 | + AgentRuntimeDeps, |
| 37 | + AgentRuntimeScopedDeps, |
| 38 | +} from '@codebuff/common/types/contracts/agent-runtime' |
33 | 39 | import type { ParamsOf } from '@codebuff/common/types/function-params' |
34 | 40 | import type { AgentState } from '@codebuff/common/types/session-state' |
35 | 41 | import type { WebSocket } from 'ws' |
36 | 42 |
|
37 | | -let agentRuntimeImpl: AgentRuntimeDeps = { ...TEST_AGENT_RUNTIME_IMPL } |
38 | | - |
39 | 43 | describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => { |
40 | 44 | let mockTemplate: AgentTemplate |
41 | 45 | let mockAgentState: AgentState |
42 | 46 | let llmCallCount: number |
| 47 | + let agentRuntimeImpl: AgentRuntimeDeps |
| 48 | + let agentRuntimeScopedImpl: AgentRuntimeScopedDeps |
43 | 49 |
|
44 | 50 | const runLoopAgentStepsWithContext = async ( |
45 | 51 | options: ParamsOf<typeof loopAgentSteps>, |
@@ -96,6 +102,9 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
96 | 102 | }) |
97 | 103 |
|
98 | 104 | beforeEach(() => { |
| 105 | + agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL } |
| 106 | + agentRuntimeScopedImpl = { ...TEST_AGENT_RUNTIME_SCOPED_IMPL } |
| 107 | + |
99 | 108 | llmCallCount = 0 |
100 | 109 |
|
101 | 110 | // Setup spies for database operations |
@@ -200,6 +209,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
200 | 209 |
|
201 | 210 | const result = await runLoopAgentStepsWithContext({ |
202 | 211 | ...agentRuntimeImpl, |
| 212 | + ...agentRuntimeScopedImpl, |
203 | 213 | ws: new MockWebSocket() as unknown as WebSocket, |
204 | 214 | userInputId: 'test-user-input', |
205 | 215 | agentType: 'test-agent', |
@@ -246,6 +256,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
246 | 256 |
|
247 | 257 | const result = await runLoopAgentStepsWithContext({ |
248 | 258 | ...agentRuntimeImpl, |
| 259 | + ...agentRuntimeScopedImpl, |
249 | 260 | ws: new MockWebSocket() as unknown as WebSocket, |
250 | 261 | userInputId: 'test-user-input', |
251 | 262 | agentType: 'test-agent', |
@@ -294,6 +305,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
294 | 305 |
|
295 | 306 | const result = await runLoopAgentStepsWithContext({ |
296 | 307 | ...agentRuntimeImpl, |
| 308 | + ...agentRuntimeScopedImpl, |
297 | 309 | ws: new MockWebSocket() as unknown as WebSocket, |
298 | 310 | userInputId: 'test-user-input', |
299 | 311 | agentType: 'test-agent', |
@@ -341,6 +353,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
341 | 353 |
|
342 | 354 | const result = await runLoopAgentStepsWithContext({ |
343 | 355 | ...agentRuntimeImpl, |
| 356 | + ...agentRuntimeScopedImpl, |
344 | 357 | ws: new MockWebSocket() as unknown as WebSocket, |
345 | 358 | userInputId: 'test-user-input', |
346 | 359 | agentType: 'test-agent', |
@@ -381,6 +394,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
381 | 394 |
|
382 | 395 | const result = await runLoopAgentStepsWithContext({ |
383 | 396 | ...agentRuntimeImpl, |
| 397 | + ...agentRuntimeScopedImpl, |
384 | 398 | ws: new MockWebSocket() as unknown as WebSocket, |
385 | 399 | userInputId: 'test-user-input', |
386 | 400 | agentType: 'test-agent', |
@@ -413,6 +427,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
413 | 427 |
|
414 | 428 | const result = await runLoopAgentStepsWithContext({ |
415 | 429 | ...agentRuntimeImpl, |
| 430 | + ...agentRuntimeScopedImpl, |
416 | 431 | ws: new MockWebSocket() as unknown as WebSocket, |
417 | 432 | userInputId: 'test-user-input', |
418 | 433 | agentType: 'test-agent', |
@@ -447,6 +462,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
447 | 462 |
|
448 | 463 | const result = await runLoopAgentStepsWithContext({ |
449 | 464 | ...agentRuntimeImpl, |
| 465 | + ...agentRuntimeScopedImpl, |
450 | 466 | ws: new MockWebSocket() as unknown as WebSocket, |
451 | 467 | userInputId: 'test-user-input', |
452 | 468 | agentType: 'test-agent', |
@@ -498,6 +514,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
498 | 514 |
|
499 | 515 | const result = await runLoopAgentStepsWithContext({ |
500 | 516 | ...agentRuntimeImpl, |
| 517 | + ...agentRuntimeScopedImpl, |
501 | 518 | ws: new MockWebSocket() as unknown as WebSocket, |
502 | 519 | userInputId: 'test-user-input', |
503 | 520 | agentType: 'test-agent', |
@@ -547,6 +564,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
547 | 564 |
|
548 | 565 | await runLoopAgentStepsWithContext({ |
549 | 566 | ...agentRuntimeImpl, |
| 567 | + ...agentRuntimeScopedImpl, |
550 | 568 | ws: new MockWebSocket() as unknown as WebSocket, |
551 | 569 | userInputId: 'test-user-input', |
552 | 570 | agentType: 'test-agent', |
@@ -634,6 +652,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
634 | 652 |
|
635 | 653 | const result = await runLoopAgentStepsWithContext({ |
636 | 654 | ...agentRuntimeImpl, |
| 655 | + ...agentRuntimeScopedImpl, |
637 | 656 | ws: new MockWebSocket() as unknown as WebSocket, |
638 | 657 | userInputId: 'test-user-input', |
639 | 658 | agentType: 'test-agent', |
@@ -707,6 +726,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
707 | 726 |
|
708 | 727 | const result = await runLoopAgentStepsWithContext({ |
709 | 728 | ...agentRuntimeImpl, |
| 729 | + ...agentRuntimeScopedImpl, |
710 | 730 | ws: new MockWebSocket() as unknown as WebSocket, |
711 | 731 | userInputId: 'test-user-input', |
712 | 732 | agentType: 'test-agent', |
@@ -753,6 +773,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
753 | 773 |
|
754 | 774 | const result = await runLoopAgentStepsWithContext({ |
755 | 775 | ...agentRuntimeImpl, |
| 776 | + ...agentRuntimeScopedImpl, |
756 | 777 | ws: new MockWebSocket() as unknown as WebSocket, |
757 | 778 | userInputId: 'test-user-input', |
758 | 779 | agentType: 'test-agent', |
@@ -821,6 +842,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () => |
821 | 842 |
|
822 | 843 | const result = await runLoopAgentStepsWithContext({ |
823 | 844 | ...agentRuntimeImpl, |
| 845 | + ...agentRuntimeScopedImpl, |
824 | 846 | ws: new MockWebSocket() as unknown as WebSocket, |
825 | 847 | userInputId: 'test-user-input', |
826 | 848 | agentType: 'test-agent', |
|
0 commit comments