@@ -32,21 +32,23 @@ struct HealthStoreStateTests {
3232 let state = AppState ( preview : true )
3333 state . connectionMode = . local
3434 state . isPaused = true
35- for ( name , fields , expected ) in [
36- ( " ready " , [ " running " : true , " connected " : true , " lifecycle " : " ready " ] as [ String : Any ] ,
35+ for ( name , channelId , fields , expected ) in [
36+ ( " ready " , " telegram " , [ " running " : true , " connected " : true , " lifecycle " : " ready " ] as [ String : Any ] ,
3737 " Telegram ready " ) ,
38- ( " startup-grace " , [
38+ ( " startup-grace " , " telegram " , [
3939 " running " : true , " connected " : false , " lifecycle " : " starting " , " lastStartAt " : 1772798370000 ,
4040 ] ,
4141 " Telegram running " ) ,
42- ( " stale-socket " , [
42+ ( " stale-socket " , " telegram " , [
4343 " running " : true , " connected " : true , " lifecycle " : " ready " , " healthState " : " stale-socket " ,
4444 " lastStartAt " : 1772794800000 , " lastTransportActivityAt " : 1772796540000 ,
4545 ] ,
4646 " Telegram degraded · stale-socket " ) ,
47- ( " disabled " , [ " enabled " : false , " running " : false ] , " Telegram disabled " ) ,
47+ ( " disabled " , " telegram " , [ " enabled " : false , " running " : false ] , " Telegram disabled " ) ,
48+ ( " probe-permission " , " imessage " , Self . permissionProbeChannel ,
49+ " iMessage degraded · \( Self . permissionProbeError ) (status unknown) " ) ,
4850 ] {
49- try Self . withSnapshot ( [ " telegram " : fields ] ) { store in
51+ try Self . withSnapshot ( [ channelId : fields ] , order : [ channelId ] ) { store in
5052 let hosting = NSHostingView ( rootView : GeneralSettings ( state : state , page : . connection , isActive : false )
5153 // Capture the view's light canvas, not transparent text over the window's excluded background.
5254 . background ( . white )
@@ -132,22 +134,25 @@ struct HealthStoreStateTests {
132134 }
133135
134136 @ Test @ MainActor func `current channel probe failure degrades state` ( ) throws {
135- try Self . withSnapshot ( [
136- " telegram " : [
137+ for ( channelId , fields , label , expected ) in [
138+ ( " imessage " , Self . permissionProbeChannel , " iMessage " , " \( Self . permissionProbeError ) (status unknown) " ) ,
139+ // Generic imsg timeouts exercise formatting, not the FDA-only public probe redactor.
140+ ( " imessage " , [
141+ " probe " : [ " ok " : false , " error " : " imsg rpc timeout (chats.list) " ] ,
142+ " running " : true , " lifecycle " : " starting " , " lastStartAt " : 1772798395000 ,
143+ ] , " iMessage " , " Health check timed out " ) ,
144+ ( " telegram " , [
137145 " probe " : [ " ok " : false , " status " : 503 , " error " : " gateway connect failed " , " elapsedMs " : 12 ] ,
138146 " lastProbeAt " : 1772798400000 ,
139147 " running " : true ,
140148 " connected " : true ,
141149 " lifecycle " : " ready " ,
142- ] ,
143- ] ) { store in
144- switch store . state {
145- case let . degraded ( message ) :
146- #expect ( message . contains ( " gateway connect failed " ) )
147- default :
148- Issue . record ( " Expected degraded state when a current channel probe fails " )
150+ ] , " Telegram " , " gateway connect failed (status 503, 12ms) " ) ,
151+ ] {
152+ try Self . withSnapshot ( [ channelId : fields ] , order : [ channelId ] ) { store in
153+ #expect ( store . state == . degraded ( expected ) )
154+ #expect ( store . summaryLine == " \( label ) degraded · \( expected ) " )
149155 }
150- #expect ( store . summaryLine . contains ( " gateway connect failed " ) )
151156 }
152157 }
153158
@@ -338,6 +343,17 @@ struct HealthStoreStateTests {
338343 }
339344 }
340345
346+ private static let permissionProbeError =
347+ " imsg cannot access ~/Library/Messages/chat.db. Grant Full Disk Access to the Gateway/launcher process and restart Gateway. "
348+
349+ private static var permissionProbeChannel : [ String : Any ] {
350+ // Public health preserves this sanitized FDA error without an HTTP status; startup has no lastError yet.
351+ [
352+ " probe " : [ " ok " : false , " error " : self . permissionProbeError ] ,
353+ " running " : true , " lifecycle " : " starting " , " lastStartAt " : 1772798395000 ,
354+ ]
355+ }
356+
341357 private static var unlinkedWhatsApp : [ String : Any ] {
342358 [
343359 " configured " : true , " linked " : false , " running " : false , " connected " : false ,
@@ -370,7 +386,7 @@ struct HealthStoreStateTests {
370386 account . merge ( fields ) { _ , value in value }
371387 return account
372388 }
373- // Fixed Gateway response time: fresh starts are 30s old; expired starts are 5m old .
389+ // Fixed Gateway response time keeps grace and expired lifecycle fixtures deterministic .
374390 let fixture : [ String : Any ] = [
375391 " ok " : true ,
376392 " ts " : 1772798400000 ,
@@ -379,7 +395,7 @@ struct HealthStoreStateTests {
379395 " channelOrder " : order ,
380396 " channelLabels " : [
381397 " telegram " : " Telegram " , " matrix " : " Matrix " , " whatsapp " : " WhatsApp " , " zalouser " : " Zalo Personal " ,
382- " disabled " : " Disabled " ,
398+ " disabled " : " Disabled " , " imessage " : " iMessage " ,
383399 ] ,
384400 " heartbeatSeconds " : 60 ,
385401 " sessions " : [ " path " : " /tmp/sessions.json " , " count " : 0 , " recent " : [ ] ] ,
0 commit comments