@@ -46,6 +46,48 @@ const readModel: OrchestrationReadModel = {
4646} ;
4747
4848it . layer ( NodeServices . layer ) ( "title regeneration decider" , ( it ) => {
49+ it . effect ( "applies a title update while the expected title is still current" , ( ) =>
50+ Effect . gen ( function * ( ) {
51+ const result = yield * decideOrchestrationCommand ( {
52+ command : {
53+ type : "thread.meta.update" ,
54+ commandId : CommandId . make ( "cmd-title-update-current" ) ,
55+ threadId : ThreadId . make ( "thread-1" ) ,
56+ title : "Provider title" ,
57+ expectedTitle : "Manual title" ,
58+ } ,
59+ readModel,
60+ } ) ;
61+ const event = Array . isArray ( result ) ? result [ 0 ] : result ;
62+
63+ expect ( event . type ) . toBe ( "thread.meta-updated" ) ;
64+ if ( event . type === "thread.meta-updated" ) {
65+ expect ( event . payload . title ) . toBe ( "Provider title" ) ;
66+ }
67+ } ) ,
68+ ) ;
69+
70+ it . effect ( "does not replace a title that changed after the caller sampled it" , ( ) =>
71+ Effect . gen ( function * ( ) {
72+ const result = yield * decideOrchestrationCommand ( {
73+ command : {
74+ type : "thread.meta.update" ,
75+ commandId : CommandId . make ( "cmd-title-update-stale" ) ,
76+ threadId : ThreadId . make ( "thread-1" ) ,
77+ title : "Provider title" ,
78+ expectedTitle : "Previous provider title" ,
79+ } ,
80+ readModel,
81+ } ) ;
82+ const event = Array . isArray ( result ) ? result [ 0 ] : result ;
83+
84+ expect ( event . type ) . toBe ( "thread.meta-updated" ) ;
85+ if ( event . type === "thread.meta-updated" ) {
86+ expect ( event . payload . title ) . toBeUndefined ( ) ;
87+ }
88+ } ) ,
89+ ) ;
90+
4991 it . effect ( "preserves updatedAt for a stale completion" , ( ) =>
5092 Effect . gen ( function * ( ) {
5193 const result = yield * decideOrchestrationCommand ( {
0 commit comments