test(plugin-sdk): tighten ACP command dispatch guards

This commit is contained in:
Peter Steinberger
2026-04-06 02:42:48 +01:00
parent 7b47d27d0a
commit bf269e7b67
4 changed files with 148 additions and 5 deletions

View File

@@ -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);

View File

@@ -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(