diff --git a/src/commands/message.e2e.test.ts b/src/commands/message.e2e.test.ts index a5ab9f36d4d..63be8ed6d03 100644 --- a/src/commands/message.e2e.test.ts +++ b/src/commands/message.e2e.test.ts @@ -1,4 +1,4 @@ -import { afterAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import type { ChannelMessageActionAdapter, ChannelOutboundAdapter, @@ -7,6 +7,7 @@ import type { import type { CliDeps } from "../cli/deps.js"; import type { RuntimeEnv } from "../runtime.js"; import { createTestRegistry } from "../test-utils/channel-plugins.js"; +import { captureEnv } from "../test-utils/env.js"; const loadMessageCommand = async () => await import("./message.js"); let testConfig: Record = {}; @@ -21,6 +22,7 @@ vi.mock("../config/config.js", async (importOriginal) => { const callGatewayMock = vi.fn(); vi.mock("../gateway/call.js", () => ({ callGateway: callGatewayMock, + callGatewayLeastPrivilege: callGatewayMock, randomIdempotencyKey: () => "idem-1", })); @@ -49,8 +51,7 @@ vi.mock("../agents/tools/whatsapp-actions.js", () => ({ handleWhatsAppAction, })); -const originalTelegramToken = process.env.TELEGRAM_BOT_TOKEN; -const originalDiscordToken = process.env.DISCORD_BOT_TOKEN; +let envSnapshot: ReturnType; const setRegistry = async (registry: ReturnType) => { const { setActivePluginRegistry } = await import("../plugins/runtime.js"); @@ -58,6 +59,7 @@ const setRegistry = async (registry: ReturnType) => { }; beforeEach(async () => { + envSnapshot = captureEnv(["TELEGRAM_BOT_TOKEN", "DISCORD_BOT_TOKEN"]); process.env.TELEGRAM_BOT_TOKEN = ""; process.env.DISCORD_BOT_TOKEN = ""; testConfig = {}; @@ -70,9 +72,8 @@ beforeEach(async () => { handleWhatsAppAction.mockReset(); }); -afterAll(() => { - process.env.TELEGRAM_BOT_TOKEN = originalTelegramToken; - process.env.DISCORD_BOT_TOKEN = originalDiscordToken; +afterEach(() => { + envSnapshot.restore(); }); const runtime: RuntimeEnv = {