@@ -85,6 +85,39 @@ const quietly = async <T>(body: () => Promise<T>): Promise<T> => {
8585}
8686
8787describe ( 'runPipeline' , ( ) => {
88+ it ( 'reports only persisted progress when an article write fails' , async ( ) => {
89+ const { ctx } = fakeCtx ( [ articleAt ( 1 , 'topic_selected' ) ] )
90+ ctx . payload . update = async ( ) => {
91+ throw new Error ( 'database write failed' )
92+ }
93+ const summary = await quietly ( ( ) => runPipeline ( ctx , {
94+ stages : [ stubStage ( 'research' , 'topic_selected' , 'researched' ) ] ,
95+ } ) )
96+ assert . equal ( summary . failed , 1 )
97+ assert . deepEqual ( summary . articleIds , [ ] )
98+ assert . deepEqual ( summary . finalStatuses , { } )
99+ assert . equal ( summary . failures [ 0 ] ?. message , 'database write failed' )
100+ } )
101+
102+ it ( 'keeps the last persisted status when a later stage write fails' , async ( ) => {
103+ const article = articleAt ( 1 , 'topic_selected' )
104+ const { ctx } = fakeCtx ( [ article ] )
105+ ctx . payload . update = ( async ( { data } : { data : { status : Article [ 'status' ] } } ) => {
106+ if ( data . status === 'drafted' ) throw new Error ( 'database write failed' )
107+ article . status = data . status
108+ return article
109+ } ) as unknown as typeof ctx . payload . update
110+ const summary = await quietly ( ( ) => runPipeline ( ctx , {
111+ stages : [
112+ stubStage ( 'research' , 'topic_selected' , 'researched' ) ,
113+ stubStage ( 'generate' , 'researched' , 'drafted' ) ,
114+ ] ,
115+ } ) )
116+ assert . equal ( summary . failed , 1 )
117+ assert . deepEqual ( summary . articleIds , [ 1 ] )
118+ assert . deepEqual ( summary . finalStatuses , { researched : 1 } )
119+ } )
120+
88121 it ( 'reports no failures for a clean run and advances every article' , async ( ) => {
89122 const { ctx, updates } = fakeCtx ( [
90123 articleAt ( 1 , 'topic_selected' ) ,
0 commit comments