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
85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
"""Tests for GitHub helper credential mapping and MCP config resolution."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from integrations.github.helpers import github_creds, resolve_github_mcp_config
|
|
from integrations.github.mcp import DEFAULT_GITHUB_MCP_MODE
|
|
|
|
|
|
def test_github_creds_maps_classified_integration_fields() -> None:
|
|
creds = github_creds(
|
|
{
|
|
"url": "https://api.githubcopilot.com/mcp/",
|
|
"mode": "streamable-http",
|
|
"auth_token": "ghp_test",
|
|
"command": "",
|
|
"args": [],
|
|
}
|
|
)
|
|
assert creds == {
|
|
"github_url": "https://api.githubcopilot.com/mcp/",
|
|
"github_mode": "streamable-http",
|
|
"github_token": "ghp_test",
|
|
}
|
|
|
|
|
|
def test_github_creds_prefers_legacy_tool_field_names() -> None:
|
|
creds = github_creds(
|
|
{
|
|
"github_url": "http://github.example.com/mcp",
|
|
"github_mode": "sse",
|
|
"github_token": "legacy-token",
|
|
"github_command": "gh-mcp",
|
|
"github_args": ["--stdio"],
|
|
}
|
|
)
|
|
assert creds == {
|
|
"github_url": "http://github.example.com/mcp",
|
|
"github_mode": "sse",
|
|
"github_token": "legacy-token",
|
|
"github_command": "gh-mcp",
|
|
"github_args": ["--stdio"],
|
|
}
|
|
|
|
|
|
def test_github_creds_omits_empty_defaults() -> None:
|
|
assert github_creds({}) == {}
|
|
|
|
|
|
def test_resolve_github_mcp_config_uses_env_when_no_overrides() -> None:
|
|
env_config = MagicMock()
|
|
with patch(
|
|
"integrations.github.helpers.github_mcp_config_from_env",
|
|
return_value=env_config,
|
|
):
|
|
assert resolve_github_mcp_config(None, None, None) is env_config
|
|
|
|
|
|
def test_resolve_github_mcp_config_builds_when_token_present() -> None:
|
|
env_config = MagicMock()
|
|
built = MagicMock()
|
|
with (
|
|
patch(
|
|
"integrations.github.helpers.github_mcp_config_from_env",
|
|
return_value=env_config,
|
|
),
|
|
patch("integrations.github.helpers.build_github_mcp_config", return_value=built) as builder,
|
|
):
|
|
result = resolve_github_mcp_config(None, None, "ghp_test")
|
|
assert result is built
|
|
builder.assert_called_once()
|
|
payload = builder.call_args.args[0]
|
|
assert payload["auth_token"] == "ghp_test"
|
|
assert payload["mode"] == env_config.mode
|
|
|
|
|
|
def test_resolve_github_mcp_config_does_not_treat_default_mode_as_override() -> None:
|
|
env_config = MagicMock()
|
|
with patch(
|
|
"integrations.github.helpers.github_mcp_config_from_env",
|
|
return_value=env_config,
|
|
):
|
|
assert resolve_github_mcp_config(None, DEFAULT_GITHUB_MCP_MODE, None) is env_config
|