@@ -17,9 +17,12 @@ import {
1717} from 'bun:test'
1818
1919import { startAgentRun , finishAgentRun , addAgentStep } from '../agent-run'
20- import { logger } from '../util/logger'
20+
21+ import type { Logger } from '@codebuff/agent-runtime'
2122
2223describe ( 'Agent Run Database Functions' , ( ) => {
24+ let logger : Logger
25+
2326 beforeEach ( ( ) => {
2427 // Setup spies for database operations
2528 spyOn ( db , 'insert' ) . mockReturnValue ( {
@@ -30,8 +33,12 @@ describe('Agent Run Database Functions', () => {
3033 where : mock ( ( ) => Promise . resolve ( ) ) ,
3134 } ) ) ,
3235 } as any )
33- // Mock logger
34- spyOn ( logger , 'error' ) . mockImplementation ( ( ) => { } )
36+ logger = {
37+ debug : mock ( ( ) => { } ) ,
38+ info : mock ( ( ) => { } ) ,
39+ warn : mock ( ( ) => { } ) ,
40+ error : mock ( ( ) => { } ) ,
41+ }
3542 } )
3643
3744 afterEach ( ( ) => {
@@ -61,6 +68,7 @@ describe('Agent Run Database Functions', () => {
6168 userId : 'user-123' ,
6269 agentId : 'test-agent' ,
6370 ancestorRunIds : [ 'parent-run-1' , 'parent-run-2' ] ,
71+ logger,
6472 } )
6573
6674 expect ( result ) . toBe ( 'generated-uuid' )
@@ -84,6 +92,7 @@ describe('Agent Run Database Functions', () => {
8492 userId : 'user-123' ,
8593 agentId : 'test-agent' ,
8694 ancestorRunIds : [ ] ,
95+ logger,
8796 } )
8897
8998 expect ( result ) . toBe ( 'custom-run-id' )
@@ -105,6 +114,7 @@ describe('Agent Run Database Functions', () => {
105114 await startAgentRun ( {
106115 agentId : 'test-agent' ,
107116 ancestorRunIds : [ ] ,
117+ logger,
108118 } )
109119
110120 expect ( mockValues ) . toHaveBeenCalledWith ( {
@@ -125,6 +135,7 @@ describe('Agent Run Database Functions', () => {
125135 await startAgentRun ( {
126136 agentId : 'test-agent' ,
127137 ancestorRunIds : [ ] ,
138+ logger,
128139 } )
129140
130141 expect ( mockValues ) . toHaveBeenCalledWith (
@@ -142,6 +153,7 @@ describe('Agent Run Database Functions', () => {
142153 await startAgentRun ( {
143154 agentId : 'test-agent' ,
144155 ancestorRunIds : [ 'root-run' , 'parent-run' ] ,
156+ logger,
145157 } )
146158
147159 expect ( mockValues ) . toHaveBeenCalledWith (
@@ -161,6 +173,7 @@ describe('Agent Run Database Functions', () => {
161173 startAgentRun ( {
162174 agentId : 'test-agent' ,
163175 ancestorRunIds : [ ] ,
176+ logger,
164177 } ) ,
165178 ) . rejects . toThrow ( 'Database connection failed' )
166179
@@ -190,6 +203,7 @@ describe('Agent Run Database Functions', () => {
190203 totalSteps : 5 ,
191204 directCredits : 150.5 ,
192205 totalCredits : 300.75 ,
206+ logger,
193207 } )
194208
195209 expect ( db . update ) . toHaveBeenCalledWith ( schema . agentRun )
@@ -217,6 +231,7 @@ describe('Agent Run Database Functions', () => {
217231 directCredits : 75.25 ,
218232 totalCredits : 125.5 ,
219233 errorMessage : 'Agent execution failed' ,
234+ logger,
220235 } )
221236
222237 expect ( mockSet ) . toHaveBeenCalledWith ( {
@@ -242,6 +257,7 @@ describe('Agent Run Database Functions', () => {
242257 totalSteps : 2 ,
243258 directCredits : 50 ,
244259 totalCredits : 100 ,
260+ logger,
245261 } )
246262
247263 expect ( mockSet ) . toHaveBeenCalledWith (
@@ -266,6 +282,7 @@ describe('Agent Run Database Functions', () => {
266282 totalSteps : 5 ,
267283 directCredits : 150 ,
268284 totalCredits : 300 ,
285+ logger,
269286 } ) ,
270287 ) . rejects . toThrow ( 'Update failed' )
271288
@@ -297,6 +314,7 @@ describe('Agent Run Database Functions', () => {
297314 messageId : 'msg-456' ,
298315 status : 'completed' ,
299316 startTime,
317+ logger,
300318 } )
301319
302320 expect ( result ) . toBe ( 'step-uuid' )
@@ -328,6 +346,7 @@ describe('Agent Run Database Functions', () => {
328346 stepNumber : 2 ,
329347 startTime,
330348 messageId : null ,
349+ logger,
331350 } )
332351
333352 expect ( mockValues ) . toHaveBeenCalledWith ( {
@@ -359,6 +378,7 @@ describe('Agent Run Database Functions', () => {
359378 errorMessage : 'Step failed validation' ,
360379 startTime,
361380 messageId : null ,
381+ logger,
362382 } )
363383
364384 expect ( mockValues ) . toHaveBeenCalledWith (
@@ -383,6 +403,7 @@ describe('Agent Run Database Functions', () => {
383403 status : 'running' ,
384404 startTime,
385405 messageId : null ,
406+ logger,
386407 } )
387408
388409 expect ( mockValues ) . toHaveBeenCalledWith (
@@ -406,6 +427,7 @@ describe('Agent Run Database Functions', () => {
406427 credits : 0 , // Zero credits
407428 startTime,
408429 messageId : null ,
430+ logger,
409431 } )
410432
411433 expect ( mockValues ) . toHaveBeenCalledWith (
@@ -430,6 +452,7 @@ describe('Agent Run Database Functions', () => {
430452 stepNumber : 6 ,
431453 startTime,
432454 messageId : null ,
455+ logger,
433456 } ) ,
434457 ) . rejects . toThrow ( 'Insert failed' )
435458
@@ -457,6 +480,7 @@ describe('Agent Run Database Functions', () => {
457480 credits : 123.456789 , // High precision number
458481 startTime : new Date ( ) ,
459482 messageId : null ,
483+ logger,
460484 } )
461485
462486 expect ( mockValues ) . toHaveBeenCalledWith (
@@ -479,6 +503,7 @@ describe('Agent Run Database Functions', () => {
479503 stepNumber : 1 ,
480504 startTime : specificStartTime ,
481505 messageId : null ,
506+ logger,
482507 } )
483508
484509 expect ( mockValues ) . toHaveBeenCalledWith (
0 commit comments