From abfde4e9f9432f4cd2259f08a112442bb281aa55 Mon Sep 17 00:00:00 2001 From: northline-lab Date: Sun, 31 May 2026 07:14:11 +0000 Subject: [PATCH] test: add repo_readme edge coverage Add focused coverage for repo_get_readme failure handling and max_chars clamp behavior. Verified with: - UV_CACHE_DIR=/tmp/uv-cache UV_PROJECT_ENVIRONMENT=/tmp/contribarena-uv-venv uv run --extra dev pytest -q tests/unit/test_github_tools.py - UV_CACHE_DIR=/tmp/uv-cache UV_PROJECT_ENVIRONMENT=/tmp/contribarena-uv-venv uv run --extra dev ruff check tests/unit/test_github_tools.py --- tests/unit/test_github_tools.py | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/unit/test_github_tools.py b/tests/unit/test_github_tools.py index fb1e173..08d92ce 100644 --- a/tests/unit/test_github_tools.py +++ b/tests/unit/test_github_tools.py @@ -290,6 +290,41 @@ def rest_text(self, path: str) -> GitHubResponse: self.assertEqual("owner/project", readme.full_name) self.assertIn("# Project", readme.content) + def test_repo_readme_reports_rest_failure(self) -> None: + class FakeClient: + def rest_text(self, path: str) -> GitHubResponse: + return GitHubResponse(ok=False, source="httpx", error="README not found") + + with patch("contribarena.tools.repo_readme.GitHubClient", FakeClient): + readme = repo_get_readme(_candidate()) + + self.assertFalse(readme.success) + self.assertEqual("owner/project", readme.full_name) + self.assertEqual("README not found", readme.error) + self.assertEqual("", readme.content) + + def test_repo_readme_enforces_minimum_content_limit(self) -> None: + class FakeClient: + def rest_text(self, path: str) -> GitHubResponse: + return GitHubResponse(ok=True, source="httpx", data="a" * 600) + + with patch("contribarena.tools.repo_readme.GitHubClient", FakeClient): + readme = repo_get_readme(_candidate(), max_chars=10) + + self.assertTrue(readme.success) + self.assertEqual(("a" * 500) + "...[truncated]", readme.content) + + def test_repo_readme_enforces_maximum_content_limit(self) -> None: + class FakeClient: + def rest_text(self, path: str) -> GitHubResponse: + return GitHubResponse(ok=True, source="httpx", data="b" * 20_100) + + with patch("contribarena.tools.repo_readme.GitHubClient", FakeClient): + readme = repo_get_readme(_candidate(), max_chars=50_000) + + self.assertTrue(readme.success) + self.assertEqual(("b" * 20_000) + "...[truncated]", readme.content) + def test_repo_pr_tools_normalize_pr_payloads(self) -> None: class FakeClient: def gh_json(self, args: list[str]) -> GitHubResponse: