Skip to content

Conversation

@seedspirit
Copy link
Contributor

resolves #6643, #6644 (BA-2969, BA-2970)

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Installer updates including:
    • Fixtures for db schema changes
    • New mandatory config options
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

@seedspirit seedspirit self-assigned this Nov 7, 2025
@github-actions github-actions bot added size:XL 500~ LoC comp:manager Related to Manager component labels Nov 7, 2025
@seedspirit seedspirit marked this pull request as ready for review November 7, 2025 10:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the container registry repository layer to use a source-based architecture, extracting database operations into a separate ContainerRegistryDBSource class and converting tests from mocked unit tests to integration tests using a real database.

Key Changes:

  • Extracted database access logic into a new ContainerRegistryDBSource class for better separation of concerns
  • Converted all tests from mocked unit tests to integration tests that use real database operations
  • Consolidated admin repository tests into the main test file (though test coverage was lost in the process)

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/ai/backend/manager/repositories/container_registry/repository.py Refactored to delegate all database operations to ContainerRegistryDBSource instead of containing DB logic directly
src/ai/backend/manager/repositories/container_registry/admin_repository.py Updated to use ContainerRegistryDBSource directly instead of wrapping ContainerRegistryRepository
src/ai/backend/manager/repositories/container_registry/db_source/db_source.py New file containing all database access logic extracted from the repository classes
src/ai/backend/manager/repositories/container_registry/db_source/__init__.py New empty __init__.py file for the db_source package
tests/manager/repositories/container_registry/test_container_registry_repository.py Converted from mocked unit tests to integration tests with real database operations and helper fixtures
tests/manager/repositories/container_registry/test_admin_container_registry_repository.py Deleted - admin repository tests were intended to be consolidated but coverage was lost
tests/manager/repositories/container_registry/BUILD Added explicit dependency on the manager source code
changes/6671.enhance.md Added changelog entry describing the refactoring

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +96 to +100
async def fetch_registry_row(
self,
registry_name: str,
project: Optional[str] = None,
) -> ContainerRegistryRow:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Depending on how the unique condition of the registry name is applied in this method, it seems like multiple values could be queried, so I need to check the behavior.

Comment on lines +81 to +86
async def fetch_known_registries(self) -> dict[str, str]:
"""Fetch all known container registries from the database."""
async with self._db.begin_readonly_session() as session:
known_registries_map = await ContainerRegistryRow.get_known_container_registries(
session
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please avoid returning a dict. You should properly define and pass the data class from where you first read the value, so that subsequent logic becomes easier to read.

Comment on lines +72 to +77
.where(ImageRow.registry == registry_name)
.where(ImageRow.status != ImageStatus.DELETED)
.values(status=ImageStatus.DELETED)
)
if project:
update_stmt = update_stmt.where(ImageRow.project == project)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We also need to check the project and registry parts once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Unit Tests for Refactored Repository Structure

3 participants