Skip to content

fix(cli): honor optional --port in local proxy mode#11

Merged
FASTSHIFT merged 2 commits into
FASTSHIFT:mainfrom
W-Mai:fix-cli-local-noport-attach
Jun 5, 2026
Merged

fix(cli): honor optional --port in local proxy mode#11
FASTSHIFT merged 2 commits into
FASTSHIFT:mainfrom
W-Mai:fix-cli-local-noport-attach

Conversation

@W-Mai
Copy link
Copy Markdown
Contributor

@W-Mai W-Mai commented Jun 5, 2026

The v1.6.6 docs and feat(cli) commit (2c1bf58) state "--port is optional in proxy mode (server owns the serial port)" and "When a server is already running and has a device connected, --port is not needed". This was implemented for remote --server-url, but the local mode init still returned offline immediately when --port was omitted, so commands like 'fpb_cli.py info' or 'file-stat' failed against a locally-running server with a connected device.

  • Probe the local WebServer before falling back to offline when --port is not supplied; attach if /api/status reports connected=true.
  • Stay offline (preserving fast ELF analysis / compile flow) when no server is running or no device is connected, so existing offline use cases are unchanged.
  • Gate the verbose proxy-attach log on _device_state.connected so a disconnect race during attach does not produce a misleading message.

Add three regression tests covering local + no --port:

  • server reachable, device connected: proxy attaches, no connect() call
  • server reachable, no device: stay offline, no proxy
  • server unreachable: stay offline, no exception

@FASTSHIFT FASTSHIFT requested a review from Copilot June 5, 2026 12:32
@W-Mai W-Mai force-pushed the fix-cli-local-noport-attach branch from 4643236 to ea2ee00 Compare June 5, 2026 12:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the WebServer CLI’s local proxy mode so --port is truly optional when a locally-running WebServer already has a device connected, aligning local behavior with the existing remote --server-url behavior and the documented CLI contract.

Changes:

  • In local mode, probe the local WebServer when --port is omitted and attach to the proxy if /api/status reports connected=true.
  • Add regression tests covering the local + no---port scenarios (server connected / server no device / server unreachable).
  • Update CLI documentation to clarify port-less proxy behavior and offline fallback expectations.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
Tools/WebServer/cli/fpb_cli.py Adds local-mode probing/attach logic when --port is omitted.
Tools/WebServer/tests/test_fpb_cli.py Adds regression tests for local proxy behavior without --port.
Docs/CLI.md Updates documentation for port-less proxy usage and offline behavior.

Comment thread Tools/WebServer/cli/fpb_cli.py Outdated
Comment thread Tools/WebServer/tests/test_fpb_cli.py
Comment thread Docs/CLI.md Outdated
@W-Mai W-Mai force-pushed the fix-cli-local-noport-attach branch from ea2ee00 to f47c027 Compare June 5, 2026 13:06
W-Mai added 2 commits June 5, 2026 21:13
The v1.6.6 docs and feat(cli) commit (2c1bf58) state '--port is
optional in proxy mode (server owns the serial port)'. This was
implemented for remote --server-url, but local mode still returned
offline immediately when --port was omitted, so device commands run
through 'fpb_cli.py' without --port failed against a locally-running
server with a connected device.

Approach:

- Init no longer probes the network. Without --port, it just remembers
  server_url/token/baudrate ('pending local server'). This keeps
  FPBCLI() instantiation side-effect-free, so unit tests do not depend
  on ambient network state.
- Add try_attach_local_server(), called from main() before dispatching
  any device-needing command, which lazily probes the local server and
  attaches if /api/status reports connected=true.
- Add ServerProxy.probe_status(): single short-timeout probe returning
  the raw /api/status dict. Replaces the old is_server_running() +
  is_device_connected() pair so we hit /api/status only once and avoid
  any inconsistency between the two responses (per Copilot review).
- Verbose 'Using WebServer proxy mode' log is gated on
  _device_state.connected so a disconnect race during attach does not
  produce a misleading message.

Tests:

- test_init_no_port_no_probe: FPBCLI() must not call ServerProxy at all.
- test_try_attach_local_server_*: device connected / no device /
  unreachable. Mocks probe_status() and asserts is_server_running() is
  not called, locking in the single-probe contract.
- TestFPBCLICommands.run_cli pins --server-url to http://127.0.0.1:1
  so subprocess-based command tests do not pick up an unrelated local
  WebServer in the developer's environment.
The 'About --port' section already promised that --port is optional
when the server has a connected device, but the operating modes table
only listed port-less attach implicitly via the remote-proxy row.

- State that port-less attach applies to BOTH local and remote.
- Add a 'Local proxy (port-less)' row to the modes table.
- Clarify that 'offline fallback' is local-only: in remote mode the
  CLI still attaches the proxy when the server is reachable even if
  no device is connected (per Copilot review).
@W-Mai W-Mai force-pushed the fix-cli-local-noport-attach branch from f47c027 to 593f648 Compare June 5, 2026 13:13
@FASTSHIFT FASTSHIFT merged commit 3482839 into FASTSHIFT:main Jun 5, 2026
4 of 6 checks passed
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