Skip to content

chore(trainer): add unit tests for lifecycle tools#95

Open
Solaris-star wants to merge 2 commits into
kubeflow:mainfrom
Solaris-star:chore/trainer-lifecycle-unit-tests
Open

chore(trainer): add unit tests for lifecycle tools#95
Solaris-star wants to merge 2 commits into
kubeflow:mainfrom
Solaris-star:chore/trainer-lifecycle-unit-tests

Conversation

@Solaris-star

Copy link
Copy Markdown
Contributor

Summary

Part of #68 — lifecycle section.

Adds unit coverage for delete_training_job and update_training_job with mocked SDK / CustomObjects API:

  • confirmed=False preview gate for delete
  • confirmed=True success path
  • MCP ownership checks for non-admin personas + platform-admin bypass
  • invalid name / invalid action / namespace policy short-circuits
  • not-found and generic SDK error wrapping
  • suspend/resume patch body (spec.suspend)

Testing

uv run pytest -q tests/unit/trainer/test_lifecycle.py
# 19 passed

make test-python
# 229 passed

ruff check / ruff format --check clean on the new file.

Part of kubeflow#68 lifecycle slice.

Cover delete_training_job and update_training_job with mocked SDK paths:
preview gate, ownership checks, admin bypass, invalid inputs, and error wrapping.

Signed-off-by: Solaris-star <solaris@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 19, 2026 10:52
@google-oss-prow

Copy link
Copy Markdown

[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 Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

Copy link
Copy Markdown

🎉 Welcome to the Kubeflow MCP Server! 🎉

Thanks for opening your first PR! We're happy to have you as part of our community 🚀

Here's what happens next:

  • If you haven't already, please check out our Contributing Guide for repo-specific guidelines and the Kubeflow Contributor Guide for general community standards
  • Our team will review your PR soon! cc @kubeflow/kubeflow-sdk-team

Join the community:

Feel free to ask questions in the comments if you need any help or clarification!
Thanks again for contributing to Kubeflow! 🙏

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds lifecycle unit coverage for Trainer job deletion, suspension, and resumption.

Changes:

  • Tests preview, success, validation, ownership, and error paths.
  • Verifies suspend/resume patch bodies.

Comment on lines +28 to +31
from types import SimpleNamespace
from unittest.mock import MagicMock, patch

from kubeflow_mcp.trainer.api.lifecycle import delete_training_job, update_training_job

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for flagging this. The shared scaffold in #6 is not on main yet, so this PR cannot import its fixtures without duplicating that open PR. I have kept this branch compatible with current main and tightened the ownership and full SDK call assertions in 23939aa. Once #6 lands, I can rebase and convert these tests to the shared fixtures.

Comment on lines +22 to +23
- MCP ownership checks for non-admin personas
- platform-admin bypass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 23939aa. The non-admin delete and update paths now capture is_mcp_managed and assert the exact ("job-a", "default") arguments for allowed, denied, and API-error outcomes.

Comment thread tests/unit/trainer/test_lifecycle.py Outdated
Comment on lines +308 to +312
api.patch_namespaced_custom_object.assert_called_once()
kwargs = api.patch_namespaced_custom_object.call_args.kwargs
assert kwargs["name"] == "job-a"
assert kwargs["namespace"] == "default"
assert kwargs["body"] == {"spec": {"suspend": True}}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 23939aa. Suspend, resume, and the managed non-admin path now use assert_called_once_with for the complete invocation, including group, version, namespace, plural, name, body, and request timeout.

Signed-off-by: Solaris-star <820622658@qq.com>
@Solaris-star

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I agree this slice should use the shared Pattern C harness. That harness currently exists only in #6, which is still open and is not present on main. Copying its fixtures into this PR would duplicate the scaffold.

I will keep this branch based on main until #6 lands, then rebase and convert the confirmed paths to mock_trainer_client + verify_tool_*. At the same time I will tighten the ownership argument checks and assert the complete SDK calls. I will not request maintainer review before that update.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants