| 1 | """Tests for unauthenticated GitHub availability + error surfacing (U5).""" |
| 2 | |
| 3 | from unittest import mock |
| 4 | |
| 5 | from lib import github, pipeline |
| 6 | |
| 7 | |
| 8 | class TestUnauthAvailability: |
| 9 | def test_github_available_without_token_or_gh(self): |
| 10 | # GitHub is reachable via the anon REST tier, so it is available even |
| 11 | # with no token and no gh CLI. |
| 12 | with mock.patch.dict("os.environ", {}, clear=True): |
| 13 | sources = pipeline.available_sources({}) |
| 14 | assert "github" in sources |
| 15 | |
| 16 | |
| 17 | class TestUnauthCap: |
| 18 | def test_unauth_caps_result_count(self): |
| 19 | with mock.patch.object(github, "_resolve_token", return_value=None), \ |
| 20 | mock.patch.object(github, "_fetch_json", return_value={"items": []}) as fetch: |
| 21 | github.search_github("kubernetes", "2026-03-01", "2026-03-31", depth="deep") |
| 22 | # deep would be 60 with a token; unauth caps to UNAUTH_COUNT_CAP. |
| 23 | called_url = fetch.call_args.args[0] |
| 24 | assert f"per_page={github.UNAUTH_COUNT_CAP}" in called_url |
| 25 | |
| 26 | def test_authed_keeps_full_depth(self): |
| 27 | with mock.patch.object(github, "_resolve_token", return_value="tok"), \ |
| 28 | mock.patch.object(github, "_fetch_json", return_value={"items": []}) as fetch: |
| 29 | github.search_github("kubernetes", "2026-03-01", "2026-03-31", depth="deep") |
| 30 | called_url = fetch.call_args.args[0] |
| 31 | assert "per_page=60" in called_url |
| 32 |