diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e73ac36d..dfde493c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.0.15-beta.0 — 2026-11-17 + +### Fixes + +- `failproofai policies` warns about an `enabledPolicies` name that matches no policy in this build, instead of dropping it without a word. On a machine with no regex pack installed that key is still what registers the built-in policies, and a misspelled or retired name never ran while nothing said so. The warning takes the screen's attention line (`Unknown enabled policy "block-env-file", possibly a typo, so it never runs.`) and sends an `enabled_policies_validation_warning` event, as an unknown `policyParams` key already does. The listing also counts the `failproofai/` spelling, which the hook path has always accepted (#998) + ## 1.0.14-beta.0 — 2026-11-16 ### Features diff --git a/__tests__/hooks/new-telemetry.test.ts b/__tests__/hooks/new-telemetry.test.ts index 8a4ba1b4c..7710b22eb 100644 --- a/__tests__/hooks/new-telemetry.test.ts +++ b/__tests__/hooks/new-telemetry.test.ts @@ -189,6 +189,30 @@ describe("new telemetry events — manager", () => { ); }); + it("fires enabled_policies_validation_warning when an enabled name matches no policy", async () => { + // No regex pack is installed (mocked above), so `enabledPolicies` is what + // the hook path registers, and a name it does not know is silently dropped. + vi.mocked(existsSync).mockReturnValue(false); + const { readMergedHooksConfig } = await import("../../src/hooks/hooks-config"); + vi.mocked(readMergedHooksConfig).mockReturnValue({ + enabledPolicies: ["block-sudo", "block-env-file"], + }); + + const { listHooks } = await import("../../src/hooks/manager"); + const { trackHookEvent } = await import("../../src/hooks/hook-telemetry"); + + await listHooks(); + + expect(trackHookEvent).toHaveBeenCalledWith( + "test-instance-id", + "enabled_policies_validation_warning", + expect.objectContaining({ + unknown_names_count: 1, + unknown_names: ["block-env-file"], + }), + ); + }); + it("respects FAILPROOFAI_TELEMETRY_DISABLED — the underlying helper is mocked, but the call still happens (test verifies the trigger fires unconditionally)", async () => { // The helper itself short-circuits when FAILPROOFAI_TELEMETRY_DISABLED=1 // (verified in __tests__/lib/telemetry.test.ts). Here we just confirm the diff --git a/__tests__/hooks/policies-listing.test.ts b/__tests__/hooks/policies-listing.test.ts index e5dd1534e..3d41cd48f 100644 --- a/__tests__/hooks/policies-listing.test.ts +++ b/__tests__/hooks/policies-listing.test.ts @@ -410,6 +410,53 @@ describe("the other sources", () => { }); }); +describe("enabledPolicies names (#998)", () => { + // With no regex pack installed, `handler.ts` still registers `enabledPolicies` + // through `registerBuiltinPolicies`, which keeps only the names this build + // knows. A misspelled or retired name was dropped there without a word, and + // this screen lists only the names that resolved, so it never showed either. + function enable(names: string[]): void { + writeFileSync(join(home, "policies-config.json"), JSON.stringify({ enabledPolicies: names })); + } + + it("warns about an enabled name that matches no policy, since it never runs", async () => { + wireClaude(); + enable(["block-sudo", "block-env-file"]); + const text = await run(); + expect(text).toContain('▲ Unknown enabled policy "block-env-file", possibly a typo, so it never runs.'); + expect(text).toMatch(/^BUILT IN {2}1 on, from before packs$/m); + }); + + it("names every unknown entry in one line", async () => { + wireClaude(); + enable(["block-sudo", "block-env-file", "failproofai/no-such-policy"]); + const text = await run(); + expect(text).toContain( + '▲ Unknown enabled policies "block-env-file", "failproofai/no-such-policy", possibly typos, so they never run.', + ); + }); + + it("accepts the qualified spelling the hook path accepts, and lists it", async () => { + // `registerBuiltinPolicies` normalizes both sides, so `failproofai/block-sudo` + // registers. The listing compared raw strings and left it out of the count. + wireClaude(); + enable(["failproofai/block-sudo"]); + const text = await run(); + expect(text).not.toMatch(/Unknown enabled polic/); + expect(text).toMatch(/^BUILT IN {2}1 on, from before packs$/m); + }); + + it("says nothing about enabledPolicies once a pack is installed, since none of it runs then", async () => { + // A regex pack retires the migration shim, so a known name is as inert as an + // unknown one. Warning about one of them would suggest the others still count. + wireClaude(); + installPack(); + enable(["block-env-file"]); + const text = await run(); + expect(text).not.toMatch(/Unknown enabled polic/); + }); +}); + describe("renderPoliciesScreen", () => { const strip = (s: string) => s.replace(/\x1B\[[0-9;]*m/g, ""); const SCREEN: PoliciesScreen = { diff --git a/src/hooks/manager.ts b/src/hooks/manager.ts index dfbcb8443..2768a920c 100644 --- a/src/hooks/manager.ts +++ b/src/hooks/manager.ts @@ -25,6 +25,7 @@ import { import { configuredCustomPolicyPaths, readMergedHooksConfig, readScopedHooksConfig, writeScopedHooksConfig, syncConventionPolicies, findProjectConfigDir } from "./hooks-config"; import type { HooksConfig, ConventionPolicyRecord } from "./policy-types"; import { BUILTIN_POLICIES } from "./builtin-policies"; +import { normalizePolicyName } from "./policy-registry"; import { loadCustomHooks, discoverPolicyFiles } from "./custom-hooks-loader"; import { getSemanticRegistrations } from "./custom-hooks-registry"; import { trackHookEvent } from "./hook-telemetry"; @@ -1501,6 +1502,28 @@ export async function listHooks(cwd?: string, { all = false }: { all?: boolean } } } + // Unknown `enabledPolicies` names (#998). Only while the migration shim is + // live: with no regex pack installed, `handler.ts` hands this key to + // `registerBuiltinPolicies`, which registers the names this build knows and + // drops the rest without a word. Names are normalized the same way it + // normalizes them, so `failproofai/` counts as known. Once a regex pack is + // installed nothing reads the key, and a typo there is no more inert than a + // correct name, so there is nothing to single out. + const legacyShimLive = !hasInstalledRegexPacks(); + const enabledBuiltinSet = new Set(config.enabledPolicies.map(normalizePolicyName)); + const builtinNames = new Set(BUILTIN_POLICIES.map((p) => normalizePolicyName(p.name))); + const unknownEnabled = legacyShimLive + ? config.enabledPolicies.filter((name) => !builtinNames.has(normalizePolicyName(name))) + : []; + if (unknownEnabled.length > 0) { + try { + await trackHookEvent(getInstanceId(), "enabled_policies_validation_warning", { + unknown_names_count: unknownEnabled.length, + unknown_names: unknownEnabled, + }); + } catch {} + } + // Explicit custom policy files. const custom: PoliciesScreenRow[] = []; let customProblem: string | null = null; @@ -1773,6 +1796,16 @@ export async function listHooks(cwd?: string, { all = false }: { all?: boolean } attention = { failed: false, text: "Policies are not enforcing yet.", fix: "failproofai config" }; } else if (customProblem) { attention = { failed: false, text: customProblem }; + } else if (unknownEnabled.length > 0) { + // Above the scope and params lines: this one is a policy the user believes + // is running and is not. + attention = { + failed: false, + text: + unknownEnabled.length === 1 + ? `Unknown enabled policy "${unknownEnabled[0]}", possibly a typo, so it never runs.` + : `Unknown enabled policies ${unknownEnabled.map((name) => `"${name}"`).join(", ")}, possibly typos, so they never run.`, + }; } else if (installedScopes.length > 1) { attention = { failed: false, @@ -1790,9 +1823,9 @@ export async function listHooks(cwd?: string, { all = false }: { all?: boolean } } // The same test the hook path uses to decide it enforces these itself. - const legacy = hasInstalledRegexPacks() + const legacy = !legacyShimLive ? [] - : BUILTIN_POLICIES.filter((p) => config.enabledPolicies.includes(p.name)).map((p) => ({ + : BUILTIN_POLICIES.filter((p) => enabledBuiltinSet.has(normalizePolicyName(p.name))).map((p) => ({ name: p.name, description: p.description, }));