fix(design/variants): guard --count against NaN/zero/negative input#2033
Open
jbetala7 wants to merge 1 commit into
Open
fix(design/variants): guard --count against NaN/zero/negative input#2033jbetala7 wants to merge 1 commit into
jbetala7 wants to merge 1 commit into
Conversation
`design variants --count <bad value>` silently produced zero variants
because the generation loop only clamped the upper bound. `--count` arrives
via `parseInt`, which yields NaN for non-numeric input ("abc") and passes
zero/negative values straight through. `Math.min(NaN, 7)` is NaN, so the
`for (i = 0; i < NaN; i++)` loop never ran and the JSON result emitted
`"count": null` — a confusing success-with-nothing for any caller parsing it.
Add an exported `normalizeVariantCount` helper that clamps to the supported
[1, 7] range and falls back to the default of 3 for non-finite input, then
use it where the bare upper-bound cap was. Pure and unit-tested so the
behavior is pinned without an API key.
Fixes garrytan#2032
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Contributor
|
@16francej ensures numers are real. merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
design variants --count <bad value>silently produces zero variants and emits a misleading JSON result.--countis parsed withparseIntand never validated (design/src/cli.ts:200), andvariants()only clamped the upper bound (design/src/variants.ts):So bad inputs flow through. Measured against the real clamp + JSON-emit path on
main(c7ae632):--countcountabcnull00-2-233107Math.min(NaN, 7)isNaN, sofor (i = 0; i < NaN; i++)never runs and the command exits "successfully" having created nothing, reporting"count": null. A single typo (--count e) is enough.Root cause
No lower-bound or NaN guard on the requested count — only the
<= 7cap.Fix
Add a small exported, pure
normalizeVariantCounthelper and use it in place of the bare cap:NaN/Infinity) -> default 30/ negative -> 1> 7-> 7 (unchanged)This mirrors the exported-helper validation shape proposed for
--api-timeoutin #1528, but is independent of it (different flag).Testing
bun test design/test/variants-retry-after.test.ts-> 10 pass / 0 fail (5 existing + 5 new). Fullbun test design/test/passes. The helper is pure, so the regression is pinned without anANTHROPIC_API_KEY/OPENAI_API_KEY.Scope / collision check
design/src/variants.ts+ its test. No behavior change for valid counts.--api-timeoutguard, fix: preserve every generated design variant in plan-design-review #1737 variant preservation) — none guard--count. Searchedvariants,design count,design timeout; no overlap.Fixes #2032