@@ -47,10 +47,10 @@ function createMockBus() {
4747 } ;
4848}
4949
50- function createRuntimeHarness ( deliveredText = "|a|b|" ) {
50+ function createRuntimeHarness ( ) {
5151 const recordInboundSession = vi . fn ( async ( ) => { } ) ;
5252 const dispatchReplyWithBufferedBlockDispatcher = vi . fn ( async ( { dispatcherOptions } ) => {
53- await dispatcherOptions . deliver ( { text : deliveredText } ) ;
53+ await dispatcherOptions . deliver ( { text : "|a|b|" } ) ;
5454 } ) ;
5555 const convertMarkdownTables = vi . fn ( ( text : string ) => `converted:${ text } ` ) ;
5656 const runtime = {
@@ -99,9 +99,8 @@ function createRuntimeHarness(deliveredText = "|a|b|") {
9999async function startGatewayHarness ( params : {
100100 account : ReturnType < typeof buildResolvedNostrAccount > ;
101101 cfg ?: Parameters < typeof createStartAccountContext > [ 0 ] [ "cfg" ] ;
102- deliveredText ?: string ;
103102} ) {
104- const harness = createRuntimeHarness ( params . deliveredText ) ;
103+ const harness = createRuntimeHarness ( ) ;
105104 const bus = createMockBus ( ) ;
106105 setNostrRuntime ( harness . runtime ) ;
107106 mocks . startNostrBus . mockResolvedValueOnce ( bus as never ) ;
@@ -244,27 +243,45 @@ describe("nostr inbound gateway path", () => {
244243 expectedText : null ,
245244 } ,
246245 ] ) ( "$name" , async ( { deliveredText, expectedText } ) => {
246+ mocks . dispatchInboundDirectDm . mockImplementationOnce (
247+ async ( params : Parameters < typeof DispatchInboundDirectDm > [ 0 ] ) => {
248+ await params . deliver ( { text : deliveredText } ) ;
249+ } ,
250+ ) ;
247251 const { harness, cleanup } = await startGatewayHarness ( {
248252 account : buildResolvedNostrAccount ( {
249253 publicKey : "bot-pubkey" ,
250254 config : { dmPolicy : "allowlist" , allowFrom : [ "nostr:sender-pubkey" ] } ,
251255 } ) ,
252- deliveredText,
253256 } ) ;
254257 const options = mockCallArg ( mocks . startNostrBus ) as {
255258 onMessage : (
256259 senderPubkey : string ,
257260 text : string ,
258261 reply : ( text : string ) => Promise < void > ,
259262 meta : { eventId : string ; createdAt : number } ,
263+ lifecycle : NostrIngressLifecycle ,
260264 ) => Promise < void > ;
261265 } ;
262266 const sendReply = vi . fn ( async ( _text : string ) => { } ) ;
267+ const lifecycle : NostrIngressLifecycle = {
268+ abortSignal : new AbortController ( ) . signal ,
269+ onAdopted : vi . fn ( async ( ) => { } ) ,
270+ onDeferred : vi . fn ( ) ,
271+ onAdoptionFinalizing : vi . fn ( ) ,
272+ onAbandoned : vi . fn ( async ( ) => { } ) ,
273+ } ;
263274
264- await options . onMessage ( "sender-pubkey" , "hello from nostr" , sendReply , {
265- eventId : "event-123" ,
266- createdAt : 1_710_000_000 ,
267- } ) ;
275+ await options . onMessage (
276+ "sender-pubkey" ,
277+ "hello from nostr" ,
278+ sendReply ,
279+ {
280+ eventId : "event-123" ,
281+ createdAt : 1_710_000_000 ,
282+ } ,
283+ lifecycle ,
284+ ) ;
268285
269286 if ( expectedText === null ) {
270287 expect ( harness . convertMarkdownTables ) . not . toHaveBeenCalled ( ) ;
0 commit comments