Files
tracer-cloud--opensre/tests/cli/test_onboard_command.py
T
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

96 lines
3.5 KiB
Python

from __future__ import annotations
import importlib
from types import SimpleNamespace
import pytest
onboard_module = importlib.import_module("surfaces.cli.commands.onboard")
@pytest.fixture(autouse=True)
def _stub_analytics(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(onboard_module, "capture_onboard_started", lambda: None)
monkeypatch.setattr(onboard_module, "capture_onboard_completed", lambda _cfg: None)
monkeypatch.setattr(onboard_module, "capture_onboard_failed", lambda: None)
def _set_tty(monkeypatch: pytest.MonkeyPatch, *, is_tty: bool) -> None:
monkeypatch.setattr(onboard_module.sys, "stdin", SimpleNamespace(isatty=lambda: is_tty))
monkeypatch.setattr(onboard_module.sys, "stdout", SimpleNamespace(isatty=lambda: is_tty))
def test_onboarding_success_launches_shell_when_interactive(
monkeypatch: pytest.MonkeyPatch,
) -> None:
launched: list[object] = []
_set_tty(monkeypatch, is_tty=True)
monkeypatch.delenv(onboard_module.OPENSRE_AUTO_LAUNCH_ENV, raising=False)
monkeypatch.delenv(onboard_module.OPENSRE_PARENT_INTERACTIVE_SHELL_ENV, raising=False)
monkeypatch.setattr(
onboard_module, "_launch_interactive_shell", lambda: (launched.append(None), 7)[1]
)
with pytest.raises(SystemExit) as exc:
onboard_module._run_onboarding_command(lambda: 0, load_config=lambda: {})
assert exc.value.code == 7
assert launched == [None]
def test_onboarding_success_does_not_launch_shell_when_non_tty(
monkeypatch: pytest.MonkeyPatch,
) -> None:
launched: list[object] = []
_set_tty(monkeypatch, is_tty=False)
monkeypatch.setattr(onboard_module, "_launch_interactive_shell", lambda: launched.append(None))
with pytest.raises(SystemExit) as exc:
onboard_module._run_onboarding_command(lambda: 0, load_config=lambda: {})
assert exc.value.code == 0
assert launched == []
def test_onboarding_success_respects_auto_launch_opt_out(monkeypatch: pytest.MonkeyPatch) -> None:
launched: list[object] = []
_set_tty(monkeypatch, is_tty=True)
monkeypatch.setenv(onboard_module.OPENSRE_AUTO_LAUNCH_ENV, "0")
monkeypatch.setattr(onboard_module, "_launch_interactive_shell", lambda: launched.append(None))
with pytest.raises(SystemExit) as exc:
onboard_module._run_onboarding_command(lambda: 0, load_config=lambda: {})
assert exc.value.code == 0
assert launched == []
def test_onboarding_success_does_not_launch_nested_shell(
monkeypatch: pytest.MonkeyPatch,
) -> None:
launched: list[object] = []
_set_tty(monkeypatch, is_tty=True)
monkeypatch.setenv(onboard_module.OPENSRE_PARENT_INTERACTIVE_SHELL_ENV, "1")
monkeypatch.setattr(onboard_module, "_launch_interactive_shell", lambda: launched.append(None))
with pytest.raises(SystemExit) as exc:
onboard_module._run_onboarding_command(lambda: 0, load_config=lambda: {})
assert exc.value.code == 0
assert launched == []
def test_onboarding_success_respects_click_no_interactive(
monkeypatch: pytest.MonkeyPatch,
) -> None:
launched: list[object] = []
ctx = SimpleNamespace(find_root=lambda: SimpleNamespace(obj={"interactive": False}))
_set_tty(monkeypatch, is_tty=True)
monkeypatch.setattr(onboard_module, "_launch_interactive_shell", lambda: launched.append(None))
with pytest.raises(SystemExit) as exc:
onboard_module._run_onboarding_command(lambda: 0, ctx=ctx, load_config=lambda: {})
assert exc.value.code == 0
assert launched == []