chore: Fix more extension test types, 2/N.

This commit is contained in:
cpojer
2026-02-17 10:12:34 +09:00
parent 72f00df95a
commit a741985574
7 changed files with 63 additions and 23 deletions

View File

@@ -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",

View File

@@ -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: {

View File

@@ -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"]);

View File

@@ -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;

View File

@@ -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" },

View File

@@ -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({

View File

@@ -17,11 +17,13 @@ async function withTempStateDir<T>(fn: (dir: string) => Promise<T>) {
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<typeof computeSinceTimestamp>[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<typeof computeSinceTimestamp>[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<typeof computeSinceTimestamp>[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<typeof computeSinceTimestamp>[0] = {
version: 2,
lastProcessedAt: null,
gatewayStartedAt: null,