4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
109 lines
3.7 KiB
Python
109 lines
3.7 KiB
Python
"""Coverage for the ``python -m integrations`` entrypoint.
|
|
|
|
Mirrors the contract from ``tests/cli/test_main.py`` for the standalone
|
|
integrations CLI: Sentry must be initialised, accepted commands must emit a
|
|
single ``cli_invoked`` event with command metadata, ``--help`` and unknown
|
|
commands must skip analytics.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from integrations import __main__ as integrations_main
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _stub_telemetry(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setattr(integrations_main, "init_sentry", lambda **_kw: None)
|
|
monkeypatch.setattr(integrations_main, "shutdown_analytics", lambda **_kw: None)
|
|
|
|
|
|
def _captures(monkeypatch: pytest.MonkeyPatch) -> list[dict[str, object] | None]:
|
|
captured: list[dict[str, object] | None] = []
|
|
monkeypatch.setattr(
|
|
integrations_main,
|
|
"capture_first_run_if_needed",
|
|
lambda: captured.append({"_marker": "install"}),
|
|
)
|
|
monkeypatch.setattr(
|
|
integrations_main,
|
|
"capture_cli_invoked",
|
|
lambda properties=None: captured.append(properties),
|
|
)
|
|
return captured
|
|
|
|
|
|
def test_help_does_not_capture_analytics(monkeypatch, capsys) -> None:
|
|
captured = _captures(monkeypatch)
|
|
monkeypatch.setattr("sys.argv", ["python -m integrations", "--help"])
|
|
|
|
integrations_main.main()
|
|
|
|
assert captured == []
|
|
assert "Commands: setup, list, show, remove, verify" in capsys.readouterr().out
|
|
|
|
|
|
def test_unknown_command_does_not_capture_analytics(monkeypatch, capsys) -> None:
|
|
captured = _captures(monkeypatch)
|
|
monkeypatch.setattr("sys.argv", ["python -m integrations", "bogus"])
|
|
|
|
with pytest.raises(SystemExit) as excinfo:
|
|
integrations_main.main()
|
|
|
|
assert excinfo.value.code == 1
|
|
assert captured == []
|
|
assert "Unknown command" in capsys.readouterr().err
|
|
|
|
|
|
def test_list_emits_cli_invoked_with_metadata(monkeypatch) -> None:
|
|
captured = _captures(monkeypatch)
|
|
monkeypatch.setattr("sys.argv", ["python -m integrations", "list"])
|
|
|
|
with patch.object(integrations_main, "cmd_list") as cmd_list:
|
|
integrations_main.main()
|
|
|
|
cmd_list.assert_called_once()
|
|
install_marker, properties = captured
|
|
assert install_marker == {"_marker": "install"}
|
|
assert properties is not None
|
|
assert properties["entrypoint"] == "python -m integrations"
|
|
assert properties["command_path"] == "python -m integrations list"
|
|
assert properties["command_family"] == "list"
|
|
assert properties["command_leaf"] == "list"
|
|
assert "subcommand" not in properties
|
|
|
|
|
|
def test_verify_emits_cli_invoked_with_service_subcommand(monkeypatch) -> None:
|
|
captured = _captures(monkeypatch)
|
|
monkeypatch.setattr("sys.argv", ["python -m integrations", "verify", "slack"])
|
|
|
|
with (
|
|
patch.object(integrations_main, "cmd_verify", return_value=0) as cmd_verify,
|
|
pytest.raises(SystemExit) as excinfo,
|
|
):
|
|
integrations_main.main()
|
|
|
|
assert excinfo.value.code == 0
|
|
cmd_verify.assert_called_once_with("slack", send_slack_test=False)
|
|
install_marker, properties = captured
|
|
assert install_marker == {"_marker": "install"}
|
|
assert properties is not None
|
|
assert properties["command_path"] == "python -m integrations verify slack"
|
|
assert properties["command_family"] == "verify"
|
|
assert properties["subcommand"] == "slack"
|
|
assert properties["command_leaf"] == "slack"
|
|
|
|
|
|
def test_main_initialises_sentry(monkeypatch) -> None:
|
|
init_calls: list[int] = []
|
|
monkeypatch.setattr(integrations_main, "init_sentry", lambda **_kw: init_calls.append(1))
|
|
_captures(monkeypatch)
|
|
monkeypatch.setattr("sys.argv", ["python -m integrations", "--help"])
|
|
|
|
integrations_main.main()
|
|
|
|
assert init_calls == [1]
|