Repository navigation
fix(cli): refuse an empty numeric flag value instead of reading it as 0 - #3793
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
No issues found across 2 files
You’re at about 98% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
|
This PR is ready at ca41e6a. The parser now refuses an empty numeric flag value instead of reading it as 0, and the change stays within the parser and its test. Only one check has run on this fork PR so far, so the full CI suite has not run yet. There are no conflicts. I did not run the new test or the base-versus-head failure locally. I traced them through the old code path. I also did not verify the pnpm check:affected result, which was run on the earlier head bc44acc. Not blocking, and you can take or leave these: parseSourceValue in packages/kernel/src/source-value.ts still converts strings with Number(value), so a config or remote-config profile with a numeric key set to "" or " " still becomes 0 and passes the min check (I read this in the code and did not run it, and env vars are not affected because blank values are skipped), and the blank-string guard at src/cli/parser/args.ts#L311 repeats the inline check used for booleanOrString, but the messages differ so it is fine as is. Nothing else needs to happen before merge. You could decide separately whether to apply the blank-numeric rule to config sources in a follow-up. |
|
Thanks! |
Summary
The CLI parser converts
intandnumberflag values withNumber(value).Number('')andNumber(' ')return0, so an empty or blank value passes the finite check and becomes0. For flags whose minimum is0, the command runs with that value and gives no error:--retries=,--hold-ms "",--delay-ms=,--pause-ms=,--interval-ms=,--duration-ms=,--jitter-px=, and--settle-quiet=. This happens, for example, when a script passes--retries="$RETRIES"and the variable is unset. For flags with a minimum of1or more, the user seesInvalid <flag>:with an empty value instead of the real cause.This change refuses an empty or blank numeric value with the existing
Flag <name> requires a value.error.booleanOrStringflags already refuse an empty inline value. String and enum flags do not change.src/cli/parser/args.ts,src/cli/parser/__tests__/args-validation.test.ts).Validation
4a8abed, headca41e6a.pnpm exec vitest run src/cli/parser/__tests__/args-validation.test.ts: base, 1 failed and 23 passed (the new test); head, 24 passed.pnpm check:affected --run --head bc44accc68fa4e1006f693841fea6282cd0700ce(the same change before a rebase onto4a8abed, which touches none of these files): format, lint, typecheck, layering, fallow, build, and vitest-related (60 files, 657 tests) passed.exactCommit=true.