Skip to content

Commit 5ac45e7

Browse files
author
HCL
committed
fix(cli): use FLAG_TERMINATOR constant in getCommandPathInternal (#83902)
`getCommandPathInternal` compared `arg === "--"` directly, while every other helper in `argv.ts` (`isHelpOrVersionInvocation`, `hasFlag`, `hasRootVersionAlias`, `isRootInvocationForFlags`, `getFlagValue`, `getCommandPositionals`, etc.) routes its terminator check through the imported `FLAG_TERMINATOR` constant from `infra/cli-root-options.ts`. Under the current value (`"--"`) the two paths agree, but any future change to the constant would silently desync command-path resolution from help/version detection — subcommand routing would break in a way that's hard to trace because the rest of the parser would still pick up the new terminator. Replace the hardcoded literal with `FLAG_TERMINATOR` and pin a regression test that pulls the live constant through the same module-resolution path the production code uses. Closes #83902.
1 parent d124c5a commit 5ac45e7

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎src/cli/argv.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,24 @@ describe("argv helpers", () => {
259259
).toEqual(["update.channel"]);
260260
});
261261

262+
// #83902: every argv helper in this module uses the imported FLAG_TERMINATOR
263+
// constant as the args-end sentinel; getCommandPathInternal used to compare
264+
// against the string literal "--", which would silently diverge from the rest
265+
// of the parser if FLAG_TERMINATOR is ever changed. Pin against the live constant.
266+
it("stops command-path extraction at the imported FLAG_TERMINATOR constant (#83902)", async () => {
267+
const { FLAG_TERMINATOR } = await import("../infra/cli-root-options.js");
268+
expect(FLAG_TERMINATOR).toBe("--"); // current value; not the point of this test
269+
expect(
270+
getCommandPath(["node", "openclaw", "channels", FLAG_TERMINATOR, "add"], 2),
271+
).toEqual(["channels"]);
272+
expect(
273+
getCommandPathWithRootOptions(
274+
["node", "openclaw", "channels", FLAG_TERMINATOR, "add"],
275+
2,
276+
),
277+
).toEqual(["channels"]);
278+
});
279+
262280
it("extracts routed config unset positionals with interleaved root options", () => {
263281
expect(
264282
getCommandPositionalsWithRootOptions(

‎src/cli/argv.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ function getCommandPathInternal(
222222
if (!arg) {
223223
continue;
224224
}
225-
if (arg === "--") {
225+
// Every other helper in this file (isHelpOrVersionInvocation,
226+
// hasRootVersionAlias, isRootInvocationForFlags, getFlagValue, hasFlag)
227+
// uses the imported FLAG_TERMINATOR constant. Mirror that here so a future
228+
// change to FLAG_TERMINATOR in cli-root-options.ts doesn't silently diverge
229+
// command-path resolution from help/version detection. See #83902.
230+
if (arg === FLAG_TERMINATOR) {
226231
break;
227232
}
228233
if (opts.skipRootOptions) {

0 commit comments

Comments
 (0)