|
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import type { OpenClawConfig } from "../config/types.openclaw.js"; |
| 3 | +import { createPluginRecord } from "../plugins/status.test-fixtures.js"; |
| 4 | +import { |
| 5 | + buildPluginDiagnosticsReportMock, |
| 6 | + buildPluginInspectReportMock, |
| 7 | + buildPluginSnapshotReportMock, |
| 8 | + pluginCliConfigMock, |
| 9 | + pluginsCliRuntimeLogs, |
| 10 | + resetPluginsCliTestState, |
| 11 | + runPluginsCommand, |
| 12 | + runtimeErrors, |
| 13 | + setInstalledPluginIndexInstallRecords, |
| 14 | +} from "./plugins-cli-test-helpers.js"; |
| 15 | + |
| 16 | +const workshopMocks = vi.hoisted(() => ({ |
| 17 | + detectToolPolicyDiagnostic: vi.fn(), |
| 18 | +})); |
| 19 | + |
| 20 | +vi.mock("../skills/workshop/tool-policy-diagnostic.js", () => ({ |
| 21 | + detectSkillWorkshopToolPolicyDiagnostic: workshopMocks.detectToolPolicyDiagnostic, |
| 22 | +})); |
| 23 | + |
| 24 | +describe("plugins cli inspect", () => { |
| 25 | + beforeEach(() => { |
| 26 | + resetPluginsCliTestState(); |
| 27 | + workshopMocks.detectToolPolicyDiagnostic.mockReset(); |
| 28 | + }); |
| 29 | + |
| 30 | + it("keeps inspect on the static snapshot and distinguishes disabled reasons from errors", async () => { |
| 31 | + setInstalledPluginIndexInstallRecords({ |
| 32 | + "openclaw-mem0": { |
| 33 | + source: "clawhub", |
| 34 | + spec: "clawhub:openclaw-mem0", |
| 35 | + installPath: "/plugins/openclaw-mem0", |
| 36 | + version: "2026.5.1", |
| 37 | + clawhubPackage: "openclaw-mem0", |
| 38 | + clawhubChannel: "official", |
| 39 | + artifactKind: "npm-pack", |
| 40 | + artifactFormat: "tgz", |
| 41 | + npmIntegrity: "sha512-clawpack", |
| 42 | + npmShasum: "1".repeat(40), |
| 43 | + npmTarballName: "openclaw-mem0-2026.5.1.tgz", |
| 44 | + clawpackSha256: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 45 | + clawpackSpecVersion: 1, |
| 46 | + clawpackManifestSha256: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", |
| 47 | + clawpackSize: 4096, |
| 48 | + }, |
| 49 | + }); |
| 50 | + buildPluginSnapshotReportMock.mockReturnValue({ |
| 51 | + plugins: [createPluginRecord({ id: "openclaw-mem0", name: "Mem0" })], |
| 52 | + diagnostics: [], |
| 53 | + }); |
| 54 | + const inspectReport = { |
| 55 | + workspaceDir: "/workspace", |
| 56 | + plugin: createPluginRecord({ id: "openclaw-mem0", name: "Mem0" }), |
| 57 | + shape: "hook-only", |
| 58 | + capabilityMode: "plain", |
| 59 | + capabilityCount: 1, |
| 60 | + capabilities: [], |
| 61 | + typedHooks: [{ name: "agent_end" }], |
| 62 | + customHooks: [], |
| 63 | + tools: [], |
| 64 | + commands: [], |
| 65 | + cliCommands: [], |
| 66 | + services: [], |
| 67 | + gatewayDiscoveryServices: [], |
| 68 | + mcpServers: [ |
| 69 | + { name: "local", hasStdioTransport: true }, |
| 70 | + { name: "remote", hasStdioTransport: false }, |
| 71 | + { name: "broken", hasStdioTransport: false, unsupported: true }, |
| 72 | + ], |
| 73 | + lspServers: [], |
| 74 | + httpRouteCount: 0, |
| 75 | + bundleCapabilities: [], |
| 76 | + diagnostics: [], |
| 77 | + policy: { |
| 78 | + allowConversationAccess: true, |
| 79 | + allowedModels: [], |
| 80 | + hasAllowedModelsConfig: false, |
| 81 | + }, |
| 82 | + usesLegacyBeforeAgentStart: false, |
| 83 | + compatibility: [], |
| 84 | + }; |
| 85 | + buildPluginInspectReportMock.mockReturnValue(inspectReport); |
| 86 | + |
| 87 | + await runPluginsCommand(["plugins", "inspect", "openclaw-mem0"]); |
| 88 | + |
| 89 | + expect(buildPluginDiagnosticsReportMock).not.toHaveBeenCalled(); |
| 90 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("Policy"); |
| 91 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("allowConversationAccess: true"); |
| 92 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("ClawHub package: openclaw-mem0"); |
| 93 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("Artifact kind: npm-pack"); |
| 94 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("Npm integrity: sha512-clawpack"); |
| 95 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain( |
| 96 | + "ClawPack sha256: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 97 | + ); |
| 98 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("ClawPack spec: 1"); |
| 99 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("ClawPack size: 4096 bytes"); |
| 100 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("remote"); |
| 101 | + expect(pluginsCliRuntimeLogs.join("\n")).not.toContain("remote (unsupported transport)"); |
| 102 | + expect(pluginsCliRuntimeLogs.join("\n")).toContain("broken (unsupported transport)"); |
| 103 | + |
| 104 | + for (const { id, status, detail, label } of [ |
| 105 | + { |
| 106 | + id: "workspace-disabled", |
| 107 | + status: "disabled" as const, |
| 108 | + detail: "workspace plugin (disabled by default)", |
| 109 | + label: "Reason", |
| 110 | + }, |
| 111 | + { id: "broken", status: "error" as const, detail: "missing plugin module", label: "Error" }, |
| 112 | + ]) { |
| 113 | + const plugin = createPluginRecord({ |
| 114 | + id, |
| 115 | + enabled: status !== "disabled", |
| 116 | + status, |
| 117 | + error: detail, |
| 118 | + ...(status === "disabled" ? { activationReason: detail } : {}), |
| 119 | + }); |
| 120 | + buildPluginSnapshotReportMock.mockReturnValue({ plugins: [plugin], diagnostics: [] }); |
| 121 | + buildPluginInspectReportMock.mockReturnValue({ ...inspectReport, plugin }); |
| 122 | + |
| 123 | + await runPluginsCommand(["plugins", "inspect", id]); |
| 124 | + |
| 125 | + const inspectOutput = pluginsCliRuntimeLogs.at(-1) ?? ""; |
| 126 | + expect(inspectOutput).toContain(`Status: ${status}`); |
| 127 | + expect(inspectOutput).toContain(`${label}: ${detail}`); |
| 128 | + expect(inspectOutput).not.toContain(`${label === "Reason" ? "Error" : "Reason"}: ${detail}`); |
| 129 | + |
| 130 | + if (status === "disabled") { |
| 131 | + await runPluginsCommand(["plugins", "inspect", id, "--json"]); |
| 132 | + expect(JSON.parse(pluginsCliRuntimeLogs.at(-1) ?? "null").plugin).toMatchObject({ |
| 133 | + status: "disabled", |
| 134 | + error: detail, |
| 135 | + activationReason: detail, |
| 136 | + }); |
| 137 | + } |
| 138 | + } |
| 139 | + }); |
| 140 | + |
| 141 | + it("runtime-inspects exact plugin ids and display names without repairing deps", async () => { |
| 142 | + buildPluginSnapshotReportMock.mockReturnValue({ |
| 143 | + plugins: [ |
| 144 | + createPluginRecord({ id: "unrelated-plugin", name: "openclaw-mem0" }), |
| 145 | + createPluginRecord({ id: "openclaw-mem0", name: "Mem0" }), |
| 146 | + ], |
| 147 | + diagnostics: [], |
| 148 | + }); |
| 149 | + buildPluginInspectReportMock.mockReturnValue({ |
| 150 | + workspaceDir: "/workspace", |
| 151 | + plugin: createPluginRecord({ id: "openclaw-mem0", name: "Mem0" }), |
| 152 | + shape: "hook-only", |
| 153 | + capabilityMode: "plain", |
| 154 | + capabilityCount: 1, |
| 155 | + capabilities: [], |
| 156 | + typedHooks: [], |
| 157 | + customHooks: [], |
| 158 | + tools: [], |
| 159 | + commands: [], |
| 160 | + cliCommands: [], |
| 161 | + services: [], |
| 162 | + gatewayDiscoveryServices: [], |
| 163 | + mcpServers: [], |
| 164 | + lspServers: [], |
| 165 | + httpRouteCount: 0, |
| 166 | + bundleCapabilities: [], |
| 167 | + diagnostics: [], |
| 168 | + policy: { |
| 169 | + allowedModels: [], |
| 170 | + hasAllowedModelsConfig: false, |
| 171 | + }, |
| 172 | + usesLegacyBeforeAgentStart: false, |
| 173 | + compatibility: [], |
| 174 | + }); |
| 175 | + |
| 176 | + for (const selector of ["openclaw-mem0", "Mem0"]) { |
| 177 | + await runPluginsCommand(["plugins", "inspect", selector, "--runtime"]); |
| 178 | + expect(buildPluginDiagnosticsReportMock).toHaveBeenLastCalledWith({ |
| 179 | + config: {}, |
| 180 | + onlyPluginIds: ["openclaw-mem0"], |
| 181 | + }); |
| 182 | + } |
| 183 | + }); |
| 184 | + |
| 185 | + it("does not runtime-load plugins when inspect target is missing", async () => { |
| 186 | + buildPluginSnapshotReportMock.mockReturnValue({ |
| 187 | + plugins: [], |
| 188 | + diagnostics: [], |
| 189 | + }); |
| 190 | + |
| 191 | + await expect(runPluginsCommand(["plugins", "inspect", "missing-plugin"])).rejects.toThrow( |
| 192 | + "__exit__:1", |
| 193 | + ); |
| 194 | + |
| 195 | + expect(buildPluginSnapshotReportMock).toHaveBeenCalledWith({ config: {} }); |
| 196 | + expect(buildPluginDiagnosticsReportMock).not.toHaveBeenCalled(); |
| 197 | + expect(runtimeErrors.at(-1)).toContain("Plugin not found: missing-plugin"); |
| 198 | + }); |
| 199 | + |
| 200 | + it("explains a policy-hidden built-in Skill Workshop at the legacy inspect surface", async () => { |
| 201 | + const config: OpenClawConfig = { |
| 202 | + tools: { profile: "messaging" }, |
| 203 | + }; |
| 204 | + pluginCliConfigMock.mockReturnValue(config); |
| 205 | + workshopMocks.detectToolPolicyDiagnostic.mockReturnValue({ |
| 206 | + agentId: "main", |
| 207 | + source: "tools.profile", |
| 208 | + detail: 'tools.profile: "messaging" does not include "skill_workshop".', |
| 209 | + fix: 'Add tools.alsoAllow: ["skill_workshop"].', |
| 210 | + message: |
| 211 | + 'Skill Workshop is active, but "skill_workshop" is hidden for agent "main": tools.profile: "messaging" does not include "skill_workshop". Add tools.alsoAllow: ["skill_workshop"].', |
| 212 | + }); |
| 213 | + buildPluginSnapshotReportMock.mockReturnValue({ |
| 214 | + plugins: [], |
| 215 | + diagnostics: [], |
| 216 | + }); |
| 217 | + |
| 218 | + await expect(runPluginsCommand(["plugins", "inspect", "skill-workshop"])).rejects.toThrow( |
| 219 | + "__exit__:1", |
| 220 | + ); |
| 221 | + |
| 222 | + expect(runtimeErrors.at(-1)).toContain( |
| 223 | + "Skill Workshop is built into OpenClaw, not a plugin; configure it under skills.workshop.", |
| 224 | + ); |
| 225 | + expect(workshopMocks.detectToolPolicyDiagnostic).toHaveBeenCalledWith({ |
| 226 | + config, |
| 227 | + workshopEnabled: true, |
| 228 | + }); |
| 229 | + expect(runtimeErrors.at(-1)).toContain( |
| 230 | + 'tools.profile: "messaging" does not include "skill_workshop".', |
| 231 | + ); |
| 232 | + expect(runtimeErrors.at(-1)).toContain('Add tools.alsoAllow: ["skill_workshop"].'); |
| 233 | + }); |
| 234 | +}); |
0 commit comments