Skip to content

Commit 595d1e7

Browse files
committed
fix process-file-block.test.ts
1 parent cfbf6b7 commit 595d1e7

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

backend/src/__tests__/process-file-block.test.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
mockModule,
99
} from '@codebuff/common/testing/mock-modules'
1010
import { cleanMarkdownCodeBlock } from '@codebuff/common/util/file'
11-
import { afterAll, beforeAll, describe, expect, it } from 'bun:test'
11+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test'
1212
import { applyPatch } from 'diff'
1313

1414
import { processFileBlock } from '../process-file-block'
@@ -18,10 +18,8 @@ import type {
1818
AgentRuntimeScopedDeps,
1919
} from '@codebuff/common/types/contracts/agent-runtime'
2020

21-
const agentRuntimeImpl: AgentRuntimeDeps = { ...TEST_AGENT_RUNTIME_IMPL }
22-
const agentRuntimeScopedImpl: AgentRuntimeScopedDeps = {
23-
...TEST_AGENT_RUNTIME_SCOPED_IMPL,
24-
}
21+
let agentRuntimeImpl: AgentRuntimeDeps
22+
let agentRuntimeScopedImpl: AgentRuntimeScopedDeps
2523

2624
describe('processFileBlockModule', () => {
2725
beforeAll(() => {
@@ -50,6 +48,13 @@ describe('processFileBlockModule', () => {
5048
clearMockedModules()
5149
})
5250

51+
beforeEach(() => {
52+
agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
53+
agentRuntimeScopedImpl = {
54+
...TEST_AGENT_RUNTIME_SCOPED_IMPL,
55+
}
56+
})
57+
5358
describe('cleanMarkdownCodeBlock', () => {
5459
it('should remove markdown code block syntax with language tag', () => {
5560
const input = '```typescript\nconst x = 1;\n```'
@@ -116,6 +121,17 @@ describe('processFileBlockModule', () => {
116121
' return "See you later!";\r\n' +
117122
'}\r\n'
118123

124+
agentRuntimeImpl.promptAiSdk = async ({ messages }) => {
125+
if (typeof messages[0].content !== 'string') {
126+
throw new Error('Expected string prompt')
127+
}
128+
const m = messages[0].content.match(/<update>([\s\S]*)<\/update>/)
129+
if (!m) {
130+
return 'Test response'
131+
}
132+
return m[1].trim()
133+
}
134+
119135
const result = await processFileBlock({
120136
...agentRuntimeImpl,
121137
...agentRuntimeScopedImpl,
@@ -177,6 +193,17 @@ describe('processFileBlockModule', () => {
177193
const oldContent = 'const x = 1;\r\nconst y = 2;\r\n'
178194
const newContent = 'const x = 1;\r\nconst z = 3;\r\n'
179195

196+
agentRuntimeImpl.promptAiSdk = async ({ messages }) => {
197+
if (typeof messages[0].content !== 'string') {
198+
throw new Error('Expected string prompt')
199+
}
200+
const m = messages[0].content.match(/<update>([\s\S]*)<\/update>/)
201+
if (!m) {
202+
return 'Test response'
203+
}
204+
return m[1].trim()
205+
}
206+
180207
const result = await processFileBlock({
181208
...agentRuntimeImpl,
182209
...agentRuntimeScopedImpl,

backend/src/fast-rewrite.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function fastRewrite(
2222
filePath: string
2323
userMessage: string | undefined
2424
logger: Logger
25-
} & ParamsExcluding<typeof promptRelaceAI, 'initialCode' | 'messageId'> &
25+
} & ParamsExcluding<typeof promptRelaceAI, 'initialCode'> &
2626
ParamsExcluding<typeof rewriteWithOpenAI, 'oldContent'>,
2727
) {
2828
const { initialContent, editSnippet, filePath, userMessage, logger } = params
@@ -31,7 +31,6 @@ export async function fastRewrite(
3131
let response = await promptRelaceAI({
3232
...params,
3333
initialCode: initialContent,
34-
messageId,
3534
})
3635
const relaceDuration = Date.now() - relaceStartTime
3736

0 commit comments

Comments
 (0)