fix: honor live matrix dm scope for owner pins

This commit is contained in:
Eva
2026-05-01 23:21:54 +07:00
committed by Josh Lehman
parent 599beba44a
commit 2492ca4220
3 changed files with 47 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ type MatrixHandlerTestHarnessOptions = {
accountId?: string;
accountConfig?: MatrixConfig;
cfg?: unknown;
liveCfg?: unknown;
client?: Partial<MatrixClient>;
runtime?: RuntimeEnv;
logger?: RuntimeLogger;
@@ -192,7 +193,7 @@ export function createMatrixHandlerTestHarness(
} as never,
core: {
config: {
current: () => cfgForHandler,
current: () => options.liveCfg ?? cfgForHandler,
},
channel: {
pairing: {

View File

@@ -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"));

View File

@@ -1956,7 +1956,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
},
});
return resolvePinnedMainDmOwnerFromAllowlist({
dmScope: cfg.session?.dmScope,
dmScope: livePinnedCfg.session?.dmScope,
allowFrom: livePinnedDmAllowFrom,
normalizeEntry: normalizeMatrixUserId,
});