From ca74eb37da0be38ba0c5d31612ba6887c8cf3313 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 19 Mar 2026 09:06:39 -0700 Subject: [PATCH] fix(extensions): repair matrix contracts and test boundaries --- extensions/matrix/src/channel.ts | 6 +++--- .../src/matrix/monitor/handler.media-failure.test.ts | 1 + extensions/matrix/src/matrix/monitor/handler.test.ts | 1 + .../src/matrix/monitor/handler.thread-root-media.test.ts | 1 + test/helpers/extensions/plugin-routing.ts | 7 +++++++ 5 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 test/helpers/extensions/plugin-routing.ts diff --git a/extensions/matrix/src/channel.ts b/extensions/matrix/src/channel.ts index 34b6b9610e3..e02e12d881d 100644 --- a/extensions/matrix/src/channel.ts +++ b/extensions/matrix/src/channel.ts @@ -434,7 +434,7 @@ export const matrixPlugin: ChannelPlugin = { // // INVARIANT: The import() below cannot hang because: // 1. It only loads local ESM modules with no circular awaits - // 2. Module initialization is synchronous (no top-level await in ./matrix/index.js) + // 2. Module initialization is synchronous (no top-level await in ./matrix/monitor/index.js) // 3. The lock only serializes the import phase, not the provider startup const previousLock = matrixStartupLock; let releaseLock: () => void = () => {}; @@ -445,9 +445,9 @@ export const matrixPlugin: ChannelPlugin = { // Lazy import: the monitor pulls the reply pipeline; avoid ESM init cycles. // Wrap in try/finally to ensure lock is released even if import fails. - let monitorMatrixProvider: typeof import("./matrix/index.js").monitorMatrixProvider; + let monitorMatrixProvider: typeof import("./matrix/monitor/index.js").monitorMatrixProvider; try { - const module = await import("./matrix/index.js"); + const module = await import("./matrix/monitor/index.js"); monitorMatrixProvider = module.monitorMatrixProvider; } finally { // Release lock after import completes or fails diff --git a/extensions/matrix/src/matrix/monitor/handler.media-failure.test.ts b/extensions/matrix/src/matrix/monitor/handler.media-failure.test.ts index 25f17cb0254..d8a0432627b 100644 --- a/extensions/matrix/src/matrix/monitor/handler.media-failure.test.ts +++ b/extensions/matrix/src/matrix/monitor/handler.media-failure.test.ts @@ -104,6 +104,7 @@ function createHandlerHarness() { directTracker: { isDirectMessage: vi.fn().mockResolvedValue(true), }, + dropPreStartupMessages: true, getRoomInfo: vi.fn().mockResolvedValue({ name: "Media Room", canonicalAlias: "#media:example.org", diff --git a/extensions/matrix/src/matrix/monitor/handler.test.ts b/extensions/matrix/src/matrix/monitor/handler.test.ts index fc55012a6b5..a02a0a825fb 100644 --- a/extensions/matrix/src/matrix/monitor/handler.test.ts +++ b/extensions/matrix/src/matrix/monitor/handler.test.ts @@ -594,6 +594,7 @@ describe("matrix monitor handler pairing account scope", () => { directTracker: { isDirectMessage: async () => false, }, + dropPreStartupMessages: true, getRoomInfo: async () => ({ altAliases: [] }), getMemberDisplayName: async () => "sender", needsRoomAliasesForConfig: false, diff --git a/extensions/matrix/src/matrix/monitor/handler.thread-root-media.test.ts b/extensions/matrix/src/matrix/monitor/handler.thread-root-media.test.ts index c08452cd76b..c3d42d87d11 100644 --- a/extensions/matrix/src/matrix/monitor/handler.thread-root-media.test.ts +++ b/extensions/matrix/src/matrix/monitor/handler.thread-root-media.test.ts @@ -119,6 +119,7 @@ describe("createMatrixRoomMessageHandler thread root media", () => { directTracker: { isDirectMessage: vi.fn().mockResolvedValue(true), }, + dropPreStartupMessages: true, getRoomInfo: vi.fn().mockResolvedValue({ name: "Media Room", canonicalAlias: "#media:example.org", diff --git a/test/helpers/extensions/plugin-routing.ts b/test/helpers/extensions/plugin-routing.ts new file mode 100644 index 00000000000..33e8b0f67c1 --- /dev/null +++ b/test/helpers/extensions/plugin-routing.ts @@ -0,0 +1,7 @@ +export { + __testing as sessionBindingTesting, + registerSessionBindingAdapter, +} from "../../../src/infra/outbound/session-binding-service.js"; +export { setActivePluginRegistry } from "../../../src/plugins/runtime.js"; +export { resolveAgentRoute } from "../../../src/routing/resolve-route.js"; +export { createTestRegistry } from "../../../src/test-utils/channel-plugins.js";