mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 06:57:26 +00:00
chore: Fix remaining extension test types, enable type checking for extension tests.
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import type { OpenClawConfig, PluginRuntime } from "openclaw/plugin-sdk";
|
||||
import type {
|
||||
OpenClawConfig,
|
||||
PluginRuntime,
|
||||
ResolvedLineAccount,
|
||||
RuntimeEnv,
|
||||
} from "openclaw/plugin-sdk";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { linePlugin } from "./channel.js";
|
||||
import { setLineRuntime } from "./runtime.js";
|
||||
@@ -59,10 +64,27 @@ describe("linePlugin gateway.logoutAccount", () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
const runtimeEnv: RuntimeEnv = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn((code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
}),
|
||||
};
|
||||
const resolveAccount = mocks.resolveLineAccount as unknown as (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string;
|
||||
}) => ResolvedLineAccount;
|
||||
const account = resolveAccount({
|
||||
cfg,
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
});
|
||||
|
||||
const result = await linePlugin.gateway.logoutAccount({
|
||||
const result = await linePlugin.gateway!.logoutAccount!({
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
cfg,
|
||||
account,
|
||||
runtime: runtimeEnv,
|
||||
});
|
||||
|
||||
expect(result.cleared).toBe(true);
|
||||
@@ -86,10 +108,27 @@ describe("linePlugin gateway.logoutAccount", () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
const runtimeEnv: RuntimeEnv = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn((code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
}),
|
||||
};
|
||||
const resolveAccount = mocks.resolveLineAccount as unknown as (params: {
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string;
|
||||
}) => ResolvedLineAccount;
|
||||
const account = resolveAccount({
|
||||
cfg,
|
||||
accountId: "primary",
|
||||
});
|
||||
|
||||
const result = await linePlugin.gateway.logoutAccount({
|
||||
const result = await linePlugin.gateway!.logoutAccount!({
|
||||
accountId: "primary",
|
||||
cfg,
|
||||
account,
|
||||
runtime: runtimeEnv,
|
||||
});
|
||||
|
||||
expect(result.cleared).toBe(true);
|
||||
|
||||
@@ -105,8 +105,9 @@ describe("linePlugin outbound.sendPayload", () => {
|
||||
},
|
||||
};
|
||||
|
||||
await linePlugin.outbound.sendPayload({
|
||||
await linePlugin.outbound!.sendPayload!({
|
||||
to: "line:group:1",
|
||||
text: payload.text,
|
||||
payload,
|
||||
accountId: "default",
|
||||
cfg,
|
||||
@@ -140,8 +141,9 @@ describe("linePlugin outbound.sendPayload", () => {
|
||||
},
|
||||
};
|
||||
|
||||
await linePlugin.outbound.sendPayload({
|
||||
await linePlugin.outbound!.sendPayload!({
|
||||
to: "line:user:1",
|
||||
text: payload.text,
|
||||
payload,
|
||||
accountId: "default",
|
||||
cfg,
|
||||
@@ -172,8 +174,9 @@ describe("linePlugin outbound.sendPayload", () => {
|
||||
},
|
||||
};
|
||||
|
||||
await linePlugin.outbound.sendPayload({
|
||||
await linePlugin.outbound!.sendPayload!({
|
||||
to: "line:user:2",
|
||||
text: "",
|
||||
payload,
|
||||
accountId: "default",
|
||||
cfg,
|
||||
@@ -210,8 +213,9 @@ describe("linePlugin outbound.sendPayload", () => {
|
||||
},
|
||||
};
|
||||
|
||||
await linePlugin.outbound.sendPayload({
|
||||
await linePlugin.outbound!.sendPayload!({
|
||||
to: "line:user:3",
|
||||
text: payload.text,
|
||||
payload,
|
||||
accountId: "default",
|
||||
cfg,
|
||||
@@ -250,8 +254,9 @@ describe("linePlugin outbound.sendPayload", () => {
|
||||
},
|
||||
};
|
||||
|
||||
await linePlugin.outbound.sendPayload({
|
||||
await linePlugin.outbound!.sendPayload!({
|
||||
to: "line:user:3",
|
||||
text: payload.text,
|
||||
payload,
|
||||
accountId: "primary",
|
||||
cfg,
|
||||
@@ -266,7 +271,8 @@ describe("linePlugin outbound.sendPayload", () => {
|
||||
|
||||
describe("linePlugin config.formatAllowFrom", () => {
|
||||
it("strips line:user: prefixes without lowercasing", () => {
|
||||
const formatted = linePlugin.config.formatAllowFrom({
|
||||
const formatted = linePlugin.config.formatAllowFrom!({
|
||||
cfg: {} as OpenClawConfig,
|
||||
allowFrom: ["line:user:UABC", "line:UDEF"],
|
||||
});
|
||||
expect(formatted).toEqual(["UABC", "UDEF"]);
|
||||
@@ -295,7 +301,7 @@ describe("linePlugin groups.resolveRequireMention", () => {
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
|
||||
const requireMention = linePlugin.groups.resolveRequireMention({
|
||||
const requireMention = linePlugin.groups!.resolveRequireMention!({
|
||||
cfg,
|
||||
accountId: "primary",
|
||||
groupId: "group-1",
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import type { OpenClawConfig, PluginRuntime } from "openclaw/plugin-sdk";
|
||||
import type {
|
||||
ChannelGatewayContext,
|
||||
ChannelAccountSnapshot,
|
||||
OpenClawConfig,
|
||||
PluginRuntime,
|
||||
ResolvedLineAccount,
|
||||
RuntimeEnv,
|
||||
} from "openclaw/plugin-sdk";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { linePlugin } from "./channel.js";
|
||||
import { setLineRuntime } from "./runtime.js";
|
||||
@@ -26,18 +33,43 @@ function createRuntime() {
|
||||
return { runtime, probeLineBot, monitorLineProvider };
|
||||
}
|
||||
|
||||
function createStartAccountCtx(params: { token: string; secret: string; runtime: unknown }) {
|
||||
function createRuntimeEnv(): RuntimeEnv {
|
||||
return {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn((code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function createStartAccountCtx(params: {
|
||||
token: string;
|
||||
secret: string;
|
||||
runtime: RuntimeEnv;
|
||||
}): ChannelGatewayContext<ResolvedLineAccount> {
|
||||
const snapshot: ChannelAccountSnapshot = {
|
||||
accountId: "default",
|
||||
configured: true,
|
||||
enabled: true,
|
||||
running: false,
|
||||
};
|
||||
return {
|
||||
accountId: "default",
|
||||
account: {
|
||||
accountId: "default",
|
||||
enabled: true,
|
||||
channelAccessToken: params.token,
|
||||
channelSecret: params.secret,
|
||||
config: {},
|
||||
tokenSource: "config" as const,
|
||||
config: {} as ResolvedLineAccount["config"],
|
||||
},
|
||||
cfg: {} as OpenClawConfig,
|
||||
runtime: params.runtime,
|
||||
abortSignal: undefined,
|
||||
log: { info: vi.fn(), debug: vi.fn() },
|
||||
abortSignal: new AbortController().signal,
|
||||
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
|
||||
getStatus: () => snapshot,
|
||||
setStatus: vi.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,12 +79,12 @@ describe("linePlugin gateway.startAccount", () => {
|
||||
setLineRuntime(runtime);
|
||||
|
||||
await expect(
|
||||
linePlugin.gateway.startAccount(
|
||||
linePlugin.gateway!.startAccount!(
|
||||
createStartAccountCtx({
|
||||
token: "token",
|
||||
secret: " ",
|
||||
runtime: {},
|
||||
}) as never,
|
||||
runtime: createRuntimeEnv(),
|
||||
}),
|
||||
),
|
||||
).rejects.toThrow(
|
||||
'LINE webhook mode requires a non-empty channel secret for account "default".',
|
||||
@@ -65,12 +97,12 @@ describe("linePlugin gateway.startAccount", () => {
|
||||
setLineRuntime(runtime);
|
||||
|
||||
await expect(
|
||||
linePlugin.gateway.startAccount(
|
||||
linePlugin.gateway!.startAccount!(
|
||||
createStartAccountCtx({
|
||||
token: " ",
|
||||
secret: "secret",
|
||||
runtime: {},
|
||||
}) as never,
|
||||
runtime: createRuntimeEnv(),
|
||||
}),
|
||||
),
|
||||
).rejects.toThrow(
|
||||
'LINE webhook mode requires a non-empty channel access token for account "default".',
|
||||
@@ -82,12 +114,12 @@ describe("linePlugin gateway.startAccount", () => {
|
||||
const { runtime, monitorLineProvider } = createRuntime();
|
||||
setLineRuntime(runtime);
|
||||
|
||||
await linePlugin.gateway.startAccount(
|
||||
await linePlugin.gateway!.startAccount!(
|
||||
createStartAccountCtx({
|
||||
token: "token",
|
||||
secret: "secret",
|
||||
runtime: {},
|
||||
}) as never,
|
||||
runtime: createRuntimeEnv(),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(monitorLineProvider).toHaveBeenCalledWith(
|
||||
|
||||
Reference in New Issue
Block a user