← Back to Pull requests

chore(trainer): add unit tests for DockerClientAdapter #821

Open
chinthanasathyajithcs opened this pull request with 434 lines diff across 1 files
View on GitHub
chinthanasathyajithcs chinthanasathyajithcs commented on Oct 05, 2026 10:45 UTC
Author

<!-- Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, check our contributor guidelines: https://www.kubeflow.org/docs/about/contributing
2. To know more about Kubeflow SDK, check the developer guide:
https://github.com/kubeflow/sdk/blob/main/CONTRIBUTING.md
3. If you want faster PR reviews, check how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
-->

What this PR does / why we need it:

Adds unit tests for DockerClientAdapter, which had 17% coverage and no test file of its own. backend_test.py replaces the adapter with a mock, so the adapter's own logic was never run.

The tests use a mocked Docker client (no daemon or network needed) and follow the existing TestCase / parametrize style. docker.py coverage goes from 17% to 95%. The simple pass-through methods (ping, stop_container, remove_container, pull_image) are intentionally left out.

The adapter is built with __new__ in the tests, and the constructor tests inject a fake docker module through sys.modules. This is because adapters/ has no __init__.py, so pytest puts that folder on sys.path and adapters/docker.py shadows the real docker package. #792 uses the same __new__ approach for the Podman adapter.

This PR only adds a test file and does not change any source code.

Local verification:

  • make verify passes

  • uv run pytest kubeflow/trainer/backends/container passes

  • docker.py coverage: 17% -> 95%
  • Assisted-by: Claude

    Which issue(s) this PR fixes (optional, in Fixes #<issue number>, #<issue number>, ... format, will close the issue(s) when PR gets merged):

    Fixes #818

    Checklist:

  • Docs included if any changes are user facing
  • Diff: 434 lines (+434 / -0) across 1 files Reviewer: tariq-hasan Review duration: 85747m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.46) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 434 lines diff across 1 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.90 · 5 substantive comment(s)
    0.90
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.363
    Real PR Conversation Timeline
    11 items
    google-oss-prow[bot] google-oss-prow[bot] commented on Oct 05, 2026 10:45 UTC
    Bot

    [APPROVALNOTIFIER] This PR is NOT APPROVED

    This pull-request has been approved by:
    Once this PR has been reviewed and has the lgtm label, please assign astefanutti for approval. For more information see the Kubernetes Code Review Process.

    The full list of commands accepted by this bot can be found here.

    <details open>
    Needs approval from an approver in each of these files:

  • OWNERS
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":["astefanutti"]} -->

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 05, 2026 10:45 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

    chinthanasathyajithcs chinthanasathyajithcs commented on Oct 13, 2026 03:30 UTC
    Author

    @tariq-hasan @Shekharrajak @andreyvelich @Electronic-Waste @astefanutti
    Could you please review this?

    tariq-hasan tariq-hasan commented on Oct 15, 2026 01:00 UTC
    Contributor

    /ok-to-test
    /retest

    tariq-hasan tariq-hasan commented on code on Oct 15, 2026 01:05 UTC
    Code Review
    kubeflow/trainer/backends/container/adapters/docker_test.py:1
    @@ -0,0 +1,434 @@
    +# Copyright 2025 The Kubeflow Authors.
    +#

    # Copyright The Kubeflow Authors.
    #
    

    tariq-hasan tariq-hasan commented on code on Oct 15, 2026 01:10 UTC
    Code Review
    kubeflow/trainer/backends/container/adapters/docker_test.py:1
    @@ -0,0 +1,434 @@
    +# Copyright 2025 The Kubeflow Authors.
    +#
    +# Licensed under the Apache License, Version 2.0 (the "License");
    +# you may not use this file except in compliance with the License.
    +# You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +Unit tests for DockerClientAdapter.
    +
    +The Docker SDK client is mocked, so no Docker daemon or network is required.
    +"""
    +
    +from unittest.mock import MagicMock, patch
    +
    +import pytest
    +
    +from kubeflow.trainer.backends.container.adapters.docker import DockerClientAdapter
    +from kubeflow.trainer.test.common import FAILED, SUCCESS, TestCase

    The test utilities have been moved to https://github.com/kubeflow/sdk/blob/ee22b33fbb261a2601f5dae9b11c2d82ea7dc7db/kubeflow/test/common.py. Please rebase the PR on main as the error would not have been detected otherwise on CI.

    from kubeflow.test.common import FAILED, SUCCESS, TestCase
    

    tariq-hasan tariq-hasan requested changes on Oct 15, 2026 01:18 UTC
    Changes Requested Reviewer

    Hi @chinthanasathyajithcs! Thanks for raising the PR. I have added a few comments.

    chinthanasathyajithcs chinthanasathyajithcs commented on code on Oct 15, 2026 17:01 UTC
    Code Review
    kubeflow/trainer/backends/container/adapters/docker_test.py:1
    @@ -0,0 +1,434 @@
    +# Copyright 2025 The Kubeflow Authors.
    +#

    Done, thanks!

    chinthanasathyajithcs chinthanasathyajithcs commented on code on Oct 15, 2026 17:01 UTC
    Code Review
    kubeflow/trainer/backends/container/adapters/docker_test.py:1
    @@ -0,0 +1,434 @@
    +# Copyright 2025 The Kubeflow Authors.
    +#
    +# Licensed under the Apache License, Version 2.0 (the "License");
    +# you may not use this file except in compliance with the License.
    +# You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +Unit tests for DockerClientAdapter.
    +
    +The Docker SDK client is mocked, so no Docker daemon or network is required.
    +"""
    +
    +from unittest.mock import MagicMock, patch
    +
    +import pytest
    +
    +from kubeflow.trainer.backends.container.adapters.docker import DockerClientAdapter
    +from kubeflow.trainer.test.common import FAILED, SUCCESS, TestCase

    Done, thanks!

    chinthanasathyajithcs chinthanasathyajithcs commented on Oct 15, 2026 17:09 UTC
    Author

    Rebased on main and addressed the review comments. PTAL, thanks! @tariq-hasan

    Reviewers
    Assignees
    chinthanasathyajithcs chinthanasathyajithcs
    Labels
    risk: low confidence: 89.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.3% (MEDIUM) · Higher = larger blast radius
    46.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.2% · Lower = rushed or shallow review
    89.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5% · Safe to merge
    5%
    Repository