11import { describe , expect , it } from "vitest" ;
22import { evaluateChannelHealth , resolveChannelRestartReason } from "./channel-health-policy.js" ;
33
4+ function evaluateDiscordHealth (
5+ account : Record < string , unknown > ,
6+ now = 100_000 ,
7+ channelId = "discord" ,
8+ ) {
9+ return evaluateChannelHealth ( account , {
10+ channelId,
11+ now,
12+ channelConnectGraceMs : 10_000 ,
13+ staleEventThresholdMs : 30_000 ,
14+ } ) ;
15+ }
16+
417describe ( "evaluateChannelHealth" , ( ) => {
518 it ( "treats disabled accounts as healthy unmanaged" , ( ) => {
619 const evaluation = evaluateChannelHealth (
@@ -144,67 +157,47 @@ describe("evaluateChannelHealth", () => {
144157 } ) ;
145158
146159 it ( "skips stale-socket detection for channels in webhook mode" , ( ) => {
147- const evaluation = evaluateChannelHealth (
148- {
149- running : true ,
150- connected : true ,
151- enabled : true ,
152- configured : true ,
153- lastStartAt : 0 ,
154- lastEventAt : 0 ,
155- mode : "webhook" ,
156- } ,
157- {
158- channelId : "discord" ,
159- now : 100_000 ,
160- channelConnectGraceMs : 10_000 ,
161- staleEventThresholdMs : 30_000 ,
162- } ,
163- ) ;
160+ const evaluation = evaluateDiscordHealth ( {
161+ running : true ,
162+ connected : true ,
163+ enabled : true ,
164+ configured : true ,
165+ lastStartAt : 0 ,
166+ lastEventAt : 0 ,
167+ mode : "webhook" ,
168+ } ) ;
164169 expect ( evaluation ) . toEqual ( { healthy : true , reason : "healthy" } ) ;
165170 } ) ;
166171
167172 it ( "does not flag stale sockets for channels without event tracking" , ( ) => {
168- const evaluation = evaluateChannelHealth (
169- {
170- running : true ,
171- connected : true ,
172- enabled : true ,
173- configured : true ,
174- lastStartAt : 0 ,
175- lastEventAt : null ,
176- } ,
177- {
178- channelId : "discord" ,
179- now : 100_000 ,
180- channelConnectGraceMs : 10_000 ,
181- staleEventThresholdMs : 30_000 ,
182- } ,
183- ) ;
173+ const evaluation = evaluateDiscordHealth ( {
174+ running : true ,
175+ connected : true ,
176+ enabled : true ,
177+ configured : true ,
178+ lastStartAt : 0 ,
179+ lastEventAt : null ,
180+ } ) ;
184181 expect ( evaluation ) . toEqual ( { healthy : true , reason : "healthy" } ) ;
185182 } ) ;
186183
187184 it ( "does not flag stale sockets without an active connected socket" , ( ) => {
188- const evaluation = evaluateChannelHealth (
185+ const evaluation = evaluateDiscordHealth (
189186 {
190187 running : true ,
191188 enabled : true ,
192189 configured : true ,
193190 lastStartAt : 0 ,
194191 lastEventAt : 0 ,
195192 } ,
196- {
197- channelId : "slack" ,
198- now : 75_000 ,
199- channelConnectGraceMs : 10_000 ,
200- staleEventThresholdMs : 30_000 ,
201- } ,
193+ 75_000 ,
194+ "slack" ,
202195 ) ;
203196 expect ( evaluation ) . toEqual ( { healthy : true , reason : "healthy" } ) ;
204197 } ) ;
205198
206199 it ( "ignores inherited event timestamps from a previous lifecycle" , ( ) => {
207- const evaluation = evaluateChannelHealth (
200+ const evaluation = evaluateDiscordHealth (
208201 {
209202 running : true ,
210203 connected : true ,
@@ -213,12 +206,8 @@ describe("evaluateChannelHealth", () => {
213206 lastStartAt : 50_000 ,
214207 lastEventAt : 10_000 ,
215208 } ,
216- {
217- channelId : "slack" ,
218- now : 75_000 ,
219- channelConnectGraceMs : 10_000 ,
220- staleEventThresholdMs : 30_000 ,
221- } ,
209+ 75_000 ,
210+ "slack" ,
222211 ) ;
223212 expect ( evaluation ) . toEqual ( { healthy : true , reason : "healthy" } ) ;
224213 } ) ;
0 commit comments