88 mockModule ,
99} from '@codebuff/common/testing/mock-modules'
1010import { 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'
1212import { applyPatch } from 'diff'
1313
1414import { 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
2624describe ( '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 ( / < u p d a t e > ( [ \s \S ] * ) < \/ u p d a t e > / )
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 ( / < u p d a t e > ( [ \s \S ] * ) < \/ u p d a t e > / )
201+ if ( ! m ) {
202+ return 'Test response'
203+ }
204+ return m [ 1 ] . trim ( )
205+ }
206+
180207 const result = await processFileBlock ( {
181208 ...agentRuntimeImpl ,
182209 ...agentRuntimeScopedImpl ,
0 commit comments