test(runtime): fix stale harness and registry mocks

This commit is contained in:
Peter Steinberger
2026-04-07 01:15:59 +01:00
parent b8c8139138
commit 017c25b075
4 changed files with 20 additions and 23 deletions

View File

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

View File

@@ -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 () => {

View File

@@ -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,

View File

@@ -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") {