Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions __tests__/hooks/policy-evaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1218,5 +1218,23 @@ describe("hooks/policy-evaluator", () => {
expect(result.decision).toBe("deny");
expect(result.reason).toBe("hard block. deny hint");
});

it("passes user-configured policyParams to custom policies without schema", async () => {
let capturedParams: unknown = null;
registerPolicy("custom/my-policy", "desc", (ctx) => {
capturedParams = ctx.params;
return { decision: "allow" };
}, { events: ["PreToolUse"] });

const config = {
enabledPolicies: ["custom/my-policy"],
policyParams: {
"custom/my-policy": { maxCount: 10, threshold: 5 },
},
};

await evaluatePolicies("PreToolUse", { tool_name: "Bash" }, undefined, config);
expect(capturedParams).toEqual({ maxCount: 10, threshold: 5 });
});
});
});
5 changes: 3 additions & 2 deletions src/hooks/policy-evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ export async function evaluatePolicies(
}
ctx = { ...baseCtx, params: resolvedParams };
} else {
// Custom hooks and policies without schema get empty params
ctx = { ...baseCtx, params: {} };
// Custom hooks and policies without schema get user-configured params if present
const userParams = getConfigParamsFor(config, policy.name) ?? {};
ctx = { ...baseCtx, params: userParams };
Comment on lines +104 to +106
}

let result: Awaited<ReturnType<typeof policy.fn>>;
Expand Down