from __future__ import annotations
from cli_agent_mcp.shared.response_formatter import DebugInfo, ResponseData, ResponseFormatter
def test_compact_success_uses_message_and_hides_thought_process() -> None:
formatter = ResponseFormatter()
data = ResponseData(
answer="FULL OUTPUT SHOULD NOT APPEAR",
message="Task completed successfully. Response written to handoff_file.",
session_id="abc123",
thought_steps=["should be hidden"],
success=True,
)
out = formatter.format(data, debug=False)
assert "<message>Task completed successfully. Response written to handoff_file.</message>" in out
assert "<answer>" not in out
assert "<thought_process>" not in out
assert "<continuation_id>abc123</continuation_id>" in out
def test_compact_error_uses_message_instead_of_partial_answer_and_hides_hint() -> None:
formatter = ResponseFormatter()
data = ResponseData(
answer="PARTIAL OUTPUT SHOULD NOT APPEAR",
message="Task failed. Partial response written to handoff_file.",
session_id="abc123",
thought_steps=["should be hidden"],
success=False,
error="boom",
)
out = formatter.format(data, debug=False)
assert "<error>boom</error>" in out
assert "<message>Task failed. Partial response written to handoff_file.</message>" in out
assert "<partial_answer>" not in out
assert "<thought_process>" not in out
assert "<hint>" not in out
assert "<continuation_id>abc123</continuation_id>" in out
def test_compact_mode_still_allows_debug_info() -> None:
formatter = ResponseFormatter()
data = ResponseData(
answer="FULL OUTPUT SHOULD NOT APPEAR",
message="Task completed successfully. Response written to handoff_file.",
session_id="abc123",
success=True,
debug_info=DebugInfo(model="x", duration_sec=1.234, message_count=1, tool_call_count=2),
)
out = formatter.format(data, debug=True)
assert "<debug_info>" in out
assert "<model>x</model>" in out