[plugin sdk] Harden finalize retry and run context cleanup (#75600)

Merged via squash.

Prepared head SHA: ec58a6212b
Co-authored-by: 100yenadmin <239388517+100yenadmin@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
Eva
2026-05-04 21:04:22 +07:00
committed by GitHub
parent 042d7b8823
commit 8afc9ef73c
22 changed files with 2112 additions and 128 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

@@ -1198,7 +1198,6 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
triggerSnapshot,
threadRootId: _threadRootId,
thread,
effectiveAllowFrom,
effectiveGroupAllowFrom,
effectiveRoomUsers,
} = resolvedIngressResult;
@@ -1940,11 +1939,27 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
onIdle: typingCallbacks.onIdle,
});
const pinnedMainDmOwner = isDirectMessage
? resolvePinnedMainDmOwnerFromAllowlist({
dmScope: cfg.session?.dmScope,
allowFrom: effectiveAllowFrom,
normalizeEntry: normalizeMatrixUserId,
})
? await (async () => {
const livePinnedCfg = core.config.current() as CoreConfig;
const livePinnedAllowlists = resolveMatrixAccountAllowlistConfig({
cfg: livePinnedCfg,
accountId,
});
const livePinnedDmAllowFrom = await resolveCachedLiveAllowlist({
cfg: livePinnedCfg,
entries: livePinnedAllowlists.dmAllowFrom,
startupResolvedEntries: allowFromResolvedEntries,
cache: liveDmAllowlistCache,
updateCache: (next) => {
liveDmAllowlistCache = next;
},
});
return resolvePinnedMainDmOwnerFromAllowlist({
dmScope: livePinnedCfg.session?.dmScope,
allowFrom: livePinnedDmAllowFrom,
normalizeEntry: normalizeMatrixUserId,
});
})()
: null;
const turnResult = await core.channel.turn.run({