@@ -22,7 +22,7 @@ import {
2222 getWatch ,
2323 listActiveWatchesForChat ,
2424 listChatIdsWithUnreadWakes ,
25- listUnreadWatchWakes ,
25+ listRecentWatchWakes ,
2626 markWatchDelivered ,
2727 recordWatchCheck ,
2828 releaseWatchDelivery ,
@@ -889,6 +889,8 @@ describe("unread watch wakes", () => {
889889 if ( ! created . ok ) return ;
890890
891891 const scope = { organizationId : seeded . organization . id , userId : seeded . user . id } ;
892+ // The toast feed lists recent DELIVERIES (read or not) inside a window.
893+ const recent = { ...scope , deliveredAfter : new Date ( Date . now ( ) - 15 * 60 * 1000 ) } ;
892894
893895 // Terminal but undelivered: the chat has no message to open yet, so the
894896 // launcher's dot and the toast must stay quiet.
@@ -898,13 +900,13 @@ describe("unread watch wakes", () => {
898900 resolution : "condition_met" ,
899901 } ) ;
900902 expect ( await countUnreadWatchWakes ( ctx . agentDb , scope ) ) . toBe ( 0 ) ;
901- expect ( await listUnreadWatchWakes ( ctx . agentDb , scope ) ) . toEqual ( [ ] ) ;
903+ expect ( await listRecentWatchWakes ( ctx . agentDb , recent ) ) . toEqual ( [ ] ) ;
902904 expect ( await listChatIdsWithUnreadWakes ( ctx . agentDb , scope ) ) . toEqual ( new Set ( ) ) ;
903905
904906 await markWatchDelivered ( ctx . agentDb , { id : created . watchId } ) ;
905907 expect ( await countUnreadWatchWakes ( ctx . agentDb , scope ) ) . toBe ( 1 ) ;
906- expect ( await listUnreadWatchWakes ( ctx . agentDb , scope ) ) . toMatchObject ( [
907- { watchId : created . watchId , chatId : "chat_1" , outcome : "fired" } ,
908+ expect ( await listRecentWatchWakes ( ctx . agentDb , recent ) ) . toMatchObject ( [
909+ { watchId : created . watchId , chatId : "chat_1" , outcome : "fired" , unread : true } ,
908910 ] ) ;
909911 expect ( await listChatIdsWithUnreadWakes ( ctx . agentDb , scope ) ) . toEqual ( new Set ( [ "chat_1" ] ) ) ;
910912 }
@@ -1666,18 +1668,21 @@ describe("appendChatMessage", () => {
16661668 await appendChatMessage ( ctx . agentDb , {
16671669 chatId : "chat_1" ,
16681670 userId : seeded . user . id ,
1671+ organizationId : seeded . organization . id ,
16691672 message : first ,
16701673 } )
16711674 ) . toBe ( true ) ;
16721675 await appendChatMessage ( ctx . agentDb , {
16731676 chatId : "chat_1" ,
16741677 userId : seeded . user . id ,
1678+ organizationId : seeded . organization . id ,
16751679 message : second ,
16761680 } ) ;
16771681
16781682 const messages = await getChatMessages ( ctx . agentDb , {
16791683 chatId : "chat_1" ,
16801684 userId : seeded . user . id ,
1685+ organizationId : seeded . organization . id ,
16811686 } ) ;
16821687 expect ( messages ) . toEqual ( [ first , second ] ) ;
16831688 }
@@ -1694,13 +1699,15 @@ describe("appendChatMessage", () => {
16941699 await appendChatMessage ( ctx . agentDb , {
16951700 chatId : "chat_1" ,
16961701 userId : "user_someone_else" ,
1702+ organizationId : seeded . organization . id ,
16971703 message : { id : "watch-card:watch_1" , role : "assistant" , parts : [ ] } ,
16981704 } )
16991705 ) . toBe ( false ) ;
17001706
17011707 const messages = await getChatMessages ( ctx . agentDb , {
17021708 chatId : "chat_1" ,
17031709 userId : seeded . user . id ,
1710+ organizationId : seeded . organization . id ,
17041711 } ) ;
17051712 expect ( messages ) . toEqual ( [ ] ) ;
17061713 }
0 commit comments