diff --git a/extensions/matrix/src/approval-handler.runtime.test.ts b/extensions/matrix/src/approval-handler.runtime.test.ts index 5638be7912e..e97082a16b4 100644 --- a/extensions/matrix/src/approval-handler.runtime.test.ts +++ b/extensions/matrix/src/approval-handler.runtime.test.ts @@ -22,9 +22,9 @@ type MatrixPendingPluginApprovalView = Extract< const MATRIX_APPROVAL_METADATA_KEY = "com.openclaw.approval"; function expectRecordFields(value: unknown, expected: Record) { - expect(value).toBeDefined(); - expect(typeof value).toBe("object"); - expect(value).not.toBeNull(); + if (!value || typeof value !== "object") { + throw new Error("Expected record"); + } const actual = value as Record; for (const [key, expectedValue] of Object.entries(expected)) { expect(actual[key]).toEqual(expectedValue); diff --git a/extensions/matrix/src/channel.message-adapter.test.ts b/extensions/matrix/src/channel.message-adapter.test.ts index 3e54eec31c0..900d1c1918a 100644 --- a/extensions/matrix/src/channel.message-adapter.test.ts +++ b/extensions/matrix/src/channel.message-adapter.test.ts @@ -52,7 +52,6 @@ describe("matrix channel message adapter", () => { it("backs declared durable-final capabilities with runtime outbound proofs", async () => { const adapter = matrixPlugin.message; - expect(adapter).toBeDefined(); if (!adapter?.send?.text || !adapter.send.media) { throw new Error("Expected Matrix message adapter send capabilities."); } diff --git a/extensions/matrix/src/matrix/client.test.ts b/extensions/matrix/src/matrix/client.test.ts index c63f5f55992..19ab9984c53 100644 --- a/extensions/matrix/src/matrix/client.test.ts +++ b/extensions/matrix/src/matrix/client.test.ts @@ -71,7 +71,6 @@ function expectSavedCredentials( accountId: string, ) { const call = mock.mock.calls[0] as unknown[] | undefined; - expect(call).toBeDefined(); if (!call) { throw new Error("missing save credentials call"); } @@ -82,7 +81,6 @@ function expectSavedCredentials( function expectMatrixLoginCall(fields: Record) { const call = matrixDoRequestMock.mock.calls[0] as unknown[] | undefined; - expect(call).toBeDefined(); if (!call) { throw new Error("missing Matrix login call"); } diff --git a/extensions/matrix/src/matrix/monitor/handler.test.ts b/extensions/matrix/src/matrix/monitor/handler.test.ts index 85623c454c5..c5cbf91642a 100644 --- a/extensions/matrix/src/matrix/monitor/handler.test.ts +++ b/extensions/matrix/src/matrix/monitor/handler.test.ts @@ -140,15 +140,22 @@ function requireArray(value: unknown, label: string): Array { function mockCalls(mock: unknown, label: string): Array> { const mockState = (mock as { mock?: { calls?: Array> } }).mock; - expect(mockState, `${label}.mock`).toBeDefined(); - expect(Array.isArray(mockState?.calls), `${label}.mock.calls`).toBe(true); - return mockState?.calls ?? []; + if (!mockState) { + throw new Error(`${label}.mock was missing`); + } + const calls = mockState.calls; + if (!Array.isArray(calls)) { + throw new Error(`${label}.mock.calls was not an array`); + } + return calls; } function callArg(mock: unknown, callIndex: number, argIndex: number, label: string) { const call = mockCalls(mock, label).at(callIndex); - expect(call, label).toBeDefined(); - return call?.[argIndex]; + if (!call) { + throw new Error(`${label} call ${callIndex} was missing`); + } + return call[argIndex]; } function lastCallArg(mock: unknown, argIndex: number, label: string) { @@ -182,8 +189,10 @@ function expectRuntimeErrorContaining(mock: unknown, text: string) { function findMockCall(mock: unknown, label: string, predicate: (call: Array) => boolean) { const call = mockCalls(mock, label).find(predicate); - expect(call, label).toBeDefined(); - return call as Array; + if (!call) { + throw new Error(`${label} was missing`); + } + return call; } function expectMatrixEdit(roomId: string, eventId: string, body: string) { @@ -193,7 +202,7 @@ function expectMatrixEdit(roomId: string, eventId: string, body: string) { ([room, editedEventId, editedBody]) => room === roomId && editedEventId === eventId && editedBody === body, ); - expect(call[3], "edit options").toBeDefined(); + requireRecord(call[3], "edit options"); } function expectFinalizedPreviewEdit(eventId: string, text: string) { @@ -730,7 +739,7 @@ describe("matrix monitor handler pairing account scope", () => { ); expect(callArg(hasControlCommand, 0, 0, "control command")).toBe("/new"); - expect(callArg(hasControlCommand, 0, 1, "control command")).toBeDefined(); + requireRecord(callArg(hasControlCommand, 0, 1, "control command"), "control command context"); expect(recordInboundSession).not.toHaveBeenCalled(); expect(finalizeInboundContext).not.toHaveBeenCalled(); }); @@ -756,7 +765,7 @@ describe("matrix monitor handler pairing account scope", () => { ); expect(callArg(hasControlCommand, 0, 0, "control command")).toBe("/new"); - expect(callArg(hasControlCommand, 0, 1, "control command")).toBeDefined(); + requireRecord(callArg(hasControlCommand, 0, 1, "control command"), "control command context"); const context = requireRecord( callArg(finalizeInboundContext, 0, 0, "finalized context"), "finalized context", @@ -1083,7 +1092,6 @@ describe("matrix monitor handler pairing account scope", () => { ); expect(callArg(sendNotice, 0, 0, "send notice")).toBe("!dm:example.org"); - expect(callArg(sendNotice, 0, 1, "send notice")).toBeDefined(); expectNoticeSent(sendNotice); await handler( @@ -1138,7 +1146,6 @@ describe("matrix monitor handler pairing account scope", () => { ); expect(callArg(sendNotice, 0, 0, "send notice")).toBe("!dm:example.org"); - expect(callArg(sendNotice, 0, 1, "send notice")).toBeDefined(); expectNoticeSent(sendNotice); } finally { fs.rmSync(tempDir, { recursive: true, force: true }); @@ -1191,7 +1198,6 @@ describe("matrix monitor handler pairing account scope", () => { ); expect(callArg(sendNotice, 0, 0, "send notice")).toBe("!dm:example.org"); - expect(callArg(sendNotice, 0, 1, "send notice")).toBeDefined(); expectNoticeSent(sendNotice); } finally { fs.rmSync(tempDir, { recursive: true, force: true }); @@ -1234,7 +1240,6 @@ describe("matrix monitor handler pairing account scope", () => { ); expect(callArg(sendNotice, 0, 0, "send notice")).toBe("!dm:example.org"); - expect(callArg(sendNotice, 0, 1, "send notice")).toBeDefined(); expectNoticeSent(sendNotice); } finally { fs.rmSync(tempDir, { recursive: true, force: true }); diff --git a/extensions/matrix/src/matrix/subagent-hooks.test.ts b/extensions/matrix/src/matrix/subagent-hooks.test.ts index c75baeb76c1..f1b0da8de39 100644 --- a/extensions/matrix/src/matrix/subagent-hooks.test.ts +++ b/extensions/matrix/src/matrix/subagent-hooks.test.ts @@ -114,7 +114,6 @@ function requireBindCallWithTarget(targetSessionKey: string) { const record = params as { targetSessionKey?: string }; return record.targetSessionKey === targetSessionKey; }); - expect(call).toBeDefined(); if (!call) { throw new Error(`missing bind call for ${targetSessionKey}`); }