def test_cli_deploy_cloud_run_failure(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
  """Exception from to_cloud_run should be caught and surfaced via click.secho."""

  def _boom(*_a: Any, **_k: Any) -> None:  # noqa: D401
    raise RuntimeError("boom")

  monkeypatch.setattr(cli_tools_click.cli_deploy, "to_cloud_run", _boom)

  # intercept click.secho(error=True) output
  captured: List[str] = []
  monkeypatch.setattr(click, "secho", lambda msg, **__: captured.append(msg))

  agent_dir = tmp_path / "agent3"
  agent_dir.mkdir()
  runner = CliRunner()
  result = runner.invoke(
      cli_tools_click.main, ["deploy", "cloud_run", str(agent_dir)]
  )

  assert result.exit_code == 0
  assert any("Deploy failed: boom" in m for m in captured)
Exception from to_cloud_run should be caught and surfaced via click.secho.
tests/unittests/cli/utils/test_cli_tools_click.py