Skip to content

Commit b10beee

Browse files
authored
fix(onboard): preserve the saved skills package manager (#130438)
Keep explicit CLI choice precedence while preserving existing pnpm, Bun, and Yarn preferences when onboarding is rerun. Retain npm defaults for fresh config and the narrower explicit CLI choices. Fixes #130433.
1 parent 86e2083 commit b10beee

5 files changed

Lines changed: 89 additions & 32 deletions

File tree

‎docs/tools/skills-config.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ Most skills configuration lives under `skills` in
8484
with WAL-reset-safe `node:sqlite` is supported as an explicit runtime opt-in.
8585
`openclaw setup --node-manager` and `openclaw onboard --node-manager` accept
8686
`npm`, `pnpm`, or `bun`; set `"yarn"` directly in config for Yarn-backed skill
87-
installs.
87+
installs. Setup preserves this preference unless you pass `--node-manager`;
88+
fresh configurations default to `npm`.
8889
</ParamField>
8990

9091
<ParamField path="skills.install.allowUploadedArchives" type="boolean" default="false">
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import type { OpenClawConfig } from "../../../config/types.openclaw.js";
3+
import { applyNonInteractiveSkillsConfig } from "./skills-config.js";
4+
5+
describe("non-interactive skills config", () => {
6+
it.each([
7+
[undefined, undefined, "npm"],
8+
["npm", undefined, "npm"],
9+
["pnpm", undefined, "pnpm"],
10+
["bun", undefined, "bun"],
11+
["yarn", undefined, "yarn"],
12+
["yarn", "npm", "npm"],
13+
["bun", "pnpm", "pnpm"],
14+
["pnpm", "bun", "bun"],
15+
] as const)("resolves saved %s with requested %s to %s", (saved, requested, expected) => {
16+
const nextConfig: OpenClawConfig = {
17+
skills: { install: { nodeManager: saved, preferBrew: false } },
18+
};
19+
const result = applyNonInteractiveSkillsConfig({
20+
nextConfig,
21+
opts: { nodeManager: requested },
22+
runtime: { log: vi.fn(), error: vi.fn(), exit: vi.fn() },
23+
});
24+
25+
expect(result.skills?.install).toEqual({ nodeManager: expected, preferBrew: false });
26+
expect(nextConfig.skills?.install?.nodeManager).toBe(saved);
27+
});
28+
29+
it("leaves skills untouched when setup is skipped, even with an explicit manager", () => {
30+
const nextConfig: OpenClawConfig = {
31+
skills: { install: { nodeManager: "yarn", preferBrew: false } },
32+
};
33+
expect(
34+
applyNonInteractiveSkillsConfig({
35+
nextConfig,
36+
opts: { skipSkills: true, nodeManager: "npm" },
37+
runtime: { log: vi.fn(), error: vi.fn(), exit: vi.fn() },
38+
}),
39+
).toEqual(nextConfig);
40+
});
41+
});

‎src/commands/onboard-non-interactive/local/skills-config.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export function applyNonInteractiveSkillsConfig(params: {
2121
return nextConfig;
2222
}
2323

24-
const nodeManager = opts.nodeManager ?? "npm";
25-
if (!["npm", "pnpm", "bun"].includes(nodeManager)) {
24+
const nodeManager = opts.nodeManager;
25+
if (nodeManager !== undefined && !["npm", "pnpm", "bun"].includes(nodeManager)) {
2626
runtime.error('Invalid --node-manager. Use "npm", "pnpm", or "bun".');
2727
runtime.exit(1);
2828
return nextConfig;
@@ -33,7 +33,7 @@ export function applyNonInteractiveSkillsConfig(params: {
3333
...nextConfig.skills,
3434
install: {
3535
...nextConfig.skills?.install,
36-
nodeManager,
36+
nodeManager: nodeManager ?? nextConfig.skills?.install?.nodeManager ?? "npm",
3737
},
3838
},
3939
};

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

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -436,35 +436,51 @@ describe("setupSkills", () => {
436436
);
437437
});
438438

439-
it("uses the requested node manager for selected node-backed installs", async () => {
440-
mockMissingBrewStatus([
441-
createBundledSkill({
442-
name: "node-helper",
443-
description: "Node helper",
444-
bins: ["node-helper"],
445-
installLabel: "Install node-helper",
446-
installKind: "node",
447-
}),
448-
]);
439+
it.each([
440+
[undefined, undefined, "npm"],
441+
["npm", undefined, "npm"],
442+
["pnpm", undefined, "pnpm"],
443+
["bun", undefined, "bun"],
444+
["yarn", undefined, "yarn"],
445+
["yarn", "npm", "npm"],
446+
["bun", "pnpm", "pnpm"],
447+
["pnpm", "bun", "bun"],
448+
] as const)(
449+
"installs with saved %s and requested %s using %s",
450+
async (saved, requested, expected) => {
451+
mockMissingBrewStatus([
452+
createBundledSkill({
453+
name: "node-helper",
454+
description: "Node helper",
455+
bins: ["node-helper"],
456+
installLabel: "Install node-helper",
457+
installKind: "node",
458+
}),
459+
]);
449460

450-
const { prompter } = createPrompter({ multiselect: ["node-helper"] });
451-
const next = await setupSkills({} as OpenClawConfig, "/tmp/ws", runtime, prompter, {
452-
nodeManager: "pnpm",
453-
});
461+
const { prompter } = createPrompter({ multiselect: ["node-helper"] });
462+
const next = await setupSkills(
463+
{ skills: { install: { nodeManager: saved } } },
464+
"/tmp/ws",
465+
runtime,
466+
prompter,
467+
{ nodeManager: requested },
468+
);
454469

455-
expect(next.skills?.install?.nodeManager).toBe("pnpm");
456-
expect(mocks.installSkill).toHaveBeenCalledWith(
457-
expect.objectContaining({
458-
skillName: "node-helper",
459-
installId: "node",
460-
config: expect.objectContaining({
461-
skills: expect.objectContaining({
462-
install: expect.objectContaining({ nodeManager: "pnpm" }),
470+
expect(next.skills?.install?.nodeManager).toBe(expected);
471+
expect(mocks.installSkill).toHaveBeenCalledWith(
472+
expect.objectContaining({
473+
skillName: "node-helper",
474+
installId: "node",
475+
config: expect.objectContaining({
476+
skills: expect.objectContaining({
477+
install: expect.objectContaining({ nodeManager: expected }),
478+
}),
463479
}),
464480
}),
465-
}),
466-
);
467-
});
481+
);
482+
},
483+
);
468484

469485
it("does not show Homebrew guidance when a missing brew dependency is not selected", async () => {
470486
if (!supportsHomebrewPrompt) {

‎src/commands/onboard-skills.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function resolveDefaultNodeManager(
120120
config: OpenClawConfig,
121121
requested: NodeManagerChoice | undefined,
122122
runtime: RuntimeEnv,
123-
): NodeManagerChoice {
123+
) {
124124
if (requested !== undefined) {
125125
if (!isNodeManagerChoice(requested)) {
126126
runtime.error('Invalid --node-manager. Use "npm", "pnpm", or "bun".');
@@ -129,8 +129,7 @@ function resolveDefaultNodeManager(
129129
}
130130
return requested;
131131
}
132-
const existing = config.skills?.install?.nodeManager;
133-
return existing === "npm" || existing === "pnpm" || existing === "bun" ? existing : "npm";
132+
return config.skills?.install?.nodeManager ?? "npm";
134133
}
135134

136135
/** Runs the interactive skills setup step and returns the updated config. */

0 commit comments

Comments
 (0)