refactor: expose plugin test helpers via sdk

This commit is contained in:
Peter Steinberger
2026-04-27 23:45:08 +01:00
parent 6f09039b0c
commit 0df6e5a473
126 changed files with 659 additions and 349 deletions

View File

@@ -1,5 +1,5 @@
import { createRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
import {
FeishuRetryableCardActionError,

View File

@@ -1,7 +1,7 @@
import type * as ConversationRuntime from "openclaw/plugin-sdk/conversation-runtime";
import type { ResolvedAgentRoute } from "openclaw/plugin-sdk/routing";
import { createRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig, PluginRuntime } from "../runtime-api.js";
import type { FeishuMessageEvent } from "./bot.js";
import { handleFeishuMessage } from "./bot.js";

View File

@@ -1,5 +1,5 @@
import { createRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { describe, expect, it, vi, beforeEach } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
import {
expectFirstSentCardUsesFillWidthOnly,

View File

@@ -1,6 +1,6 @@
import "./lifecycle.test-support.js";
import { createRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig } from "../runtime-api.js";
import {
getFeishuLifecycleTestMocks,
@@ -30,7 +30,7 @@ const {
} = getFeishuLifecycleTestMocks();
let _handlers: Record<string, (data: unknown) => Promise<void>> = {};
let lastRuntime: ReturnType<typeof createRuntimeEnv> | null = null;
let lastRuntime = createRuntimeEnv();
const originalStateDir = process.env.OPENCLAW_STATE_DIR;
const { cfg: lifecycleConfig, account: lifecycleAccount } = createFeishuLifecycleFixture({
accountId: "acct-acp",
@@ -78,7 +78,7 @@ describe("Feishu ACP-init failure lifecycle", () => {
vi.useRealTimers();
resetFeishuLifecycleTestMocks();
_handlers = {};
lastRuntime = null;
lastRuntime = createRuntimeEnv();
setFeishuLifecycleStateDir("openclaw-feishu-acp-failure");
resolveBoundConversationMock.mockReturnValue(null);

View File

@@ -1,5 +1,5 @@
import { createRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import "./lifecycle.test-support.js";
import {
getFeishuLifecycleTestMocks,
@@ -33,7 +33,7 @@ const {
} = getFeishuLifecycleTestMocks();
let _handlers: Record<string, (data: unknown) => Promise<void>> = {};
let lastRuntime: ReturnType<typeof createRuntimeEnv> | null = null;
let lastRuntime = createRuntimeEnv();
const originalStateDir = process.env.OPENCLAW_STATE_DIR;
const lifecycleConfig = createFeishuLifecycleConfig({
accountId: "acct-menu",
@@ -90,7 +90,7 @@ describe("Feishu bot-menu lifecycle", () => {
vi.useRealTimers();
resetFeishuLifecycleTestMocks();
_handlers = {};
lastRuntime = null;
lastRuntime = createRuntimeEnv();
setFeishuLifecycleStateDir("openclaw-feishu-bot-menu");
createFeishuReplyDispatcherMock.mockReturnValue(createFeishuLifecycleReplyDispatcher());

View File

@@ -1,6 +1,6 @@
import "./lifecycle.test-support.js";
import { createNonExitingRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createNonExitingRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
import { FeishuConfigSchema } from "./config-schema.js";
import {

View File

@@ -1,5 +1,5 @@
import { createRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import "./lifecycle.test-support.js";
import { resetProcessedFeishuCardActionTokensForTests } from "./card-action.js";
import { createFeishuCardInteractionEnvelope } from "./card-interaction.js";
@@ -35,7 +35,7 @@ const {
} = getFeishuLifecycleTestMocks();
let _handlers: Record<string, (data: unknown) => Promise<void>> = {};
let lastRuntime: ReturnType<typeof createRuntimeEnv> | null = null;
let lastRuntime = createRuntimeEnv();
const originalStateDir = process.env.OPENCLAW_STATE_DIR;
const lifecycleConfig = createFeishuLifecycleConfig({
accountId: "acct-card",
@@ -117,7 +117,7 @@ describe("Feishu card-action lifecycle", () => {
vi.useRealTimers();
resetFeishuLifecycleTestMocks();
_handlers = {};
lastRuntime = null;
lastRuntime = createRuntimeEnv();
resetProcessedFeishuCardActionTokensForTests();
setFeishuLifecycleStateDir("openclaw-feishu-card-action");

View File

@@ -1,5 +1,5 @@
import { createNonExitingRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createNonExitingRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig } from "../runtime-api.js";
import * as dedup from "./dedup.js";
import { createFeishuDriveCommentNoticeHandler } from "./monitor.comment-notice-handler.js";
@@ -11,7 +11,7 @@ import {
const handleFeishuCommentEventMock = vi.hoisted(() => vi.fn(async () => {}));
const createFeishuClientMock = vi.hoisted(() => vi.fn());
let lastRuntime: ReturnType<typeof createNonExitingRuntimeEnv> | null = null;
let lastRuntime = createNonExitingRuntimeEnv();
const TEST_DOC_TOKEN = "ZsJfdxrBFo0RwuxteOLc1Ekvneb";
const TEST_WIKI_TOKEN = "OtYpd5pKOoMeQzxrzkocv9KIn4H";
@@ -804,7 +804,7 @@ describe("resolveDriveCommentEventTurn", () => {
describe("drive.notice.comment_add_v1 monitor handler", () => {
beforeEach(() => {
lastRuntime = null;
lastRuntime = createNonExitingRuntimeEnv();
handleFeishuCommentEventMock.mockClear();
createFeishuClientMock.mockReset().mockReturnValue(makeOpenApiClient({}) as never);
vi.spyOn(dedup, "claimUnprocessedFeishuMessage").mockResolvedValue("claimed");

View File

@@ -3,8 +3,8 @@ import {
resolveInboundDebounceMs,
} from "openclaw/plugin-sdk/channel-inbound-debounce";
import { hasControlCommand } from "openclaw/plugin-sdk/command-detection";
import { createNonExitingTypedRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createNonExitingTypedRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
import { parseFeishuMessageEvent, type FeishuMessageEvent } from "./bot.js";
import * as dedup from "./dedup.js";

View File

@@ -1,5 +1,5 @@
import { createRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import "./lifecycle.test-support.js";
import {
getFeishuLifecycleTestMocks,
@@ -27,7 +27,7 @@ const {
withReplyDispatcherMock,
} = getFeishuLifecycleTestMocks();
let lastRuntime: ReturnType<typeof createRuntimeEnv> | null = null;
let lastRuntime = createRuntimeEnv();
let lifecycleCore: ReturnType<typeof installFeishuLifecycleReplyRuntime>;
const handleMessageMock = vi.fn();
const originalStateDir = process.env.OPENCLAW_STATE_DIR;
@@ -67,7 +67,7 @@ describe("Feishu reply-once lifecycle", () => {
vi.useRealTimers();
resetFeishuLifecycleTestMocks();
handleMessageMock.mockReset();
lastRuntime = null;
lastRuntime = createRuntimeEnv();
setFeishuLifecycleStateDir("openclaw-feishu-lifecycle");
createFeishuReplyDispatcherMock.mockReturnValue(createFeishuLifecycleReplyDispatcher());

View File

@@ -1,5 +1,5 @@
import { createNonExitingRuntimeEnv } from "openclaw/plugin-sdk/testing";
import { afterEach, describe, expect, it, vi } from "vitest";
import { createNonExitingRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import type { ClawdbotConfig } from "../runtime-api.js";
import { monitorFeishuProvider, stopFeishuMonitor } from "./monitor.js";

View File

@@ -1,11 +1,11 @@
import { describe, expect, it, vi } from "vitest";
import { createNonExitingTypedRuntimeEnv } from "../../../test/helpers/plugins/runtime-env.js";
import {
createNonExitingTypedRuntimeEnv,
createPluginSetupWizardConfigure,
createPluginSetupWizardStatus,
createTestWizardPrompter,
runSetupWizardConfigure,
} from "../../../test/helpers/plugins/setup-wizard.js";
} from "openclaw/plugin-sdk/testing";
import { describe, expect, it, vi } from "vitest";
vi.mock("./probe.js", () => ({
probeFeishu: vi.fn(async () => ({ ok: false, error: "mocked" })),