Skip to content

Commit 50718fb

Browse files
Leon-SK668altaywtf
authored andcommitted
fix(channels): restrict directory fast path to loaded plugins
1 parent 1530f50 commit 50718fb

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎src/commands/channel-setup/channel-plugin-resolution.test.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const mocks = vi.hoisted(() => ({
99
listChannelPluginCatalogEntries: vi.fn(),
1010
getChannelPluginCatalogEntry: vi.fn(),
1111
getChannelPlugin: vi.fn(),
12+
getLoadedChannelPlugin: vi.fn(),
1213
loadChannelSetupPluginRegistrySnapshotForChannel: vi.fn(),
1314
ensureChannelSetupPluginInstalled: vi.fn(),
1415
createClackPrompter: vi.fn(() => ({}) as never),
@@ -26,6 +27,7 @@ vi.mock("../../channels/plugins/catalog.js", () => ({
2627

2728
vi.mock("../../channels/plugins/index.js", () => ({
2829
getChannelPlugin: mocks.getChannelPlugin,
30+
getLoadedChannelPlugin: mocks.getLoadedChannelPlugin,
2931
normalizeChannelId: (value: unknown) => (typeof value === "string" ? value.trim() || null : null),
3032
}));
3133

@@ -81,6 +83,7 @@ describe("resolveInstallableChannelPlugin", () => {
8183
mocks.resolveAgentWorkspaceDir.mockReturnValue("/tmp/workspace");
8284
mocks.resolveDefaultAgentId.mockReturnValue("default");
8385
mocks.getChannelPlugin.mockReturnValue(undefined);
86+
mocks.getLoadedChannelPlugin.mockReturnValue(undefined);
8487
mocks.getChannelPluginCatalogEntry.mockReturnValue(undefined);
8588
mocks.ensureChannelSetupPluginInstalled.mockResolvedValue({
8689
cfg: {},
@@ -93,7 +96,7 @@ describe("resolveInstallableChannelPlugin", () => {
9396
...createPlugin("telegram"),
9497
directory: { self: vi.fn() },
9598
} as ChannelPlugin;
96-
mocks.getChannelPlugin.mockReturnValue(registeredPlugin);
99+
mocks.getLoadedChannelPlugin.mockReturnValue(registeredPlugin);
97100
mocks.resolveDefaultAgentId.mockImplementation(() => {
98101
throw new Error("agent selection required");
99102
});
@@ -119,10 +122,37 @@ describe("resolveInstallableChannelPlugin", () => {
119122
supportsRequestedCapability: true,
120123
});
121124
expect(mocks.resolveDefaultAgentId).not.toHaveBeenCalled();
125+
expect(mocks.getLoadedChannelPlugin).toHaveBeenCalledWith("telegram");
126+
expect(mocks.getChannelPlugin).not.toHaveBeenCalled();
122127
expect(mocks.listChannelPluginCatalogEntries).not.toHaveBeenCalled();
123128
expect(mocks.loadChannelSetupPluginRegistrySnapshotForChannel).not.toHaveBeenCalled();
124129
});
125130

131+
it("requires a workspace owner before falling back to an unloaded bundled plugin", async () => {
132+
mocks.getChannelPlugin.mockReturnValue(createPlugin("telegram"));
133+
mocks.resolveDefaultAgentId.mockImplementation(() => {
134+
throw new Error("agent selection required");
135+
});
136+
137+
await expect(
138+
resolveInstallableChannelPlugin({
139+
cfg: {
140+
agents: {
141+
list: [{ id: "alpha" }, { id: "beta" }],
142+
},
143+
},
144+
runtime: {} as never,
145+
rawChannel: "telegram",
146+
allowInstall: false,
147+
preferRegisteredPlugin: true,
148+
}),
149+
).rejects.toThrow("agent selection required");
150+
151+
expect(mocks.getLoadedChannelPlugin).toHaveBeenCalledWith("telegram");
152+
expect(mocks.getChannelPlugin).not.toHaveBeenCalled();
153+
expect(mocks.resolveDefaultAgentId).toHaveBeenCalledTimes(1);
154+
});
155+
126156
it("still requires a workspace owner before resolving an unregistered plugin", async () => {
127157
mocks.resolveDefaultAgentId.mockImplementation(() => {
128158
throw new Error("agent selection required");
@@ -142,7 +172,8 @@ describe("resolveInstallableChannelPlugin", () => {
142172
}),
143173
).rejects.toThrow("agent selection required");
144174

145-
expect(mocks.getChannelPlugin).toHaveBeenCalledWith("workspace-channel");
175+
expect(mocks.getLoadedChannelPlugin).toHaveBeenCalledWith("workspace-channel");
176+
expect(mocks.getChannelPlugin).not.toHaveBeenCalled();
146177
expect(mocks.resolveDefaultAgentId).toHaveBeenCalledTimes(1);
147178
expect(mocks.listChannelPluginCatalogEntries).not.toHaveBeenCalled();
148179
});

‎src/commands/channel-setup/channel-plugin-resolution.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
listRawChannelPluginCatalogEntries,
66
type ChannelPluginCatalogEntry,
77
} from "../../channels/plugins/catalog.js";
8-
import { getChannelPlugin, normalizeChannelId } from "../../channels/plugins/index.js";
8+
import {
9+
getChannelPlugin,
10+
getLoadedChannelPlugin,
11+
normalizeChannelId,
12+
} from "../../channels/plugins/index.js";
913
import type { ChannelPlugin } from "../../channels/plugins/types.plugin.js";
1014
import type { ChannelId } from "../../channels/plugins/types.public.js";
1115
import type { OpenClawConfig } from "../../config/types.openclaw.js";
@@ -127,7 +131,7 @@ export async function resolveInstallableChannelPlugin(params: {
127131
const directChannelId = params.channelId ?? normalizeChannelId(params.rawChannel);
128132
const registeredPlugin =
129133
params.preferRegisteredPlugin && directChannelId
130-
? getChannelPlugin(directChannelId)
134+
? getLoadedChannelPlugin(directChannelId)
131135
: undefined;
132136
if (params.preferRegisteredPlugin && directChannelId && registeredPlugin) {
133137
return {

0 commit comments

Comments
 (0)