diff --git a/extensions/matrix/src/matrix/monitor/index.test.ts b/extensions/matrix/src/matrix/monitor/index.test.ts index 7dccced5c300..d7eaf3787e80 100644 --- a/extensions/matrix/src/matrix/monitor/index.test.ts +++ b/extensions/matrix/src/matrix/monitor/index.test.ts @@ -418,13 +418,21 @@ describe("monitorMatrixProvider", () => { } function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0, argIndex = 0): unknown { - const call = mock.mock.calls[index]; + const call = mock.mock.calls.at(index); if (!call) { throw new Error(`expected mock call ${index}`); } return call[argIndex]; } + function directRoomTrackerOptions(): DirectRoomTrackerOptions { + const opts = mockCallArg(hoisted.createDirectRoomTracker, 0, 1); + if (!opts || typeof opts !== "object") { + throw new Error("expected direct room tracker options"); + } + return opts as DirectRoomTrackerOptions; + } + function lastMockCallArg(mock: { mock: { calls: unknown[][] } }, argIndex = 0): unknown { const call = mock.mock.calls.at(-1); if (!call) { @@ -811,12 +819,9 @@ describe("monitorMatrixProvider", () => { it("resolves text chunk limit for the effective Matrix account", async () => { await startMonitorAndAbortAfterStartup(); - const textLimitCall = hoisted.resolveTextChunkLimit.mock.calls[0]; - if (textLimitCall?.[0] === undefined) { - throw new Error("Expected Matrix text chunk limit config argument"); - } - expect(textLimitCall?.[1]).toBe("matrix"); - expect(textLimitCall?.[2]).toBe("default"); + expect(mockCallArg(hoisted.resolveTextChunkLimit, 0, 0)).toBeDefined(); + expect(mockCallArg(hoisted.resolveTextChunkLimit, 0, 1)).toBe("matrix"); + expect(mockCallArg(hoisted.resolveTextChunkLimit, 0, 2)).toBe("default"); }); it("starts monitoring without waiting for best-effort deviceId backfill", async () => { @@ -931,7 +936,7 @@ describe("monitorMatrixProvider", () => { it("wires recent-invite promotion to fail closed when room metadata is unresolved", async () => { await startMonitorAndAbortAfterStartup(); - const trackerOpts = hoisted.createDirectRoomTracker.mock.calls[0]?.[1]; + const trackerOpts = directRoomTrackerOptions(); if (!trackerOpts?.canPromoteRecentInvite) { throw new Error("recent invite promotion callback was not wired"); } @@ -948,7 +953,7 @@ describe("monitorMatrixProvider", () => { it("wires recent-invite promotion to reject named rooms", async () => { await startMonitorAndAbortAfterStartup(); - const trackerOpts = hoisted.createDirectRoomTracker.mock.calls[0]?.[1]; + const trackerOpts = directRoomTrackerOptions(); if (!trackerOpts?.canPromoteRecentInvite) { throw new Error("recent invite promotion callback was not wired"); } @@ -970,7 +975,7 @@ describe("monitorMatrixProvider", () => { await startMonitorAndAbortAfterStartup(); - const trackerOpts = hoisted.createDirectRoomTracker.mock.calls[0]?.[1]; + const trackerOpts = directRoomTrackerOptions(); if (!trackerOpts?.canPromoteRecentInvite) { throw new Error("recent invite promotion callback was not wired"); } @@ -987,7 +992,7 @@ describe("monitorMatrixProvider", () => { it("does not wire unmapped strict room promotion for per-user DM scope", async () => { await startMonitorAndAbortAfterStartup(); - const trackerOpts = hoisted.createDirectRoomTracker.mock.calls[0]?.[1]; + const trackerOpts = directRoomTrackerOptions(); expect(trackerOpts?.canPromoteUnmappedStrictRoom).toBeUndefined(); }); @@ -997,7 +1002,7 @@ describe("monitorMatrixProvider", () => { await startMonitorAndAbortAfterStartup(); - const trackerOpts = hoisted.createDirectRoomTracker.mock.calls[0]?.[1]; + const trackerOpts = directRoomTrackerOptions(); if (!trackerOpts?.canPromoteUnmappedStrictRoom) { throw new Error("per-room strict fallback callback was not wired"); } @@ -1021,7 +1026,7 @@ describe("monitorMatrixProvider", () => { it("treats unresolved room metadata as indeterminate for local promotion revalidation", async () => { await startMonitorAndAbortAfterStartup(); - const trackerOpts = hoisted.createDirectRoomTracker.mock.calls[0]?.[1]; + const trackerOpts = directRoomTrackerOptions(); if (!trackerOpts?.shouldKeepLocallyPromotedDirectRoom) { throw new Error("local promotion revalidation callback was not wired"); }