fix(cli): add __main__ guard so python -m decnet.cli actually runs the app

The collector subprocess was spawned via 'python3 -m decnet.cli collect'
but cli.py had no 'if __name__ == __main__: app()' guard. Python executed
the module, defined all functions, then exited cleanly with code 0 without
ever calling the collect command. No output, no log file, exit 0 — silent
non-start every time.

Also route collector stderr to <log_file>.collector.log so future crashes
are visible instead of disappearing into DEVNULL.
This commit is contained in:
2026-04-11 19:42:10 -04:00
parent a6063efbb9
commit ce182652ad

View File

@@ -401,10 +401,12 @@ def deploy(
if effective_log_file and not dry_run and not api: if effective_log_file and not dry_run and not api:
import subprocess # noqa: F811 # nosec B404 import subprocess # noqa: F811 # nosec B404
import sys import sys
_collector_err = Path(effective_log_file).with_suffix(".collector.log")
console.print(f"[bold cyan]Starting log collector[/] → {effective_log_file}") console.print(f"[bold cyan]Starting log collector[/] → {effective_log_file}")
subprocess.Popen( # nosec B603 subprocess.Popen( # nosec B603
[sys.executable, "-m", "decnet.cli", "collect", "--log-file", str(effective_log_file)], [sys.executable, "-m", "decnet.cli", "collect", "--log-file", str(effective_log_file)],
stdout=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
stdout=open(_collector_err, "a"), # nosec B603
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
start_new_session=True, start_new_session=True,
) )
@@ -613,3 +615,6 @@ def serve_web(
httpd.serve_forever() httpd.serve_forever()
except KeyboardInterrupt: except KeyboardInterrupt:
console.print("\n[dim]Shutting down dashboard server.[/]") console.print("\n[dim]Shutting down dashboard server.[/]")
if __name__ == '__main__': # pragma: no cover
app()