mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 20:56:40 +00:00
refactor(agents): unify subagent announce delivery pipeline
Co-authored-by: Smith Labs <SmithLabsLLC@users.noreply.github.com> Co-authored-by: Do Cao Hieu <docaohieu2808@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@ const mocks = vi.hoisted(() => ({
|
||||
getChannelPlugin: vi.fn(),
|
||||
resolveOutboundTarget: vi.fn(),
|
||||
deliverOutboundPayloads: vi.fn(),
|
||||
loadOpenClawPlugins: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../../channels/plugins/index.js", () => ({
|
||||
@@ -11,6 +12,19 @@ vi.mock("../../channels/plugins/index.js", () => ({
|
||||
getChannelPlugin: mocks.getChannelPlugin,
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/agent-scope.js", () => ({
|
||||
resolveDefaultAgentId: () => "main",
|
||||
resolveAgentWorkspaceDir: () => "/tmp/openclaw-test-workspace",
|
||||
}));
|
||||
|
||||
vi.mock("../../config/plugin-auto-enable.js", () => ({
|
||||
applyPluginAutoEnable: ({ config }: { config: unknown }) => ({ config, changes: [] }),
|
||||
}));
|
||||
|
||||
vi.mock("../../plugins/loader.js", () => ({
|
||||
loadOpenClawPlugins: mocks.loadOpenClawPlugins,
|
||||
}));
|
||||
|
||||
vi.mock("./targets.js", () => ({
|
||||
resolveOutboundTarget: mocks.resolveOutboundTarget,
|
||||
}));
|
||||
@@ -19,13 +33,17 @@ vi.mock("./deliver.js", () => ({
|
||||
deliverOutboundPayloads: mocks.deliverOutboundPayloads,
|
||||
}));
|
||||
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import { createTestRegistry } from "../../test-utils/channel-plugins.js";
|
||||
import { sendMessage } from "./message.js";
|
||||
|
||||
describe("sendMessage", () => {
|
||||
beforeEach(() => {
|
||||
setActivePluginRegistry(createTestRegistry([]));
|
||||
mocks.getChannelPlugin.mockClear();
|
||||
mocks.resolveOutboundTarget.mockClear();
|
||||
mocks.deliverOutboundPayloads.mockClear();
|
||||
mocks.loadOpenClawPlugins.mockClear();
|
||||
|
||||
mocks.getChannelPlugin.mockReturnValue({
|
||||
outbound: { deliveryMode: "direct" },
|
||||
@@ -37,8 +55,8 @@ describe("sendMessage", () => {
|
||||
it("passes explicit agentId to outbound delivery for scoped media roots", async () => {
|
||||
await sendMessage({
|
||||
cfg: {},
|
||||
channel: "mattermost",
|
||||
to: "channel:town-square",
|
||||
channel: "telegram",
|
||||
to: "123456",
|
||||
content: "hi",
|
||||
agentId: "work",
|
||||
});
|
||||
@@ -46,9 +64,34 @@ describe("sendMessage", () => {
|
||||
expect(mocks.deliverOutboundPayloads).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
agentId: "work",
|
||||
channel: "mattermost",
|
||||
to: "channel:town-square",
|
||||
channel: "telegram",
|
||||
to: "123456",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("recovers telegram plugin resolution so message/send does not fail with Unknown channel: telegram", async () => {
|
||||
const telegramPlugin = {
|
||||
outbound: { deliveryMode: "direct" },
|
||||
};
|
||||
mocks.getChannelPlugin
|
||||
.mockReturnValueOnce(undefined)
|
||||
.mockReturnValueOnce(telegramPlugin)
|
||||
.mockReturnValue(telegramPlugin);
|
||||
|
||||
await expect(
|
||||
sendMessage({
|
||||
cfg: { channels: { telegram: { botToken: "test-token" } } },
|
||||
channel: "telegram",
|
||||
to: "123456",
|
||||
content: "hi",
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
channel: "telegram",
|
||||
to: "123456",
|
||||
via: "direct",
|
||||
});
|
||||
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user