Skip to content

fix(import): reject a non-numeric --max-repos instead of passing NaN - #1781

Merged
SaulMoro merged 1 commit into
Tencent:mainfrom
pcbeingused333:fix/import-max-repos-validation
Nov 7, 2026
Merged

SaulMoro merged 1 commit into
Tencent:mainfrom
pcbeingused333:fix/import-max-repos-validation

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

teamai import --from-org <org> --max-repos abc parsed the cap with parseInt, giving NaN. The org listing loops (while (repos.length < maxRepos)) never run with NaN, so the command ended with an empty whitelist and no error.

Fix: a small parsePositiveInt helper in src/import.ts, same contract as the existing parseMaxFiles (positive integer or ... must be a positive integer). Used for --max-repos (default 200 unchanged); the --from-repo branch's depth setting (default 1, not exposed as an import flag today) goes through the same helper so it cannot become NaN either.

Test: new src/__tests__/import-numeric-options.test.ts (valid value, default, and abc/0/-3/1.5 rejected without calling importFromOrg). Red before the fix (4 failed), green after (6 passed). import-org and import-dir tests still pass; npm run typecheck and oxlint clean.

Real CLI (after npm run build): node dist/index.js import --from-org acme --max-repos abc prints ✖ Import from organization [FAILED: --max-repos must be a positive integer] and exits non-zero.

This change was prepared with AI assistance (Claude Code) and reviewed before submission.

parseInt('abc') gave NaN, which importFromOrg's listing loop (while len < NaN) never entered, so the run finished with an empty whitelist and no error. Validate like --max-files: a positive integer or an error.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

No findings in the scoped diff.

The PR description provides sufficient testing: focused unit tests, related import tests, typecheck, lint, and a representative real-CLI run after build showing invalid --max-repos input rejected with a non-zero exit.

No code was run, built, or installed during this review.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Approving. parseInt('abc') gave NaN, and while (repos.length < NaN) never runs, so import --from-org <org> --max-repos abc ended with an empty whitelist and exit 0. parsePositiveInt uses the same contract as the existing parseMaxFiles (Number, an integer of 1 or more, otherwise "<flag> must be a positive integer"), so 0, -3 and 1.5 are refused too. The default of 200 is unchanged. depth is not an import flag, and import-from-repo.ts:64 already required a positive integer there, so routing it through the same helper only moves the refusal earlier. The new non-zero exit replaces a silent no-op, so it is the fix, not a breaking change.

The new tests go through importCmd, and the description has a built-CLI run of the failing input.

[P3 nit] parseMaxFiles and parsePositiveInt now share their body. parseMaxFiles could be the helper with --max-files and no default, if you want one copy. Optional.

Merge risk: low

Alignment: good

  • The fix covers the reported input. The only other change is depth, which the description explains.

Impact: small

  • One option parser of import. A valid value behaves as before.

Verification: good

  • The description shows the four refused inputs red before the fix, and a built-CLI run of --max-repos abc.

Rollback cost: low

  • A revert restores the old parse.

Error detection: good

  • A bad value now fails with a message naming the flag, instead of importing nothing.

CI review: no findings, and we agree. I'll merge once CI is green at this head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants