@@ -14,6 +14,9 @@ const state = vi.hoisted(() => ({
1414 completedAt : null as string | null ,
1515 archivedAt : null as string | null ,
1616 input : false ,
17+ approval : false ,
18+ sessionError : false ,
19+ turnError : false ,
1720 add : vi . fn (
1821 ( _toast : { title : string ; description : string ; actionProps : { onClick : ( ) => void } } ) =>
1922 "toast-1" ,
@@ -34,9 +37,11 @@ vi.mock("@effect/atom-react", () => ({
3437 title : "Fix the login form" ,
3538 archivedAt : state . archivedAt ,
3639 hasPendingUserInput : state . input ,
40+ hasPendingApprovals : state . approval ,
41+ session : state . sessionError ? { status : "error" } : null ,
3742 latestTurn : {
3843 turnId : "turn-1" ,
39- state : state . completedAt ? "completed" : "running" ,
44+ state : state . turnError ? "error" : state . completedAt ? "completed" : "running" ,
4045 completedAt : state . completedAt ,
4146 } ,
4247 } ,
@@ -98,6 +103,9 @@ beforeEach(() => {
98103 completedAt : null ,
99104 archivedAt : null ,
100105 input : false ,
106+ approval : false ,
107+ sessionError : false ,
108+ turnError : false ,
101109 } ) ;
102110 vi . stubGlobal ( "IS_REACT_ACT_ENVIRONMENT" , true ) ;
103111 vi . stubGlobal ( "document" , {
@@ -135,21 +143,51 @@ describe("thread notifications", () => {
135143 expect ( state . notification ) . not . toHaveBeenCalled ( ) ;
136144 } ) ;
137145
138- it . each ( [ "active" , "blurred" , "hidden" , "archived" , "input" , " disabled"] ) (
146+ it . each ( [ "active" , "blurred" , "hidden" , "archived" , "disabled" ] ) (
139147 "does not show a completion toast for %s threads" ,
140148 async ( condition ) => {
141149 await render ( ) ;
142150 if ( condition === "active" ) state . active . threadId = "thread-1" ;
143151 if ( condition === "blurred" ) state . focused = false ;
144152 if ( condition === "hidden" ) state . visible = "hidden" ;
145153 if ( condition === "archived" ) state . archivedAt = "2026-09-13T09:00:00.000Z" ;
146- if ( condition === "input" ) state . input = true ;
147154 if ( condition === "disabled" ) state . inApp = false ;
148155 await complete ( ) ;
149156 expect ( state . add ) . not . toHaveBeenCalled ( ) ;
150157 } ,
151158 ) ;
152159
160+ it . each ( [
161+ [ "input" , "Input needed" ] ,
162+ [ "approval" , "Approval needed" ] ,
163+ [ "sessionError" , "Thread failed" ] ,
164+ [ "turnError" , "Thread failed" ] ,
165+ ] as const ) ( "uses the same %s event for in-app and desktop alerts" , async ( event , title ) => {
166+ state . mode = "notifications-and-sound" ;
167+ await render ( ) ;
168+ state [ event ] = true ;
169+ await render ( ) ;
170+ await render ( ) ;
171+ expect ( state . add ) . toHaveBeenCalledTimes ( 1 ) ;
172+ expect ( state . add ) . toHaveBeenLastCalledWith ( expect . objectContaining ( { title } ) ) ;
173+ expect ( state . sound ) . toHaveBeenCalledWith ( "input" , expect . any ( Function ) ) ;
174+ expect ( state . notification ) . not . toHaveBeenCalled ( ) ;
175+
176+ state [ event ] = false ;
177+ await render ( ) ;
178+ state . focused = false ;
179+ state [ event ] = true ;
180+ await render ( ) ;
181+ await render ( ) ;
182+ expect ( state . add ) . toHaveBeenCalledTimes ( 1 ) ;
183+ expect ( state . notification ) . toHaveBeenCalledTimes ( 1 ) ;
184+ expect ( state . notification ) . toHaveBeenCalledWith ( title , {
185+ body : "Fix the login form" ,
186+ tag : "env-1:thread-1" ,
187+ silent : true ,
188+ } ) ;
189+ } ) ;
190+
153191 it ( "keeps desktop alerts when in-app notifications are disabled" , async ( ) => {
154192 state . inApp = false ;
155193 state . mode = "notifications" ;
0 commit comments