fix(ci): restore plugin runtime boundaries

This commit is contained in:
Peter Steinberger
2026-03-27 14:38:40 +00:00
parent f9b8499bf6
commit 87dddb818d
24 changed files with 266 additions and 65 deletions

View File

@@ -55,7 +55,12 @@ vi.mock("./channel.runtime.js", () => ({
},
}));
import { feishuPlugin } from "./channel.js";
vi.mock("../../../src/channels/plugins/bundled.js", () => ({
bundledChannelPlugins: [],
bundledChannelSetupPlugins: [],
}));
let feishuPlugin: typeof import("./channel.js").feishuPlugin;
function getDescribedActions(cfg: OpenClawConfig): string[] {
return [...(feishuPlugin.actions?.describeMessageTool?.({ cfg })?.actions ?? [])];
@@ -97,6 +102,11 @@ async function expectLegacyFeishuCardPayloadRejected(cfg: OpenClawConfig, card:
}
describe("feishuPlugin.status.probeAccount", () => {
beforeEach(async () => {
vi.resetModules();
({ feishuPlugin } = await import("./channel.js"));
});
it("uses current account credentials for multi-account config", async () => {
const cfg = {
channels: {

View File

@@ -94,6 +94,11 @@ vi.mock("./subagent-hooks.js", () => ({
registerFeishuSubagentHooks: registerFeishuSubagentHooksMock,
}));
vi.mock("../../../src/channels/plugins/bundled.js", () => ({
bundledChannelPlugins: [],
bundledChannelSetupPlugins: [],
}));
const baseAccount: ResolvedFeishuAccount = {
accountId: "main",
selectionSource: "explicit",

View File

@@ -42,12 +42,15 @@ vi.mock("./runtime.js", () => ({
}),
}));
import {
downloadImageFeishu,
downloadMessageResourceFeishu,
sanitizeFileNameForUpload,
sendMediaFeishu,
} from "./media.js";
vi.mock("../../../src/channels/plugins/bundled.js", () => ({
bundledChannelPlugins: [],
bundledChannelSetupPlugins: [],
}));
let downloadImageFeishu: typeof import("./media.js").downloadImageFeishu;
let downloadMessageResourceFeishu: typeof import("./media.js").downloadMessageResourceFeishu;
let sanitizeFileNameForUpload: typeof import("./media.js").sanitizeFileNameForUpload;
let sendMediaFeishu: typeof import("./media.js").sendMediaFeishu;
function expectPathIsolatedToTmpRoot(pathValue: string, key: string): void {
expect(pathValue).not.toContain(key);
@@ -79,7 +82,14 @@ function mockResolvedFeishuAccount() {
}
describe("sendMediaFeishu msg_type routing", () => {
beforeEach(() => {
beforeEach(async () => {
vi.resetModules();
({
downloadImageFeishu,
downloadMessageResourceFeishu,
sanitizeFileNameForUpload,
sendMediaFeishu,
} = await import("./media.js"));
vi.clearAllMocks();
mockResolvedFeishuAccount();

View File

@@ -1,6 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../runtime-api.js";
import { resolveFeishuSendTarget } from "./send-target.js";
const resolveFeishuAccountMock = vi.hoisted(() => vi.fn());
const createFeishuClientMock = vi.hoisted(() => vi.fn());
@@ -14,11 +13,15 @@ vi.mock("./client.js", () => ({
createFeishuClient: createFeishuClientMock,
}));
let resolveFeishuSendTarget: typeof import("./send-target.js").resolveFeishuSendTarget;
describe("resolveFeishuSendTarget", () => {
const cfg = {} as ClawdbotConfig;
const client = { id: "client" };
beforeEach(() => {
beforeEach(async () => {
vi.resetModules();
({ resolveFeishuSendTarget } = await import("./send-target.js"));
resolveFeishuAccountMock.mockReset().mockReturnValue({
accountId: "default",
enabled: true,

View File

@@ -9,6 +9,7 @@ vi.mock("./send-target.js", () => ({
}));
vi.mock("./runtime.js", () => ({
setFeishuRuntime: vi.fn(),
getFeishuRuntime: () => ({
channel: {
text: {
@@ -19,7 +20,13 @@ vi.mock("./runtime.js", () => ({
}),
}));
import { sendCardFeishu, sendMessageFeishu } from "./send.js";
vi.mock("../../../src/channels/plugins/bundled.js", () => ({
bundledChannelPlugins: [],
bundledChannelSetupPlugins: [],
}));
let sendCardFeishu: typeof import("./send.js").sendCardFeishu;
let sendMessageFeishu: typeof import("./send.js").sendMessageFeishu;
describe("Feishu reply fallback for withdrawn/deleted targets", () => {
const replyMock = vi.fn();
@@ -35,7 +42,9 @@ describe("Feishu reply fallback for withdrawn/deleted targets", () => {
expect(result.messageId).toBe(expectedMessageId);
}
beforeEach(() => {
beforeEach(async () => {
vi.resetModules();
({ sendCardFeishu, sendMessageFeishu } = await import("./send.js"));
vi.clearAllMocks();
resolveFeishuSendTargetMock.mockReturnValue({
client: {

View File

@@ -1,12 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../runtime-api.js";
import {
buildStructuredCard,
editMessageFeishu,
getMessageFeishu,
listFeishuThreadMessages,
resolveFeishuCardTemplate,
} from "./send.js";
const {
mockClientGet,
@@ -42,8 +35,22 @@ vi.mock("./runtime.js", () => ({
}),
}));
let buildStructuredCard: typeof import("./send.js").buildStructuredCard;
let editMessageFeishu: typeof import("./send.js").editMessageFeishu;
let getMessageFeishu: typeof import("./send.js").getMessageFeishu;
let listFeishuThreadMessages: typeof import("./send.js").listFeishuThreadMessages;
let resolveFeishuCardTemplate: typeof import("./send.js").resolveFeishuCardTemplate;
describe("getMessageFeishu", () => {
beforeEach(() => {
beforeEach(async () => {
vi.resetModules();
({
buildStructuredCard,
editMessageFeishu,
getMessageFeishu,
listFeishuThreadMessages,
resolveFeishuCardTemplate,
} = await import("./send.js"));
vi.clearAllMocks();
mockResolveFeishuAccount.mockReturnValue({
accountId: "default",

View File

@@ -1,10 +1,6 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
import type { OpenClawPluginApi } from "../runtime-api.js";
import { registerFeishuBitableTools } from "./bitable.js";
import { registerFeishuDriveTools } from "./drive.js";
import { registerFeishuPermTools } from "./perm.js";
import { createToolFactoryHarness } from "./tool-factory-test-harness.js";
import { registerFeishuWikiTools } from "./wiki.js";
const createFeishuClientMock = vi.fn((account: { appId?: string } | undefined) => ({
__appId: account?.appId,
@@ -14,6 +10,11 @@ vi.mock("./client.js", () => ({
createFeishuClient: (account: { appId?: string } | undefined) => createFeishuClientMock(account),
}));
let registerFeishuBitableTools: typeof import("./bitable.js").registerFeishuBitableTools;
let registerFeishuDriveTools: typeof import("./drive.js").registerFeishuDriveTools;
let registerFeishuPermTools: typeof import("./perm.js").registerFeishuPermTools;
let registerFeishuWikiTools: typeof import("./wiki.js").registerFeishuWikiTools;
function createConfig(params: {
toolsA?: {
wiki?: boolean;
@@ -50,7 +51,16 @@ function createConfig(params: {
}
describe("feishu tool account routing", () => {
beforeEach(() => {
beforeEach(async () => {
vi.resetModules();
({ registerFeishuBitableTools, registerFeishuDriveTools, registerFeishuPermTools } =
await import("./bitable.js").then(async ({ registerFeishuBitableTools }) => ({
registerFeishuBitableTools,
...(await import("./drive.js")),
...(await import("./perm.js")),
...(await import("./wiki.js")),
})));
({ registerFeishuWikiTools } = await import("./wiki.js"));
vi.clearAllMocks();
});