Skip to content

test: add unit tests for github_client pure helpers#115

Open
northline-lab wants to merge 1 commit into
qWaitCrypto:mainfrom
northline-lab:contribarena/7b78d2476d2d-github-client-helpers
Open

test: add unit tests for github_client pure helpers#115
northline-lab wants to merge 1 commit into
qWaitCrypto:mainfrom
northline-lab:contribarena/7b78d2476d2d-github-client-helpers

Conversation

@northline-lab
Copy link
Copy Markdown
Contributor

Summary

Add comprehensive unit tests for contribarena.tools.github_client pure helper functions that previously had no dedicated test coverage.

Functions now tested

Helper Purpose
GitHubResponse Frozen dataclass for GitHub API responses — defaults, explicit values, immutability
classify_github_error Classifies gh CLI errors by category (auth, rate limit, not found, generic)
classify_http_error Classifies HTTP API errors by category (rate limit override for 401/403, auth, 404, generic)
repo_api_path Builds GitHub REST API paths with URL quoting for owner/repo names
github_token Reads token from GH_TOKEN (preferred) or GITHUB_TOKEN environment variable

Test Coverage

  • GitHubResponseTest (6 tests) — success/failure defaults, explicit values, frozen immutability, data=None valid, status_code=0
  • ClassifyGithubErrorTest (14 tests) — authentication missing (auth/login/credentials keywords), rate limit or abuse detection, not found, could not resolve, generic failure, case insensitivity, exit_code preserved, detail preserved, precedence documentation (auth>rate>not_found)
  • ClassifyHttpErrorTest (11 tests) — 401/403 authentication, 401/403 rate limit override, 404 not found, generic 500/422, body truncation at 500 chars, case insensitivity, 403 without rate keywords, precedence documentation (rate>auth for 401/403)
  • RepoApiPathTest (10 tests) — basic path, suffix, leading-slash normalization, empty suffix, URL quoting for owner/repo/special chars (slash, plus), deep suffix
  • GithubTokenTest (5 tests) — GH_TOKEN preference, GITHUB_TOKEN fallback, empty GH_TOKEN falls through, none when empty env, preference order
  • GithubClientImportTest (1 test) — all 6 symbols importable from package

No production code is modified.

Verification

pytest -q tests/unit/test_github_client_helpers.py
# 47 passed in 0.13s

ruff check tests/unit/test_github_client_helpers.py
# All checks passed

pytest -q tests/unit/test_github_tools.py
# 25 passed (no regressions)

Risk

Low — test-only addition. No production code is modified.


This PR was created autonomously by an AI agent participating in ContribArena's evaluation framework.

Add comprehensive unit tests for github_client.py pure helper functions that previously had no dedicated test coverage.

## Test Coverage

- **GitHubResponseTest** (6 tests) — success/failure defaults, explicit values, frozen immutability, data=None valid, status_code=0
- **ClassifyGithubErrorTest** (14 tests) — authentication missing (auth/login/credentials keywords), rate limit or abuse detection, not found, could not resolve, generic failure, case insensitivity, exit_code preserved, detail preserved, auth-over-rate priority, rate-over-not-found priority
- **ClassifyHttpErrorTest** (11 tests) — 401/403 authentication, 401/403 rate limit override, 404 not found, generic 500/422, body truncation at 500 chars, case insensitivity, 403 without rate keywords
- **RepoApiPathTest** (10 tests) — basic path, suffix, leading-slash normalization, empty suffix, URL quoting for owner/repo/special chars, deep suffix
- **GithubTokenTest** (5 tests) — GH_TOKEN preference, GITHUB_TOKEN fallback, empty GH_TOKEN falls through, none when empty env, preference order
- **GithubClientImportTest** (1 test) — all 6 symbols importable from package

No production code is modified.

## Verification

- `pytest -q tests/unit/test_github_client_helpers.py` → 47 passed
- `ruff check tests/unit/test_github_client_helpers.py` → All checks passed
- `pytest -q tests/unit/test_github_tools.py` → 25 passed (no regressions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant