Skip to content

feat(cli): add --port-base to shift port-probe range#635

Open
finklang wants to merge 1 commit into
mpfaffenberger:mainfrom
finklang:feat/cli-port-base-oss
Open

feat(cli): add --port-base to shift port-probe range#635
finklang wants to merge 1 commit into
mpfaffenberger:mainfrom
finklang:feat/cli-port-base-oss

Conversation

@finklang

Copy link
Copy Markdown

Adds three layers of override for the port probe's start port so users can dodge collisions with other local dev servers (Apollo BE on 8090, etc.) without editing source:

  1. --port-base PORT CLI arg (per-invocation)
  2. CODE_PUPPY_PORT_BASE env var (per-shell)
  3. port_base key in puppy.cfg (persistent, seeded on first run)

Precedence: CLI > env > puppy.cfg > 8090 default. All three sources funnel through resolve_port_base() + _coerce_port_base() for DRY validation with a consistent warning UX.

Robustness:

  • CLI arg is type=str so bad input is caught by our validator and falls through to the next source rather than argparse-exiting.
  • MIN_PORT_BASE=1024 / MAX_PORT_BASE=65535-PORT_PROBE_WIDTH reject values that would probe outside the 16-bit port range or hit privileged ports the process can't bind anyway.
  • ensure_config_exists() seeds port_base in fresh puppy.cfg so users discover the knob (matches the existing auto_save_session seeding pattern).

Tests: 13 new tests across TestGetPortBase, TestResolvePortBase, and TestPortAvailability covering precedence, bounds, graceful fallback, empty-string handling, exact boundaries, config seeding, and a regression guard on MAX_PORT_BASE + PORT_PROBE_WIDTH <= 65535.

Adds three layers of override for the port probe's start port so users
can dodge collisions with other local dev servers (Apollo BE on 8090,
etc.) without editing source:

  1. --port-base PORT CLI arg (per-invocation)
  2. CODE_PUPPY_PORT_BASE env var (per-shell)
  3. port_base key in puppy.cfg (persistent, seeded on first run)

Precedence: CLI > env > puppy.cfg > 8090 default. All three sources
funnel through resolve_port_base() + _coerce_port_base() for DRY
validation with a consistent warning UX.

Robustness:
  * CLI arg is type=str so bad input is caught by our validator and
    falls through to the next source rather than argparse-exiting.
  * MIN_PORT_BASE=1024 / MAX_PORT_BASE=65535-PORT_PROBE_WIDTH reject
    values that would probe outside the 16-bit port range or hit
    privileged ports the process can't bind anyway.
  * ensure_config_exists() seeds port_base in fresh puppy.cfg so
    users discover the knob (matches the existing auto_save_session
    seeding pattern).

Tests: 13 new tests across TestGetPortBase, TestResolvePortBase, and
TestPortAvailability covering precedence, bounds, graceful fallback,
empty-string handling, exact boundaries, config seeding, and a
regression guard on MAX_PORT_BASE + PORT_PROBE_WIDTH <= 65535.
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.

1 participant