Skip to content

Commit dfb32f6

Browse files
Refactor clearAgentGeneratorCache to pass logger as parameter
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 6f17f50 commit dfb32f6

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

backend/src/__tests__/loop-agent-steps.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
101101
})
102102

103103
beforeEach(() => {
104-
clearAgentGeneratorCache()
104+
clearAgentGeneratorCache({ logger })
105105

106106
llmCallCount = 0
107107

@@ -172,7 +172,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
172172
})
173173

174174
afterEach(() => {
175-
clearAgentGeneratorCache()
175+
clearAgentGeneratorCache({ logger })
176176

177177
mock.restore()
178178
})

backend/src/__tests__/run-agent-step-tools.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ describe('runAgentStep - set_output tool', () => {
113113
spyOn(aisdk, 'promptAiSdk').mockImplementation(() =>
114114
Promise.resolve('Test response'),
115115
)
116-
clearAgentGeneratorCache()
116+
clearAgentGeneratorCache({ logger })
117117
})
118118

119119
afterEach(() => {
120120
mock.restore()
121121
})
122122

123123
afterAll(() => {
124-
clearAgentGeneratorCache()
124+
clearAgentGeneratorCache({ logger })
125125
})
126126

127127
class MockWebSocket {

backend/src/__tests__/run-programmatic-step.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('runProgrammaticStep', () => {
143143
afterEach(() => {
144144
mock.restore()
145145
// Clear the generator cache between tests
146-
clearAgentGeneratorCache()
146+
clearAgentGeneratorCache({ logger })
147147
})
148148

149149
describe('generator lifecycle', () => {

backend/src/__tests__/sandbox-generator.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('QuickJS Sandbox Generator', () => {
3030
let mockTemplate: AgentTemplate
3131

3232
beforeEach(() => {
33-
clearAgentGeneratorCache()
33+
clearAgentGeneratorCache({ logger })
3434

3535
// Mock dependencies
3636
spyOn(agentRun, 'addAgentStep').mockImplementation(
@@ -100,7 +100,7 @@ describe('QuickJS Sandbox Generator', () => {
100100
})
101101

102102
afterEach(() => {
103-
clearAgentGeneratorCache()
103+
clearAgentGeneratorCache({ logger })
104104
})
105105

106106
test('should execute string-based generator in QuickJS sandbox', async () => {

backend/src/run-programmatic-step.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { cloneDeep } from 'lodash'
44

55
import { addAgentStep } from './agent-run'
66
import { executeToolCall } from './tools/tool-executor'
7-
import { logger } from './util/logger'
87
import { SandboxManager } from './util/quickjs-sandbox'
98
import { getRequestContext } from './websockets/request-context'
109
import { sendAction } from './websockets/websocket-action'
@@ -22,6 +21,7 @@ import type {
2221
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
2322
import type { AgentState } from '@codebuff/common/types/session-state'
2423
import type { ProjectFileContext } from '@codebuff/common/util/file'
24+
import type { ParamsOf } from '@codebuff/types/common'
2525
import type { Logger } from '@codebuff/types/logger'
2626
import type { WebSocket } from 'ws'
2727

@@ -33,13 +33,15 @@ const runIdToGenerator: Record<string, StepGenerator | undefined> = {}
3333
export const runIdToStepAll: Set<string> = new Set()
3434

3535
// Function to clear the generator cache for testing purposes
36-
export function clearAgentGeneratorCache() {
36+
export function clearAgentGeneratorCache(
37+
params: ParamsOf<typeof sandboxManager.dispose>,
38+
) {
3739
for (const key in runIdToGenerator) {
3840
delete runIdToGenerator[key]
3941
}
4042
runIdToStepAll.clear()
4143
// Clean up QuickJS sandboxes
42-
sandboxManager.dispose({ logger })
44+
sandboxManager.dispose(params)
4345
}
4446

4547
// Function to handle programmatic agents

0 commit comments

Comments
 (0)