Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions core/services/versionchooser/test_versionchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from utils.chooser import VersionChooser
from utils.dockerhub import TagFetcher, TagMetadata

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
Expand Down Expand Up @@ -236,3 +237,41 @@ async def is_valid_version(image: str) -> Tuple[bool, str]:
result = await chooser.set_version("bluerobotics/blueos-core", "master")
assert result.status_code == 500
assert len(json_mock.mock_calls) > 0


class TestTagFetcher:
"""Test class for TagFetcher functionality"""

@pytest.mark.asyncio
async def test_fetch_real_blueos_core_tags(self) -> None:
"""Integration test: Fetch real tags from bluerobotics/blueos-core repository"""
fetcher = TagFetcher()

try:
errors, tags = await fetcher.fetch_remote_tags("bluerobotics/blueos-core", [])

# Verify we got some tags back
assert isinstance(tags, list)
assert len(tags) > 0, "Should have found some tags for bluerobotics/blueos-core"

# Verify tag structure
for tag in tags[:3]: # Check first 3 tags
assert isinstance(tag, TagMetadata)
assert tag.repository == "bluerobotics/blueos-core"
assert tag.image == "blueos-core"
assert tag.tag is not None
assert len(tag.tag) > 0
assert tag.last_modified is not None
assert tag.digest is not None
Comment on lines +258 to +265
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test does not cover edge case for tags with missing images (digest set to '------').

Please add a test for tags with missing images (digest set to '------') to confirm TagMetadata is constructed correctly and downstream code handles this case.


# Should find the 'master' tag
tag_names = [tag.tag for tag in tags]
assert "master" in tag_names, f"Expected to find 'master' tag in tags: {tag_names[:10]}"

# Errors should be empty string if successful
if errors:
print(f"Non-fatal errors during fetch: {errors}")

except Exception as e:
# If this fails due to network issues, skip the test
pytest.skip(f"Could not fetch tags from DockerHub, likely network issue: {e}")
16 changes: 16 additions & 0 deletions core/services/versionchooser/utils/dockerhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ async def fetch_remote_tags(self, repository: str, local_images: List[str]) -> T
my_architecture = get_current_arch()
valid_images = []
for tag in tags:
images = tag["images"]
if len(images) == 0:
# this is a hack to deal with https://github.com/docker/hub-feedback/issues/2484
Comment on lines +114 to +115
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider logging or surfacing when tags have no images for better traceability.

Logging a warning when this fallback is triggered will help with monitoring and debugging, especially if Docker Hub's behavior changes or unexpected tags appear.

Suggested implementation:

                import logging
                logger = logging.getLogger(__name__)

                my_architecture = get_current_arch()
                valid_images = []
                for tag in tags:
                    images = tag["images"]
                    if len(images) == 0:
                        logger.warning(
                            "Tag '%s' in repository '%s' has no images. Fallback logic triggered. See https://github.com/docker/hub-feedback/issues/2484",
                            tag.get("name", "<unknown>"),
                            repository,
                        )
                        # this is a hack to deal with https://github.com/docker/hub-feedback/issues/2484
                        # we lost the ability to properly identify the images as we dont have the digest,
                        # and also the ability to filter for compatible architectures.
                        # so we just add the tag and hope for the best.
                        tag = TagMetadata(
                            repository=repository,
                            image=repository.split("/")[-1],
                            tag=tag["name"],
                            last_modified=tag["last_updated"],
                            sha=None,
                            digest="------",
                        )
                        valid_images.append(tag)

If your project already has a logger instance (e.g., logger defined at the module level), use that instead of creating a new one with logging.getLogger(__name__). Remove the import and logger assignment if not needed.

# we lost the ability to properly identify the images as we dont have the digest,
# and also the ability to filter for compatible architectures.
# so we just add the tag and hope for the best.
tag = TagMetadata(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should log a warning here

repository=repository,
image=repository.split("/")[-1],
tag=tag["name"],
last_modified=tag["last_updated"],
sha=None,
digest="------",
)
valid_images.append(tag)
continue
for image in tag["images"]:
if image["architecture"] == my_architecture:
tag = TagMetadata(
Expand Down