feat(hooks): support multiple custom policy file paths in customPolic… - #620
feat(hooks): support multiple custom policy file paths in customPolic…#620AVPthegreat wants to merge 2 commits into
Conversation
|
Your PR is awaiting review by a reviewer. Till then you can join the Discord for conversation: https://discord.befailproof.ai |
|
Warning Review limit reached
Next review available in: 52 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesMultiple custom policy paths
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hooks/manager.ts (1)
219-246: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winReject empty policy files individually.
A valid file masks another configured file that registers no hooks because
validatedHooksis aggregated. Validate each path sequentially and reject any zero-hook file before persisting the configuration.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/hooks/manager.ts` around lines 219 - 246, Update the custom policy validation around loadCustomHooks so each configured path is loaded and checked individually, rejecting immediately when any file returns zero hooks instead of relying on the aggregated validatedHooks length. Preserve strict loading, tracking, and error reporting, and only persist the configuration after every path has registered at least one hook.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@__tests__/hooks/custom-hooks-loader.test.ts`:
- Around line 48-51: Update the rewriteFileTree mock in the custom hooks loader
test to resolve an array of temporary-path strings, not source/destination
objects; use the expected __failproofai_tmp__ path string so it matches the
loader and cleanup contract.
---
Outside diff comments:
In `@src/hooks/manager.ts`:
- Around line 219-246: Update the custom policy validation around
loadCustomHooks so each configured path is loaded and checked individually,
rejecting immediately when any file returns zero hooks instead of relying on the
aggregated validatedHooks length. Preserve strict loading, tracking, and error
reporting, and only persist the configuration after every path has registered at
least one hook.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 57d6afc0-0d65-4ee4-83c0-04077cc4f6f7
📒 Files selected for processing (4)
__tests__/hooks/custom-hooks-loader.test.tssrc/hooks/custom-hooks-loader.tssrc/hooks/manager.tssrc/hooks/policy-types.ts
Summary
Fixes #60 by updating
customPoliciesPathto supportstring | string[]acrossHooksConfig,loadCustomHooks,loadAllCustomHooks, andmanager.tsCLI output.❌ Motivation & Problem
Previously,
customPoliciesPathinpolicies-config.jsononly accepted a single string file path (string). If a user or team wanted to specify multiple custom policy files explicitly across different directories,customPoliciesPathcould not accept an array of file paths (string[]).✅ Feature Implementation
Type Signature Update (
src/hooks/policy-types.ts):Updated
HooksConfigtype definition:Custom Hook Loader (
src/hooks/custom-hooks-loader.ts):Updated
loadCustomHooksandloadAllCustomHooksto handlestring | string[] | undefined:Array.isArray(customPoliciesPath) ? customPoliciesPath : [customPoliciesPath].CLI & Management Plumbing (
src/hooks/manager.ts):installHooks/installHooksImplparameters to acceptstring | string[].resolve(p).listHooksoutput formatting to render each custom policy file section cleanly.🧪 Unit Tests & Verification
Added unit test in
__tests__/hooks/custom-hooks-loader.test.ts:Test Results:
vitest run __tests__/hooks/custom-hooks-loader.test.ts __tests__/hooks/hooks-config.test.ts✓ 48 passed (48)Summary by CodeRabbit
New Features
Bug Fixes
Tests