test: continue vitest threads migration

This commit is contained in:
Peter Steinberger
2026-03-24 02:00:22 +00:00
parent d41b92fff2
commit 2833b27f52
110 changed files with 3163 additions and 994 deletions

View File

@@ -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"),
});