mirror of
https://github.com/nicolargo/glances.git
synced 2026-06-03 19:35:32 -04:00
Wires the ``-s`` / ``--server`` flag introduced in Task 1 to the actual
runtime — fulfils the G2 design alignment table:
Mode | Scheduler | TUI | REST | MCP
-----------------|-----------|-----|-------|-----
Default | yes | yes | no | no
-s | yes | no | yes | no (Task 2)
-s --enable-mcp | yes | no | yes | yes (Task 2)
(Plan: ``docs/superpowers/plans/2026-05-15-glances-v5-phase2-g2.md``;
Tasks 2 and 3 were swapped — see the previous discussion thread —
because Task 1 standalone left the system in a state contradicting the
design table.)
Refactor:
- ``assemble`` returns ``app=None`` in TUI mode — no FastAPI app built,
no plugin registration on a server. In ``-s`` mode the TUI is not
instantiated (``-s`` is headless per alignment #1).
- ``serve`` takes ``args`` as the leading argument; branches on
``args.server`` inside a single ``try`` whose ``finally`` cleanly
stops the TUI + scheduler in both modes. Server mode runs uvicorn as
before; TUI mode awaits ``scheduler_task`` until SIGINT (raised by
``on_quit`` when the user types ``q``/ESC).
- ``main`` logs the mode-specific startup line ("TUI mode (no REST API
bound)" vs the existing REST line).
Tests:
- Existing ``test_assemble_*`` cases that need a FastAPI app now pass
``-s`` instead of ``--no-tui``. Existing semantics preserved.
- New ``test_assemble_default_mode_builds_no_app`` and
``test_assemble_server_mode_skips_tui`` lock in the dispatch contract.
- ``test_assemble_server_mode_plus_no_tui_is_idempotent`` covers the
redundant ``-s --quiet`` combo (TUI still off).
- ``test_assemble_default_mode_no_tui_disables_everything`` documents
the scheduler-only degenerate mode (useful for test rigs).
- New ``test_serve_tui_mode_does_not_instantiate_uvicorn`` is the
bind-no-socket regression guard: patches ``uvicorn.Server`` and
asserts it is never called in default mode.
Manual smoke (regression guard for the bug raised by the user):
- ``python -m glances.main_v5 -C conf/glances.conf --no-tui``: no
socket on :61208, log line confirms TUI mode.
- ``python -m glances.main_v5 -C conf/glances.conf -s``: :61208
reachable, log line confirms REST mode.
622 v5 tests green (+5 dispatch cases), lint clean.