Skip to content
Open
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
32 changes: 22 additions & 10 deletions python/tests/unit/kernel/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,25 +1038,37 @@ def test_kernel_deep_copy(


def test_kernel_model_dump_fail_with_services(kernel: Kernel):
open_ai_chat_completion = OpenAIChatCompletion(ai_model_id="abc", api_key="abc")
kernel.add_service(open_ai_chat_completion)
class _UnserializableService:
service_id = "unserializable"

def __init__(self):
async def _agen():
yield "tick"

# Async generator objects are not deepcopy/pickle friendly.
self._bad = _agen()

kernel.add_service(_UnserializableService())
Comment on lines +1041 to +1051

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

Kernel.add_service is typed to accept AIServiceClientBase, but this test inserts a plain object. That can make model_dump(deep=True)/model_copy(deep=True) fail for reasons unrelated to the intended “unpickleable internal state” (for example, serializer/type handling of non-AIServiceClientBase values). Consider making _UnserializableService a minimal AIServiceClientBase subclass (with required ai_model_id and a field holding the async generator) so the failure is specifically attributable to the unpickleable state while staying within the API contract.

Copilot uses AI. Check for mistakes.

with pytest.raises(TypeError):
# This will fail because OpenAIChatCompletion is not serializable, more specifically,
# the client is not serializable
kernel.model_dump(deep=True)


def test_kernel_deep_copy_fail_with_services(kernel: Kernel):
open_ai_chat_completion = OpenAIChatCompletion(ai_model_id="abc", api_key="abc")
kernel.add_service(open_ai_chat_completion)
class _UnserializableService:
service_id = "unserializable"

def __init__(self):
async def _agen():
yield "tick"

# Async generator objects are not deepcopy/pickle friendly.
self._bad = _agen()

kernel.add_service(_UnserializableService())
Comment on lines +1041 to +1067

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

_UnserializableService is defined twice with identical logic. To reduce duplication and keep the two failure-path tests aligned over time, consider defining a single reusable helper (module-level class or small factory) and using it in both tests.

Copilot uses AI. Check for mistakes.

with pytest.raises(TypeError):
# This will fail because OpenAIChatCompletion is not serializable, more specifically,
# the client is not serializable
kernel.model_copy(deep=True)


def test_kernel_clone(
kernel: Kernel,
custom_plugin_class: type,
Expand Down
Loading