Skip to content

Commit 86921b6

Browse files
committed
test: speed up telegram extension suites
1 parent a29b9f2 commit 86921b6

11 files changed

+64
-30
lines changed

extensions/telegram/src/bot-message-context.acp-bindings.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22

33
const ensureConfiguredBindingRouteReadyMock = vi.hoisted(() => vi.fn());
44
const resolveConfiguredBindingRouteMock = vi.hoisted(() => vi.fn());
@@ -128,14 +128,17 @@ function createConfiguredTelegramRoute() {
128128
}
129129

130130
describe("buildTelegramMessageContext ACP configured bindings", () => {
131-
beforeEach(async () => {
131+
beforeAll(async () => {
132132
vi.resetModules();
133+
({ buildTelegramMessageContextForTest } =
134+
await import("./bot-message-context.test-harness.js"));
135+
});
136+
137+
beforeEach(() => {
133138
ensureConfiguredBindingRouteReadyMock.mockReset();
134139
resolveConfiguredBindingRouteMock.mockReset();
135140
resolveConfiguredBindingRouteMock.mockReturnValue(createConfiguredTelegramRoute());
136141
ensureConfiguredBindingRouteReadyMock.mockResolvedValue({ ok: true });
137-
({ buildTelegramMessageContextForTest } =
138-
await import("./bot-message-context.test-harness.js"));
139142
});
140143

141144
it("treats configured topic bindings as explicit route matches on non-default accounts", async () => {

extensions/telegram/src/bot-message-context.audio-transcript.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22

33
const transcribeFirstAudioMock = vi.fn();
44
const DEFAULT_MODEL = "anthropic/claude-opus-4-5";
@@ -75,13 +75,16 @@ function expectAudioPlaceholderRendered(ctx: Awaited<ReturnType<typeof buildGrou
7575
}
7676

7777
describe("buildTelegramMessageContext audio transcript body", () => {
78-
beforeEach(async () => {
78+
beforeAll(async () => {
7979
vi.resetModules();
80-
transcribeFirstAudioMock.mockReset();
8180
({ buildTelegramMessageContextForTest } =
8281
await import("./bot-message-context.test-harness.js"));
8382
});
8483

84+
beforeEach(() => {
85+
transcribeFirstAudioMock.mockReset();
86+
});
87+
8588
it("uses preflight transcript as BodyForAgent for mention-gated group voice messages", async () => {
8689
transcribeFirstAudioMock.mockResolvedValueOnce("hey bot please help");
8790

extensions/telegram/src/bot-message-context.dm-threads.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22

33
let buildTelegramMessageContextForTest: typeof import("./bot-message-context.test-harness.js").buildTelegramMessageContextForTest;
44
let clearRuntimeConfigSnapshot: typeof import("../../../src/config/config.js").clearRuntimeConfigSnapshot;
55
let setRuntimeConfigSnapshot: typeof import("../../../src/config/config.js").setRuntimeConfigSnapshot;
66

7-
beforeEach(async () => {
7+
beforeAll(async () => {
88
vi.resetModules();
99
({ buildTelegramMessageContextForTest } = await import("./bot-message-context.test-harness.js"));
1010
({ clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } =
1111
await import("../../../src/config/config.js"));
12+
});
13+
14+
beforeEach(() => {
1215
clearRuntimeConfigSnapshot();
1316
});
1417

extensions/telegram/src/bot-message-context.dm-topic-threadid.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22

33
// Mock recordInboundSession to capture updateLastRoute parameter
44
const recordInboundSessionMock = vi.fn().mockResolvedValue(undefined);
@@ -36,13 +36,17 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
3636
recordInboundSessionMock.mockClear();
3737
});
3838

39-
beforeEach(async () => {
39+
beforeAll(async () => {
4040
vi.resetModules();
4141
({ clearRuntimeConfigSnapshot } = await import("../../../src/config/config.js"));
4242
({ buildTelegramMessageContextForTest } =
4343
await import("./bot-message-context.test-harness.js"));
4444
});
4545

46+
beforeEach(() => {
47+
recordInboundSessionMock.mockClear();
48+
});
49+
4650
it("passes threadId to updateLastRoute for DM topics", async () => {
4751
const ctx = await buildCtx({
4852
message: {

extensions/telegram/src/bot-message-context.named-account-dm.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22

33
const recordInboundSessionMock = vi.fn().mockResolvedValue(undefined);
44
vi.mock("openclaw/plugin-sdk/conversation-runtime", async (importOriginal) => {
@@ -25,14 +25,18 @@ describe("buildTelegramMessageContext named-account DM fallback", () => {
2525
recordInboundSessionMock.mockClear();
2626
});
2727

28-
beforeEach(async () => {
28+
beforeAll(async () => {
2929
vi.resetModules();
3030
({ clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } =
3131
await import("../../../src/config/config.js"));
3232
({ buildTelegramMessageContextForTest } =
3333
await import("./bot-message-context.test-harness.js"));
3434
});
3535

36+
beforeEach(() => {
37+
recordInboundSessionMock.mockClear();
38+
});
39+
3640
function getLastUpdateLastRoute(): { sessionKey?: string } | undefined {
3741
const callArgs = recordInboundSessionMock.mock.calls.at(-1)?.[0] as {
3842
updateLastRoute?: { sessionKey?: string };

extensions/telegram/src/bot-message-context.thread-binding.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22

33
const hoisted = vi.hoisted(() => {
44
const resolveByConversationMock = vi.fn();
@@ -27,14 +27,17 @@ vi.mock("openclaw/plugin-sdk/conversation-runtime", async (importOriginal) => {
2727
let buildTelegramMessageContextForTest: typeof import("./bot-message-context.test-harness.js").buildTelegramMessageContextForTest;
2828

2929
describe("buildTelegramMessageContext bound conversation override", () => {
30-
beforeEach(async () => {
30+
beforeAll(async () => {
3131
vi.resetModules();
32-
hoisted.resolveByConversationMock.mockReset().mockReturnValue(null);
33-
hoisted.touchMock.mockReset();
3432
({ buildTelegramMessageContextForTest } =
3533
await import("./bot-message-context.test-harness.js"));
3634
});
3735

36+
beforeEach(() => {
37+
hoisted.resolveByConversationMock.mockReset().mockReturnValue(null);
38+
hoisted.touchMock.mockReset();
39+
});
40+
3841
it("routes forum topic messages to the bound session", async () => {
3942
hoisted.resolveByConversationMock.mockReturnValue({
4043
bindingId: "default:-100200300:topic:77",

extensions/telegram/src/bot-native-commands.registry.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22
import type { OpenClawConfig } from "../../../src/config/config.js";
33
const deliveryMocks = vi.hoisted(() => ({
44
deliverReplies: vi.fn(async () => ({ delivered: true })),
@@ -45,7 +45,7 @@ async function registerPairMenu(params: {
4545
}
4646

4747
describe("registerTelegramNativeCommands real plugin registry", () => {
48-
beforeEach(async () => {
48+
beforeAll(async () => {
4949
vi.resetModules();
5050
vi.doMock("./bot/delivery.js", () => ({
5151
deliverReplies: deliveryMocks.deliverReplies,
@@ -62,6 +62,9 @@ describe("registerTelegramNativeCommands real plugin registry", () => {
6262
createPrivateCommandContext,
6363
waitForRegisteredCommands,
6464
} = await import("./bot-native-commands.menu-test-support.js"));
65+
});
66+
67+
beforeEach(() => {
6568
clearPluginCommands();
6669
deliveryMocks.deliverReplies.mockClear();
6770
deliveryMocks.deliverReplies.mockResolvedValue({ delivered: true });

extensions/telegram/src/bot-native-commands.session-meta.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22
import type { OpenClawConfig } from "../../../src/config/config.js";
33
import type { ResolvedAgentRoute } from "../../../src/routing/resolve-route.js";
44
import type { TelegramBotDeps } from "./bot-deps.js";
@@ -389,9 +389,12 @@ function expectUnauthorizedNewCommandBlocked(sendMessage: ReturnType<typeof vi.f
389389
}
390390

391391
describe("registerTelegramNativeCommands — session metadata", () => {
392-
beforeEach(async () => {
392+
beforeAll(async () => {
393393
vi.resetModules();
394394
({ registerTelegramNativeCommands } = await import("./bot-native-commands.js"));
395+
});
396+
397+
beforeEach(() => {
395398
persistentBindingMocks.resolveConfiguredBindingRoute.mockClear();
396399
persistentBindingMocks.resolveConfiguredBindingRoute.mockImplementation(({ route }) =>
397400
createConfiguredBindingRoute(route, null),

extensions/telegram/src/bot-native-commands.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22
import type { OpenClawConfig } from "../../../src/config/config.js";
33
import { STATE_DIR } from "../../../src/config/paths.js";
44
import { TELEGRAM_COMMAND_NAME_PATTERN } from "../../../src/config/telegram-custom-commands.js";
@@ -86,9 +86,12 @@ function resolveDeliverRepliesCalls() {
8686
}
8787

8888
describe("registerTelegramNativeCommands", () => {
89-
beforeEach(async () => {
89+
beforeAll(async () => {
9090
vi.resetModules();
9191
({ registerTelegramNativeCommands } = await import("./bot-native-commands.js"));
92+
});
93+
94+
beforeEach(() => {
9295
skillCommandMocks.listSkillCommandsForAgents.mockClear();
9396
skillCommandMocks.listSkillCommandsForAgents.mockReturnValue([]);
9497
deliveryMocks.deliverReplies.mockClear();

extensions/telegram/src/send.proxy.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22

33
const { botApi, botCtorSpy } = vi.hoisted(() => ({
44
botApi: {
@@ -89,14 +89,17 @@ describe("telegram proxy client", () => {
8989
);
9090
};
9191

92-
beforeEach(async () => {
92+
beforeAll(async () => {
9393
vi.resetModules();
9494
({
9595
deleteMessageTelegram,
9696
reactMessageTelegram,
9797
resetTelegramClientOptionsCacheForTests,
9898
sendMessageTelegram,
9999
} = await import("./send.js"));
100+
});
101+
102+
beforeEach(() => {
100103
resetTelegramClientOptionsCacheForTests();
101104
vi.unstubAllEnvs();
102105
botApi.sendMessage.mockResolvedValue({ message_id: 1, chat: { id: "123" } });

0 commit comments

Comments
 (0)