test: trim extension test import churn

This commit is contained in:
Peter Steinberger
2026-04-03 04:37:34 +01:00
parent 2f013b68f8
commit 847faa3d04
87 changed files with 293 additions and 286 deletions

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../runtime-api.js";
import { createFeishuCardInteractionEnvelope } from "./card-interaction.js";
import { looksLikeFeishuId, normalizeFeishuTarget, resolveReceiveIdType } from "./targets.js";
@@ -101,12 +101,11 @@ async function expectLegacyFeishuCardPayloadRejected(cfg: OpenClawConfig, card:
expect(sendCardFeishuMock).not.toHaveBeenCalled();
}
describe("feishuPlugin.status.probeAccount", () => {
beforeEach(async () => {
vi.resetModules();
({ feishuPlugin } = await import("./channel.js"));
});
beforeAll(async () => {
({ feishuPlugin } = await import("./channel.js"));
});
describe("feishuPlugin.status.probeAccount", () => {
it("uses current account credentials for multi-account config", async () => {
const cfg = {
channels: {
@@ -145,9 +144,7 @@ describe("feishuPlugin.status.probeAccount", () => {
});
describe("feishuPlugin.pairing.notifyApproval", () => {
beforeEach(async () => {
vi.resetModules();
({ feishuPlugin } = await import("./channel.js"));
beforeEach(() => {
sendMessageFeishuMock.mockReset();
sendMessageFeishuMock.mockResolvedValue({ messageId: "pairing-msg", chatId: "ou_user" });
});
@@ -184,11 +181,6 @@ describe("feishuPlugin.pairing.notifyApproval", () => {
});
describe("feishuPlugin messaging", () => {
beforeEach(async () => {
vi.resetModules();
({ feishuPlugin } = await import("./channel.js"));
});
it("owns sender/topic session inheritance candidates", () => {
expect(
feishuPlugin.messaging?.resolveSessionConversation?.({

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { createTestPluginApi } from "../../../test/helpers/plugins/plugin-api.js";
import { createPluginRuntimeMock } from "../../../test/helpers/plugins/plugin-runtime-mock.js";
import type { OpenClawPluginApi } from "../runtime-api.js";
@@ -30,8 +30,11 @@ describe("registerFeishuChatTools", () => {
});
}
beforeAll(async () => {
({ registerFeishuChatTools } = await import("./chat.js"));
});
beforeEach(() => {
vi.resetModules();
vi.clearAllMocks();
createFeishuClientMock.mockReturnValue({
im: {
@@ -44,10 +47,6 @@ describe("registerFeishuChatTools", () => {
});
});
beforeEach(async () => {
({ registerFeishuChatTools } = await import("./chat.js"));
});
it("registers feishu_chat and handles info/members actions", async () => {
const registerTool = vi.fn();
registerFeishuChatTools(

View File

@@ -133,7 +133,6 @@ function firstWsClientOptions(): { agent?: unknown } {
}
beforeAll(async () => {
vi.resetModules();
vi.doMock("@larksuiteoapi/node-sdk", () => ({
AppType: { SelfBuild: "self" },
Domain: { Feishu: "https://open.feishu.cn", Lark: "https://open.larksuite.com" },

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
import type { OpenClawPluginApi } from "../runtime-api.js";
import { createToolFactoryHarness } from "./tool-factory-test-harness.js";
@@ -22,9 +22,11 @@ vi.mock("@larksuiteoapi/node-sdk", () => {
describe("feishu_doc account selection", () => {
let registerFeishuDocTools: typeof import("./docx.js").registerFeishuDocTools;
beforeEach(async () => {
vi.resetModules();
beforeAll(async () => {
({ registerFeishuDocTools } = await import("./docx.js"));
});
beforeEach(() => {
vi.clearAllMocks();
});

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { createTestPluginApi } from "../../../test/helpers/plugins/plugin-api.js";
import { createPluginRuntimeMock } from "../../../test/helpers/plugins/plugin-runtime-mock.js";
import type { OpenClawPluginApi } from "../runtime-api.js";
@@ -31,10 +31,12 @@ function createDriveToolApi(params: {
describe("registerFeishuDriveTools", () => {
const requestMock = vi.fn();
beforeEach(async () => {
vi.resetModules();
vi.clearAllMocks();
beforeAll(async () => {
({ registerFeishuDriveTools } = await import("./drive.js"));
});
beforeEach(() => {
vi.clearAllMocks();
resolveAnyEnabledFeishuToolsConfigMock.mockReturnValue({
doc: false,
chat: false,

View File

@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import path from "node:path";
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../runtime-api.js";
const createFeishuClientMock = vi.hoisted(() => vi.fn());
@@ -82,14 +82,16 @@ function mockResolvedFeishuAccount() {
}
describe("sendMediaFeishu msg_type routing", () => {
beforeEach(async () => {
vi.resetModules();
beforeAll(async () => {
({
downloadImageFeishu,
downloadMessageResourceFeishu,
sanitizeFileNameForUpload,
sendMediaFeishu,
} = await import("./media.js"));
});
beforeEach(() => {
vi.clearAllMocks();
mockResolvedFeishuAccount();

View File

@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const createFeishuClientMock = vi.hoisted(() => vi.fn());
@@ -6,12 +6,6 @@ vi.mock("./client.js", () => ({
createFeishuClient: createFeishuClientMock,
}));
async function importProbeModule(scope: string) {
void scope;
vi.resetModules();
return await import("./probe.js");
}
let FEISHU_PROBE_REQUEST_TIMEOUT_MS: typeof import("./probe.js").FEISHU_PROBE_REQUEST_TIMEOUT_MS;
let probeFeishu: typeof import("./probe.js").probeFeishu;
let clearProbeCache: typeof import("./probe.js").clearProbeCache;
@@ -106,10 +100,12 @@ async function readSequentialDefaultProbePair() {
}
describe("probeFeishu", () => {
beforeEach(async () => {
({ FEISHU_PROBE_REQUEST_TIMEOUT_MS, probeFeishu, clearProbeCache } = await importProbeModule(
`probe-${Date.now()}-${Math.random()}`,
));
beforeAll(async () => {
({ FEISHU_PROBE_REQUEST_TIMEOUT_MS, probeFeishu, clearProbeCache } =
await import("./probe.js"));
});
beforeEach(() => {
clearProbeCache();
vi.restoreAllMocks();
});

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../runtime-api.js";
const resolveFeishuAccountMock = vi.hoisted(() => vi.fn());
@@ -19,9 +19,11 @@ describe("resolveFeishuSendTarget", () => {
const cfg = {} as ClawdbotConfig;
const client = { id: "client" };
beforeEach(async () => {
vi.resetModules();
beforeAll(async () => {
({ resolveFeishuSendTarget } = await import("./send-target.js"));
});
beforeEach(() => {
resolveFeishuAccountMock.mockReset().mockReturnValue({
accountId: "default",
enabled: true,

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const resolveFeishuSendTargetMock = vi.hoisted(() => vi.fn());
const resolveMarkdownTableModeMock = vi.hoisted(() => vi.fn(() => "preserve"));
@@ -42,9 +42,11 @@ describe("Feishu reply fallback for withdrawn/deleted targets", () => {
expect(result.messageId).toBe(expectedMessageId);
}
beforeEach(async () => {
vi.resetModules();
beforeAll(async () => {
({ sendCardFeishu, sendMessageFeishu } = await import("./send.js"));
});
beforeEach(() => {
vi.clearAllMocks();
resolveFeishuSendTargetMock.mockReturnValue({
client: {

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../runtime-api.js";
const {
@@ -59,8 +59,7 @@ let resolveFeishuCardTemplate: typeof import("./send.js").resolveFeishuCardTempl
let sendMessageFeishu: typeof import("./send.js").sendMessageFeishu;
describe("getMessageFeishu", () => {
beforeEach(async () => {
vi.resetModules();
beforeAll(async () => {
({
buildStructuredCard,
editMessageFeishu,
@@ -69,6 +68,9 @@ describe("getMessageFeishu", () => {
resolveFeishuCardTemplate,
sendMessageFeishu,
} = await import("./send.js"));
});
beforeEach(() => {
vi.clearAllMocks();
mockResolveMarkdownTableMode.mockReturnValue("preserve");
mockConvertMarkdownTables.mockImplementation((text: string) => text);

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
import type { OpenClawPluginApi } from "../runtime-api.js";
import { createToolFactoryHarness } from "./tool-factory-test-harness.js";
@@ -51,8 +51,7 @@ function createConfig(params: {
}
describe("feishu tool account routing", () => {
beforeEach(async () => {
vi.resetModules();
beforeAll(async () => {
({ registerFeishuBitableTools, registerFeishuDriveTools, registerFeishuPermTools } =
await import("./bitable.js").then(async ({ registerFeishuBitableTools }) => ({
registerFeishuBitableTools,
@@ -61,6 +60,9 @@ describe("feishu tool account routing", () => {
...(await import("./wiki.js")),
})));
({ registerFeishuWikiTools } = await import("./wiki.js"));
});
beforeEach(() => {
vi.clearAllMocks();
});