Skip to content

Commit 97a2ff3

Browse files
Refactor three files to pass logger as parameter
Refactored batch-str-replace.ts, stream-parser.ts, and api/agents.ts to pass logger as a parameter instead of importing it directly. Updated all callers including run-agent-step.ts and test files. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent e5b56fa commit 97a2ff3

File tree

5 files changed

+245
-165
lines changed

5 files changed

+245
-165
lines changed

backend/src/__tests__/malformed-tool-call.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ describe('malformed tool call error handling', () => {
131131
agentContext: {},
132132
onResponseChunk,
133133
fullResponse: '',
134+
logger,
134135
})
135136

136137
// Should have tool result errors in the final message history
@@ -187,6 +188,7 @@ describe('malformed tool call error handling', () => {
187188
agentContext: {},
188189
onResponseChunk,
189190
fullResponse: '',
191+
logger,
190192
})
191193

192194
// Should have multiple error tool results
@@ -233,6 +235,7 @@ describe('malformed tool call error handling', () => {
233235
agentContext: {},
234236
onResponseChunk,
235237
fullResponse: '',
238+
logger,
236239
})
237240

238241
// Should have error in both toolResults and message history
@@ -283,6 +286,7 @@ describe('malformed tool call error handling', () => {
283286
agentContext: {},
284287
onResponseChunk,
285288
fullResponse: '',
289+
logger,
286290
})
287291

288292
const toolMessages = result.state.messages.filter(
@@ -335,6 +339,7 @@ describe('malformed tool call error handling', () => {
335339
agentContext: {},
336340
onResponseChunk,
337341
fullResponse: '',
342+
logger,
338343
})
339344

340345
const toolMessages = result.state.messages.filter(
@@ -389,6 +394,7 @@ describe('malformed tool call error handling', () => {
389394
agentContext: {},
390395
onResponseChunk,
391396
fullResponse: '',
397+
logger,
392398
})
393399

394400
const toolMessages = result.state.messages.filter(

backend/src/__tests__/process-str-replace.test.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import {
2-
describe,
3-
expect,
4-
it,
5-
spyOn,
6-
beforeEach,
7-
afterEach,
8-
mock,
9-
} from 'bun:test'
1+
import { describe, expect, it, mock } from 'bun:test'
102
import { applyPatch } from 'diff'
113

4+
import { processStrReplace } from '../process-str-replace'
5+
import {
6+
executeBatchStrReplaces,
7+
benchifyCanFixLanguage,
8+
} from '../tools/batch-str-replace'
9+
10+
import type { Logger } from '@codebuff/types/logger'
11+
1212
// Mock the benchify module to simulate missing API key
1313
mock.module('benchify', () => ({
1414
Benchify: class MockBenchify {
@@ -19,15 +19,6 @@ mock.module('benchify', () => ({
1919
},
2020
}))
2121

22-
import { processStrReplace } from '../process-str-replace'
23-
import { mockFileContext } from './test-utils'
24-
import {
25-
executeBatchStrReplaces,
26-
benchifyCanFixLanguage,
27-
} from '../tools/batch-str-replace'
28-
29-
import type { Logger } from '@codebuff/types/logger'
30-
3122
const logger: Logger = {
3223
debug: () => {},
3324
info: () => {},
@@ -283,12 +274,12 @@ describe('processStrReplace', () => {
283274
const oldStr = 'const x'
284275
const newStr = 'let x'
285276

286-
const result = await processStrReplace({
287-
path: 'test.ts',
288-
replacements: [{ old: oldStr, new: newStr, allowMultiple: false }],
289-
initialContentPromise: Promise.resolve(initialContent),
290-
logger,
291-
})
277+
const result = await processStrReplace({
278+
path: 'test.ts',
279+
replacements: [{ old: oldStr, new: newStr, allowMultiple: false }],
280+
initialContentPromise: Promise.resolve(initialContent),
281+
logger,
282+
})
292283

293284
expect(result).not.toBeNull()
294285
expect('error' in result).toBe(true)
@@ -563,6 +554,7 @@ describe('Benchify resilience', () => {
563554
onResponseChunk: () => {},
564555
state: { messages: [] },
565556
userId: 'test-user',
557+
logger,
566558
})
567559

568560
// Should complete without error even when Benchify is unavailable
@@ -590,6 +582,7 @@ describe('Benchify resilience', () => {
590582
onResponseChunk: () => {},
591583
state: { messages: [] },
592584
userId: 'test-user',
585+
logger,
593586
}),
594587
).resolves.toBeUndefined() // Should complete without throwing
595588
})
@@ -627,6 +620,7 @@ describe('Benchify resilience', () => {
627620
onResponseChunk: () => {},
628621
state: { messages: [] },
629622
userId: 'test-user',
623+
logger,
630624
})
631625

632626
// Should complete without throwing an error

backend/src/run-agent-step.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export const runAgentStep = async (
306306
agentContext,
307307
onResponseChunk,
308308
fullResponse,
309+
logger,
309310
})
310311
toolResults.push(...newToolResults)
311312

0 commit comments

Comments
 (0)