mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-31 20:01:36 +00:00
test: continue vitest threads migration
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolveOutboundTarget } from "../../infra/outbound/targets.js";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import { createTestRegistry } from "../../test-utils/channel-plugins.js";
|
||||
import { sendHandlers } from "./send.js";
|
||||
import type { GatewayRequestContext } from "./types.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
@@ -31,6 +29,7 @@ vi.mock("../../channels/plugins/index.js", () => ({
|
||||
}));
|
||||
|
||||
const TEST_AGENT_WORKSPACE = "/tmp/openclaw-test-workspace";
|
||||
let sendHandlers: typeof import("./send.js").sendHandlers;
|
||||
|
||||
function resolveAgentIdFromSessionKeyForTests(params: { sessionKey?: string }): string {
|
||||
if (typeof params.sessionKey === "string") {
|
||||
@@ -89,6 +88,11 @@ vi.mock("../../config/sessions.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
async function loadFreshSendHandlersForTest() {
|
||||
vi.resetModules();
|
||||
({ sendHandlers } = await import("./send.js"));
|
||||
}
|
||||
|
||||
const makeContext = (): GatewayRequestContext =>
|
||||
({
|
||||
dedupe: new Map(),
|
||||
@@ -142,7 +146,7 @@ function mockDeliverySuccess(messageId: string) {
|
||||
describe("gateway send mirroring", () => {
|
||||
let registrySeq = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
registrySeq += 1;
|
||||
setActivePluginRegistry(createTestRegistry([]), `send-test-${registrySeq}`);
|
||||
@@ -153,6 +157,7 @@ describe("gateway send mirroring", () => {
|
||||
});
|
||||
mocks.sendPoll.mockResolvedValue({ messageId: "poll-1" });
|
||||
mocks.getChannelPlugin.mockReturnValue({ outbound: { sendPoll: mocks.sendPoll } });
|
||||
await loadFreshSendHandlersForTest();
|
||||
});
|
||||
|
||||
it("accepts media-only sends without message", async () => {
|
||||
@@ -508,7 +513,7 @@ describe("gateway send mirroring", () => {
|
||||
});
|
||||
|
||||
it("returns invalid request when outbound target resolution fails", async () => {
|
||||
vi.mocked(resolveOutboundTarget).mockReturnValue({
|
||||
mocks.resolveOutboundTarget.mockReturnValue({
|
||||
ok: false,
|
||||
error: new Error("target not found"),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user