fix(hooks): pass user-configured policyParams to custom policies (#585) - #616
fix(hooks): pass user-configured policyParams to custom policies (#585)#616AVPthegreat wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesCustom policy parameter forwarding
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Your PR is awaiting review by a reviewer. Till then you can join the Discord for conversation: https://discord.befailproof.ai |
There was a problem hiding this comment.
Pull request overview
This PR fixes an evaluation gap in the hook policy system by ensuring custom policies (and any policies without a built-in params schema) receive user-configured policyParams via ctx.params, aligning behavior with user expectations and the existing config surface.
Changes:
- Updated
evaluatePolicies()to passgetConfigParamsFor(config, policy.name)through when a policy has no schema (instead of always{}). - Added a unit test verifying that a custom policy without schema receives configured params.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/hooks/policy-evaluator.ts | Passes user-configured params to schema-less/custom policies during evaluation. |
| tests/hooks/policy-evaluator.test.ts | Adds coverage to ensure custom policies without schema receive configured policyParams. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Custom hooks and policies without schema get user-configured params if present | ||
| const userParams = getConfigParamsFor(config, policy.name) ?? {}; | ||
| ctx = { ...baseCtx, params: userParams }; |
Summary
Fixes #585 by passing user-configured
policyParamsto custom policies and policies without a pre-defined schema inpolicy-evaluator.ts.❌ Root Cause Analysis
In
src/hooks/policy-evaluator.ts(lines 94-106):Why it failed:
POLICY_PARAMS_MAPonly contains schemas for built-in policies. For custom policies (e.g.custom/my-policy),schemaisundefined.schemawasundefined, theelsebranch unconditionally setparams: {}.getConfigParamsFor(config, policy.name), meaning anypolicyParams: { "custom/my-policy": { maxCount: 10 } }configured inpolicies-config.jsonwas completely ignored for custom policies.✅ Fix Details
Updated the
elsebranch insrc/hooks/policy-evaluator.tsto querygetConfigParamsFor(config, policy.name)whenschemaisundefined:🧪 Unit Tests & Verification
Added unit test in
__tests__/hooks/policy-evaluator.test.ts:Test Results:
vitest run __tests__/hooks/policy-evaluator.test.ts✓ 70 passed (70)Summary by CodeRabbit
Bug Fixes
Tests