mirror of https://github.com/openclaw/openclaw.git
test: speed up signal and whatsapp extension suites
This commit is contained in:
parent
86921b624c
commit
49ae71fa62
|
|
@ -1,4 +1,4 @@
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { MsgContext } from "../../../../src/auto-reply/templating.js";
|
||||
import { buildDispatchInboundCaptureMock } from "../../../../src/channels/plugins/contracts/inbound-testkit.js";
|
||||
import type { OpenClawConfig } from "../../../../src/config/types.js";
|
||||
|
|
@ -100,15 +100,18 @@ async function expectSkippedGroupHistory(opts: GroupEventOpts, expectedBody: str
|
|||
}
|
||||
|
||||
describe("signal mention gating", () => {
|
||||
beforeEach(async () => {
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
capturedCtx = undefined;
|
||||
({ createBaseSignalEventHandlerDeps, createSignalReceiveEvent } =
|
||||
await import("./event-handler.test-harness.js"));
|
||||
({ createSignalEventHandler } = await import("./event-handler.js"));
|
||||
({ renderSignalMentions } = await import("./mentions.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
capturedCtx = undefined;
|
||||
});
|
||||
|
||||
it("drops group messages without mention when requireMention is configured", async () => {
|
||||
const handler = createMentionHandler({ requireMention: true });
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { logVerbose } from "../../../../src/globals.js";
|
||||
import { sleep } from "../../../../src/utils.js";
|
||||
import { loadWebMedia } from "../media.js";
|
||||
|
|
@ -85,7 +85,7 @@ async function expectReplySuppressed(replyResult: { text: string; isReasoning?:
|
|||
}
|
||||
|
||||
describe("deliverWebReply", () => {
|
||||
beforeEach(async () => {
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({ deliverWebReply } = await import("./deliver-reply.js"));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { getReplyFromConfig } from "../../../../src/auto-reply/reply.js";
|
||||
import { HEARTBEAT_TOKEN } from "../../../../src/auto-reply/tokens.js";
|
||||
import { redactIdentifier } from "../../../../src/logging/redact-identifier.js";
|
||||
|
|
@ -160,8 +160,12 @@ describe("runWebHeartbeatOnce", () => {
|
|||
...overrides,
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({ runWebHeartbeatOnce } = await import("./heartbeat-runner.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
state.visibility = { showAlerts: true, showOk: true, useIndicator: false };
|
||||
state.store = { k: { updatedAt: 999, sessionId: "s1" } };
|
||||
state.snapshot = {
|
||||
|
|
@ -182,7 +186,6 @@ describe("runWebHeartbeatOnce", () => {
|
|||
sender = senderMock as unknown as typeof sendMessageWhatsApp;
|
||||
replyResolverMock = vi.fn(async () => undefined);
|
||||
replyResolver = replyResolverMock as unknown as typeof getReplyFromConfig;
|
||||
({ runWebHeartbeatOnce } = await import("./heartbeat-runner.js"));
|
||||
});
|
||||
|
||||
it("supports manual override body dry-run without sending", async () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
readAllowFromStoreMock,
|
||||
sendMessageMock,
|
||||
|
|
@ -10,6 +10,11 @@ import {
|
|||
setupAccessControlTestHarness();
|
||||
let checkInboundAccessControl: typeof import("./access-control.js").checkInboundAccessControl;
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({ checkInboundAccessControl } = await import("./access-control.js"));
|
||||
});
|
||||
|
||||
async function checkUnauthorizedWorkDmSender() {
|
||||
return checkInboundAccessControl({
|
||||
accountId: "work",
|
||||
|
|
@ -31,11 +36,6 @@ function expectSilentlyBlocked(result: { allowed: boolean }) {
|
|||
}
|
||||
|
||||
describe("checkInboundAccessControl pairing grace", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ checkInboundAccessControl } = await import("./access-control.js"));
|
||||
});
|
||||
|
||||
async function runPairingGraceCase(messageTimestampMs: number) {
|
||||
const connectedAtMs = 1_000_000;
|
||||
return await checkInboundAccessControl({
|
||||
|
|
@ -72,11 +72,6 @@ describe("checkInboundAccessControl pairing grace", () => {
|
|||
});
|
||||
|
||||
describe("WhatsApp dmPolicy precedence", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ checkInboundAccessControl } = await import("./access-control.js"));
|
||||
});
|
||||
|
||||
it("uses account-level dmPolicy instead of channel-level (#8736)", async () => {
|
||||
// Channel-level says "pairing" but the account-level says "allowlist".
|
||||
// The account-level override should take precedence, so an unauthorized
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { installCommonResolveTargetErrorCases } from "openclaw/plugin-sdk/testing";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("./runtime-api.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./runtime-api.js")>("./runtime-api.js");
|
||||
|
|
@ -71,7 +71,7 @@ let resolveTarget: NonNullable<
|
|||
>;
|
||||
|
||||
describe("whatsapp resolveTarget", () => {
|
||||
beforeEach(async () => {
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
const outbound = (await import("./channel.js")).whatsappPlugin.outbound;
|
||||
if (!outbound?.resolveTarget) {
|
||||
|
|
@ -80,6 +80,10 @@ describe("whatsapp resolveTarget", () => {
|
|||
resolveTarget = outbound.resolveTarget;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should resolve valid target in explicit mode", () => {
|
||||
const result = resolveTarget({
|
||||
to: "5511999999999",
|
||||
|
|
|
|||
Loading…
Reference in New Issue