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
84 lines
2.9 KiB
Python
84 lines
2.9 KiB
Python
"""Tests for get_github_repository."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
from integrations.github.client import GitHubApiError
|
|
from integrations.github.tools.repository import get_github_repository
|
|
from tests.tools.conftest import BaseToolContract, mock_agent_state
|
|
|
|
|
|
class TestGetGitHubRepositoryToolContract(BaseToolContract):
|
|
def get_tool_under_test(self):
|
|
return get_github_repository.__opensre_registered_tool__
|
|
|
|
|
|
def test_is_available_requires_connection_verified_owner_repo() -> None:
|
|
rt = get_github_repository.__opensre_registered_tool__
|
|
assert (
|
|
rt.is_available({"github": {"connection_verified": True, "owner": "org", "repo": "repo"}})
|
|
is True
|
|
)
|
|
assert rt.is_available({"github": {"connection_verified": True}}) is False
|
|
assert rt.is_available({}) is False
|
|
|
|
|
|
def test_extract_params_maps_classified_credentials() -> None:
|
|
rt = get_github_repository.__opensre_registered_tool__
|
|
sources = mock_agent_state()
|
|
sources["github"] = {
|
|
"connection_verified": True,
|
|
"owner": "Tracer-Cloud",
|
|
"repo": "opensre",
|
|
"url": "https://api.githubcopilot.com/mcp/",
|
|
"mode": "streamable-http",
|
|
"auth_token": "ghp_test",
|
|
}
|
|
params = rt.extract_params(sources)
|
|
assert params["owner"] == "Tracer-Cloud"
|
|
assert params["repo"] == "opensre"
|
|
assert params["github_token"] == "ghp_test"
|
|
|
|
|
|
def test_run_happy_path() -> None:
|
|
payload = {
|
|
"full_name": "Tracer-Cloud/opensre",
|
|
"html_url": "https://github.com/Tracer-Cloud/opensre",
|
|
"description": "OpenSRE",
|
|
"default_branch": "main",
|
|
"visibility": "public",
|
|
"stargazers_count": 42,
|
|
"watchers_count": 42,
|
|
"forks_count": 7,
|
|
"open_issues_count": 3,
|
|
"subscribers_count": 10,
|
|
"language": "Python",
|
|
"topics": ["sre"],
|
|
"license": {"spdx_id": "MIT"},
|
|
"created_at": "2024-01-01T00:00:00Z",
|
|
"updated_at": "2024-02-01T00:00:00Z",
|
|
"pushed_at": "2024-02-02T00:00:00Z",
|
|
"archived": False,
|
|
"disabled": False,
|
|
}
|
|
with patch(
|
|
"integrations.github.tools.repository.GitHubRestClient.request",
|
|
return_value=payload,
|
|
):
|
|
result = get_github_repository(owner="Tracer-Cloud", repo="opensre", github_token="tok")
|
|
assert result["available"] is True
|
|
assert result["stargazers_count"] == 42
|
|
assert result["repository"]["forks_count"] == 7
|
|
assert result["repository"]["license"] == "MIT"
|
|
|
|
|
|
def test_run_api_error() -> None:
|
|
with patch(
|
|
"integrations.github.tools.repository.GitHubRestClient.request",
|
|
side_effect=GitHubApiError("not found", status_code=404, path="/repos/o/r"),
|
|
):
|
|
result = get_github_repository(owner="o", repo="r", github_token="tok")
|
|
assert result["available"] is False
|
|
assert "404" in result["error"]
|