- Remove 'or (empty)' fallback in build_ping_embed to preserve empty strings in raw_content - Fix parse_ping_embed to use direct indexing for all required fields (modality, raw_content, captured_at) - Remove unused timezone import - Add test case for empty raw_content round-trip to catch future regressions Fixes code review findings: empty raw_content was being converted to literal "(empty)" string, breaking lossless round-trip requirement needed by Task 7's thread-open handler.
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
from datetime import datetime, timezone
|
|
from chorus_bot import ping
|
|
|
|
|
|
def test_build_and_parse_round_trip():
|
|
captured_at = datetime(2026, 7, 13, 7, 0, 0, tzinfo=timezone.utc)
|
|
embed = ping.build_ping_embed(
|
|
modality="bh_email",
|
|
sender_id="jane@example.com",
|
|
snippet="I have some books to donate...",
|
|
raw_content="I have some books to donate. Full text goes here.",
|
|
captured_at=captured_at,
|
|
)
|
|
assert "bh_email" in embed.title or "bh_email" in str(embed.fields)
|
|
assert "I have some books to donate..." in (embed.description or "")
|
|
|
|
parsed = ping.parse_ping_embed(embed)
|
|
assert parsed["modality"] == "bh_email"
|
|
assert parsed["sender_id"] == "jane@example.com"
|
|
assert parsed["raw_content"] == "I have some books to donate. Full text goes here."
|
|
assert parsed["captured_at"] == captured_at
|
|
|
|
|
|
def test_build_ping_embed_handles_missing_sender():
|
|
embed = ping.build_ping_embed(
|
|
modality="voice",
|
|
sender_id=None,
|
|
snippet="call about donation",
|
|
raw_content="call about donation",
|
|
captured_at=datetime(2026, 7, 13, 8, 0, 0, tzinfo=timezone.utc),
|
|
)
|
|
parsed = ping.parse_ping_embed(embed)
|
|
assert parsed["sender_id"] is None
|
|
|
|
|
|
def test_build_and_parse_empty_raw_content():
|
|
"""Verify empty raw_content round-trips correctly without being converted to '(empty)'."""
|
|
captured_at = datetime(2026, 7, 13, 9, 0, 0, tzinfo=timezone.utc)
|
|
embed = ping.build_ping_embed(
|
|
modality="bh_email",
|
|
sender_id="test@example.com",
|
|
snippet="Empty message",
|
|
raw_content="",
|
|
captured_at=captured_at,
|
|
)
|
|
parsed = ping.parse_ping_embed(embed)
|
|
assert parsed["raw_content"] == "", "Empty raw_content should round-trip as empty string, not '(empty)'"
|