@@ -5,7 +5,7 @@ import { normalizeLegacySessionEntryDelivery } from "../../infra/state-migration
55import type { ChannelRouteRef } from "../../plugin-sdk/channel-route.js" ;
66import { normalizeSessionDeliveryState } from "../../utils/delivery-context.shared.js" ;
77import type { DeliveryContext } from "../../utils/delivery-context.types.js" ;
8- import { isSystemEventProvider , resolveEffectiveReplyRoute } from "./effective-reply-route.js" ;
8+ import { resolveEffectiveReplyRoute } from "./effective-reply-route.js" ;
99
1010type EffectiveReplyRouteParams = Parameters < typeof resolveEffectiveReplyRoute > [ 0 ] ;
1111type EffectiveReplyRouteContext = EffectiveReplyRouteParams [ "ctx" ] ;
@@ -53,10 +53,14 @@ describe("resolveEffectiveReplyRoute", () => {
5353 } ) ;
5454 } ) ;
5555
56- it ( "does not use persisted fallbacks for normal providers" , ( ) => {
56+ it . each < EffectiveReplyRouteContext > ( [
57+ { Provider : "slack" } ,
58+ { InputProvenance : { kind : "internal_system" , sourceTool : "restart-sentinel" } } ,
59+ { InputProvenance : { kind : "internal_system" , sourceTool : "main_session_restart_recovery" } } ,
60+ ] ) ( "does not inherit a route without an internal wake source (%j)" , ( context ) => {
5761 expect (
5862 resolveEffectiveReplyRoute ( {
59- ctx : ctx ( { Provider : "slack" } ) ,
63+ ctx : context ,
6064 entry : entry ( {
6165 deliveryContext : {
6266 channel : "telegram" ,
@@ -300,7 +304,7 @@ describe("resolveEffectiveReplyRoute", () => {
300304 expect (
301305 resolveEffectiveReplyRoute ( {
302306 ctx : ctx ( {
303- Provider : "exec-event " ,
307+ InternalTurnSource : "exec" ,
304308 OriginatingChannel : "telegram" ,
305309 OriginatingTo : "chat:live" ,
306310 AccountId : "live-account" ,
@@ -323,31 +327,34 @@ describe("resolveEffectiveReplyRoute", () => {
323327 } ) ;
324328 } ) ;
325329
326- it ( "falls back to deliveryContext for exec-event replies" , ( ) => {
327- expect (
328- resolveEffectiveReplyRoute ( {
329- ctx : ctx ( { Provider : "exec-event" } ) ,
330- entry : {
331- delivery : normalizeSessionDeliveryState ( {
332- context : {
333- channel : "telegram" ,
334- to : "chat:persisted" ,
335- accountId : "persisted-account" ,
336- } ,
337- } ) ,
338- } ,
339- } ) ,
340- ) . toEqual ( {
341- channel : "telegram" ,
342- to : "chat:persisted" ,
343- accountId : "persisted-account" ,
344- } ) ;
345- } ) ;
330+ it . each ( [ "heartbeat" , "cron" , "exec" ] as const ) (
331+ "inherits session delivery for %s replies" ,
332+ ( source ) => {
333+ expect (
334+ resolveEffectiveReplyRoute ( {
335+ ctx : ctx ( { InternalTurnSource : source } ) ,
336+ entry : {
337+ delivery : normalizeSessionDeliveryState ( {
338+ context : {
339+ channel : "telegram" ,
340+ to : "chat:persisted" ,
341+ accountId : "persisted-account" ,
342+ } ,
343+ } ) ,
344+ } ,
345+ } ) ,
346+ ) . toEqual ( {
347+ channel : "telegram" ,
348+ to : "chat:persisted" ,
349+ accountId : "persisted-account" ,
350+ } ) ;
351+ } ,
352+ ) ;
346353
347354 it ( "falls back to legacy last route fields for exec-event replies" , ( ) => {
348355 expect (
349356 resolveEffectiveReplyRoute ( {
350- ctx : ctx ( { Provider : "exec-event " } ) ,
357+ ctx : ctx ( { InternalTurnSource : "exec" } ) ,
351358 entry : entry ( {
352359 lastChannel : "slack" ,
353360 lastTo : "last-to" ,
@@ -365,7 +372,7 @@ describe("resolveEffectiveReplyRoute", () => {
365372 expect (
366373 resolveEffectiveReplyRoute ( {
367374 ctx : ctx ( {
368- Provider : "exec-event " ,
375+ InternalTurnSource : "exec" ,
369376 OriginatingChannel : "telegram" ,
370377 OriginatingTo : "chat:live" ,
371378 } ) ,
@@ -388,7 +395,7 @@ describe("resolveEffectiveReplyRoute", () => {
388395 expect (
389396 resolveEffectiveReplyRoute ( {
390397 ctx : ctx ( {
391- Provider : "exec-event " ,
398+ InternalTurnSource : "exec" ,
392399 OriginatingChannel : "telegram" ,
393400 OriginatingTo : "chat:live" ,
394401 } ) ,
@@ -409,13 +416,3 @@ describe("resolveEffectiveReplyRoute", () => {
409416 } ) ;
410417 } ) ;
411418} ) ;
412-
413- describe ( "isSystemEventProvider" , ( ) => {
414- it ( "recognizes persisted-delivery event providers" , ( ) => {
415- expect ( isSystemEventProvider ( "heartbeat" ) ) . toBe ( true ) ;
416- expect ( isSystemEventProvider ( "cron-event" ) ) . toBe ( true ) ;
417- expect ( isSystemEventProvider ( "exec-event" ) ) . toBe ( true ) ;
418- expect ( isSystemEventProvider ( "slack" ) ) . toBe ( false ) ;
419- expect ( isSystemEventProvider ( undefined ) ) . toBe ( false ) ;
420- } ) ;
421- } ) ;
0 commit comments