Skip to content

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

Open
finklang wants to merge 2 commits 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 2 commits 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.

George Finklang added 2 commits July 16, 2026 13:53
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.
Upstream introduced code_puppy.i18n (t/ngettext) after this branch was
cut and will want the 'no available ports' error message routed through
the translation layer. Rather than hardcode 8090-9010 in the locale
string (which would lie to anyone using --port-base to shift the probe
range), the message is parameterized on {port_base}/{port_end} and the
call site passes both.

Localizations for other languages fall back to en-US per the existing
i18n resolution chain; contributors can override per-locale later.
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