diff --git a/extensions/matrix/src/matrix/monitor/handler.test-helpers.ts b/extensions/matrix/src/matrix/monitor/handler.test-helpers.ts index b0d486e090f..b75ad343ed3 100644 --- a/extensions/matrix/src/matrix/monitor/handler.test-helpers.ts +++ b/extensions/matrix/src/matrix/monitor/handler.test-helpers.ts @@ -23,6 +23,7 @@ type MatrixHandlerTestHarnessOptions = { accountId?: string; accountConfig?: MatrixConfig; cfg?: unknown; + liveCfg?: unknown; client?: Partial; runtime?: RuntimeEnv; logger?: RuntimeLogger; @@ -192,7 +193,7 @@ export function createMatrixHandlerTestHarness( } as never, core: { config: { - current: () => cfgForHandler, + current: () => options.liveCfg ?? cfgForHandler, }, channel: { pairing: { diff --git a/extensions/matrix/src/matrix/monitor/handler.test.ts b/extensions/matrix/src/matrix/monitor/handler.test.ts index a8278f4ce8c..d9036d85935 100644 --- a/extensions/matrix/src/matrix/monitor/handler.test.ts +++ b/extensions/matrix/src/matrix/monitor/handler.test.ts @@ -228,6 +228,50 @@ describe("matrix monitor handler pairing account scope", () => { ); }); + it("uses live dmScope when deciding whether to pin main DM route updates", async () => { + const startupCfg = { + session: { dmScope: "main" }, + channels: { + matrix: { + dm: { allowFrom: ["@owner:example.org"] }, + }, + }, + }; + const liveCfg = { + session: { dmScope: "per-channel-peer" }, + channels: { + matrix: { + dm: { allowFrom: ["@owner:example.org"] }, + }, + }, + }; + const { handler, recordInboundSession } = createMatrixHandlerTestHarness({ + cfg: startupCfg, + liveCfg, + dmPolicy: "allowlist", + allowFrom: ["@owner:example.org"], + allowFromResolvedEntries: [{ input: "@owner:example.org", id: "@owner:example.org" }], + isDirectMessage: true, + }); + + await handler( + "!dm:example.org", + createMatrixTextMessageEvent({ + eventId: "$owner-dm-live-scope", + sender: "@owner:example.org", + body: "hello", + }), + ); + + expect(recordInboundSession).toHaveBeenCalledWith( + expect.objectContaining({ + updateLastRoute: expect.objectContaining({ + mainDmOwnerPin: undefined, + }), + }), + ); + }); + it("sends pairing reminders for pending requests with cooldown", async () => { vi.useFakeTimers(); vi.setSystemTime(new Date("2026-03-01T10:00:00.000Z")); diff --git a/extensions/matrix/src/matrix/monitor/handler.ts b/extensions/matrix/src/matrix/monitor/handler.ts index da1ee646f23..7527397b1f1 100644 --- a/extensions/matrix/src/matrix/monitor/handler.ts +++ b/extensions/matrix/src/matrix/monitor/handler.ts @@ -1956,7 +1956,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam }, }); return resolvePinnedMainDmOwnerFromAllowlist({ - dmScope: cfg.session?.dmScope, + dmScope: livePinnedCfg.session?.dmScope, allowFrom: livePinnedDmAllowFrom, normalizeEntry: normalizeMatrixUserId, });