fix(scripts): reject invalid mock API ports#3072
Conversation
Constraint: E2E scripts pass an explicit mock API port, so malformed values should fail before server startup. Rejected: Fall back to the default port for invalid --port values | it hides the caller mistake and can start the server on the wrong port. Confidence: high Scope-risk: narrow Directive: Treat explicit CLI configuration as authoritative; reject malformed values rather than silently falling back. Tested: node --test scripts/__tests__/mock-api-server-args.test.mjs; node scripts/mock-api-server.mjs --help; node scripts/mock-api-server.mjs --port nope; node scripts/codex-pr-preflight.mjs --lightweight; pnpm typecheck; git diff --check Not-tested: Full format:check/pre-push hook; cargo is not installed in this environment, though the app Prettier phase passed. Did not start the mock server because local sandbox denies listen on 127.0.0.1.
📝 WalkthroughWalkthroughAdds structured CLI parsing to ChangesMock API Server CLI Argument Parsing
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/mock-api-server.mjs`:
- Around line 12-15: parsePortValue currently accepts any positive integer so
values >65535 (e.g., 70000) slip through; update the validation in
parsePortValue to ensure the port is within the TCP range (1–65535) by checking
Number.isInteger(port) && port > 0 && port <= 65535, and update the thrown Error
(using the existing label variable) to state the valid range so CLI fails fast
on invalid ports.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fcdc966f-f02c-42ee-9f6c-ff72345a8a36
📒 Files selected for processing (2)
scripts/__tests__/mock-api-server-args.test.mjsscripts/mock-api-server.mjs
Constraint: CodeRabbit identified that explicit mock API ports above the TCP range still reached listener startup. Rejected: Delegate invalid high ports to Node listener errors | contributors need deterministic CLI validation before startup. Confidence: high Scope-risk: narrow Directive: Keep script argument validators aligned with TCP listener bounds. Tested: node --test scripts/__tests__/mock-api-server-args.test.mjs; node scripts/mock-api-server.mjs --port 65536; git diff --check Not-tested: Full repository format/check; cargo is unavailable locally.
|
Thanks for the checks. I rechecked this PR on current state:
|
|
I reviewed all open PRs from Clarification on
|
sanil-23
left a comment
There was a problem hiding this comment.
@alexzhu0 the code looks good — the argument parsing is clean, the port range validation (CodeRabbit's finding) was already addressed in e85596a, and the focused tests cover the right rejection paths.
One CI check is failing: Rust Core Coverage (cargo-llvm-cov). This PR only touches scripts/ with no Rust changes, so the failure looks pre-existing and unrelated to these changes. Once CI is green i'll come back and approve. Let me know if you need help sorting it out.
graycyrus
left a comment
There was a problem hiding this comment.
Review Summary
This PR fixes a real bug where malformed --port arguments would silently fall back to the default port instead of failing fast. Good catch.
What changed: argument validation for scripts/mock-api-server.mjs — now rejects non-integer, out-of-range, or missing explicit port values with clear error messages before server startup. Adds --help flag and comprehensive Node tests.
Quality: Code is clean, focused, and correct. Tests cover the key paths: help flag, invalid ports (non-integer, out-of-range), missing ports, and flag-shaped arguments. No AI slop, proper error handling, good exit codes.
CodeRabbit dedup: CodeRabbit flagged missing upper-bound check on port validation. Already fixed in this commit — validation properly checks port <= 65535 and test includes ['--port', '65536'] to verify rejection.
No code issues — structure, logic, and edge case handling all look solid.
CI blocker: Rust Core Coverage is failing. Once that's resolved, this is ready to merge. @alexzhu0 let me know if you need help with the coverage issue.
Otherwise this looks great — clean fix, good tests, backward-compatible. Approving once CI goes green.
sanil-23
left a comment
There was a problem hiding this comment.
@alexzhu0 quick update — i dug into the Rust Core Coverage failure and it's a CI runner infrastructure issue: the action log shows "No space left on device" on the runner host. Completely unrelated to this PR (no Rust files changed). Recommend re-triggering the check run; the code here is clean and ready to go once that passes.
sanil-23
left a comment
There was a problem hiding this comment.
@alexzhu0 picked up the merge-from-upstream commit — thanks for keeping the branch current.
CI is still not fully green on the new run:
- Rust Core Coverage — same persistent failure as before (infrastructure issue, pre-existing on the repo, not caused by this JS-only PR).
- E2E Playwright web lane 1/4 — this one is new, but lanes 2/4, 3/4, and 4/4 all passed in the same run. That asymmetry is a flaky-test pattern, not a real regression from this PR's argument-parsing changes.
The code itself is still clean. Once both of these checks go green (re-trigger if the flake recurs), I'll approve.
Summary
scripts/mock-api-server.mjsreject malformed explicit--port/-pvalues.Problem
node scripts/mock-api-server.mjs --port nopecurrently falls back to the default port.Solution
Submission Checklist
Impact
Related
AI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
Commit & Branch
codex/OH-2611-mock-api-port-arge85596aValidation Run
pnpm --filter openhuman-app format:check(blocked after app Prettier passed; see below)pnpm typechecknode --test scripts/__tests__/mock-api-server-args.test.mjsnode scripts/mock-api-server.mjs --helpnode scripts/mock-api-server.mjs --port nopenode scripts/mock-api-server.mjs --port 65536node scripts/codex-pr-preflight.mjs --lightweightgit diff --checkValidation Blocked
command:env COREPACK_HOME=/Users/alex/PR/.corepack PNPM_HOME=/Users/alex/PR/.pnpm-home pnpm --filter openhuman-app format:checkerror:sh: cargo: command not foundimpact:The app Prettier phase passed, but Rust formatting and the pre-push hook cannot complete in this local environment until Cargo is installed.Behavior Changes
Parity Contract
Duplicate / Superseded PR Handling