Files
tracer-cloud--opensre/tests/cli/test_integrations_setup_posthog_alias.py
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

77 lines
2.8 KiB
Python

"""`opensre integrations <cmd> posthog` resolves to the `posthog_mcp` flow.
The bare ``posthog`` integration is env-configured analytics with no interactive
setup/verify flow, so management commands accept ``posthog`` as an alias for the
only real target, ``posthog_mcp``. Previously ``click.Choice`` rejected
``posthog`` with exit code 2 before any handler ran.
"""
from __future__ import annotations
from unittest.mock import patch
import pytest
from click.testing import CliRunner
from integrations.cli import _HANDLERS, cmd_setup, cmd_verify
from surfaces.cli.__main__ import cli
def test_setup_posthog_alias_resolves_to_posthog_mcp() -> None:
runner = CliRunner()
with (
patch("surfaces.cli.commands.integrations.capture_integration_setup_started"),
patch("surfaces.cli.commands.integrations.capture_integration_setup_completed"),
patch("surfaces.cli.commands.integrations.capture_integration_verified"),
patch("integrations.cli.cmd_setup") as mock_cmd,
patch("integrations.cli.cmd_verify", return_value=0),
):
mock_cmd.return_value = "posthog_mcp"
result = runner.invoke(cli, ["integrations", "setup", "posthog"])
assert result.exit_code == 0
# The alias is resolved at the Click boundary, so cmd_setup receives the
# canonical service name rather than the raw "posthog".
mock_cmd.assert_called_once_with("posthog_mcp")
def test_setup_rejects_unknown_service() -> None:
runner = CliRunner()
result = runner.invoke(cli, ["integrations", "setup", "not-a-real-service"])
assert result.exit_code == 2
assert "not one of" in result.output
def test_cmd_setup_posthog_alias_dispatches_posthog_mcp_handler(
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
"""Direct cmd_setup('posthog') (python -m integrations path) dispatches MCP."""
called: list[str] = []
monkeypatch.setitem(_HANDLERS, "posthog_mcp", lambda: called.append("posthog_mcp"))
resolved = cmd_setup("posthog")
assert resolved == "posthog_mcp"
assert called == ["posthog_mcp"]
assert "Setting up" in capsys.readouterr().out
def test_cmd_verify_posthog_alias_resolves_before_verifying(
monkeypatch: pytest.MonkeyPatch,
) -> None:
captured: dict[str, str | None] = {}
def fake_verify(*, service: str | None, send_slack_test: bool = False) -> list[dict[str, str]]:
captured["service"] = service
return []
monkeypatch.setattr("integrations.cli.verify_integrations", fake_verify)
monkeypatch.setattr("integrations.cli.format_verification_results", lambda _results: "")
monkeypatch.setattr(
"integrations.cli.verification_exit_code",
lambda *_args, **_kwargs: 0,
)
assert cmd_verify("posthog") == 0
assert captured["service"] == "posthog_mcp"