From 775330ff167aaa5e835f0c8bb90414357157d4e7 Mon Sep 17 00:00:00 2001 From: Harwinder Sekhon Date: Mon, 3 Aug 2026 18:06:44 -0400 Subject: [PATCH] /news: normalize rounded-zero score so "-0.00" renders as "+0.00" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A balanced feed (XAU and USD means nearly cancelling) yields a tiny negative net that "+.2f" rendered as "-0.00" — seen live 2026-08-03. Regression test uses that day's actual per-currency means (300 tests). Claude-Session: https://claude.ai/code/session_017975c1TufZ3xRYAq8iWTCS --- telegram_bot.py | 2 ++ test_all.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/telegram_bot.py b/telegram_bot.py index bb3978a..d32a281 100755 --- a/telegram_bot.py +++ b/telegram_bot.py @@ -1036,6 +1036,8 @@ async def cmd_status(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None def _news_text(context: FundamentalContext, engine: NewsEngine) -> str: net, desc = engine.get_pair_sentiment(XAUUSD, context) + if round(net, 2) == 0: + net = 0.0 # a tiny negative mean would render as "-0.00" lines = [ "📰 *XAU/USD News Score*\n", f"*Net score:* `{net:+.2f}` — {desc}", diff --git a/test_all.py b/test_all.py index ebd2254..580eee0 100644 --- a/test_all.py +++ b/test_all.py @@ -1898,6 +1898,17 @@ def _(): assert "Bearish" in text +@test("_news_text never renders negative zero") +def _(): + # Balanced feed: XAU and USD means nearly cancel → net -0.0035, + # which "+.2f" would render as "-0.00" without normalization. + ctx = FundamentalContext(news_sentiment={"XAU": 0.0238, "USD": 0.0273}) + text = _news_text(ctx, NewsEngine(PlatformConfig().news)) + assert "-0.00" not in text + assert "+0.00" in text + assert "Neutral" in text + + @test("_news_text degrades on empty context") def _(): text = _news_text(FundamentalContext(), NewsEngine(PlatformConfig().news))