From 101774235b2f310ae5a3a04e8e46cddeef16b1c0 Mon Sep 17 00:00:00 2001 From: anantvardhanpandey Date: Tue, 28 Jul 2026 14:20:30 +0530 Subject: [PATCH] fix(hooks): propagate customPoliciesEnabled in readMergedHooksConfig (#590) --- __tests__/hooks/hooks-config.test.ts | 20 ++++++++++++++++++++ src/hooks/hooks-config.ts | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/__tests__/hooks/hooks-config.test.ts b/__tests__/hooks/hooks-config.test.ts index c9bc8be0..6c2e201c 100644 --- a/__tests__/hooks/hooks-config.test.ts +++ b/__tests__/hooks/hooks-config.test.ts @@ -185,6 +185,26 @@ describe("hooks/hooks-config", () => { expect(config.customPoliciesPath).toBe("/project/hooks.js"); }); + it("customPoliciesEnabled: first scope that defines it wins", async () => { + mockFiles({ + [projectPath]: { enabledPolicies: [], customPoliciesEnabled: false }, + [globalPath]: { enabledPolicies: [], customPoliciesEnabled: true }, + }); + const { readMergedHooksConfig } = await import("../../src/hooks/hooks-config"); + const config = readMergedHooksConfig(CWD); + expect(config.customPoliciesEnabled).toBe(false); + }); + + it("customPoliciesEnabled: local scope wins over global when project is undefined", async () => { + mockFiles({ + [localPath]: { enabledPolicies: [], customPoliciesEnabled: false }, + [globalPath]: { enabledPolicies: [], customPoliciesEnabled: true }, + }); + const { readMergedHooksConfig } = await import("../../src/hooks/hooks-config"); + const config = readMergedHooksConfig(CWD); + expect(config.customPoliciesEnabled).toBe(false); + }); + it("returns no policyParams key when no params configured", async () => { mockFiles({ [globalPath]: { enabledPolicies: ["block-sudo"] }, diff --git a/src/hooks/hooks-config.ts b/src/hooks/hooks-config.ts index c2fee069..29118a21 100644 --- a/src/hooks/hooks-config.ts +++ b/src/hooks/hooks-config.ts @@ -90,6 +90,10 @@ export function readMergedHooksConfig(cwd?: string): HooksConfig { const customPoliciesPath = project.customPoliciesPath ?? local.customPoliciesPath ?? global_.customPoliciesPath; + // customPoliciesEnabled: first scope wins + const customPoliciesEnabled = + project.customPoliciesEnabled ?? local.customPoliciesEnabled ?? global_.customPoliciesEnabled; + // llm: first scope wins const llm = project.llm ?? local.llm ?? global_.llm; @@ -97,6 +101,7 @@ export function readMergedHooksConfig(cwd?: string): HooksConfig { enabledPolicies: [...enabledSet], ...(Object.keys(mergedParams).length > 0 ? { policyParams: mergedParams } : {}), ...(customPoliciesPath !== undefined ? { customPoliciesPath } : {}), + ...(customPoliciesEnabled !== undefined ? { customPoliciesEnabled } : {}), ...(llm !== undefined ? { llm } : {}), }; }