Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(cli): stop deploy status crashing when no port is saved
trohitg60f2e556d0dd
diff --git a/cli/commands/deploy/status.py b/cli/commands/deploy/status.pyindex d00cf37a..5bec63bc 100644--- a/cli/commands/deploy/status.py+++ b/cli/commands/deploy/status.py@@ -16,7 +16,7 @@ from . import _state, _terraformdef status_command() -> None:# Establish the same DATA_DIR context as `deploy up` (load_config sets it)# so workdir() resolves to the directory `up` created.- preflight()+ cfg, _ = preflight()meta = _state.read_meta()if meta is None:console.print("[yellow]No OpenCompany deployment found.[/]")@@ -25,7 +25,7 @@ def status_command() -> None:wd = _state.workdir()ip = _terraform.tf_output(wd, "external_ip")url = _terraform.tf_output(wd, "url") or (- f"http://{ip}:{meta.get('port') or load_config().backend_port}" if ip else None+ f"http://{ip}:{meta.get('port') or cfg.backend_port}" if ip else None)console.print(" Deployment: OpenCompany")diff --git a/cli/tests/test_deploy_status.py b/cli/tests/test_deploy_status.pynew file mode 100644index 00000000..f9a73039--- /dev/null+++ b/cli/tests/test_deploy_status.py@@ -0,0 +1,39 @@+"""``company deploy status`` URL fallback."""++from __future__ import annotations++import urllib.error+from types import SimpleNamespace+from unittest.mock import patch++import pytest+import typer++from cli.commands.deploy import status+++def test_status_falls_back_to_configured_port(tmp_path) -> None:+ """No saved port and no Terraform ``url`` output: the URL is built from the+ backend port in the loaded config. This path used to raise NameError."""+ printed: list[str] = []++ def fake_output(_wd, name):+ return "203.0.113.7" if name == "external_ip" else None++ def refuse(*_args, **_kwargs):+ raise urllib.error.URLError("unreachable")++ with (+ patch.object(status, "preflight", return_value=(SimpleNamespace(backend_port=4321), tmp_path)),+ patch.object(status._state, "read_meta", return_value={"provider": "gcp"}),+ patch.object(status._state, "workdir", return_value=tmp_path),+ patch.object(status._state, "resource_name", return_value="opencompany"),+ patch.object(status._terraform, "tf_output", side_effect=fake_output),+ patch.object(status.urllib.request, "urlopen", side_effect=refuse),+ patch.object(status.console, "print", side_effect=lambda msg="": printed.append(str(msg))),+ pytest.raises(typer.Exit) as exc,+ ):+ status.status_command()++ assert exc.value.exit_code == 1+ assert any("http://203.0.113.7:4321" in line for line in printed)