Skip to content

Commit ad92a49

Browse files
committed
fix(cli): honor profile selection before cached help
1 parent be5e79c commit ad92a49

2 files changed

Lines changed: 52 additions & 23 deletions

File tree

‎openclaw.mjs‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -457,37 +457,29 @@ const resolvePrecomputedCommandHelpByName = (commandName) => {
457457

458458
const resolvePrecomputedCommandHelp = (argv) => {
459459
const args = argv.slice(2);
460-
let commandHelp = null;
461-
let sawHelp = false;
462-
463460
for (let index = 0; index < args.length; index += 1) {
464461
const arg = args[index];
465462
if (!arg || arg === "--") {
466463
return null;
467464
}
468-
if (!commandHelp) {
469-
const consumed = consumeLauncherRootOptionToken(args, index);
470-
if (consumed > 0) {
471-
index += consumed - 1;
472-
continue;
473-
}
474-
if (arg.startsWith("-")) {
475-
return null;
476-
}
477-
commandHelp = resolvePrecomputedCommandHelpByName(arg);
478-
if (!commandHelp) {
479-
return null;
480-
}
481-
continue;
465+
// The runtime entry owns profile validation and config projection before cached help.
466+
if (arg === "--dev" || arg === "--profile" || arg.startsWith("--profile=")) {
467+
return null;
482468
}
483-
if (LAUNCHER_HELP_FLAGS.has(arg)) {
484-
sawHelp = true;
469+
const consumed = consumeLauncherRootOptionToken(args, index);
470+
if (consumed > 0) {
471+
index += consumed - 1;
485472
continue;
486473
}
487-
return null;
474+
const commandHelp = resolvePrecomputedCommandHelpByName(arg);
475+
const helpFlags = args.slice(index + 1);
476+
return commandHelp &&
477+
helpFlags.length > 0 &&
478+
helpFlags.every((flag) => LAUNCHER_HELP_FLAGS.has(flag))
479+
? commandHelp
480+
: null;
488481
}
489-
490-
return commandHelp && sawHelp ? commandHelp : null;
482+
return null;
491483
};
492484

493485
const isHelpFastPathDisabled = () =>

‎test/openclaw-launcher.e2e.test.ts‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ describe("openclaw launcher", () => {
454454

455455
const result = spawnSync(
456456
process.execPath,
457-
[path.join(fixtureRoot, "openclaw.mjs"), "--profile", "work", "--no-color", "models", "-h"],
457+
[path.join(fixtureRoot, "openclaw.mjs"), "--log-level", "warn", "--no-color", "models", "-h"],
458458
{
459459
cwd: fixtureRoot,
460460
env: launcherEnv(),
@@ -466,6 +466,43 @@ describe("openclaw launcher", () => {
466466
expect(result.stdout).toBe("PRECOMPUTED models help\n");
467467
});
468468

469+
it.each(
470+
[
471+
["--profile", "work", "nodes", "--help"],
472+
["--profile=work", "nodes", "--help"],
473+
["--dev", "nodes", "--help"],
474+
["--profile", "default", "models", "--help"],
475+
["--profile=", "models", "--help"],
476+
["--profile", "bad profile", "models", "--help"],
477+
["--dev", "--profile", "work", "models", "--help"],
478+
["--profile", "work", "--dev", "models", "--help"],
479+
].map((args) => ({ args, invocation: args.join(" ") })),
480+
)("passes profile selection to the runtime before cached help: $invocation", async ({ args }) => {
481+
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
482+
await fs.writeFile(
483+
path.join(fixtureRoot, "dist", "cli-startup-metadata.json"),
484+
JSON.stringify({
485+
nodesHelpText: "PRECOMPUTED nodes help\n",
486+
subcommandHelpText: { models: "PRECOMPUTED models help\n" },
487+
}),
488+
"utf8",
489+
);
490+
await fs.writeFile(
491+
path.join(fixtureRoot, "dist", "entry.js"),
492+
"process.stdout.write(JSON.stringify(process.argv.slice(2)));\n",
493+
"utf8",
494+
);
495+
496+
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs"), ...args], {
497+
cwd: fixtureRoot,
498+
env: launcherEnv(),
499+
encoding: "utf8",
500+
});
501+
502+
expect(result.status).toBe(0);
503+
expect(result.stdout).toBe(JSON.stringify(args));
504+
});
505+
469506
it("defers precomputed subcommand help to the runtime entry when container env is set", async () => {
470507
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
471508
await fs.writeFile(

0 commit comments

Comments
 (0)