Files
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

124 lines
4.4 KiB
Python

"""Tests for GitHub repository scope inference helpers."""
from __future__ import annotations
from typing import Any
from unittest.mock import MagicMock, patch
import pytest
from integrations.github.mcp import GitHubMCPConfig
from integrations.github.repo_scope import (
apply_github_repo_scope,
detect_git_remote_repo_scope,
infer_github_repo_scope,
parse_github_repository_reference,
split_repo_full_name,
)
@pytest.mark.parametrize(
("text", "expected"),
[
("https://github.com/Tracer-Cloud/opensre", ("Tracer-Cloud", "opensre")),
("https://github.com/Tracer-Cloud/opensre.git", ("Tracer-Cloud", "opensre")),
(
"https://github.com/Tracer-Cloud/opensre/issues/42",
("Tracer-Cloud", "opensre"),
),
("github.com/org/my-repo", ("org", "my-repo")),
("repo:Tracer-Cloud/opensre windows crash", ("Tracer-Cloud", "opensre")),
("see Tracer-Cloud/opensre for details", ("Tracer-Cloud", "opensre")),
],
)
def test_parse_github_repository_reference(text: str, expected: tuple[str, str]) -> None:
assert parse_github_repository_reference(text) == expected
def test_parse_github_repository_reference_last_match_wins() -> None:
text = "https://github.com/first/a and https://github.com/second/b"
assert parse_github_repository_reference(text) == ("second", "b")
def test_parse_github_repository_reference_rejects_paths() -> None:
assert parse_github_repository_reference("cli/interactive_shell/chat") is None
def test_split_repo_full_name() -> None:
assert split_repo_full_name("Tracer-Cloud/opensre.git") == ("Tracer-Cloud", "opensre")
assert split_repo_full_name("owner-only") == ("", "")
def test_infer_github_repo_scope_prefers_current_message_over_cache() -> None:
scope = infer_github_repo_scope(
message="issues in https://github.com/new-org/new-repo",
conversation_messages=[],
cached=("old-org", "old-repo"),
)
assert scope == ("new-org", "new-repo")
def test_infer_github_repo_scope_uses_conversation_before_cache() -> None:
scope = infer_github_repo_scope(
message="do these searches",
conversation_messages=[
("user", "https://github.com/Tracer-Cloud/opensre"),
("assistant", "Got it."),
],
cached=("other", "repo"),
)
assert scope == ("Tracer-Cloud", "opensre")
def test_infer_github_repo_scope_uses_cache_when_no_explicit_reference() -> None:
scope = infer_github_repo_scope(
message="do these searches",
conversation_messages=[("user", "hello"), ("assistant", "hi")],
cached=("Tracer-Cloud", "opensre"),
)
assert scope == ("Tracer-Cloud", "opensre")
def test_infer_github_repo_scope_uses_github_repository_env() -> None:
scope = infer_github_repo_scope(
message="any issues?",
conversation_messages=[],
env={"GITHUB_REPOSITORY": "Tracer-Cloud/opensre"},
cached=None,
)
assert scope == ("Tracer-Cloud", "opensre")
def test_detect_git_remote_repo_scope_parses_https_remote() -> None:
with patch("integrations.github.repo_scope.subprocess.run") as run:
run.return_value = MagicMock(returncode=0, stdout="https://github.com/org/repo.git\n")
assert detect_git_remote_repo_scope("/tmp/repo") == ("org", "repo")
run.assert_called_once()
def test_detect_git_remote_repo_scope_parses_ssh_remote() -> None:
with patch("integrations.github.repo_scope.subprocess.run") as run:
run.return_value = MagicMock(returncode=0, stdout="git@github.com:org/repo.git\n")
assert detect_git_remote_repo_scope() == ("org", "repo")
def test_apply_github_repo_scope_merges_into_github_mcp_config() -> None:
resolved: dict[str, Any] = {
"github": GitHubMCPConfig(
url="https://api.githubcopilot.com/mcp/",
auth_token="tok",
)
}
merged = apply_github_repo_scope(resolved, "Tracer-Cloud", "opensre")
gh = merged["github"]
assert isinstance(gh, dict)
assert gh["owner"] == "Tracer-Cloud"
assert gh["repo"] == "opensre"
assert gh["url"] == "https://api.githubcopilot.com/mcp/"
assert isinstance(resolved["github"], GitHubMCPConfig)
def test_apply_github_repo_scope_noop_without_github() -> None:
resolved = {"datadog": {"connection_verified": True}}
assert apply_github_repo_scope(resolved, "o", "r") == {"datadog": {"connection_verified": True}}