mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-15 03:01:02 +00:00
test(runtime): fix stale harness and registry mocks
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import type { ChannelOutboundAdapter } from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { ReplyPayload } from "openclaw/plugin-sdk/reply-runtime";
|
||||
import {
|
||||
loadBundledPluginTestApiSync,
|
||||
primeChannelOutboundSendMock,
|
||||
} from "openclaw/plugin-sdk/testing";
|
||||
import { primeChannelOutboundSendMock } from "openclaw/plugin-sdk/testing";
|
||||
import { vi, type Mock } from "vitest";
|
||||
import { slackOutbound } from "./outbound-adapter.js";
|
||||
|
||||
type OutboundSendMock = Mock<(...args: unknown[]) => Promise<Record<string, unknown>>>;
|
||||
|
||||
@@ -14,17 +11,6 @@ type SlackOutboundPayloadHarness = {
|
||||
to: string;
|
||||
};
|
||||
|
||||
let slackOutboundCache: ChannelOutboundAdapter | undefined;
|
||||
|
||||
function getSlackOutbound(): ChannelOutboundAdapter {
|
||||
if (!slackOutboundCache) {
|
||||
({ slackOutbound: slackOutboundCache } = loadBundledPluginTestApiSync<{
|
||||
slackOutbound: ChannelOutboundAdapter;
|
||||
}>("slack"));
|
||||
}
|
||||
return slackOutboundCache;
|
||||
}
|
||||
|
||||
export function createSlackOutboundPayloadHarness(params: {
|
||||
payload: ReplyPayload;
|
||||
sendResults?: Array<{ messageId: string }>;
|
||||
@@ -45,7 +31,7 @@ export function createSlackOutboundPayloadHarness(params: {
|
||||
},
|
||||
};
|
||||
return {
|
||||
run: async () => await getSlackOutbound().sendPayload!(ctx),
|
||||
run: async () => await slackOutbound.sendPayload!(ctx),
|
||||
sendMock: sendSlack,
|
||||
to: ctx.to,
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ const resolveDefaultAgentIdMock = vi.hoisted(() => vi.fn());
|
||||
const resolveAgentWorkspaceDirMock = vi.hoisted(() => vi.fn());
|
||||
const getChannelPluginMock = vi.hoisted(() => vi.fn());
|
||||
const getActivePluginChannelRegistryVersionMock = vi.hoisted(() => vi.fn());
|
||||
const requireActivePluginChannelRegistryMock = vi.hoisted(() => vi.fn(() => ({})));
|
||||
|
||||
vi.mock("../../agents/agent-scope.js", () => ({
|
||||
resolveAgentConfig: (...args: unknown[]) => resolveAgentConfigMock(...args),
|
||||
@@ -20,6 +21,8 @@ vi.mock("./index.js", () => ({
|
||||
vi.mock("../../plugins/runtime.js", () => ({
|
||||
getActivePluginChannelRegistryVersion: (...args: unknown[]) =>
|
||||
getActivePluginChannelRegistryVersionMock(...args),
|
||||
requireActivePluginChannelRegistry: (...args: unknown[]) =>
|
||||
requireActivePluginChannelRegistryMock(...args),
|
||||
}));
|
||||
|
||||
async function importConfiguredBindings() {
|
||||
@@ -100,6 +103,7 @@ describe("configured binding registry", () => {
|
||||
resolveAgentWorkspaceDirMock.mockReset().mockReturnValue("/tmp/workspace");
|
||||
getChannelPluginMock.mockReset();
|
||||
getActivePluginChannelRegistryVersionMock.mockReset().mockReturnValue(1);
|
||||
requireActivePluginChannelRegistryMock.mockReset().mockReturnValue({});
|
||||
});
|
||||
|
||||
it("resolves configured ACP bindings from an already loaded channel plugin", async () => {
|
||||
|
||||
@@ -15,11 +15,15 @@ const {
|
||||
} = createCliRuntimeCapture();
|
||||
const runtimeExit = runtime.exit;
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
loadConfig: loadConfigMock,
|
||||
readConfigFileSnapshot: readConfigFileSnapshotMock,
|
||||
resolveGatewayPort: resolveGatewayPortMock,
|
||||
}));
|
||||
vi.mock("../config/config.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: loadConfigMock,
|
||||
readConfigFileSnapshot: readConfigFileSnapshotMock,
|
||||
resolveGatewayPort: resolveGatewayPortMock,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../infra/clipboard.js", () => ({
|
||||
copyToClipboard: copyToClipboardMock,
|
||||
|
||||
@@ -969,6 +969,9 @@ function validateConfigObjectWithPluginsBase(
|
||||
const entry = normalizedPlugins.entries[pluginId];
|
||||
const entryExists = entry !== undefined;
|
||||
const entryHasConfig = Boolean(entry?.config);
|
||||
const shouldReplacePluginConfig = opts.applyDefaults
|
||||
? entryExists || entryHasConfig
|
||||
: entryHasConfig;
|
||||
|
||||
const activationState = resolveEffectivePluginActivationState({
|
||||
id: pluginId,
|
||||
@@ -1014,7 +1017,7 @@ function validateConfigObjectWithPluginsBase(
|
||||
allowedValuesHiddenCount: error.allowedValuesHiddenCount,
|
||||
});
|
||||
}
|
||||
} else if (entryExists || entryHasConfig) {
|
||||
} else if (shouldReplacePluginConfig) {
|
||||
replacePluginEntryConfig(pluginId, res.value as Record<string, unknown>);
|
||||
}
|
||||
} else if (record.format === "bundle") {
|
||||
|
||||
Reference in New Issue
Block a user