mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
b1914e8433
* Add Workflow.reset() public method as recovery escape hatch when an in-flight run aborted (e.g. WorkflowConvergenceException) and the workflow is not checkpointed. Update the in-flight messages guard's error message to point callers at it. * Add test_workflow_run_inflight_messages_guard exercising both the guard (sync + streaming) and the reset() recovery path. * Add test_workflow_reset_rejects_concurrent_runs to lock down the in-progress guard on reset. * Add test_as_agent_continuation_preserves_prior_state covering the is_continuation branch in _ensure_state_initialized: stamps a marker between calls and asserts it survives, while Inputs.input and System.LastMessageText refresh to the new turn. * Add test_powerfx_safe.py regression tests for the Enum branch in _make_powerfx_safe (str-subclass, int-subclass, plain Enum, and Enums nested in dict/list). * Drop redundant @pytest.mark.asyncio on test_as_agent_round_trip_with_last_message_text (asyncio_mode='auto'). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
"""Regression tests for ``_make_powerfx_safe``.
|
|
|
|
PowerFx (via pythonnet) only accepts plain primitives, dicts, and lists.
|
|
``Enum`` instances - especially ``str``- and ``int``-subclass enums like
|
|
MAF's ``MessageRole`` - silently pass ``isinstance(v, str)`` /
|
|
``isinstance(v, int)`` checks but blow up later inside pythonnet with
|
|
``'<EnumName>' value cannot be converted to System.<X>``. These tests
|
|
pin down the Enum coercion branch so we don't regress that interop fix.
|
|
"""
|
|
|
|
from enum import Enum, IntEnum
|
|
|
|
from agent_framework_declarative._workflows._declarative_base import _make_powerfx_safe
|
|
|
|
|
|
class _StrRole(str, Enum):
|
|
USER = "user"
|
|
SYSTEM = "system"
|
|
|
|
|
|
class _IntCode(IntEnum):
|
|
ONE = 1
|
|
TWO = 2
|
|
|
|
|
|
class _PlainEnum(Enum):
|
|
X = "x"
|
|
Y = 42
|
|
|
|
|
|
def test_str_subclass_enum_reduces_to_str():
|
|
assert _make_powerfx_safe(_StrRole.USER) == "user"
|
|
assert type(_make_powerfx_safe(_StrRole.USER)) is str
|
|
|
|
|
|
def test_int_subclass_enum_reduces_to_int():
|
|
assert _make_powerfx_safe(_IntCode.ONE) == 1
|
|
assert type(_make_powerfx_safe(_IntCode.ONE)) is int
|
|
|
|
|
|
def test_plain_enum_reduces_to_underlying_value():
|
|
assert _make_powerfx_safe(_PlainEnum.X) == "x"
|
|
assert _make_powerfx_safe(_PlainEnum.Y) == 42
|
|
|
|
|
|
def test_enum_inside_dict_is_coerced():
|
|
safe = _make_powerfx_safe({"role": _StrRole.USER, "code": _IntCode.TWO})
|
|
assert safe == {"role": "user", "code": 2}
|
|
assert type(safe["role"]) is str
|
|
assert type(safe["code"]) is int
|
|
|
|
|
|
def test_enum_inside_list_is_coerced():
|
|
safe = _make_powerfx_safe([_StrRole.USER, _IntCode.ONE])
|
|
assert safe == ["user", 1]
|
|
assert type(safe[0]) is str
|
|
assert type(safe[1]) is int
|