Skip to content

Commit f2a6d40

Browse files
fix(hooks): preserve disabled hook status compatibility
Co-authored-by: sunlit-deng <[email protected]>
1 parent 70decfe commit f2a6d40

2 files changed

Lines changed: 38 additions & 14 deletions

File tree

‎src/cli/hooks-cli.test.ts‎

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,6 @@ describe("hooks cli formatting", () => {
128128
expect(output).not.toContain("Internal Hooks");
129129
});
130130

131-
it("labels hooks status output", () => {
132-
const output = formatHooksCheck(report, {});
133-
expect(output).toContain("Hooks Status");
134-
});
135-
136-
it("classifies eventless hooks as not ready in human check output", () => {
137-
const output = formatHooksCheck(createEventlessHookReport(), {});
138-
139-
expect(output).toContain("Ready: 0");
140-
expect(output).toContain("Not ready: 1");
141-
expect(output).toContain("session-memory - no events defined");
142-
});
143-
144131
it("shows eventless hooks as blocked by their event declaration in list output", () => {
145132
const output = formatHooksList(createEventlessHookReport(), {});
146133

@@ -156,6 +143,30 @@ describe("hooks cli formatting", () => {
156143
expect(output).not.toContain("missing requirements");
157144
});
158145

146+
it.each([
147+
["disabled in config", "disabled in config"],
148+
["workspace hook (disabled by default)", "workspace hook"],
149+
] as const)(
150+
"does not report disabled hook policy as a missing requirement: %s",
151+
(blockedReason, displayedPolicyReason) => {
152+
const disabledReport: HookStatusReport = {
153+
...report,
154+
hooks: [
155+
{
156+
...expectDefined(report.hooks[0], "report.hooks[0] test invariant"),
157+
enabledByConfig: false,
158+
loadable: false,
159+
blockedReason,
160+
},
161+
],
162+
};
163+
const output = formatHooksList(disabledReport, { verbose: true });
164+
165+
expect(output).toContain("disabled");
166+
expect(output).not.toContain(displayedPolicyReason);
167+
},
168+
);
169+
159170
it("shows eventless hooks as blocked by their event declaration in info output", () => {
160171
const output = formatHookInfo(createEventlessHookReport(), "session-memory", {});
161172

@@ -171,6 +182,19 @@ describe("hooks cli formatting", () => {
171182
expect(output).toContain("DEMO_HOOK_TOKEN");
172183
});
173184

185+
it("labels hooks status output", () => {
186+
const output = formatHooksCheck(report, {});
187+
expect(output).toContain("Hooks Status");
188+
});
189+
190+
it("classifies eventless hooks as not ready in human check output", () => {
191+
const output = formatHooksCheck(createEventlessHookReport(), {});
192+
193+
expect(output).toContain("Ready: 0");
194+
expect(output).toContain("Not ready: 1");
195+
expect(output).toContain("session-memory - no events defined");
196+
});
197+
174198
it("classifies eventless hooks as not eligible in JSON check output", () => {
175199
const output = JSON.parse(formatHooksCheck(createEventlessHookReport(), { json: true }));
176200

‎src/cli/hooks-cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function formatHookSource(hook: HookStatusEntry): string {
143143

144144
function formatHookMissingSummary(hook: HookStatusEntry): string {
145145
const missing: string[] = [];
146-
if (hook.blockedReason && hook.blockedReason !== "missing requirements") {
146+
if (hook.enabledByConfig && hook.blockedReason && hook.blockedReason !== "missing requirements") {
147147
missing.push(hook.blockedReason);
148148
}
149149
if (hook.missing.bins.length > 0) {

0 commit comments

Comments
 (0)