chore(trainer): add unit tests for lifecycle tools#95
Conversation
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
🎉 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:
Join the community:
Feel free to ask questions in the comments if you need any help or clarification! |
| from types import SimpleNamespace | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from kubeflow_mcp.trainer.api.lifecycle import delete_training_job, update_training_job |
There was a problem hiding this comment.
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.
| - MCP ownership checks for non-admin personas | ||
| - platform-admin bypass |
There was a problem hiding this comment.
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.
| 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}} |
There was a problem hiding this comment.
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>
|
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 I will keep this branch based on |
Summary
Part of #68 — lifecycle section.
Adds unit coverage for
delete_training_jobandupdate_training_jobwith mocked SDK / CustomObjects API:confirmed=Falsepreview gate for deleteconfirmed=Truesuccess pathspec.suspend)Testing
ruff check / ruff format --check clean on the new file.