mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
test(plugin-sdk): tighten ACP command dispatch guards
This commit is contained in:
@@ -55,6 +55,25 @@ describe("tryDispatchAcpReplyHook", () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("skips ACP runtime lookup for plain-text deny turns", async () => {
|
||||
const result = await tryDispatchAcpReplyHook(
|
||||
{
|
||||
...event,
|
||||
sendPolicy: "deny",
|
||||
ctx: buildTestCtx({
|
||||
SessionKey: "agent:test:session",
|
||||
BodyForCommands: "write a test",
|
||||
BodyForAgent: "write a test",
|
||||
}),
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
expect(bypassMock).not.toHaveBeenCalled();
|
||||
expect(dispatchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("skips ACP dispatch when send policy denies delivery and no bypass applies", async () => {
|
||||
bypassMock.mockResolvedValue(false);
|
||||
|
||||
|
||||
@@ -42,9 +42,22 @@ function loadDispatchAcpRuntime() {
|
||||
}
|
||||
|
||||
function hasExplicitCommandCandidate(ctx: PluginHookReplyDispatchEvent["ctx"]): boolean {
|
||||
return [ctx.CommandBody, ctx.BodyForCommands].some(
|
||||
(value) => typeof value === "string" && value.trim().length > 0,
|
||||
);
|
||||
const commandBody = ctx.CommandBody;
|
||||
if (typeof commandBody === "string" && commandBody.trim().length > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const bodyForCommands = ctx.BodyForCommands;
|
||||
if (typeof bodyForCommands !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const normalized = bodyForCommands.trim();
|
||||
if (!normalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return normalized.startsWith("!") || normalized.startsWith("/");
|
||||
}
|
||||
|
||||
export async function tryDispatchAcpReplyHook(
|
||||
|
||||
Reference in New Issue
Block a user