mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 01:13:29 +00:00
test(commands): stabilize message e2e env and gateway mock
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type {
|
import type {
|
||||||
ChannelMessageActionAdapter,
|
ChannelMessageActionAdapter,
|
||||||
ChannelOutboundAdapter,
|
ChannelOutboundAdapter,
|
||||||
@@ -7,6 +7,7 @@ import type {
|
|||||||
import type { CliDeps } from "../cli/deps.js";
|
import type { CliDeps } from "../cli/deps.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import { createTestRegistry } from "../test-utils/channel-plugins.js";
|
import { createTestRegistry } from "../test-utils/channel-plugins.js";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
const loadMessageCommand = async () => await import("./message.js");
|
const loadMessageCommand = async () => await import("./message.js");
|
||||||
|
|
||||||
let testConfig: Record<string, unknown> = {};
|
let testConfig: Record<string, unknown> = {};
|
||||||
@@ -21,6 +22,7 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
const callGatewayMock = vi.fn();
|
const callGatewayMock = vi.fn();
|
||||||
vi.mock("../gateway/call.js", () => ({
|
vi.mock("../gateway/call.js", () => ({
|
||||||
callGateway: callGatewayMock,
|
callGateway: callGatewayMock,
|
||||||
|
callGatewayLeastPrivilege: callGatewayMock,
|
||||||
randomIdempotencyKey: () => "idem-1",
|
randomIdempotencyKey: () => "idem-1",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -49,8 +51,7 @@ vi.mock("../agents/tools/whatsapp-actions.js", () => ({
|
|||||||
handleWhatsAppAction,
|
handleWhatsAppAction,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const originalTelegramToken = process.env.TELEGRAM_BOT_TOKEN;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
const originalDiscordToken = process.env.DISCORD_BOT_TOKEN;
|
|
||||||
|
|
||||||
const setRegistry = async (registry: ReturnType<typeof createTestRegistry>) => {
|
const setRegistry = async (registry: ReturnType<typeof createTestRegistry>) => {
|
||||||
const { setActivePluginRegistry } = await import("../plugins/runtime.js");
|
const { setActivePluginRegistry } = await import("../plugins/runtime.js");
|
||||||
@@ -58,6 +59,7 @@ const setRegistry = async (registry: ReturnType<typeof createTestRegistry>) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
envSnapshot = captureEnv(["TELEGRAM_BOT_TOKEN", "DISCORD_BOT_TOKEN"]);
|
||||||
process.env.TELEGRAM_BOT_TOKEN = "";
|
process.env.TELEGRAM_BOT_TOKEN = "";
|
||||||
process.env.DISCORD_BOT_TOKEN = "";
|
process.env.DISCORD_BOT_TOKEN = "";
|
||||||
testConfig = {};
|
testConfig = {};
|
||||||
@@ -70,9 +72,8 @@ beforeEach(async () => {
|
|||||||
handleWhatsAppAction.mockReset();
|
handleWhatsAppAction.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterEach(() => {
|
||||||
process.env.TELEGRAM_BOT_TOKEN = originalTelegramToken;
|
envSnapshot.restore();
|
||||||
process.env.DISCORD_BOT_TOKEN = originalDiscordToken;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const runtime: RuntimeEnv = {
|
const runtime: RuntimeEnv = {
|
||||||
|
|||||||
Reference in New Issue
Block a user