diff --git a/extensions/matrix/src/channel.directory.test.ts b/extensions/matrix/src/channel.directory.test.ts index 4857ee93a3..5fc6bbe28f 100644 --- a/extensions/matrix/src/channel.directory.test.ts +++ b/extensions/matrix/src/channel.directory.test.ts @@ -1,4 +1,4 @@ -import type { PluginRuntime } from "openclaw/plugin-sdk"; +import type { PluginRuntime, RuntimeEnv } from "openclaw/plugin-sdk"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { matrixPlugin } from "./channel.js"; import { setMatrixRuntime } from "./runtime.js"; @@ -24,10 +24,18 @@ vi.mock("@vector-im/matrix-bot-sdk", () => ({ })); describe("matrix directory", () => { + const runtimeEnv: RuntimeEnv = { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn((code: number): never => { + throw new Error(`exit ${code}`); + }), + }; + beforeEach(() => { setMatrixRuntime({ state: { - resolveStateDir: (_env, homeDir) => homeDir(), + resolveStateDir: (_env, homeDir) => (homeDir ?? (() => "/tmp"))(), }, } as PluginRuntime); }); @@ -51,11 +59,12 @@ describe("matrix directory", () => { expect(matrixPlugin.directory?.listGroups).toBeTruthy(); await expect( - matrixPlugin.directory!.listPeers({ + matrixPlugin.directory!.listPeers!({ cfg, accountId: undefined, query: undefined, limit: undefined, + runtime: runtimeEnv, }), ).resolves.toEqual( expect.arrayContaining([ @@ -67,11 +76,12 @@ describe("matrix directory", () => { ); await expect( - matrixPlugin.directory!.listGroups({ + matrixPlugin.directory!.listGroups!({ cfg, accountId: undefined, query: undefined, limit: undefined, + runtime: runtimeEnv, }), ).resolves.toEqual( expect.arrayContaining([ @@ -130,11 +140,11 @@ describe("matrix directory", () => { }, } as unknown as CoreConfig; - expect(matrixPlugin.groups.resolveRequireMention({ cfg, groupId: "!room:example.org" })).toBe( + expect(matrixPlugin.groups!.resolveRequireMention!({ cfg, groupId: "!room:example.org" })).toBe( true, ); expect( - matrixPlugin.groups.resolveRequireMention({ + matrixPlugin.groups!.resolveRequireMention!({ cfg, accountId: "assistant", groupId: "!room:example.org", diff --git a/extensions/matrix/src/matrix/send.test.ts b/extensions/matrix/src/matrix/send.test.ts index 7f84f9385a..931a92e3aa 100644 --- a/extensions/matrix/src/matrix/send.test.ts +++ b/extensions/matrix/src/matrix/send.test.ts @@ -40,11 +40,13 @@ const runtimeStub = { loadConfig: () => ({}), }, media: { - loadWebMedia: (...args: unknown[]) => loadWebMediaMock(...args), - mediaKindFromMime: (...args: unknown[]) => mediaKindFromMimeMock(...args), - isVoiceCompatibleAudio: (...args: unknown[]) => isVoiceCompatibleAudioMock(...args), - getImageMetadata: (...args: unknown[]) => getImageMetadataMock(...args), - resizeToJpeg: (...args: unknown[]) => resizeToJpegMock(...args), + loadWebMedia: loadWebMediaMock as unknown as PluginRuntime["media"]["loadWebMedia"], + mediaKindFromMime: + mediaKindFromMimeMock as unknown as PluginRuntime["media"]["mediaKindFromMime"], + isVoiceCompatibleAudio: + isVoiceCompatibleAudioMock as unknown as PluginRuntime["media"]["isVoiceCompatibleAudio"], + getImageMetadata: getImageMetadataMock as unknown as PluginRuntime["media"]["getImageMetadata"], + resizeToJpeg: resizeToJpegMock as unknown as PluginRuntime["media"]["resizeToJpeg"], }, channel: { text: { diff --git a/extensions/mattermost/src/channel.test.ts b/extensions/mattermost/src/channel.test.ts index 64bd2bd0c3..cf178ab833 100644 --- a/extensions/mattermost/src/channel.test.ts +++ b/extensions/mattermost/src/channel.test.ts @@ -191,9 +191,10 @@ describe("mattermostPlugin", () => { describe("config", () => { it("formats allowFrom entries", () => { - const formatAllowFrom = mattermostPlugin.config.formatAllowFrom; + const formatAllowFrom = mattermostPlugin.config.formatAllowFrom!; const formatted = formatAllowFrom({ + cfg: {} as OpenClawConfig, allowFrom: ["@Alice", "user:USER123", "mattermost:BOT999"], }); expect(formatted).toEqual(["@alice", "user123", "bot999"]); diff --git a/extensions/msteams/src/attachments.test.ts b/extensions/msteams/src/attachments.test.ts index 5de4b9a587..f04e16040a 100644 --- a/extensions/msteams/src/attachments.test.ts +++ b/extensions/msteams/src/attachments.test.ts @@ -10,11 +10,12 @@ const saveMediaBufferMock = vi.fn(async () => ({ const runtimeStub = { media: { - detectMime: (...args: unknown[]) => detectMimeMock(...args), + detectMime: detectMimeMock as unknown as PluginRuntime["media"]["detectMime"], }, channel: { media: { - saveMediaBuffer: (...args: unknown[]) => saveMediaBufferMock(...args), + saveMediaBuffer: + saveMediaBufferMock as unknown as PluginRuntime["channel"]["media"]["saveMediaBuffer"], }, }, } as unknown as PluginRuntime; diff --git a/extensions/msteams/src/channel.directory.test.ts b/extensions/msteams/src/channel.directory.test.ts index e334edf999..26a9bec2f5 100644 --- a/extensions/msteams/src/channel.directory.test.ts +++ b/extensions/msteams/src/channel.directory.test.ts @@ -1,8 +1,16 @@ -import type { OpenClawConfig } from "openclaw/plugin-sdk"; +import type { OpenClawConfig, RuntimeEnv } from "openclaw/plugin-sdk"; import { describe, expect, it } from "vitest"; import { msteamsPlugin } from "./channel.js"; describe("msteams directory", () => { + const runtimeEnv: RuntimeEnv = { + log: () => {}, + error: () => {}, + exit: (code: number): never => { + throw new Error(`exit ${code}`); + }, + }; + it("lists peers and groups from config", async () => { const cfg = { channels: { @@ -26,7 +34,12 @@ describe("msteams directory", () => { expect(msteamsPlugin.directory?.listGroups).toBeTruthy(); await expect( - msteamsPlugin.directory!.listPeers({ cfg, query: undefined, limit: undefined }), + msteamsPlugin.directory!.listPeers!({ + cfg, + query: undefined, + limit: undefined, + runtime: runtimeEnv, + }), ).resolves.toEqual( expect.arrayContaining([ { kind: "user", id: "user:alice" }, @@ -37,7 +50,12 @@ describe("msteams directory", () => { ); await expect( - msteamsPlugin.directory!.listGroups({ cfg, query: undefined, limit: undefined }), + msteamsPlugin.directory!.listGroups!({ + cfg, + query: undefined, + limit: undefined, + runtime: runtimeEnv, + }), ).resolves.toEqual( expect.arrayContaining([ { kind: "group", id: "conversation:chan1" }, diff --git a/extensions/msteams/src/messenger.test.ts b/extensions/msteams/src/messenger.test.ts index 9ff3c0d286..977af0c966 100644 --- a/extensions/msteams/src/messenger.test.ts +++ b/extensions/msteams/src/messenger.test.ts @@ -125,6 +125,7 @@ describe("msteams messenger", () => { const adapter: MSTeamsAdapter = { continueConversation: async () => {}, + process: async () => {}, }; const ids = await sendMSTeamsMessages({ @@ -154,6 +155,7 @@ describe("msteams messenger", () => { }, }); }, + process: async () => {}, }; const ids = await sendMSTeamsMessages({ @@ -191,6 +193,7 @@ describe("msteams messenger", () => { const adapter: MSTeamsAdapter = { continueConversation: async () => {}, + process: async () => {}, }; const ids = await sendMSTeamsMessages({ @@ -250,6 +253,7 @@ describe("msteams messenger", () => { const adapter: MSTeamsAdapter = { continueConversation: async () => {}, + process: async () => {}, }; const ids = await sendMSTeamsMessages({ @@ -277,6 +281,7 @@ describe("msteams messenger", () => { const adapter: MSTeamsAdapter = { continueConversation: async () => {}, + process: async () => {}, }; await expect( @@ -310,6 +315,7 @@ describe("msteams messenger", () => { }, }); }, + process: async () => {}, }; const ids = await sendMSTeamsMessages({ diff --git a/extensions/nostr/src/nostr-state-store.test.ts b/extensions/nostr/src/nostr-state-store.test.ts index 23a8430c74..2dcb9d2d49 100644 --- a/extensions/nostr/src/nostr-state-store.test.ts +++ b/extensions/nostr/src/nostr-state-store.test.ts @@ -17,11 +17,13 @@ async function withTempStateDir(fn: (dir: string) => Promise) { setNostrRuntime({ state: { resolveStateDir: (env, homedir) => { - const override = env.OPENCLAW_STATE_DIR?.trim() || env.OPENCLAW_STATE_DIR?.trim(); + const stateEnv = env ?? process.env; + const override = stateEnv.OPENCLAW_STATE_DIR?.trim() || stateEnv.CLAWDBOT_STATE_DIR?.trim(); if (override) { return override; } - return path.join(homedir(), ".openclaw"); + const resolveHome = homedir ?? os.homedir; + return path.join(resolveHome(), ".openclaw"); }, }, } as PluginRuntime); @@ -90,7 +92,7 @@ describe("computeSinceTimestamp", () => { }); it("uses lastProcessedAt when available", () => { - const state = { + const state: Parameters[0] = { version: 2, lastProcessedAt: 1699999000, gatewayStartedAt: null, @@ -100,7 +102,7 @@ describe("computeSinceTimestamp", () => { }); it("uses gatewayStartedAt when lastProcessedAt is null", () => { - const state = { + const state: Parameters[0] = { version: 2, lastProcessedAt: null, gatewayStartedAt: 1699998000, @@ -110,7 +112,7 @@ describe("computeSinceTimestamp", () => { }); it("uses the max of both timestamps", () => { - const state = { + const state: Parameters[0] = { version: 2, lastProcessedAt: 1699999000, gatewayStartedAt: 1699998000, @@ -120,7 +122,7 @@ describe("computeSinceTimestamp", () => { }); it("falls back to now if both are null", () => { - const state = { + const state: Parameters[0] = { version: 2, lastProcessedAt: null, gatewayStartedAt: null,