From 9971632cd1779e3a92695bc5a0790732666b2d6d Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 13 Jul 2026 13:56:53 -0700 Subject: [PATCH] fix(bot): fix raw_content round-trip and parsing consistency - 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. --- bot/chorus_bot/ping.py | 8 ++++---- bot/tests/test_ping.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/bot/chorus_bot/ping.py b/bot/chorus_bot/ping.py index 3bf2151..1fe3221 100644 --- a/bot/chorus_bot/ping.py +++ b/bot/chorus_bot/ping.py @@ -1,4 +1,4 @@ -from datetime import datetime, timezone +from datetime import datetime import discord MODALITY_LABELS = { @@ -24,15 +24,15 @@ def build_ping_embed( embed.add_field(name="modality", value=modality, inline=True) embed.add_field(name="sender_id", value=sender_id or "", inline=True) embed.add_field(name="captured_at", value=captured_at.isoformat(), inline=True) - embed.add_field(name="raw_content", value=raw_content or "(empty)", inline=False) + embed.add_field(name="raw_content", value=raw_content, inline=False) return embed def parse_ping_embed(embed: discord.Embed) -> dict: values = {field.name: field.value for field in embed.fields} return { - "modality": values.get("modality"), + "modality": values["modality"], "sender_id": values.get("sender_id") or None, - "raw_content": values.get("raw_content"), + "raw_content": values["raw_content"], "captured_at": datetime.fromisoformat(values["captured_at"]), } diff --git a/bot/tests/test_ping.py b/bot/tests/test_ping.py index 361a7ed..4094cde 100644 --- a/bot/tests/test_ping.py +++ b/bot/tests/test_ping.py @@ -31,3 +31,17 @@ def test_build_ping_embed_handles_missing_sender(): ) 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)'"