mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
fix(ci): repair tsgo test harnesses
This commit is contained in:
@@ -29,18 +29,25 @@ vi.spyOn(replyRuntimeModule, "dispatchInboundMessageWithBufferedDispatcher").moc
|
||||
(...args) => dispatchMock(...args) as never,
|
||||
);
|
||||
|
||||
const conversationRuntimeModule = await import("openclaw/plugin-sdk/conversation-runtime");
|
||||
type ReadChannelAllowFromStore = typeof conversationRuntimeModule.readChannelAllowFromStore;
|
||||
type UpsertChannelPairingRequest = typeof conversationRuntimeModule.upsertChannelPairingRequest;
|
||||
|
||||
function createPairingStoreMocks() {
|
||||
return {
|
||||
readChannelAllowFromStore(...args: unknown[]) {
|
||||
return readAllowFromStoreMock(...args);
|
||||
readChannelAllowFromStore(
|
||||
...args: Parameters<ReadChannelAllowFromStore>
|
||||
): ReturnType<ReadChannelAllowFromStore> {
|
||||
return readAllowFromStoreMock(...args) as ReturnType<ReadChannelAllowFromStore>;
|
||||
},
|
||||
upsertChannelPairingRequest(...args: unknown[]) {
|
||||
return upsertPairingRequestMock(...args);
|
||||
upsertChannelPairingRequest(
|
||||
...args: Parameters<UpsertChannelPairingRequest>
|
||||
): ReturnType<UpsertChannelPairingRequest> {
|
||||
return upsertPairingRequestMock(...args) as ReturnType<UpsertChannelPairingRequest>;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const conversationRuntimeModule = await import("openclaw/plugin-sdk/conversation-runtime");
|
||||
const pairingStoreMocks = createPairingStoreMocks();
|
||||
vi.spyOn(conversationRuntimeModule, "readChannelAllowFromStore").mockImplementation((...args) =>
|
||||
pairingStoreMocks.readChannelAllowFromStore(...args),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { MockFn } from "openclaw/plugin-sdk/testing";
|
||||
import { vi } from "vitest";
|
||||
import type { DiscordInboundWorkerTestingHooks } from "./inbound-worker.js";
|
||||
|
||||
export const preflightDiscordMessageMock: MockFn = vi.fn();
|
||||
export const processDiscordMessageMock: MockFn = vi.fn();
|
||||
@@ -7,6 +8,15 @@ export const deliverDiscordReplyMock: MockFn = vi.fn(async () => undefined);
|
||||
|
||||
const { createDiscordMessageHandler: createRealDiscordMessageHandler } =
|
||||
await import("./message-handler.js");
|
||||
type DiscordMessageHandlerParams = Parameters<typeof createRealDiscordMessageHandler>[0];
|
||||
type DiscordMessageHandlerTestingHooks = NonNullable<DiscordMessageHandlerParams["__testing"]>;
|
||||
type PreflightDiscordMessageHook = NonNullable<
|
||||
DiscordMessageHandlerTestingHooks["preflightDiscordMessage"]
|
||||
>;
|
||||
type ProcessDiscordMessageHook = NonNullable<
|
||||
DiscordInboundWorkerTestingHooks["processDiscordMessage"]
|
||||
>;
|
||||
type DeliverDiscordReplyHook = NonNullable<DiscordInboundWorkerTestingHooks["deliverDiscordReply"]>;
|
||||
|
||||
export function createDiscordMessageHandler(
|
||||
...args: Parameters<typeof createRealDiscordMessageHandler>
|
||||
@@ -16,9 +26,9 @@ export function createDiscordMessageHandler(
|
||||
...params,
|
||||
__testing: {
|
||||
...params.__testing,
|
||||
preflightDiscordMessage: preflightDiscordMessageMock,
|
||||
processDiscordMessage: processDiscordMessageMock,
|
||||
deliverDiscordReply: deliverDiscordReplyMock,
|
||||
preflightDiscordMessage: preflightDiscordMessageMock as PreflightDiscordMessageHook,
|
||||
processDiscordMessage: processDiscordMessageMock as ProcessDiscordMessageHook,
|
||||
deliverDiscordReply: deliverDiscordReplyMock as DeliverDiscordReplyHook,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,7 +122,9 @@ vi.mock("openclaw/plugin-sdk/reply-runtime", async () => {
|
||||
waitForIdle?: () => Promise<void>;
|
||||
};
|
||||
}) => {
|
||||
const resolved = await replyMock(params.ctx, {}, params.cfg);
|
||||
const resolved = (await replyMock(params.ctx, {}, params.cfg)) as
|
||||
| { text?: string }
|
||||
| undefined;
|
||||
const text = typeof resolved?.text === "string" ? resolved.text.trim() : "";
|
||||
if (text) {
|
||||
params.dispatcher.sendFinalReply({ text });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { vi } from "vitest";
|
||||
import { __testing as queueCleanupTesting } from "../auto-reply/reply/queue/cleanup.js";
|
||||
import type { CallGatewayOptions } from "../gateway/call.js";
|
||||
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
|
||||
import { __testing as subagentAnnounceTesting } from "./subagent-announce.js";
|
||||
import { __testing as subagentControlTesting } from "./subagent-control.js";
|
||||
@@ -17,6 +18,12 @@ const defaultConfig: LoadedConfig = {
|
||||
|
||||
let configOverride: LoadedConfig = defaultConfig;
|
||||
|
||||
async function callGatewayForTest<T = Record<string, unknown>>(
|
||||
opts: CallGatewayOptions,
|
||||
): Promise<T> {
|
||||
return (await callGatewayMock(opts)) as T;
|
||||
}
|
||||
|
||||
export function setSubagentsConfigOverride(next: LoadedConfig) {
|
||||
configOverride = next;
|
||||
}
|
||||
@@ -27,10 +34,10 @@ export function resetSubagentsConfigOverride() {
|
||||
|
||||
function applySharedSubagentTestDeps() {
|
||||
subagentControlTesting.setDepsForTest({
|
||||
callGateway: (optsUnknown) => callGatewayMock(optsUnknown),
|
||||
callGateway: callGatewayForTest,
|
||||
});
|
||||
subagentAnnounceTesting.setDepsForTest({
|
||||
callGateway: (optsUnknown) => callGatewayMock(optsUnknown),
|
||||
callGateway: callGatewayForTest,
|
||||
loadConfig: () => configOverride,
|
||||
});
|
||||
queueCleanupTesting.setDepsForTests({
|
||||
@@ -41,7 +48,7 @@ function applySharedSubagentTestDeps() {
|
||||
applySharedSubagentTestDeps();
|
||||
|
||||
vi.mock("../gateway/call.js", () => ({
|
||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
||||
callGateway: callGatewayForTest,
|
||||
}));
|
||||
|
||||
vi.mock("../config/config.js", async () => {
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
type SessionBindingContractChannelId,
|
||||
} from "./manifest.js";
|
||||
import { importBundledChannelContractArtifact } from "./runtime-artifacts.js";
|
||||
import "./registry.js";
|
||||
import "../registry.js";
|
||||
|
||||
type SessionBindingContractEntry = {
|
||||
id: string;
|
||||
|
||||
@@ -79,11 +79,8 @@ export type ChannelConfigSchema = {
|
||||
/** Full capability contract for a native channel plugin. */
|
||||
type ChannelPluginSetupWizard = ChannelSetupWizard | ChannelSetupWizardAdapter;
|
||||
|
||||
export type ChannelPlugin<
|
||||
ResolvedAccount = Record<string, unknown>,
|
||||
Probe = unknown,
|
||||
Audit = unknown,
|
||||
> = {
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
export type ChannelPlugin<ResolvedAccount = any, Probe = unknown, Audit = unknown> = {
|
||||
id: ChannelId;
|
||||
meta: ChannelMeta;
|
||||
capabilities: ChannelCapabilities;
|
||||
|
||||
@@ -50,5 +50,6 @@ export interface ChannelsConfig {
|
||||
/** Map provider -> channel id -> model override. */
|
||||
modelByChannel?: ChannelModelByChannelConfig;
|
||||
/** Channel sections are plugin-owned; concrete channel files augment this interface. */
|
||||
[key: string]: unknown;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ function normalizeBundledChannelConfigs(
|
||||
continue;
|
||||
}
|
||||
next ??= { ...value };
|
||||
next[channelId] = parsed.data;
|
||||
next[channelId] = parsed.data as ChannelsConfig[string];
|
||||
}
|
||||
|
||||
return next ?? value;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Centralized Vitest mock type for harness modules under `src/`.
|
||||
// Using an explicit named type avoids exporting inferred `vi.fn()` types that can trip TS2742.
|
||||
//
|
||||
export type MockFn<T extends (...args: never[]) => unknown = (...args: never[]) => unknown> =
|
||||
// Test harnesses need a permissive default callable shape so vi.fn() can stand in for many signatures.
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
export type MockFn<T extends (...args: any[]) => unknown = (...args: any[]) => unknown> =
|
||||
import("vitest").Mock<T>;
|
||||
|
||||
Reference in New Issue
Block a user