mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 17:10:25 +00:00
test: harden threaded shared-worker suites
This commit is contained in:
@@ -3,6 +3,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
let collectTelegramUnmentionedGroupIds: typeof import("./audit.js").collectTelegramUnmentionedGroupIds;
|
||||
let auditTelegramGroupMembership: typeof import("./audit.js").auditTelegramGroupMembership;
|
||||
const fetchWithTimeoutMock = vi.hoisted(() => vi.fn());
|
||||
const resolveTelegramFetchMock = vi.hoisted(() => vi.fn(() => fetchWithTimeoutMock));
|
||||
const resolveTelegramApiBaseMock = vi.hoisted(() => vi.fn(() => "https://api.telegram.org"));
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/text-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/text-runtime")>();
|
||||
@@ -33,9 +35,15 @@ async function auditSingleGroup() {
|
||||
describe("telegram audit", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
vi.doMock("./fetch.js", () => ({
|
||||
resolveTelegramApiBase: resolveTelegramApiBaseMock,
|
||||
resolveTelegramFetch: resolveTelegramFetchMock,
|
||||
}));
|
||||
({ collectTelegramUnmentionedGroupIds, auditTelegramGroupMembership } =
|
||||
await import("./audit.js"));
|
||||
fetchWithTimeoutMock.mockReset();
|
||||
resolveTelegramFetchMock.mockClear();
|
||||
resolveTelegramApiBaseMock.mockClear();
|
||||
});
|
||||
|
||||
it("collects unmentioned numeric group ids and flags wildcard", async () => {
|
||||
@@ -57,6 +65,7 @@ describe("telegram audit", () => {
|
||||
expect(res.ok).toBe(true);
|
||||
expect(res.groups[0]?.chatId).toBe("-1001");
|
||||
expect(res.groups[0]?.status).toBe("member");
|
||||
expect(resolveTelegramFetchMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reports bot not in group when status is left", async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock recordInboundSession to capture updateLastRoute parameter
|
||||
const recordInboundSessionMock = vi.fn().mockResolvedValue(undefined);
|
||||
@@ -11,6 +11,7 @@ vi.mock("openclaw/plugin-sdk/conversation-runtime", async (importOriginal) => {
|
||||
});
|
||||
|
||||
let buildTelegramMessageContextForTest: typeof import("./bot-message-context.test-harness.js").buildTelegramMessageContextForTest;
|
||||
let clearRuntimeConfigSnapshot: typeof import("../../../src/config/config.js").clearRuntimeConfigSnapshot;
|
||||
|
||||
describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#8891)", () => {
|
||||
async function buildCtx(params: {
|
||||
@@ -30,9 +31,14 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889
|
||||
return callArgs?.updateLastRoute;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
clearRuntimeConfigSnapshot();
|
||||
recordInboundSessionMock.mockClear();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
recordInboundSessionMock.mockClear();
|
||||
({ clearRuntimeConfigSnapshot } = await import("../../../src/config/config.js"));
|
||||
({ buildTelegramMessageContextForTest } =
|
||||
await import("./bot-message-context.test-harness.js"));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user