Repository navigation
fix(cli): reject a non-numeric --port or --project-id instead of passing NaN - #1782
Conversation
…ing NaN
dashboard --port abc gave Number('abc') = NaN to server.listen, which threw a raw
range error; bind-project --project-id abc passed NaN to the local agent. Validate
both as integers (port 1-65535, project id >= 1) and fail with a clear message.
|
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Approving. --port and --project-id now fail with a message that names the flag, before any work starts. I ran the built CLI on this head and on main and added the runs to the description, which closes the CI review's missing-record item:
dashboard --port abc: Node'soptions.port … Received type number (NaN)becomes--port must be an integer between 1 and 65535. Both exit 1.bind-project --project-id abc: the value is refused before the "Local agent not initialized" check runs.
Two things in the description did not reproduce here. On main, dashboard --port abc exited 1 immediately and left no process running, so it did not keep running. With no HTTP install, bind-project stopped at "Local agent not initialized" before it reached the picker. The fix is right either way: a bad value is refused up front with a clear message.
--port 0 is refused now. On main it printed "Dashboard running at http://localhost:0", which is not a usable address, so refusing it is the fix and not a lost feature.
[P2 non-blocking] The CI review is right that --project-id "" still slips through: cmdOpts.projectId ? … : undefined treats the empty string as "not given" and falls back to the picker. Main does the same, so this PR does not regress it, and an empty id is an unusual input, so we don't block on it. Checking cmdOpts.projectId !== undefined would close it.
[P3 nit] parsePositiveInt in src/import.ts (#1781) and the new parseIntOption do the same job. A later change could point import at cli-int.ts, so there is one parser.
Merge risk: low
Alignment: good
- Rejects the bad values the title names. The other change is the
12abc→ 12 case, which is now refused, as the description says.
Impact: small
- Two option parsers. Valid values behave as before.
Verification: decent
- Unit tests for the parser and the built-CLI runs above. The hang and picker paths the description mentions were not reproduced.
Rollback cost: low
- A revert restores the old parse.
Error detection: good
- A bad value now fails with a message naming the flag.
CI review: the empty-string point is the P2 above, which we take as non-blocking. The missing real-CLI record is now in the description. I'll merge once CI is green at this head.
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
@pcbeingused333 I'm changing my approval to request changes. I was wrong about --port 0.
[P1 blocking] Refusing --port 0 breaks a real use. E2E shard 1/3 fails at report-scope-reuse.test.ts:128 with ✖ --port must be an integer between 1 and 65535 (job 128507769496). That test starts teamai dashboard --port 0 (:121) to get a free port from the OS, and it passes on main. Port 0 listens on an OS-assigned port. Only the startup message prints localhost:0, which I misread as an unusable address in my review. Refusing it is also a stricter-validation change for anyone who scripts the dashboard that way. Fix: allow 0 for --port, i.e. parseIntOption('--port', String(cmdOpts.port), 0, 65535), with a test case for 0. Printing the port the server actually got (server.address().port) would be a nice touch, but it is not needed for this PR.
The rest of my earlier review stands: the --project-id "" P2 and the parser-duplication P3.
No other confident findings in the scoped diff. |
|
Port 0 is now accepted and covered by the parser test. A built-CLI run confirms that the dashboard starts with This comment was drafted with Claude Code. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Thanks, --port 0 is fixed. At 0e2faa4b it starts and listens on an OS-assigned port, and report-scope-reuse.test.ts passes in E2E shard 1/3. One item is still open, so my request for changes stands.
[P1 blocking] bind-project --project-id "" still skips validation. The empty string is falsy, so src/index.ts:1547 passes undefined, and the command falls back to the interactive picker without saying anything. I reproduced it on the built CLI: the output matches a run with no flag at all. The CI review raises the same point. Rejecting an invalid value is the purpose of this PR, so this case belongs here. Fix: check cmdOpts.projectId !== undefined before parsing, and add a test case for "".
[P3 nit] The new parser refuses more than 12abc. --port "", --port 1e3 and --project-id 0 all worked on main and are refused now. That is reasonable, but the body only mentions 12abc, so listing the others would help anyone whose script passes one of them.
A correction to your last comment: on main, dashboard --port abc does not exit 1. It keeps running, which is what the body says.
The parser duplication with #1781 is still a separate follow-up, and it doesn't block this PR.
Merge risk: medium
- Alignment: decent. Non-numeric values are rejected, but
""still gets through for--project-id. - Impact: small. Two option parsers in two commands.
- Verification: decent. CI is green at this head. The real-CLI record in the body is from an earlier commit, and the
""path has no run. - Rollback cost: low.
- Error detection: decent. A refused value names its flag, but
--project-id ""silently falls back to the picker.
… picker An empty string is falsy, so bind-project skipped the parser and passed undefined, which opened the interactive project picker. Parse whenever the flag is given, so "" fails with the same error as other bad values.
|
No confident findings in the scoped diff.
Review was read-only; no PR code was run, built, or installed. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Approving. I pushed 8791bd627 to fix the remaining item: bind-project now parses --project-id whenever the flag is given, so "" fails with the same error as other bad values instead of opening the picker. The --project-id parser test now covers "". Built CLI, against a local stand-in for the project service:
# before (PR head 0e2faa4b4, built dist/index.js)
$ node dist/index.js bind-project --project-id ""
ℹ Workspace enrolled for local-agent sync: /private/tmp/teamai-1782-run.RYYX1d/ws
ℹ 可用项目:
ℹ 1. Demo project - fixture [id=7]
ℹ 未绑定项目。
exit 0
# after (fix 8791bd627, built dist/index.js)
$ node dist/index.js bind-project --project-id ""
✖ --project-id must be an integer >= 1
exit 1
# valid id still binds (after)
$ node dist/index.js bind-project --project-id 7
✔ 已将工作区绑定到项目:Demo project [id=7]
exit 0
--port 0 (fixed earlier) and --port "" (refused) are unchanged. The parser duplication with #1781 is still a separate follow-up.
Merge risk: low
- Alignment: good. Non-numeric and empty values are refused for both flags.
- Impact: small. Two option parsers in two commands.
- Verification: good. Built-CLI before and after, plus the parser tests.
- Rollback cost: low.
- Error detection: good. Every refused value names its flag.
Summary
teamai dashboard --port abcpassedNumber('abc')=NaNtoserver.listen. Node throwsoptions.port should be >= 0 and < 65536. Received type number (NaN)., but by thenstartDashboardhas already started the events watcher and its two intervals, so the error is printed and the process keeps running instead of exiting.teamai bind-project --project-id abcproducedNaN, which is falsy, sobindWorkspaceToProjectsilently fell back to the interactive project picker instead of failing. Same pattern as the--max-reposfix in #1781.Both options now go through a small
parseIntOptionhelper (src/cli-int.ts):--portmust be an integer in 0-65535 and--project-idan integer >= 1. Anything else fails before any work starts, with--port must be an integer between 0 and 65535(or the--project-idequivalent), through the existing command error path.Number.parseIntused to accept12abcas 12; that is rejected now too.Type of Change
Test Plan
New
src/__tests__/cli-int.test.tscovers valid values and rejectsabc, empty,1.5,-3,70000,1e3,0x10(9 tests).npx tsc --noEmitpassesnpm run lintpasses (oxlint on the touched files)npx vitest runpasses (only the new test file was run)Related Issues
None filed; found next to #1781.
Notes for Reviewers
This change was prepared with the assistance of an AI coding tool (Claude) and reviewed before submission.
Real-CLI verification (added by a reviewer)