Comprehensive update to complete the openclaw → ironclaw CLI rename across the codebase, fix build/runtime issues, and add test coverage for infra modules. CLI binary rename (openclaw → ironclaw): - Update DEFAULT_CLI_NAME and all argv parsing to recognize "ironclaw" binary - Extend package name sets (CORE_PACKAGE_NAMES, ALL_PACKAGE_NAMES) to include both "ironclaw" and "openclaw" for backward compatibility - Update NPM registry URL to fetch from ironclaw package - Update gateway lock detection, port listener classification, and launchd/systemd service scanning to recognize ironclaw-prefixed services and binaries - Update daemon inspect markers and legacy detection for ironclaw - Update voice-call extension core-bridge to resolve ironclaw package root - Fix install instructions in embeddings error messages (npm i -g ironclaw@latest) Web app / Next.js fixes: - Replace fragile `npx next` invocations with direct `node next-bin` resolution to avoid broken pnpm virtual-store symlinks in global installs - Add resolveNextBin() helper that resolves apps/web/node_modules/next directly Infra hardening: - Workspace templates: compute both source and dist fallback paths for template directory resolution (fixes templates not found in bundled builds) - Control UI assets: recognize both "openclaw" and "ironclaw" package names - Update-check, update-runner, update-cli: normalize ironclaw@ tag prefixes New tests: - Add openclaw-root.test.ts, ports-format.test.ts, update-global.test.ts - Add workspace-templates.test.ts and control-ui-assets.test.ts coverage - Add argv.test.ts coverage for ironclaw binary detection Test fixes (28 failures → 0): - Update all test assertions expecting "openclaw" CLI command output to "ironclaw" - Fix version.test.ts package name from "openclaw" to "ironclaw" - Fix camera/canvas temp path patterns in nodes-camera and program.nodes-media tests - Fix pairing message, telegram bot, channels, daemon, onboard, gateway tool, status, and profile test expectations Version: 2026.2.10-1.2 (published to npm as ironclaw@2026.2.10-1.2) Co-authored-by: Cursor <cursoragent@cursor.com>
246 lines
8.4 KiB
TypeScript
246 lines
8.4 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import type { HookStatusReport } from "../hooks/hooks-status.js";
|
|
import type { RuntimeEnv } from "../runtime.js";
|
|
import type { WizardPrompter } from "../wizard/prompts.js";
|
|
import { setupInternalHooks } from "./onboard-hooks.js";
|
|
|
|
// Mock hook discovery modules
|
|
vi.mock("../hooks/hooks-status.js", () => ({
|
|
buildWorkspaceHookStatus: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("../agents/agent-scope.js", () => ({
|
|
resolveAgentWorkspaceDir: vi.fn().mockReturnValue("/mock/workspace"),
|
|
resolveDefaultAgentId: vi.fn().mockReturnValue("main"),
|
|
}));
|
|
|
|
describe("onboard-hooks", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
const createMockPrompter = (multiselectValue: string[]): WizardPrompter => ({
|
|
confirm: vi.fn().mockResolvedValue(true),
|
|
note: vi.fn().mockResolvedValue(undefined),
|
|
intro: vi.fn().mockResolvedValue(undefined),
|
|
outro: vi.fn().mockResolvedValue(undefined),
|
|
text: vi.fn().mockResolvedValue(""),
|
|
select: vi.fn().mockResolvedValue(""),
|
|
multiselect: vi.fn().mockResolvedValue(multiselectValue),
|
|
progress: vi.fn().mockReturnValue({
|
|
stop: vi.fn(),
|
|
update: vi.fn(),
|
|
}),
|
|
});
|
|
|
|
const createMockRuntime = (): RuntimeEnv => ({
|
|
log: vi.fn(),
|
|
error: vi.fn(),
|
|
exit: vi.fn(),
|
|
});
|
|
|
|
const createMockHookReport = (eligible = true): HookStatusReport => ({
|
|
workspaceDir: "/mock/workspace",
|
|
managedHooksDir: "/mock/.openclaw/hooks",
|
|
hooks: [
|
|
{
|
|
name: "session-memory",
|
|
description: "Save session context to memory when /new command is issued",
|
|
source: "openclaw-bundled",
|
|
pluginId: undefined,
|
|
filePath: "/mock/workspace/hooks/session-memory/HOOK.md",
|
|
baseDir: "/mock/workspace/hooks/session-memory",
|
|
handlerPath: "/mock/workspace/hooks/session-memory/handler.js",
|
|
hookKey: "session-memory",
|
|
emoji: "💾",
|
|
events: ["command:new"],
|
|
homepage: undefined,
|
|
always: false,
|
|
disabled: false,
|
|
eligible,
|
|
managedByPlugin: false,
|
|
requirements: {
|
|
bins: [],
|
|
anyBins: [],
|
|
env: [],
|
|
config: ["workspace.dir"],
|
|
os: [],
|
|
},
|
|
missing: {
|
|
bins: [],
|
|
anyBins: [],
|
|
env: [],
|
|
config: eligible ? [] : ["workspace.dir"],
|
|
os: [],
|
|
},
|
|
configChecks: [],
|
|
install: [],
|
|
},
|
|
{
|
|
name: "command-logger",
|
|
description: "Log all command events to a centralized audit file",
|
|
source: "openclaw-bundled",
|
|
pluginId: undefined,
|
|
filePath: "/mock/workspace/hooks/command-logger/HOOK.md",
|
|
baseDir: "/mock/workspace/hooks/command-logger",
|
|
handlerPath: "/mock/workspace/hooks/command-logger/handler.js",
|
|
hookKey: "command-logger",
|
|
emoji: "📝",
|
|
events: ["command"],
|
|
homepage: undefined,
|
|
always: false,
|
|
disabled: false,
|
|
eligible,
|
|
managedByPlugin: false,
|
|
requirements: {
|
|
bins: [],
|
|
anyBins: [],
|
|
env: [],
|
|
config: ["workspace.dir"],
|
|
os: [],
|
|
},
|
|
missing: {
|
|
bins: [],
|
|
anyBins: [],
|
|
env: [],
|
|
config: eligible ? [] : ["workspace.dir"],
|
|
os: [],
|
|
},
|
|
configChecks: [],
|
|
install: [],
|
|
},
|
|
],
|
|
});
|
|
|
|
describe("setupInternalHooks", () => {
|
|
it("should enable hooks when user selects them", async () => {
|
|
const { buildWorkspaceHookStatus } = await import("../hooks/hooks-status.js");
|
|
vi.mocked(buildWorkspaceHookStatus).mockReturnValue(createMockHookReport());
|
|
|
|
const cfg: OpenClawConfig = {};
|
|
const prompter = createMockPrompter(["session-memory"]);
|
|
const runtime = createMockRuntime();
|
|
|
|
const result = await setupInternalHooks(cfg, runtime, prompter);
|
|
|
|
expect(result.hooks?.internal?.enabled).toBe(true);
|
|
expect(result.hooks?.internal?.entries).toEqual({
|
|
"session-memory": { enabled: true },
|
|
});
|
|
expect(prompter.note).toHaveBeenCalledTimes(2);
|
|
expect(prompter.multiselect).toHaveBeenCalledWith({
|
|
message: "Enable hooks?",
|
|
options: [
|
|
{ value: "__skip__", label: "Skip for now" },
|
|
{
|
|
value: "session-memory",
|
|
label: "💾 session-memory",
|
|
hint: "Save session context to memory when /new command is issued",
|
|
},
|
|
{
|
|
value: "command-logger",
|
|
label: "📝 command-logger",
|
|
hint: "Log all command events to a centralized audit file",
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it("should not enable hooks when user skips", async () => {
|
|
const { buildWorkspaceHookStatus } = await import("../hooks/hooks-status.js");
|
|
vi.mocked(buildWorkspaceHookStatus).mockReturnValue(createMockHookReport());
|
|
|
|
const cfg: OpenClawConfig = {};
|
|
const prompter = createMockPrompter(["__skip__"]);
|
|
const runtime = createMockRuntime();
|
|
|
|
const result = await setupInternalHooks(cfg, runtime, prompter);
|
|
|
|
expect(result.hooks?.internal).toBeUndefined();
|
|
expect(prompter.note).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("should handle no eligible hooks", async () => {
|
|
const { buildWorkspaceHookStatus } = await import("../hooks/hooks-status.js");
|
|
vi.mocked(buildWorkspaceHookStatus).mockReturnValue(createMockHookReport(false));
|
|
|
|
const cfg: OpenClawConfig = {};
|
|
const prompter = createMockPrompter([]);
|
|
const runtime = createMockRuntime();
|
|
|
|
const result = await setupInternalHooks(cfg, runtime, prompter);
|
|
|
|
expect(result).toEqual(cfg);
|
|
expect(prompter.multiselect).not.toHaveBeenCalled();
|
|
expect(prompter.note).toHaveBeenCalledWith(
|
|
"No eligible hooks found. You can configure hooks later in your config.",
|
|
"No Hooks Available",
|
|
);
|
|
});
|
|
|
|
it("should preserve existing hooks config when enabled", async () => {
|
|
const { buildWorkspaceHookStatus } = await import("../hooks/hooks-status.js");
|
|
vi.mocked(buildWorkspaceHookStatus).mockReturnValue(createMockHookReport());
|
|
|
|
const cfg: OpenClawConfig = {
|
|
hooks: {
|
|
enabled: true,
|
|
path: "/webhook",
|
|
token: "existing-token",
|
|
},
|
|
};
|
|
const prompter = createMockPrompter(["session-memory"]);
|
|
const runtime = createMockRuntime();
|
|
|
|
const result = await setupInternalHooks(cfg, runtime, prompter);
|
|
|
|
expect(result.hooks?.enabled).toBe(true);
|
|
expect(result.hooks?.path).toBe("/webhook");
|
|
expect(result.hooks?.token).toBe("existing-token");
|
|
expect(result.hooks?.internal?.enabled).toBe(true);
|
|
expect(result.hooks?.internal?.entries).toEqual({
|
|
"session-memory": { enabled: true },
|
|
});
|
|
});
|
|
|
|
it("should preserve existing config when user skips", async () => {
|
|
const { buildWorkspaceHookStatus } = await import("../hooks/hooks-status.js");
|
|
vi.mocked(buildWorkspaceHookStatus).mockReturnValue(createMockHookReport());
|
|
|
|
const cfg: OpenClawConfig = {
|
|
agents: { defaults: { workspace: "/workspace" } },
|
|
};
|
|
const prompter = createMockPrompter(["__skip__"]);
|
|
const runtime = createMockRuntime();
|
|
|
|
const result = await setupInternalHooks(cfg, runtime, prompter);
|
|
|
|
expect(result).toEqual(cfg);
|
|
expect(result.agents?.defaults?.workspace).toBe("/workspace");
|
|
});
|
|
|
|
it("should show informative notes to user", async () => {
|
|
const { buildWorkspaceHookStatus } = await import("../hooks/hooks-status.js");
|
|
vi.mocked(buildWorkspaceHookStatus).mockReturnValue(createMockHookReport());
|
|
|
|
const cfg: OpenClawConfig = {};
|
|
const prompter = createMockPrompter(["session-memory"]);
|
|
const runtime = createMockRuntime();
|
|
|
|
await setupInternalHooks(cfg, runtime, prompter);
|
|
|
|
const noteCalls = (prompter.note as ReturnType<typeof vi.fn>).mock.calls;
|
|
expect(noteCalls).toHaveLength(2);
|
|
|
|
// First note should explain what hooks are
|
|
expect(noteCalls[0][0]).toContain("Hooks let you automate actions");
|
|
expect(noteCalls[0][0]).toContain("automate actions");
|
|
|
|
// Second note should confirm configuration
|
|
expect(noteCalls[1][0]).toContain("Enabled 1 hook: session-memory");
|
|
expect(noteCalls[1][0]).toMatch(/(?:ironclaw|openclaw)( --profile isolated)? hooks list/);
|
|
});
|
|
});
|
|
});
|