refactor(cli): split decnet/cli.py monolith into decnet/cli/ package
The 1,878-line cli.py held every Typer command plus process/HTTP helpers and mode-gating logic. Split into one module per command using a register(app) pattern so submodules never import app at module scope, eliminating circular-import risk. - utils.py: process helpers, _http_request, _kill_all_services, console, log - gating.py: MASTER_ONLY_* sets, _require_master_mode, _gate_commands_by_mode - deploy.py: deploy + _deploy_swarm (tightly coupled) - lifecycle.py: status, teardown, redeploy - workers.py: probe, collect, mutate, correlate - inventory.py, swarm.py, db.py, and one file per remaining command __init__.py calls register(app) on each module then runs the mode gate last, and re-exports the private symbols tests patch against (_db_reset_mysql_async, _kill_all_services, _require_master_mode, etc.). Test patches retargeted to the submodule where each name now resolves. Enroll-bundle tarball test updated to assert decnet/cli/__init__.py. No behavioral change.
This commit is contained in:
@@ -15,7 +15,7 @@ import pytest
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from decnet import cli as cli_mod
|
||||
from decnet.cli import app
|
||||
from decnet.cli import app, deploy as cli_deploy, utils as cli_utils
|
||||
|
||||
|
||||
runner = CliRunner()
|
||||
@@ -49,7 +49,7 @@ def http_stub(monkeypatch: pytest.MonkeyPatch) -> _HttpStub:
|
||||
return resp
|
||||
raise AssertionError(f"Unscripted HTTP call: {method} {url}")
|
||||
|
||||
monkeypatch.setattr(cli_mod, "_http_request", _fake)
|
||||
monkeypatch.setattr(cli_utils, "_http_request", _fake)
|
||||
return calls
|
||||
|
||||
|
||||
@@ -259,9 +259,9 @@ def test_deploy_swarm_round_robins_and_posts(http_stub, monkeypatch: pytest.Monk
|
||||
})
|
||||
|
||||
# Stub network detection so we don't need root / real NICs.
|
||||
monkeypatch.setattr(cli_mod, "detect_interface", lambda: "eth0")
|
||||
monkeypatch.setattr(cli_mod, "detect_subnet", lambda _iface: ("10.0.0.0/24", "10.0.0.254"))
|
||||
monkeypatch.setattr(cli_mod, "get_host_ip", lambda _iface: "10.0.0.100")
|
||||
monkeypatch.setattr(cli_deploy, "detect_interface", lambda: "eth0")
|
||||
monkeypatch.setattr(cli_deploy, "detect_subnet", lambda _iface: ("10.0.0.0/24", "10.0.0.254"))
|
||||
monkeypatch.setattr(cli_deploy, "get_host_ip", lambda _iface: "10.0.0.100")
|
||||
|
||||
result = runner.invoke(app, [
|
||||
"deploy", "--mode", "swarm", "--deckies", "3",
|
||||
@@ -280,9 +280,9 @@ def test_deploy_swarm_round_robins_and_posts(http_stub, monkeypatch: pytest.Monk
|
||||
def test_deploy_swarm_fails_if_no_workers(http_stub, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
http_stub.script[("GET", "/swarm/hosts?host_status=enrolled")] = _FakeResp([])
|
||||
http_stub.script[("GET", "/swarm/hosts?host_status=active")] = _FakeResp([])
|
||||
monkeypatch.setattr(cli_mod, "detect_interface", lambda: "eth0")
|
||||
monkeypatch.setattr(cli_mod, "detect_subnet", lambda _iface: ("10.0.0.0/24", "10.0.0.254"))
|
||||
monkeypatch.setattr(cli_mod, "get_host_ip", lambda _iface: "10.0.0.100")
|
||||
monkeypatch.setattr(cli_deploy, "detect_interface", lambda: "eth0")
|
||||
monkeypatch.setattr(cli_deploy, "detect_subnet", lambda _iface: ("10.0.0.0/24", "10.0.0.254"))
|
||||
monkeypatch.setattr(cli_deploy, "get_host_ip", lambda _iface: "10.0.0.100")
|
||||
|
||||
result = runner.invoke(app, [
|
||||
"deploy", "--mode", "swarm", "--deckies", "2",
|
||||
|
||||
Reference in New Issue
Block a user