mirror of https://github.com/openclaw/openclaw.git
fix: recover outbound plugins from the active registry
This commit is contained in:
parent
402f2556b9
commit
fa6ff39b9b
|
|
@ -58,6 +58,22 @@ function maybeBootstrapChannelPlugin(params: {
|
|||
}
|
||||
}
|
||||
|
||||
function resolveDirectFromActiveRegistry(
|
||||
channel: DeliverableMessageChannel,
|
||||
): ChannelPlugin | undefined {
|
||||
const activeRegistry = getActivePluginRegistry();
|
||||
if (!activeRegistry) {
|
||||
return undefined;
|
||||
}
|
||||
for (const entry of activeRegistry.channels) {
|
||||
const plugin = entry?.plugin;
|
||||
if (plugin?.id === channel) {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveOutboundChannelPlugin(params: {
|
||||
channel: string;
|
||||
cfg?: OpenClawConfig;
|
||||
|
|
@ -72,7 +88,11 @@ export function resolveOutboundChannelPlugin(params: {
|
|||
if (current) {
|
||||
return current;
|
||||
}
|
||||
const directCurrent = resolveDirectFromActiveRegistry(normalized);
|
||||
if (directCurrent) {
|
||||
return directCurrent;
|
||||
}
|
||||
|
||||
maybeBootstrapChannelPlugin({ channel: normalized, cfg: params.cfg });
|
||||
return resolve();
|
||||
return resolve() ?? resolveDirectFromActiveRegistry(normalized);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { telegramOutbound } from "../../channels/plugins/outbound/telegram.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import { createOutboundTestPlugin, createTestRegistry } from "../../test-utils/channel-plugins.js";
|
||||
import {
|
||||
resolveHeartbeatDeliveryTarget,
|
||||
resolveOutboundTarget,
|
||||
|
|
@ -64,6 +67,27 @@ describe("resolveOutboundTarget defaultTo config fallback", () => {
|
|||
});
|
||||
expect(res.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("falls back to the active registry when the cached channel map is stale", () => {
|
||||
const registry = createTestRegistry([]);
|
||||
setActivePluginRegistry(registry, "stale-registry-test");
|
||||
|
||||
// Warm the cached channel map before mutating the registry in place.
|
||||
expect(resolveOutboundTarget({ channel: "telegram", to: "123", mode: "explicit" }).ok).toBe(
|
||||
false,
|
||||
);
|
||||
|
||||
registry.channels.push({
|
||||
pluginId: "telegram",
|
||||
plugin: createOutboundTestPlugin({ id: "telegram", outbound: telegramOutbound }),
|
||||
source: "test",
|
||||
});
|
||||
|
||||
expect(resolveOutboundTarget({ channel: "telegram", to: "123", mode: "explicit" })).toEqual({
|
||||
ok: true,
|
||||
to: "123",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveSessionDeliveryTarget", () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue