diff --git a/bowtie/_core.py b/bowtie/_core.py index 83aeb2d85..e46957fe0 100644 --- a/bowtie/_core.py +++ b/bowtie/_core.py @@ -549,23 +549,22 @@ async def get_versions(self) -> Iterable[str]: url = CONTAINER_PACKAGES_API / self.id / "versions" gh = github() - pages: list[GitHubCore] = [] - with suppress(GitHubError): - pages = gh._iter(count=-1, url=str(url), cls=GitHubCore) # type: ignore[reportPrivateUsage] versions: Set[str] = ( {self.info.version} if self.info.version else set() ) - for page in pages: - try: - tags = cast( - "Iterable[str]", - page.as_dict()["metadata"]["container"]["tags"], - ) - except KeyError: - continue - else: - versions.update([tag for tag in tags if "." in tag]) + + with suppress(GitHubError): + for page in gh._iter(count=-1, url=str(url), cls=GitHubCore): # type: ignore[reportPrivateUsage] + try: + tags = cast( + "Iterable[str]", + page.as_dict()["metadata"]["container"]["tags"], # type: ignore[reportUnknownMemberType] + ) + except KeyError: + continue + else: + versions.update([tag for tag in tags if "." in tag]) return sorted(versions, key=sortable_version_key, reverse=True) diff --git a/bowtie/tests/test_info_versions.py b/bowtie/tests/test_info_versions.py new file mode 100644 index 000000000..845bdccf9 --- /dev/null +++ b/bowtie/tests/test_info_versions.py @@ -0,0 +1,38 @@ +from unittest.mock import Mock, patch + +from github3.exceptions import GitHubError +import pytest + +from bowtie._core import Implementation, ImplementationInfo + + +@pytest.mark.asyncio +async def test_get_versions_suppresses_github_error(): + """ + Test that get_versions() catches GitHub API errors (like rate limits) + and returns the local fallback version instead of crashing. + """ + info = ImplementationInfo.from_dict( + name="fake-runner", + language="python", + homepage="https://example.com", + issues="https://example.com/issues", + source="https://example.com/source", + dialects=["http://json-schema.org/draft-07/schema#"], + version="1.2.3", + ) + + impl = Implementation( + id="python-fake-runner", + info=info, + harness=Mock(), + reporter=Mock(), + ) + + with patch("bowtie._core.github") as mock_github_func: + mock_gh_client = Mock() + mock_github_func.return_value = mock_gh_client + mock_gh_client._iter.side_effect = GitHubError(resp=Mock()) + versions = await impl.get_versions() + + assert versions == ["1.2.3"]