refactor: unify skills+cli runtime and streamline ag-ui flow
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from schemas.agent.runtime_models import ToolAgentOutput, ToolStatus
|
||||
|
||||
|
||||
class TestToolAgentOutputResultCoercion:
|
||||
def test_dict_result_stays_dict(self) -> None:
|
||||
output = ToolAgentOutput(
|
||||
tool_name="project_cli",
|
||||
tool_call_id="call-1",
|
||||
tool_call_args={},
|
||||
status=ToolStatus.SUCCESS,
|
||||
result={"total": 0, "items": []},
|
||||
)
|
||||
assert isinstance(output.result, dict)
|
||||
assert output.result == {"total": 0, "items": []}
|
||||
|
||||
def test_list_result_stays_list(self) -> None:
|
||||
output = ToolAgentOutput(
|
||||
tool_name="project_cli",
|
||||
tool_call_id="call-1",
|
||||
tool_call_args={},
|
||||
status=ToolStatus.SUCCESS,
|
||||
result=[{"id": "evt_1"}],
|
||||
)
|
||||
assert isinstance(output.result, list)
|
||||
|
||||
def test_string_result_stays_string(self) -> None:
|
||||
output = ToolAgentOutput(
|
||||
tool_name="project_cli",
|
||||
tool_call_id="call-1",
|
||||
tool_call_args={},
|
||||
status=ToolStatus.SUCCESS,
|
||||
result="not json",
|
||||
)
|
||||
assert isinstance(output.result, str)
|
||||
assert output.result == "not json"
|
||||
|
||||
def test_none_result_stays_none(self) -> None:
|
||||
output = ToolAgentOutput(
|
||||
tool_name="project_cli",
|
||||
tool_call_id="call-1",
|
||||
tool_call_args={},
|
||||
status=ToolStatus.FAILURE,
|
||||
result=None,
|
||||
error={"code": "ERR", "message": "fail", "retryable": False},
|
||||
)
|
||||
assert output.result is None
|
||||
|
||||
def test_ui_hints_preserved(self) -> None:
|
||||
output = ToolAgentOutput(
|
||||
tool_name="project_cli",
|
||||
tool_call_id="call-1",
|
||||
tool_call_args={},
|
||||
status=ToolStatus.SUCCESS,
|
||||
result={"total": 0, "items": []},
|
||||
ui_hints={"view": "calendar_event_list", "total": 0},
|
||||
)
|
||||
assert output.ui_hints == {"view": "calendar_event_list", "total": 0}
|
||||
|
||||
def test_model_dump_includes_ui_hints(self) -> None:
|
||||
output = ToolAgentOutput(
|
||||
tool_name="project_cli",
|
||||
tool_call_id="call-1",
|
||||
tool_call_args={},
|
||||
status=ToolStatus.SUCCESS,
|
||||
result={"total": 0, "items": []},
|
||||
ui_hints={"view": "calendar_event_list"},
|
||||
)
|
||||
dumped = output.model_dump(mode="json", exclude_none=True)
|
||||
assert "ui_hints" in dumped
|
||||
assert dumped["ui_hints"] == {"view": "calendar_event_list"}
|
||||
assert isinstance(dumped["result"], dict)
|
||||
|
||||
def test_model_dump_excludes_none_ui_hints(self) -> None:
|
||||
output = ToolAgentOutput(
|
||||
tool_name="project_cli",
|
||||
tool_call_id="call-1",
|
||||
tool_call_args={},
|
||||
status=ToolStatus.SUCCESS,
|
||||
result={"total": 0},
|
||||
ui_hints=None,
|
||||
)
|
||||
dumped = output.model_dump(mode="json", exclude_none=True)
|
||||
assert "ui_hints" not in dumped
|
||||
Reference in New Issue
Block a user