From 4765838330dfc6725d4330021f1ea505d2cae74c Mon Sep 17 00:00:00 2001 From: bearsyankees Date: Thu, 27 Aug 2026 17:35:56 -0400 Subject: [PATCH] fix(cloud): make session command help non-destructive --- strix/interface/cloud/__init__.py | 21 +++++++++++++++------ tests/test_cloud_cli.py | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/strix/interface/cloud/__init__.py b/strix/interface/cloud/__init__.py index f906a121..2838e32b 100644 --- a/strix/interface/cloud/__init__.py +++ b/strix/interface/cloud/__init__.py @@ -43,12 +43,7 @@ def run_cloud(argv: list[str]) -> int: group, rest = argv[0], argv[1:] if group in ("login", "logout", "whoami"): - session_argv = { - "login": rest, - "logout": ["logout"], - "whoami": ["status", *rest], - } - return run_login(session_argv[group]) + return _run_session(console, group, rest) if group == "credits": group, rest = "billing", ["credits", *rest] if group == "workspaces" and rest and rest[0] == "use": @@ -68,6 +63,20 @@ def run_cloud(argv: list[str]) -> int: return run(group, verb_label, cmd, remaining) +def _run_session(console: Console, group: str, rest: list[str]) -> int: + if rest and rest[0] in ("-h", "--help", "help"): + return run_login(["--help"]) + if group == "logout" and rest: + console.print("[red]Unknown argument for logout:[/] " + " ".join(rest)) + return 2 + session_argv = { + "login": rest, + "logout": ["logout"], + "whoami": ["status", *rest], + } + return run_login(session_argv[group]) + + def _print_usage(console: Console) -> None: console.print(_USAGE_HEADER) for group in SPEC: diff --git a/tests/test_cloud_cli.py b/tests/test_cloud_cli.py index 09dcb743..d6dc8fc2 100644 --- a/tests/test_cloud_cli.py +++ b/tests/test_cloud_cli.py @@ -634,3 +634,26 @@ def test_group_help_lists_all_verbs_instead_of_default_verb_help(capsys: Any) -> assert "list" in output assert "create" in output assert "use" in output + + +def test_logout_help_does_not_remove_stored_auth( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path, capsys: Any +) -> None: + auth_path = tmp_path / "platform-auth.json" + monkeypatch.setattr(platform_cli, "AUTH_PATH", auth_path) + platform_cli.save_record({"api_token": "keep-me"}) + + assert cloud.run_cloud(["logout", "--help"]) == 0 + assert platform_cli.read_record() == {"api_token": "keep-me"} + assert "Usage:" in capsys.readouterr().out + + +def test_logout_rejects_unknown_arguments_without_removing_stored_auth( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path +) -> None: + auth_path = tmp_path / "platform-auth.json" + monkeypatch.setattr(platform_cli, "AUTH_PATH", auth_path) + platform_cli.save_record({"api_token": "keep-me"}) + + assert cloud.run_cloud(["logout", "--bogus"]) == 2 + assert platform_cli.read_record() == {"api_token": "keep-me"}