@@ -21,6 +21,7 @@ vi.mock("./matrix/send.js", () => ({
2121} ) ) ;
2222
2323vi . mock ( "./runtime.js" , ( ) => ( {
24+ getOptionalMatrixRuntime : ( ) => undefined ,
2425 getMatrixRuntime : ( ) => ( {
2526 channel : {
2627 text : {
@@ -35,6 +36,8 @@ import { matrixPlugin } from "./channel.js";
3536const cfg = {
3637 channels : {
3738 matrix : {
39+ homeserver : "https://matrix.example.org" ,
40+ userId : "@bot:example.org" ,
3841 accessToken : "resolved-token" ,
3942 } ,
4043 } ,
@@ -68,6 +71,58 @@ describe("matrix channel message adapter", () => {
6871 expect ( matrixPlugin . meta . markdownCapable ) . toBe ( true ) ;
6972 } ) ;
7073
74+ it ( "opts ordinary durable text and media sends into Matrix reconciliation" , ( ) => {
75+ expect ( matrixPlugin . message ?. durableFinal ) . toMatchObject ( {
76+ automaticUnknownSendReconciliation : true ,
77+ capabilities : {
78+ text : true ,
79+ media : true ,
80+ afterCommit : true ,
81+ reconcileUnknownSend : true ,
82+ } ,
83+ reconcileUnknownSendKinds : { text : true , media : true } ,
84+ } ) ;
85+ expect ( matrixPlugin . message ?. durableFinal ?. capabilities ?. payload ) . not . toBe ( true ) ;
86+ expect ( matrixPlugin . message ?. durableFinal ?. capabilities ?. batch ) . not . toBe ( true ) ;
87+ } ) ;
88+
89+ it ( "forwards the exact durable part topology into Matrix sends" , async ( ) => {
90+ const sendText = matrixPlugin . message ?. send ?. text ;
91+ if ( ! sendText ) {
92+ throw new Error ( "Expected Matrix message adapter text sender" ) ;
93+ }
94+ await sendText ( {
95+ cfg,
96+ to : "room:!room:example" ,
97+ text : "durable" ,
98+ accountId : "default" ,
99+ deliveryQueueId : "queue-1" ,
100+ deliveryPartIndex : 2 ,
101+ deliveryPartCount : 3 ,
102+ } ) ;
103+
104+ expect ( lastMatrixSendOptions ( ) ) . toMatchObject ( {
105+ deliveryQueueId : "queue-1" ,
106+ deliveryPartIndex : 2 ,
107+ deliveryPartCount : 3 ,
108+ } ) ;
109+ } ) ;
110+
111+ it ( "routes the standard Matrix send action through canonical durable delivery" , async ( ) => {
112+ const prepareSendPayload = matrixPlugin . actions ?. prepareSendPayload ;
113+ if ( ! prepareSendPayload ) {
114+ throw new Error ( "Expected Matrix prepared-send adapter" ) ;
115+ }
116+ const payload = { text : "durable tool send" } ;
117+
118+ expect ( prepareSendPayload ( { ctx : { action : "send" , cfg } as never , payload } as never ) ) . toBe (
119+ payload ,
120+ ) ;
121+ expect (
122+ prepareSendPayload ( { ctx : { action : "edit" , cfg } as never , payload } as never ) ,
123+ ) . toBeNull ( ) ;
124+ } ) ;
125+
71126 it . each ( [
72127 {
73128 name : "the current room with reply quoting disabled" ,
@@ -224,6 +279,13 @@ describe("matrix channel message adapter", () => {
224279 messageSendingHooks : ( ) => {
225280 expect ( adapter . send ?. text ) . toBeTypeOf ( "function" ) ;
226281 } ,
282+ afterCommit : ( ) => {
283+ expect ( adapter . send ?. lifecycle ?. afterCommit ) . toBeTypeOf ( "function" ) ;
284+ } ,
285+ reconcileUnknownSend : ( ) => {
286+ expect ( adapter . durableFinal ?. reconcileUnknownSend ) . toBeTypeOf ( "function" ) ;
287+ expect ( adapter . durableFinal ?. afterUnknownSendTerminal ) . toBeTypeOf ( "function" ) ;
288+ } ,
227289 } ,
228290 } ) ;
229291 } ) ;
0 commit comments