refactor: rename hooks docs and add tests
This commit is contained in:
54
src/cli/hooks-cli.test.ts
Normal file
54
src/cli/hooks-cli.test.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { HookStatusReport } from "../hooks/hooks-status.js";
|
||||
import { formatHooksCheck, formatHooksList } from "./hooks-cli.js";
|
||||
|
||||
const report: HookStatusReport = {
|
||||
workspaceDir: "/tmp/workspace",
|
||||
managedHooksDir: "/tmp/hooks",
|
||||
hooks: [
|
||||
{
|
||||
name: "session-memory",
|
||||
description: "Save session context to memory",
|
||||
source: "clawdbot-bundled",
|
||||
filePath: "/tmp/hooks/session-memory/HOOK.md",
|
||||
baseDir: "/tmp/hooks/session-memory",
|
||||
handlerPath: "/tmp/hooks/session-memory/handler.js",
|
||||
hookKey: "session-memory",
|
||||
emoji: "💾",
|
||||
homepage: "https://docs.clawd.bot/hooks#session-memory",
|
||||
events: ["command:new"],
|
||||
always: false,
|
||||
disabled: false,
|
||||
eligible: true,
|
||||
requirements: {
|
||||
bins: [],
|
||||
anyBins: [],
|
||||
env: [],
|
||||
config: [],
|
||||
os: [],
|
||||
},
|
||||
missing: {
|
||||
bins: [],
|
||||
anyBins: [],
|
||||
env: [],
|
||||
config: [],
|
||||
os: [],
|
||||
},
|
||||
configChecks: [],
|
||||
install: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("hooks cli formatting", () => {
|
||||
it("labels hooks list output", () => {
|
||||
const output = formatHooksList(report, {});
|
||||
expect(output).toContain("Hooks");
|
||||
expect(output).not.toContain("Internal Hooks");
|
||||
});
|
||||
|
||||
it("labels hooks status output", () => {
|
||||
const output = formatHooksCheck(report, {});
|
||||
expect(output).toContain("Hooks Status");
|
||||
});
|
||||
});
|
||||
@@ -125,9 +125,7 @@ export function formatHooksList(report: HookStatusReport, opts: HooksListOptions
|
||||
const notEligible = hooks.filter((h) => !h.eligible);
|
||||
|
||||
const lines: string[] = [];
|
||||
lines.push(
|
||||
chalk.bold.cyan("Internal Hooks") + chalk.gray(` (${eligible.length}/${hooks.length} ready)`),
|
||||
);
|
||||
lines.push(chalk.bold.cyan("Hooks") + chalk.gray(` (${eligible.length}/${hooks.length} ready)`));
|
||||
lines.push("");
|
||||
|
||||
if (eligible.length > 0) {
|
||||
@@ -273,7 +271,7 @@ export function formatHooksCheck(report: HookStatusReport, opts: HooksCheckOptio
|
||||
const notEligible = report.hooks.filter((h) => !h.eligible);
|
||||
|
||||
const lines: string[] = [];
|
||||
lines.push(chalk.bold.cyan("Internal Hooks Status"));
|
||||
lines.push(chalk.bold.cyan("Hooks Status"));
|
||||
lines.push("");
|
||||
lines.push(`Total hooks: ${report.hooks.length}`);
|
||||
lines.push(chalk.green(`Ready: ${eligible.length}`));
|
||||
@@ -373,7 +371,7 @@ export function registerHooksCli(program: Command): void {
|
||||
|
||||
hooks
|
||||
.command("list")
|
||||
.description("List all internal hooks")
|
||||
.description("List all hooks")
|
||||
.option("--eligible", "Show only eligible hooks", false)
|
||||
.option("--json", "Output as JSON", false)
|
||||
.option("-v, --verbose", "Show more details including missing requirements", false)
|
||||
|
||||
Reference in New Issue
Block a user