@@ -30,34 +30,43 @@ vi.mock("execa", () => ({
3030 execa : vi . fn ( ) ,
3131} ) )
3232
33- vi . mock ( "fs/promises" , ( ) => ( {
34- mkdir : vi . fn ( ) . mockResolvedValue ( undefined ) ,
35- writeFile : vi . fn ( ) . mockResolvedValue ( undefined ) ,
36- readFile : vi . fn ( ) . mockImplementation ( ( filePath ) => {
37- if ( filePath . includes ( "ui_messages.json" ) ) {
38- return Promise . resolve ( JSON . stringify ( mockMessages ) )
39- }
40- if ( filePath . includes ( "api_conversation_history.json" ) ) {
41- return Promise . resolve (
42- JSON . stringify ( [
43- {
44- role : "user" ,
45- content : [ { type : "text" , text : "historical task" } ] ,
46- ts : Date . now ( ) ,
47- } ,
48- {
49- role : "assistant" ,
50- content : [ { type : "text" , text : "I'll help you with that task." } ] ,
51- ts : Date . now ( ) ,
52- } ,
53- ] ) ,
54- )
55- }
56- return Promise . resolve ( "[]" )
57- } ) ,
58- unlink : vi . fn ( ) . mockResolvedValue ( undefined ) ,
59- rmdir : vi . fn ( ) . mockResolvedValue ( undefined ) ,
60- } ) )
33+ vi . mock ( "fs/promises" , async ( importOriginal ) => {
34+ const actual = ( await importOriginal ( ) ) as Record < string , any >
35+ const mockFunctions = {
36+ mkdir : vi . fn ( ) . mockResolvedValue ( undefined ) ,
37+ writeFile : vi . fn ( ) . mockResolvedValue ( undefined ) ,
38+ readFile : vi . fn ( ) . mockImplementation ( ( filePath ) => {
39+ if ( filePath . includes ( "ui_messages.json" ) ) {
40+ return Promise . resolve ( JSON . stringify ( mockMessages ) )
41+ }
42+ if ( filePath . includes ( "api_conversation_history.json" ) ) {
43+ return Promise . resolve (
44+ JSON . stringify ( [
45+ {
46+ role : "user" ,
47+ content : [ { type : "text" , text : "historical task" } ] ,
48+ ts : Date . now ( ) ,
49+ } ,
50+ {
51+ role : "assistant" ,
52+ content : [ { type : "text" , text : "I'll help you with that task." } ] ,
53+ ts : Date . now ( ) ,
54+ } ,
55+ ] ) ,
56+ )
57+ }
58+ return Promise . resolve ( "[]" )
59+ } ) ,
60+ unlink : vi . fn ( ) . mockResolvedValue ( undefined ) ,
61+ rmdir : vi . fn ( ) . mockResolvedValue ( undefined ) ,
62+ }
63+
64+ return {
65+ ...actual ,
66+ ...mockFunctions ,
67+ default : mockFunctions ,
68+ }
69+ } )
6170
6271vi . mock ( "p-wait-for" , ( ) => ( {
6372 default : vi . fn ( ) . mockImplementation ( async ( ) => Promise . resolve ( ) ) ,
0 commit comments