test(messages): lock external alias authorization order

This commit is contained in:
joshavant
2026-07-27 21:17:16 -05:00
committed by Josh Avant
parent e0a119dabf
commit 8d682b74bd

View File

@@ -890,6 +890,70 @@ describe("runMessageAction plugin dispatch", () => {
},
);
it("rejects directory-only external aliases before resolver or plugin code", async () => {
const looksLikeId = vi.fn(() => false);
const resolveTarget = vi.fn(async () => ({
to: "actionhub:current",
kind: "group" as const,
}));
const listGroups = vi.fn(async () => [
{ kind: "group" as const, id: "actionhub:current", name: "current-room" },
]);
const listGroupsLive = vi.fn(async () => [
{ kind: "group" as const, id: "actionhub:current", name: "current-room" },
]);
setActivePluginRegistry(
createTestRegistry([
{
pluginId: "actionhub",
source: "test",
origin: "config",
plugin: {
...actionHubPlugin,
messaging: {
...actionHubPlugin.messaging,
targetResolver: { looksLikeId, resolveTarget },
},
directory: { listGroups, listGroupsLive },
},
},
]),
);
await expect(
runMessageAction({
cfg: {
channels: {
actionhub: {
enabled: true,
},
},
} as OpenClawConfig,
action: "pin",
params: {
channel: "actionhub",
target: "current-room",
messageId: "om_123",
},
defaultAccountId: "default",
requesterAccountId: "default",
conversationReadOrigin: "delegated",
toolContext: {
currentChannelId: "actionhub:current",
currentChannelProvider: "actionhub",
currentChatType: "group",
},
dryRun: false,
}),
).rejects.toThrow("requires the exact current conversation and account");
expect(looksLikeId).not.toHaveBeenCalled();
expect(resolveTarget).not.toHaveBeenCalled();
expect(listGroups).not.toHaveBeenCalled();
expect(listGroupsLive).not.toHaveBeenCalled();
expect(handleAction).not.toHaveBeenCalled();
});
it("preserves no-context owner Discord admin actions through the shared runner", async () => {
const handleDiscordAction = vi.fn(async (ctx: ChannelMessageActionContext) => {
const currentProvider = ctx.toolContext?.currentChannelProvider?.trim().toLowerCase();