Skip to content

Commit 506e140

Browse files
committed
fix(cli): exit non-zero when skills info misses
1 parent 8739432 commit 506e140

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

‎src/cli/skills-cli.commands.test.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ function primeSkillVerification(overrides: Record<string, unknown> = {}) {
167167
});
168168
}
169169

170-
afterEach(() => restoreTty());
170+
afterEach(() => {
171+
restoreTty();
172+
vi.unstubAllEnvs();
173+
});
171174

172175
function mockCall(mock: unknown, index = 0): Array<unknown> {
173176
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
@@ -1376,6 +1379,39 @@ describe("skills cli commands", () => {
13761379
assert(payload);
13771380
});
13781381

1382+
it.each([
1383+
{
1384+
label: "human",
1385+
argv: ["skills", "info", "missing-skill"],
1386+
expected:
1387+
'Skill "missing-skill" not found. Run `openclaw skills list` to see available skills.\n\nTip: use `openclaw skills search`, `openclaw skills install`, and `openclaw skills update` for ClawHub-backed skills.',
1388+
},
1389+
{
1390+
label: "JSON",
1391+
argv: ["skills", "info", "missing-skill", "--json"],
1392+
expected: JSON.stringify({ error: "not found", skill: "missing-skill" }, null, 2),
1393+
},
1394+
])("exits nonzero for missing skill info in $label mode", async ({ argv, expected }) => {
1395+
vi.stubEnv("OPENCLAW_PROFILE", "");
1396+
vi.stubEnv("OPENCLAW_CONTAINER_HINT", "");
1397+
1398+
await expect(runCommand(argv)).rejects.toThrow("__exit__:1");
1399+
1400+
expect(runtimeStdout).toEqual([expected]);
1401+
expect(runtimeErrors).toStrictEqual([]);
1402+
expect(defaultRuntime.exit).toHaveBeenCalledOnce();
1403+
expect(defaultRuntime.exit).toHaveBeenCalledWith(1);
1404+
});
1405+
1406+
it("keeps successful human skill info output at exit zero", async () => {
1407+
await runCommand(["skills", "info", "calendar"]);
1408+
1409+
expect(defaultRuntime.exit).not.toHaveBeenCalled();
1410+
expect(runtimeStdout).toHaveLength(1);
1411+
expect(runtimeStdout.at(-1)).toContain("📅 calendar ✓ Ready");
1412+
expect(runtimeStdout.at(-1)).toContain("Calendar helpers");
1413+
});
1414+
13791415
it.each([
13801416
["list", ["skills", "list", "--json"]],
13811417
["info", ["skills", "info", "calendar", "--json"]],

‎src/cli/skills-cli.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from "../infra/clawhub-skills.js";
2626
import { formatErrorMessage } from "../infra/errors.js";
2727
import { defaultRuntime } from "../runtime.js";
28+
import { resolveSkillStatusEntry, type SkillStatusReport } from "../skills/discovery/status.js";
2829
import {
2930
installSkillFromClawHub,
3031
readVerifiedClawHubSkillSourceUrl,
@@ -80,9 +81,6 @@ export type {
8081
} from "./skills-cli.format.js";
8182
export { formatSkillInfo, formatSkillsCheck, formatSkillsList } from "./skills-cli.format.js";
8283

83-
type SkillStatusReport = Awaited<
84-
ReturnType<(typeof import("../skills/discovery/status.js"))["buildWorkspaceSkillStatus"]>
85-
>;
8684
type ResolvedClawHubSkillVerificationTarget = Extract<
8785
Awaited<ReturnType<typeof resolveClawHubSkillVerificationTarget>>,
8886
{ ok: true }
@@ -1236,16 +1234,22 @@ export function registerSkillsCli(program: Command) {
12361234
.option("--json", "Output as JSON", false)
12371235
.option("--agent <id>", "Target agent workspace (defaults to cwd-inferred, then default agent)")
12381236
.action(async (name: string, opts: { json?: boolean; agent?: string }, command: Command) => {
1237+
let skillFound = false;
12391238
await runSkillsAction(
1240-
(report) =>
1241-
formatSkillInfo(report, name, {
1239+
(report) => {
1240+
skillFound = resolveSkillStatusEntry(report.skills, name) !== null;
1241+
return formatSkillInfo(report, name, {
12421242
...opts,
12431243
json: hasJsonOutput(opts),
1244-
}),
1244+
});
1245+
},
12451246
{
12461247
agentId: resolveAgentOption(command, opts),
12471248
},
12481249
);
1250+
if (!skillFound) {
1251+
defaultRuntime.exit(1);
1252+
}
12491253
});
12501254

12511255
skills

0 commit comments

Comments
 (0)