feat: msgspec schemas for jsonl decoding (#37)
This commit is contained in:
@@ -1,5 +1,21 @@
|
||||
import json
|
||||
|
||||
from takopi.events import EventFactory
|
||||
from takopi.model import ActionEvent
|
||||
from takopi.runners.codex import translate_codex_event
|
||||
from takopi.schemas import codex as codex_schema
|
||||
|
||||
|
||||
def _decode_event(payload: dict) -> codex_schema.ThreadEvent:
|
||||
return codex_schema.decode_event(json.dumps(payload))
|
||||
|
||||
|
||||
def _translate_event(payload: dict) -> list:
|
||||
return translate_codex_event(
|
||||
_decode_event(payload),
|
||||
title="Codex",
|
||||
factory=EventFactory("codex"),
|
||||
)
|
||||
|
||||
|
||||
def test_translate_mcp_tool_call_summarizes_structured_content() -> None:
|
||||
@@ -20,7 +36,7 @@ def test_translate_mcp_tool_call_summarizes_structured_content() -> None:
|
||||
},
|
||||
}
|
||||
|
||||
out = translate_codex_event(evt, title="Codex")
|
||||
out = _translate_event(evt)
|
||||
assert len(out) == 1
|
||||
assert isinstance(out[0], ActionEvent)
|
||||
summary = out[0].action.detail["result_summary"]
|
||||
@@ -36,38 +52,19 @@ def test_translate_mcp_tool_call_summarizes_null_structured_content() -> None:
|
||||
"type": "mcp_tool_call",
|
||||
"server": "docs",
|
||||
"tool": "search",
|
||||
"arguments": None,
|
||||
"result": {"content": [], "structured_content": None},
|
||||
"error": None,
|
||||
"status": "completed",
|
||||
},
|
||||
}
|
||||
|
||||
out = translate_codex_event(evt, title="Codex")
|
||||
out = _translate_event(evt)
|
||||
assert len(out) == 1
|
||||
assert isinstance(out[0], ActionEvent)
|
||||
assert out[0].action.detail["result_summary"]["has_structured"] is False
|
||||
|
||||
|
||||
def test_translate_mcp_tool_call_summarizes_legacy_structured_key() -> None:
|
||||
evt = {
|
||||
"type": "item.completed",
|
||||
"item": {
|
||||
"id": "item_3",
|
||||
"type": "mcp_tool_call",
|
||||
"server": "docs",
|
||||
"tool": "search",
|
||||
"result": {"structured": {"matches": 3}},
|
||||
"error": None,
|
||||
"status": "completed",
|
||||
},
|
||||
}
|
||||
|
||||
out = translate_codex_event(evt, title="Codex")
|
||||
assert len(out) == 1
|
||||
assert isinstance(out[0], ActionEvent)
|
||||
assert out[0].action.detail["result_summary"]["has_structured"] is True
|
||||
|
||||
|
||||
def test_translate_mcp_tool_call_missing_error_is_ok() -> None:
|
||||
evt = {
|
||||
"type": "item.completed",
|
||||
@@ -76,18 +73,20 @@ def test_translate_mcp_tool_call_missing_error_is_ok() -> None:
|
||||
"type": "mcp_tool_call",
|
||||
"server": "docs",
|
||||
"tool": "search",
|
||||
"arguments": None,
|
||||
"status": "completed",
|
||||
"result": {"content": []},
|
||||
"result": {"content": [], "structured_content": None},
|
||||
"error": None,
|
||||
},
|
||||
}
|
||||
|
||||
out = translate_codex_event(evt, title="Codex")
|
||||
out = _translate_event(evt)
|
||||
assert len(out) == 1
|
||||
assert isinstance(out[0], ActionEvent)
|
||||
assert out[0].ok is True
|
||||
|
||||
|
||||
def test_translate_command_execution_allows_missing_exit_code() -> None:
|
||||
def test_translate_command_execution_allows_null_exit_code() -> None:
|
||||
evt = {
|
||||
"type": "item.completed",
|
||||
"item": {
|
||||
@@ -95,11 +94,12 @@ def test_translate_command_execution_allows_missing_exit_code() -> None:
|
||||
"type": "command_execution",
|
||||
"command": "ls -la",
|
||||
"aggregated_output": "",
|
||||
"exit_code": None,
|
||||
"status": "completed",
|
||||
},
|
||||
}
|
||||
|
||||
out = translate_codex_event(evt, title="Codex")
|
||||
out = _translate_event(evt)
|
||||
assert len(out) == 1
|
||||
assert isinstance(out[0], ActionEvent)
|
||||
assert out[0].ok is True
|
||||
|
||||
Reference in New Issue
Block a user