test(commands): stabilize message e2e env and gateway mock

This commit is contained in:
Peter Steinberger
2026-02-21 18:36:59 +00:00
parent 1b585b2959
commit 1fd88af219

View File

@@ -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<string, unknown> = {};
@@ -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<typeof captureEnv>;
const setRegistry = async (registry: ReturnType<typeof createTestRegistry>) => {
const { setActivePluginRegistry } = await import("../plugins/runtime.js");
@@ -58,6 +59,7 @@ const setRegistry = async (registry: ReturnType<typeof createTestRegistry>) => {
};
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 = {