11/* eslint-disable @typescript-eslint/unbound-method */
2- import { describe , test , expect , beforeEach , jest } from "@jest/globals " ;
2+ import { describe , test , expect , beforeEach , mock } from "bun:test " ;
33import { PartialService } from "./partialService" ;
44import type { HistoryService } from "./historyService" ;
55import type { Config } from "@/config" ;
@@ -9,18 +9,18 @@ import { Ok } from "@/types/result";
99// Mock Config
1010const createMockConfig = ( ) : Config => {
1111 return {
12- getSessionDir : jest . fn ( ( workspaceId : string ) => `/tmp/test-sessions/${ workspaceId } ` ) ,
12+ getSessionDir : mock ( ( workspaceId : string ) => `/tmp/test-sessions/${ workspaceId } ` ) ,
1313 } as unknown as Config ;
1414} ;
1515
1616// Mock HistoryService
1717const createMockHistoryService = ( ) : HistoryService => {
1818 return {
19- appendToHistory : jest . fn ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ,
20- getHistory : jest . fn ( ( ) => Promise . resolve ( Ok ( [ ] ) ) ) ,
21- updateHistory : jest . fn ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ,
22- truncateAfterMessage : jest . fn ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ,
23- clearHistory : jest . fn ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ,
19+ appendToHistory : mock ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ,
20+ getHistory : mock ( ( ) => Promise . resolve ( Ok ( [ ] ) ) ) ,
21+ updateHistory : mock ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ,
22+ truncateAfterMessage : mock ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ,
23+ clearHistory : mock ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ,
2424 } as unknown as HistoryService ;
2525} ;
2626
@@ -55,13 +55,13 @@ describe("PartialService - Error Recovery", () => {
5555 } ;
5656
5757 // Mock readPartial to return errored partial
58- partialService . readPartial = jest . fn ( ( ) => Promise . resolve ( erroredPartial ) ) ;
58+ partialService . readPartial = mock ( ( ) => Promise . resolve ( erroredPartial ) ) ;
5959
6060 // Mock deletePartial
61- partialService . deletePartial = jest . fn ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ;
61+ partialService . deletePartial = mock ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ;
6262
6363 // Mock getHistory to return no existing messages
64- mockHistoryService . getHistory = jest . fn ( ( ) => Promise . resolve ( Ok ( [ ] ) ) ) ;
64+ mockHistoryService . getHistory = mock ( ( ) => Promise . resolve ( Ok ( [ ] ) ) ) ;
6565
6666 // Call commitToHistory
6767 const result = await partialService . commitToHistory ( workspaceId ) ;
@@ -70,7 +70,7 @@ describe("PartialService - Error Recovery", () => {
7070 expect ( result . success ) . toBe ( true ) ;
7171
7272 // Should have called appendToHistory with cleaned metadata (no error/errorType)
73- const appendToHistory = mockHistoryService . appendToHistory as ReturnType < typeof jest . fn > ;
73+ const appendToHistory = mockHistoryService . appendToHistory as ReturnType < typeof mock > ;
7474 expect ( appendToHistory ) . toHaveBeenCalledTimes ( 1 ) ;
7575 const appendedMessage = appendToHistory . mock . calls [ 0 ] [ 1 ] as CmuxMessage ;
7676
@@ -81,7 +81,7 @@ describe("PartialService - Error Recovery", () => {
8181 expect ( appendedMessage . metadata ?. historySequence ) . toBe ( 1 ) ;
8282
8383 // Should have deleted the partial after committing
84- const deletePartial = partialService . deletePartial as ReturnType < typeof jest . fn > ;
84+ const deletePartial = partialService . deletePartial as ReturnType < typeof mock > ;
8585 expect ( deletePartial ) . toHaveBeenCalledWith ( workspaceId ) ;
8686 } ) ;
8787
@@ -123,13 +123,13 @@ describe("PartialService - Error Recovery", () => {
123123 } ;
124124
125125 // Mock readPartial to return errored partial
126- partialService . readPartial = jest . fn ( ( ) => Promise . resolve ( erroredPartial ) ) ;
126+ partialService . readPartial = mock ( ( ) => Promise . resolve ( erroredPartial ) ) ;
127127
128128 // Mock deletePartial
129- partialService . deletePartial = jest . fn ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ;
129+ partialService . deletePartial = mock ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ;
130130
131131 // Mock getHistory to return existing placeholder
132- mockHistoryService . getHistory = jest . fn ( ( ) => Promise . resolve ( Ok ( [ existingPlaceholder ] ) ) ) ;
132+ mockHistoryService . getHistory = mock ( ( ) => Promise . resolve ( Ok ( [ existingPlaceholder ] ) ) ) ;
133133
134134 // Call commitToHistory
135135 const result = await partialService . commitToHistory ( workspaceId ) ;
@@ -138,8 +138,8 @@ describe("PartialService - Error Recovery", () => {
138138 expect ( result . success ) . toBe ( true ) ;
139139
140140 // Should have called updateHistory (not append) with cleaned metadata
141- const updateHistory = mockHistoryService . updateHistory as ReturnType < typeof jest . fn > ;
142- const appendToHistory = mockHistoryService . appendToHistory as ReturnType < typeof jest . fn > ;
141+ const updateHistory = mockHistoryService . updateHistory as ReturnType < typeof mock > ;
142+ const appendToHistory = mockHistoryService . appendToHistory as ReturnType < typeof mock > ;
143143 expect ( updateHistory ) . toHaveBeenCalledTimes ( 1 ) ;
144144 expect ( appendToHistory ) . not . toHaveBeenCalled ( ) ;
145145
@@ -150,7 +150,7 @@ describe("PartialService - Error Recovery", () => {
150150 expect ( updatedMessage . metadata ?. errorType ) . toBeUndefined ( ) ;
151151
152152 // Should have deleted the partial after updating
153- const deletePartial = partialService . deletePartial as ReturnType < typeof jest . fn > ;
153+ const deletePartial = partialService . deletePartial as ReturnType < typeof mock > ;
154154 expect ( deletePartial ) . toHaveBeenCalledWith ( workspaceId ) ;
155155 } ) ;
156156
@@ -171,13 +171,13 @@ describe("PartialService - Error Recovery", () => {
171171 } ;
172172
173173 // Mock readPartial to return empty errored partial
174- partialService . readPartial = jest . fn ( ( ) => Promise . resolve ( emptyErrorPartial ) ) ;
174+ partialService . readPartial = mock ( ( ) => Promise . resolve ( emptyErrorPartial ) ) ;
175175
176176 // Mock deletePartial
177- partialService . deletePartial = jest . fn ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ;
177+ partialService . deletePartial = mock ( ( ) => Promise . resolve ( Ok ( undefined ) ) ) ;
178178
179179 // Mock getHistory to return no existing messages
180- mockHistoryService . getHistory = jest . fn ( ( ) => Promise . resolve ( Ok ( [ ] ) ) ) ;
180+ mockHistoryService . getHistory = mock ( ( ) => Promise . resolve ( Ok ( [ ] ) ) ) ;
181181
182182 // Call commitToHistory
183183 const result = await partialService . commitToHistory ( workspaceId ) ;
@@ -186,11 +186,11 @@ describe("PartialService - Error Recovery", () => {
186186 expect ( result . success ) . toBe ( true ) ;
187187
188188 // Should NOT call appendToHistory for empty message (no value to preserve)
189- const appendToHistory = mockHistoryService . appendToHistory as ReturnType < typeof jest . fn > ;
189+ const appendToHistory = mockHistoryService . appendToHistory as ReturnType < typeof mock > ;
190190 expect ( appendToHistory ) . not . toHaveBeenCalled ( ) ;
191191
192192 // Should still delete the partial (cleanup)
193- const deletePartial = partialService . deletePartial as ReturnType < typeof jest . fn > ;
193+ const deletePartial = partialService . deletePartial as ReturnType < typeof mock > ;
194194 expect ( deletePartial ) . toHaveBeenCalledWith ( workspaceId ) ;
195195 } ) ;
196196} ) ;
0 commit comments