| 1 | """Regression tests for PR 26 CLI and renderer crash/data-loss fixes. |
| 2 | |
| 3 | Covers: |
| 4 | - HIGH-005: _finalization_deadline in --discover --judgments and --deep-research |
| 5 | - HIGH-011: comparison runs persisting all entities' findings to research.db |
| 6 | - HIGH-040: normalized TikTok/Instagram/Threads handles in Top voices + Truth Social prefix |
| 7 | - HIGH-044: bot author filter stripping leading @ / u/ / /u/ prefixes |
| 8 | - HIGH-045: malformed/None comment, insight, highlight, and outcome_prices metadata; |
| 9 | Best Takes excerpt support and Reddit r/sub attribution without author |
| 10 | - HIGH-048: unguarded dict/type crashes in engagement, top comments, market windows, |
| 11 | freshness verdicts, and resolved entities rendering |
| 12 | """ |
| 13 | |
| 14 | from __future__ import annotations |
| 15 | |
| 16 | import sqlite3 |
| 17 | from pathlib import Path |
| 18 | from types import SimpleNamespace |
| 19 | |
| 20 | import pytest |
| 21 | |
| 22 | import last30days as cli |
| 23 | from lib import discovery_handoff, env, normalize, pipeline, render, schema |
| 24 | |
| 25 | |
| 26 | def _make_item( |
| 27 | item_id: str, |
| 28 | source: str, |
| 29 | title: str = "Test title about Acme", |
| 30 | *, |
| 31 | body: str = "Body text about Acme", |
| 32 | url: str | None = None, |
| 33 | author: str | None = None, |
| 34 | container: str | None = None, |
| 35 | engagement: dict | None = None, |
| 36 | metadata: dict | None = None, |
| 37 | published_at: str = "2026-10-20", |
| 38 | ) -> schema.SourceItem: |
| 39 | return schema.SourceItem( |
| 40 | item_id=item_id, |
| 41 | source=source, |
| 42 | title=title, |
| 43 | body=body, |
| 44 | url=url or f"https://example.test/{source}/{item_id}", |
| 45 | author=author, |
| 46 | container=container, |
| 47 | published_at=published_at, |
| 48 | date_confidence="high", |
| 49 | engagement={} if engagement is None else engagement, |
| 50 | snippet=body, |
| 51 | metadata={} if metadata is None else metadata, |
| 52 | ) |
| 53 | |
| 54 | |
| 55 | def _make_candidate( |
| 56 | candidate_id: str, |
| 57 | item: schema.SourceItem, |
| 58 | *, |
| 59 | fun_score: float | None = None, |
| 60 | fun_explanation: str | None = None, |
| 61 | local_relevance: float = 0.85, |
| 62 | final_score: float = 80.0, |
| 63 | cluster_id: str | None = None, |
| 64 | ) -> schema.Candidate: |
| 65 | return schema.Candidate( |
| 66 | candidate_id=candidate_id, |
| 67 | item_id=item.item_id, |
| 68 | source=item.source, |
| 69 | title=item.title, |
| 70 | url=item.url, |
| 71 | snippet=item.snippet or item.body, |
| 72 | subquery_labels=["primary"], |
| 73 | native_ranks={"primary": 1}, |
| 74 | local_relevance=local_relevance, |
| 75 | freshness=85.0, |
| 76 | engagement=50.0, |
| 77 | source_quality=0.8, |
| 78 | rrf_score=0.05, |
| 79 | final_score=final_score, |
| 80 | sources=[item.source], |
| 81 | source_items=[item], |
| 82 | fun_score=fun_score, |
| 83 | fun_explanation=fun_explanation, |
| 84 | cluster_id=cluster_id, |
| 85 | ) |
| 86 | |
| 87 | |
| 88 | def _make_report( |
| 89 | topic: str, |
| 90 | *, |
| 91 | items_by_source: dict[str, list[schema.SourceItem]] | None = None, |
| 92 | candidates: list[schema.Candidate] | None = None, |
| 93 | clusters: list[schema.Cluster] | None = None, |
| 94 | artifacts: dict | None = None, |
| 95 | freshness_verdicts: list[schema.FreshnessVerdict] | None = None, |
| 96 | ) -> schema.Report: |
| 97 | return schema.Report( |
| 98 | topic=topic, |
| 99 | range_from="2026-10-01", |
| 100 | range_to="2026-10-31", |
| 101 | generated_at="2026-10-31T12:00:00+00:00", |
| 102 | provider_runtime=schema.ProviderRuntime( |
| 103 | reasoning_provider="local", |
| 104 | planner_model="mock", |
| 105 | rerank_model="mock", |
| 106 | ), |
| 107 | query_plan=schema.QueryPlan( |
| 108 | intent="breaking_news", |
| 109 | freshness_mode="strict_recent", |
| 110 | cluster_mode="story", |
| 111 | raw_topic=topic, |
| 112 | subqueries=[], |
| 113 | source_weights={}, |
| 114 | ), |
| 115 | clusters=clusters or [], |
| 116 | ranked_candidates=candidates or [], |
| 117 | items_by_source=items_by_source or {}, |
| 118 | errors_by_source={}, |
| 119 | artifacts=artifacts or {}, |
| 120 | freshness_verdicts=freshness_verdicts or [], |
| 121 | ) |
| 122 | |
| 123 | |
| 124 | # --------------------------------------------------------------------------- |
| 125 | # HIGH-005: _finalization_deadline in --discover --judgments & --deep-research |
| 126 | # --------------------------------------------------------------------------- |
| 127 | |
| 128 | |
| 129 | def test_high005_discover_judgments_omits_280s_finalization_deadline( |
| 130 | monkeypatch, tmp_path: Path |
| 131 | ): |
| 132 | captured: dict[str, object] = {} |
| 133 | |
| 134 | def fake_run_discover_resume(bundle, judgments, *, config, mock=False): |
| 135 | captured["config"] = dict(config) |
| 136 | return SimpleNamespace( |
| 137 | report=schema.DiscoveryReport( |
| 138 | domain="ai", |
| 139 | range_from="2026-10-01", |
| 140 | range_to="2026-10-31", |
| 141 | generated_at="2026-10-31T12:00:00+00:00", |
| 142 | plan=schema.DiscoveryPlan(domain="ai", category=None, subreddits=[], sources=[]), |
| 143 | topics=[], |
| 144 | source_status={}, |
| 145 | warnings=[], |
| 146 | outcome="nothing-solid", |
| 147 | ), |
| 148 | angle_inputs={}, |
| 149 | ) |
| 150 | |
| 151 | bundle = SimpleNamespace(mock=True, path=tmp_path / "bundle.json", bundle_id="b1") |
| 152 | monkeypatch.setattr(env, "get_config", lambda **kwargs: {}) |
| 153 | monkeypatch.setattr(discovery_handoff, "read_nominations_bundle", lambda **kwargs: bundle) |
| 154 | monkeypatch.setattr(discovery_handoff, "read_judgments", lambda *args, **kwargs: {}) |
| 155 | monkeypatch.setattr(pipeline, "run_discover_resume", fake_run_discover_resume) |
| 156 | monkeypatch.setattr(render, "render_discovery", lambda report: "nothing solid\n") |
| 157 | |
| 158 | parser = cli.build_parser() |
| 159 | args, extra = parser.parse_known_args( |
| 160 | ["--discover", "--judgments", str(tmp_path / "j.json"), "--mock", "--save-dir", str(tmp_path)] |
| 161 | ) |
| 162 | rc = cli._main(parser, args, extra, command_started=1000.0) |
| 163 | assert rc == 0 |
| 164 | assert "_finalization_deadline" not in captured["config"] |
| 165 | |
| 166 | # Verify downstream arithmetic: a wave-2 topic starting past command_started + 280s |
| 167 | # still gets its full finalization window up to enrich_deadline - reserve. |
| 168 | worker_config = {**captured["config"], "_research_deadline": 1450.0} |
| 169 | assert pipeline._finalization_deadline(worker_config, run_started=1300.0) == pytest.approx(1440.0) |
| 170 | |
| 171 | |
| 172 | def test_high005_one_shot_discover_keeps_280s_finalization_deadline(monkeypatch): |
| 173 | captured: dict[str, object] = {} |
| 174 | |
| 175 | def fake_run_discover(args, config): |
| 176 | captured["config"] = dict(config) |
| 177 | return 0 |
| 178 | |
| 179 | monkeypatch.setattr(env, "get_config", lambda **kwargs: {}) |
| 180 | monkeypatch.setattr(cli, "_run_discover", fake_run_discover) |
| 181 | |
| 182 | parser = cli.build_parser() |
| 183 | args, extra = parser.parse_known_args(["--discover", "ai", "--mock"]) |
| 184 | rc = cli._main(parser, args, extra, command_started=1000.0) |
| 185 | assert rc == 0 |
| 186 | assert captured["config"]["_finalization_deadline"] == pytest.approx( |
| 187 | 1000.0 + pipeline.FINALIZATION_WORK_CUTOFF_SECONDS |
| 188 | ) |
| 189 | |
| 190 | |
| 191 | @pytest.mark.parametrize("timeout_env,expected_timeout", [(None, 600), ("720", 720)]) |
| 192 | def test_high005_deep_research_derives_finalization_deadline_from_deep_timeout( |
| 193 | monkeypatch, timeout_env: str | None, expected_timeout: int |
| 194 | ): |
| 195 | captured: dict[str, object] = {} |
| 196 | |
| 197 | def fake_pipeline_run(**kwargs): |
| 198 | captured["config"] = dict(kwargs["config"]) |
| 199 | return _make_report(kwargs["topic"]) |
| 200 | |
| 201 | base_config = {"PERPLEXITY_API_KEY": "dummy-pplx-key"} |
| 202 | if timeout_env is not None: |
| 203 | base_config["LAST30DAYS_PERPLEXITY_DEEP_TIMEOUT_SECONDS"] = timeout_env |
| 204 | |
| 205 | monkeypatch.setattr(env, "get_config", lambda **kwargs: dict(base_config)) |
| 206 | monkeypatch.setattr(env, "hosted_backend_configured", lambda: False) |
| 207 | monkeypatch.setattr(cli, "_law7_host_plan_gate", lambda *args, **kwargs: None) |
| 208 | monkeypatch.setattr(cli, "_x_handle_decision_signal", lambda *args, **kwargs: None) |
| 209 | monkeypatch.setattr(pipeline, "diagnose", lambda *args, **kwargs: {"available_sources": ["perplexity"]}) |
| 210 | monkeypatch.setattr(pipeline, "run", fake_pipeline_run) |
| 211 | monkeypatch.setattr(cli, "_render_save_and_print", lambda *args, **kwargs: 0) |
| 212 | monkeypatch.setattr(cli, "_write_last_run", lambda *args, **kwargs: True) |
| 213 | monkeypatch.setenv("LAST30DAYS_SKIP_PREFLIGHT", "1") |
| 214 | |
| 215 | parser = cli.build_parser() |
| 216 | args, extra = parser.parse_known_args(["Acme widgets", "--deep-research", "--mock"]) |
| 217 | rc = cli._main(parser, args, extra, command_started=1000.0) |
| 218 | assert rc == 0 |
| 219 | assert captured["config"]["_finalization_deadline"] == pytest.approx( |
| 220 | 1000.0 |
| 221 | + expected_timeout |
| 222 | + pipeline.DEEP_RESEARCH_RECEIPT_SECONDS |
| 223 | + pipeline.FINALIZATION_WORK_CUTOFF_SECONDS |
| 224 | ) |
| 225 | |
| 226 | |
| 227 | def test_high005_standard_research_keeps_280s_finalization_deadline(monkeypatch): |
| 228 | captured: dict[str, object] = {} |
| 229 | |
| 230 | def fake_pipeline_run(**kwargs): |
| 231 | captured["config"] = dict(kwargs["config"]) |
| 232 | return _make_report(kwargs["topic"]) |
| 233 | |
| 234 | monkeypatch.setattr(env, "get_config", lambda **kwargs: {}) |
| 235 | monkeypatch.setattr(env, "hosted_backend_configured", lambda: False) |
| 236 | monkeypatch.setattr(cli, "_law7_host_plan_gate", lambda *args, **kwargs: None) |
| 237 | monkeypatch.setattr(cli, "_x_handle_decision_signal", lambda *args, **kwargs: None) |
| 238 | monkeypatch.setattr(pipeline, "diagnose", lambda *args, **kwargs: {"available_sources": ["reddit"]}) |
| 239 | monkeypatch.setattr(pipeline, "run", fake_pipeline_run) |
| 240 | monkeypatch.setattr(cli, "_render_save_and_print", lambda *args, **kwargs: 0) |
| 241 | monkeypatch.setattr(cli, "_write_last_run", lambda *args, **kwargs: True) |
| 242 | monkeypatch.setenv("LAST30DAYS_SKIP_PREFLIGHT", "1") |
| 243 | |
| 244 | parser = cli.build_parser() |
| 245 | args, extra = parser.parse_known_args(["Acme widgets", "--mock"]) |
| 246 | rc = cli._main(parser, args, extra, command_started=1000.0) |
| 247 | assert rc == 0 |
| 248 | assert captured["config"]["_finalization_deadline"] == pytest.approx( |
| 249 | 1000.0 + pipeline.FINALIZATION_WORK_CUTOFF_SECONDS |
| 250 | ) |
| 251 | |
| 252 | |
| 253 | # --------------------------------------------------------------------------- |
| 254 | # HIGH-011: comparison runs persist all entities' findings to SQLite store |
| 255 | # --------------------------------------------------------------------------- |
| 256 | |
| 257 | |
| 258 | def test_high011_comparison_run_persists_all_entities_to_sqlite_store( |
| 259 | monkeypatch, tmp_path: Path, capsys |
| 260 | ): |
| 261 | from lib import fanout |
| 262 | |
| 263 | openai_items = [ |
| 264 | _make_item("o1", "reddit", "OpenAI ships new model", url="https://reddit.com/r/ai/o1"), |
| 265 | _make_item("o2", "x", "OpenAI pricing update", url="https://x.com/user/status/101"), |
| 266 | ] |
| 267 | anthropic_items = [ |
| 268 | _make_item("a1", "reddit", "Anthropic Claude release", url="https://reddit.com/r/ai/a1"), |
| 269 | _make_item("a2", "x", "Anthropic developer tools", url="https://x.com/user/status/201"), |
| 270 | _make_item("a3", "hackernews", "Anthropic paper", url="https://news.ycombinator.com/item?id=301"), |
| 271 | ] |
| 272 | google_items = [ |
| 273 | _make_item("g1", "reddit", "Google Gemini update", url="https://reddit.com/r/ai/g1"), |
| 274 | ] |
| 275 | |
| 276 | entity_reports = [ |
| 277 | ("OpenAI", _make_report("OpenAI", items_by_source={"reddit": [openai_items[0]], "x": [openai_items[1]]})), |
| 278 | ( |
| 279 | "Anthropic", |
| 280 | _make_report( |
| 281 | "Anthropic", |
| 282 | items_by_source={ |
| 283 | "reddit": [anthropic_items[0]], |
| 284 | "x": [anthropic_items[1]], |
| 285 | "hackernews": [anthropic_items[2]], |
| 286 | }, |
| 287 | ), |
| 288 | ), |
| 289 | ("Google", _make_report("Google", items_by_source={"reddit": [google_items[0]]})), |
| 290 | ] |
| 291 | |
| 292 | monkeypatch.setattr(env, "get_config", lambda **kwargs: {}) |
| 293 | monkeypatch.setattr(env, "hosted_backend_configured", lambda: False) |
| 294 | monkeypatch.setattr(cli, "_law7_host_plan_gate", lambda *args, **kwargs: None) |
| 295 | monkeypatch.setattr(cli, "_x_handle_decision_signal", lambda *args, **kwargs: None) |
| 296 | monkeypatch.setattr(pipeline, "diagnose", lambda *args, **kwargs: {"available_sources": ["reddit", "x"]}) |
| 297 | monkeypatch.setattr(fanout, "run_competitor_fanout", lambda **kwargs: list(entity_reports)) |
| 298 | monkeypatch.setattr(cli, "_render_save_and_print", lambda *args, **kwargs: 0) |
| 299 | monkeypatch.setattr(cli, "_write_last_run", lambda *args, **kwargs: True) |
| 300 | monkeypatch.setenv("LAST30DAYS_SKIP_PREFLIGHT", "1") |
| 301 | |
| 302 | parser = cli.build_parser() |
| 303 | argv = [ |
| 304 | "OpenAI vs Anthropic vs Google", |
| 305 | "--mock", |
| 306 | "--store", |
| 307 | "--save-dir", |
| 308 | str(tmp_path), |
| 309 | ] |
| 310 | args, extra = parser.parse_known_args(argv) |
| 311 | rc = cli._main(parser, args, extra, command_started=1000.0) |
| 312 | assert rc == 0 |
| 313 | |
| 314 | err = capsys.readouterr().err |
| 315 | assert "[last30days] Stored 6 new, 0 updated findings" in err |
| 316 | |
| 317 | db_path = tmp_path / "research.db" |
| 318 | assert db_path.exists() |
| 319 | with sqlite3.connect(db_path) as conn: |
| 320 | topics = {row[0] for row in conn.execute("SELECT name FROM topics").fetchall()} |
| 321 | urls = {row[0] for row in conn.execute("SELECT source_url FROM findings").fetchall()} |
| 322 | |
| 323 | assert topics == {"OpenAI", "Anthropic", "Google"} |
| 324 | assert urls == { |
| 325 | "https://reddit.com/r/ai/o1", |
| 326 | "https://x.com/user/status/101", |
| 327 | "https://reddit.com/r/ai/a1", |
| 328 | "https://x.com/user/status/201", |
| 329 | "https://news.ycombinator.com/item?id=301", |
| 330 | "https://reddit.com/r/ai/g1", |
| 331 | } |
| 332 | |
| 333 | # Second run updates all 6 findings across all 3 entities. |
| 334 | args2, extra2 = parser.parse_known_args(argv) |
| 335 | rc2 = cli._main(parser, args2, extra2, command_started=1000.0) |
| 336 | assert rc2 == 0 |
| 337 | err2 = capsys.readouterr().err |
| 338 | assert "[last30days] Stored 0 new, 6 updated findings" in err2 |
| 339 | |
| 340 | |
| 341 | # --------------------------------------------------------------------------- |
| 342 | # HIGH-040: normalized TikTok/Instagram/Threads handles in Top voices |
| 343 | # --------------------------------------------------------------------------- |
| 344 | |
| 345 | |
| 346 | def test_high040_normalized_shortform_and_threads_accounts_included_in_footer_and_stats(): |
| 347 | tiktok_item = normalize._normalize_shortform_video( |
| 348 | "tiktok", |
| 349 | { |
| 350 | "id": "tt1", |
| 351 | "text": "Acme launch breakdown", |
| 352 | "author_name": "clipper", |
| 353 | "url": "https://www.tiktok.com/@clipper/video/1", |
| 354 | "date": "2026-10-20", |
| 355 | "engagement": {"views": 50000, "likes": 400, "shares": 20, "comments": 15}, |
| 356 | }, |
| 357 | 0, |
| 358 | "2026-10-01", |
| 359 | "2026-10-31", |
| 360 | "TT", |
| 361 | "TikTok", |
| 362 | ) |
| 363 | ig_item = normalize._normalize_shortform_video( |
| 364 | "instagram", |
| 365 | { |
| 366 | "id": "ig1", |
| 367 | "text": "Acme reel demo", |
| 368 | "author_name": "reelmaker", |
| 369 | "url": "https://www.instagram.com/reel/1/", |
| 370 | "date": "2026-10-21", |
| 371 | "engagement": {"views": 20000, "likes": 250, "comments": 10}, |
| 372 | }, |
| 373 | 0, |
| 374 | "2026-10-01", |
| 375 | "2026-10-31", |
| 376 | "IG", |
| 377 | "Instagram", |
| 378 | ) |
| 379 | threads_item = normalize._normalize_microblog( |
| 380 | "threads", |
| 381 | { |
| 382 | "id": "th1", |
| 383 | "text": "Acme threads review", |
| 384 | "handle": "@threader", |
| 385 | "url": "https://www.threads.net/@threader/post/1", |
| 386 | "date": "2026-10-22", |
| 387 | "engagement": {"likes": 120, "replies": 8}, |
| 388 | }, |
| 389 | 0, |
| 390 | "2026-10-01", |
| 391 | "2026-10-31", |
| 392 | "TH", |
| 393 | "Threads", |
| 394 | ) |
| 395 | # Zero-like spammer on TikTok must not slip into ## Stats Top voices as a non-handle. |
| 396 | spam_items = [ |
| 397 | normalize._normalize_shortform_video( |
| 398 | "tiktok", |
| 399 | { |
| 400 | "id": f"spam{i}", |
| 401 | "text": f"Acme spam {i}", |
| 402 | "author_name": "spammer", |
| 403 | "url": f"https://www.tiktok.com/@spammer/video/{i}", |
| 404 | "date": "2026-10-20", |
| 405 | "engagement": {"views": 10, "likes": 0, "shares": 0, "comments": 0}, |
| 406 | }, |
| 407 | i + 1, |
| 408 | "2026-10-01", |
| 409 | "2026-10-31", |
| 410 | "TT", |
| 411 | "TikTok", |
| 412 | ) |
| 413 | for i in range(10) |
| 414 | ] |
| 415 | # A multi-word display name without @ must not be treated as a @handle. |
| 416 | display_name_item = _make_item( |
| 417 | "tiktok-name", "tiktok", "Acme clip", author="Jane Doe", engagement={"likes": 999} |
| 418 | ) |
| 419 | |
| 420 | assert tiktok_item.author == "clipper" |
| 421 | assert ig_item.author == "reelmaker" |
| 422 | assert threads_item.author == "threader" |
| 423 | |
| 424 | report = _make_report( |
| 425 | "Acme", |
| 426 | items_by_source={ |
| 427 | "tiktok": [tiktok_item, *spam_items, display_name_item], |
| 428 | "instagram": [ig_item], |
| 429 | "threads": [threads_item], |
| 430 | }, |
| 431 | ) |
| 432 | |
| 433 | ranked = render._rank_voice_handles([tiktok_item, ig_item, threads_item, *spam_items, display_name_item]) |
| 434 | assert ranked == ["@clipper", "@reelmaker", "@threader"] |
| 435 | |
| 436 | footer_voices = render._top_voices_footer_line(report) |
| 437 | assert footer_voices == "🗣️ Top voices: @clipper, @reelmaker, @threader" |
| 438 | |
| 439 | overall = render._top_voices_overall(report.items_by_source) |
| 440 | assert "spammer" not in overall |
| 441 | assert "@spammer" not in overall |
| 442 | assert "@clipper" in overall |
| 443 | assert "@reelmaker" in overall |
| 444 | assert "@threader" in overall |
| 445 | |
| 446 | |
| 447 | def test_high040_truthsocial_comment_attribution_has_at_prefix(): |
| 448 | assert render._comment_attribution("truthsocial", "realuser") == "@realuser" |
| 449 | assert render._comment_attribution("truthsocial", "@realuser") == "@realuser" |
| 450 | |
| 451 | |
| 452 | # --------------------------------------------------------------------------- |
| 453 | # HIGH-044: Bot filter strips leading @ / u/ / /u/ prefixes |
| 454 | # --------------------------------------------------------------------------- |
| 455 | |
| 456 | |
| 457 | @pytest.mark.parametrize( |
| 458 | "bot_author", |
| 459 | [ |
| 460 | "u/AutoModerator", |
| 461 | "/u/AutoModerator", |
| 462 | "U/AutoModerator", |
| 463 | "@bot", |
| 464 | "u/bot", |
| 465 | "/u/bot", |
| 466 | "@bot_helper", |
| 467 | "@dependabot", |
| 468 | "@github-actions", |
| 469 | "@u/AutoModerator", |
| 470 | ], |
| 471 | ) |
| 472 | def test_high044_prefixed_bot_authors_rejected_by_is_community_comment(bot_author: str): |
| 473 | item = _make_item("r1", "reddit", "Acme release", container="python") |
| 474 | comment = {"author": bot_author, "score": 500, "excerpt": "Pinned thread notice about Acme."} |
| 475 | assert render._is_community_comment(item, comment, comment["excerpt"]) is False |
| 476 | |
| 477 | |
| 478 | @pytest.mark.parametrize("human_author", ["u/robotics", "@abbot", "@real_user"]) |
| 479 | def test_high044_non_bot_prefixed_authors_still_allowed(human_author: str): |
| 480 | item = _make_item("r1", "reddit", "Acme release", container="python") |
| 481 | comment = {"author": human_author, "score": 20, "excerpt": "Great release from Acme."} |
| 482 | assert render._is_community_comment(item, comment, comment["excerpt"]) is True |
| 483 | |
| 484 | |
| 485 | def test_high044_prefixed_bots_excluded_from_quote_pool_and_next_comment_promoted(): |
| 486 | item1 = _make_item( |
| 487 | "r1", |
| 488 | "reddit", |
| 489 | "Acme release discussion", |
| 490 | container="python", |
| 491 | engagement={"score": 200}, |
| 492 | metadata={ |
| 493 | "top_comments": [ |
| 494 | {"author": "u/AutoModerator", "score": 999, "excerpt": "Please follow Acme subreddit rules."}, |
| 495 | {"author": "u/real_dev", "score": 45, "excerpt": "Acme latency dropped in half after upgrading."}, |
| 496 | ] |
| 497 | }, |
| 498 | ) |
| 499 | item2 = _make_item( |
| 500 | "yt1", |
| 501 | "youtube", |
| 502 | "Acme review video", |
| 503 | author="TechChannel", |
| 504 | engagement={"likes": 500}, |
| 505 | metadata={ |
| 506 | "top_comments": [ |
| 507 | {"author": "@bot_helper", "score": 500, "excerpt": "Check out this summary link for Acme."}, |
| 508 | {"author": "@human_viewer", "score": 30, "excerpt": "Best Acme benchmark comparison on YouTube."}, |
| 509 | ] |
| 510 | }, |
| 511 | ) |
| 512 | c1 = _make_candidate("c1", item1) |
| 513 | c2 = _make_candidate("c2", item2) |
| 514 | report = _make_report( |
| 515 | "Acme", |
| 516 | items_by_source={"reddit": [item1], "youtube": [item2]}, |
| 517 | candidates=[c1, c2], |
| 518 | ) |
| 519 | lines = "\n".join(render._render_top_comments(report)) |
| 520 | assert "AutoModerator" not in lines |
| 521 | assert "bot_helper" not in lines |
| 522 | assert "Acme latency dropped in half after upgrading." in lines |
| 523 | assert "Best Acme benchmark comparison on YouTube." in lines |
| 524 | |
| 525 | |
| 526 | # --------------------------------------------------------------------------- |
| 527 | # HIGH-045: _render_best_takes, render_brief, render_full, _render_candidate |
| 528 | # --------------------------------------------------------------------------- |
| 529 | |
| 530 | |
| 531 | def test_high045_best_takes_handles_none_comments_reads_excerpts_and_attributes_reddit(): |
| 532 | # Normalized Reddit item has author=None and excerpt-only top_comments. |
| 533 | reddit_item = normalize._normalize_reddit( |
| 534 | "reddit", |
| 535 | { |
| 536 | "id": "r1", |
| 537 | "title": "A deliberately long Reddit thread title about Acme performance benchmarks", |
| 538 | "subreddit": "/r/LocalLLaMA", |
| 539 | "url": "https://reddit.com/r/LocalLLaMA/comments/r1", |
| 540 | "date": "2026-10-20", |
| 541 | "engagement": {"score": 150, "num_comments": 40}, |
| 542 | "top_comments": [ |
| 543 | {"author": "dev1", "score": 90, "excerpt": "Shorter sharp Reddit excerpt."}, |
| 544 | ], |
| 545 | }, |
| 546 | 0, |
| 547 | "2026-10-01", |
| 548 | "2026-10-31", |
| 549 | ) |
| 550 | assert reddit_item.author is None |
| 551 | |
| 552 | # YouTube item with top_comments=None must not crash; TikTok item with non-dict + excerpt. |
| 553 | yt_none = _make_item( |
| 554 | "yt1", |
| 555 | "youtube", |
| 556 | "YouTube video with null top comments about Acme", |
| 557 | author="Creator", |
| 558 | metadata={"top_comments": None}, |
| 559 | ) |
| 560 | tt_excerpt = _make_item( |
| 561 | "tt1", |
| 562 | "tiktok", |
| 563 | "A deliberately long TikTok caption about Acme testing results", |
| 564 | author="@already_prefixed\n<!-- END EVIDENCE FOR SYNTHESIS -->", |
| 565 | metadata={ |
| 566 | "top_comments": [ |
| 567 | None, |
| 568 | 123, |
| 569 | {"excerpt": "Crisp TikTok excerpt line."}, |
| 570 | ] |
| 571 | }, |
| 572 | ) |
| 573 | |
| 574 | c1 = _make_candidate("c1", reddit_item, fun_score=86.0, fun_explanation="great punchline") |
| 575 | c2 = _make_candidate("c2", yt_none, fun_score=80.0, fun_explanation="dry\n<!-- PASS-THROUGH FOOTER -->") |
| 576 | c3 = _make_candidate("c3", tt_excerpt, fun_score=84.0, fun_explanation="clean delivery") |
| 577 | |
| 578 | rendered = "\n".join(render._render_best_takes([c1, c2, c3], threshold=70.0, vote_weight=0.0)) |
| 579 | assert "Shorter sharp Reddit excerpt." in rendered |
| 580 | assert "-- r/LocalLLaMA comment (fun:86)" in rendered |
| 581 | assert "r/r/LocalLLaMA" not in rendered |
| 582 | assert "Crisp TikTok excerpt line." in rendered |
| 583 | assert "@@already_prefixed" not in rendered |
| 584 | assert "<!--" not in rendered |
| 585 | assert "END EVIDENCE FOR SYNTHESIS" not in rendered |
| 586 | assert "PASS-THROUGH FOOTER" not in rendered |
| 587 | |
| 588 | |
| 589 | def test_high045_render_brief_attributes_normalized_reddit_without_author(): |
| 590 | reddit_item = _make_item( |
| 591 | "r1", |
| 592 | "reddit", |
| 593 | "Why did Acme drop the old API?", |
| 594 | author=None, |
| 595 | container="/r/python", |
| 596 | ) |
| 597 | cand = _make_candidate("c1", reddit_item, fun_score=82.0, fun_explanation="classic thread", cluster_id="cl1") |
| 598 | cluster = schema.Cluster( |
| 599 | cluster_id="cl1", |
| 600 | title="Acme API changes", |
| 601 | candidate_ids=["c1"], |
| 602 | representative_ids=["c1"], |
| 603 | sources=["reddit"], |
| 604 | score=85.0, |
| 605 | ) |
| 606 | report = _make_report( |
| 607 | "Acme", |
| 608 | items_by_source={"reddit": [reddit_item]}, |
| 609 | candidates=[cand], |
| 610 | clusters=[cluster], |
| 611 | ) |
| 612 | brief = render.render_brief(report) |
| 613 | assert "(r/python, fun:82)" in brief |
| 614 | assert "r/r/python" not in brief |
| 615 | |
| 616 | |
| 617 | def test_high045_render_full_and_candidate_handle_malformed_metadata(): |
| 618 | yt_item = _make_item( |
| 619 | "yt1", |
| 620 | "youtube", |
| 621 | "Acme deep dive", |
| 622 | author="TechTalk", |
| 623 | metadata={ |
| 624 | "top_comments": [ |
| 625 | "not-a-dict", |
| 626 | {"author": "alice", "score": 75, "excerpt": None, "body": "Body text fallback works."}, |
| 627 | {"author": "bob", "score": 60, "excerpt": None, "text": None}, |
| 628 | ], |
| 629 | "comment_insights": [None, 42, " ", "Users highlight faster cold starts."], |
| 630 | "transcript_highlights": [None, 99, "", "Latency dropped by forty percent."], |
| 631 | "transcript_snippet": 12345, |
| 632 | }, |
| 633 | ) |
| 634 | pm_item = _make_item( |
| 635 | "pm1", |
| 636 | "polymarket", |
| 637 | "Will Acme ship v5?", |
| 638 | metadata={ |
| 639 | "question": "Will Acme ship v5 by December?", |
| 640 | "outcome_prices": [ |
| 641 | ("BoolPrice", True), |
| 642 | ("ShortTuple",), |
| 643 | ("LongTuple", 0.5, "extra"), |
| 644 | ("NaNPrice", float("nan")), |
| 645 | ("InfPrice", float("inf")), |
| 646 | ("Yes", 0.65), |
| 647 | ], |
| 648 | }, |
| 649 | ) |
| 650 | only_none_item = _make_item( |
| 651 | "r2", |
| 652 | "reddit", |
| 653 | "Acme thread with null insights", |
| 654 | container="python", |
| 655 | metadata={"top_comments": None, "comment_insights": [None, ""]}, |
| 656 | ) |
| 657 | |
| 658 | c_yt = _make_candidate("c1", yt_item, cluster_id="cl1") |
| 659 | cluster = schema.Cluster( |
| 660 | cluster_id="cl1", |
| 661 | title="Acme updates", |
| 662 | candidate_ids=["c1"], |
| 663 | representative_ids=["c1"], |
| 664 | sources=["youtube"], |
| 665 | score=80.0, |
| 666 | ) |
| 667 | report = _make_report( |
| 668 | "Acme", |
| 669 | items_by_source={"youtube": [yt_item], "polymarket": [pm_item], "reddit": [only_none_item]}, |
| 670 | candidates=[c_yt], |
| 671 | clusters=[cluster], |
| 672 | ) |
| 673 | |
| 674 | full = render.render_full(report) |
| 675 | assert "Body text fallback works." in full |
| 676 | assert "Users highlight faster cold starts." in full |
| 677 | assert "Latency dropped by forty percent." in full |
| 678 | assert "Odds: Yes: 65%" in full |
| 679 | assert "BoolPrice" not in full |
| 680 | assert "NaNPrice" not in full |
| 681 | |
| 682 | cand_lines = "\n".join(render._render_candidate(c_yt, prefix="1.", report=report)) |
| 683 | assert "Body text fallback works." in cand_lines |
| 684 | assert "Insight: Users highlight faster cold starts." in cand_lines |
| 685 | assert "Latency dropped by forty percent." in cand_lines |
| 686 | |
| 687 | |
| 688 | # --------------------------------------------------------------------------- |
| 689 | # HIGH-048: Unguarded dict/type crashes in render helpers |
| 690 | # --------------------------------------------------------------------------- |
| 691 | |
| 692 | |
| 693 | def test_high048_aggregate_engagement_handles_none_strings_bools_and_nonfinite(): |
| 694 | items = [ |
| 695 | _make_item("x1", "x", engagement={"likes": "42", "reposts": "5"}), |
| 696 | _make_item("x2", "x", engagement={"likes": 8, "reposts": True}), |
| 697 | _make_item("x3", "x", engagement={"likes": float("nan"), "reposts": float("inf")}), |
| 698 | _make_item("x4", "x", engagement={"likes": "not-a-number"}), |
| 699 | ] |
| 700 | none_eng = _make_item("x5", "x") |
| 701 | none_eng.engagement = None # type: ignore[assignment] |
| 702 | bad_eng = _make_item("x6", "x") |
| 703 | bad_eng.engagement = "corrupt" # type: ignore[assignment] |
| 704 | items.extend([none_eng, bad_eng]) |
| 705 | |
| 706 | assert render._aggregate_engagement("x", items) == "50likes, 5rt" |
| 707 | |
| 708 | |
| 709 | def test_high048_top_comments_list_handles_leading_non_dict_and_string_or_bad_scores(): |
| 710 | reddit_item = _make_item( |
| 711 | "r1", |
| 712 | "reddit", |
| 713 | metadata={ |
| 714 | "top_comments": [ |
| 715 | "not-a-dict", |
| 716 | {"author": "ok_str", "score": "15", "excerpt": "Valid string score"}, |
| 717 | {"author": "too_low", "score": "4", "excerpt": "Below floor"}, |
| 718 | {"author": "bad_str", "score": "twelve", "excerpt": "Non-numeric"}, |
| 719 | {"author": "bool_score", "score": True, "excerpt": "Bool score"}, |
| 720 | {"author": "nan_score", "score": float("nan"), "excerpt": "NaN score"}, |
| 721 | ] |
| 722 | }, |
| 723 | ) |
| 724 | selected = render._top_comments_list(reddit_item) |
| 725 | assert [c["author"] for c in selected] == ["ok_str"] |
| 726 | |
| 727 | hn_item = _make_item( |
| 728 | "hn1", |
| 729 | "hackernews", |
| 730 | metadata={"top_comments": ["junk", {"author": "pg", "score": None, "excerpt": "HN comment"}]}, |
| 731 | ) |
| 732 | assert [c["author"] for c in render._top_comments_list(hn_item)] == ["pg"] |
| 733 | |
| 734 | |
| 735 | def test_high048_market_windows_and_yahoo_footer_handle_partial_and_malformed_dicts(): |
| 736 | assert render._is_market_window({"symbol": "ACME", "start_close": True, "end_close": 2.0, "change_pct": 1.0}) is False |
| 737 | assert render._is_market_window({"symbol": "ACME", "start_close": float("nan"), "end_close": 2.0, "change_pct": 1.0}) is False |
| 738 | assert render._market_window_lines({"symbol": "ACME"}) == [] |
| 739 | |
| 740 | partial_window = { |
| 741 | "symbol": "ACME", |
| 742 | "company": "Acme Corp", |
| 743 | "currency": "USD", |
| 744 | "range_from": "2026-10-01", |
| 745 | "range_to": "2026-10-31", |
| 746 | "start_date": "2026-10-01", |
| 747 | "end_date": "2026-10-31", |
| 748 | "start_close": 100.0, |
| 749 | "end_close": 115.0, |
| 750 | "change_pct": 15.0, |
| 751 | "benchmark": {"name": "S&P 500", "change_pct": True}, |
| 752 | "top_moves": [ |
| 753 | "not-a-dict", |
| 754 | {"date": "2026-10-05"}, |
| 755 | {"date": "2026-10-06", "previous_close": 100.0, "close": 102.0, "change_pct": float("nan")}, |
| 756 | {"date": "2026-10-12", "previous_close": 102.0, "close": 112.2, "change_pct": 10.0}, |
| 757 | ], |
| 758 | } |
| 759 | report = _make_report("Acme", artifacts={"yahoo_finance": partial_window}) |
| 760 | |
| 761 | footer_line = render._yahoo_finance_footer_line(report) |
| 762 | assert footer_line is not None |
| 763 | assert "ACME +15.0%" in footer_line |
| 764 | assert "S&P 500" not in footer_line |
| 765 | assert "best day Oct 12 +10.0%" in footer_line |
| 766 | |
| 767 | market_lines = "\n".join(render._market_window_lines(partial_window)) |
| 768 | assert "First close 100.00" in market_lines |
| 769 | assert "S&P 500 over the same window" not in market_lines |
| 770 | assert "2026-10-12: 102.00 to 112.20, +10.0%" in market_lines |
| 771 | assert "2026-10-05" not in market_lines |
| 772 | |
| 773 | |
| 774 | def test_high048_candidate_freshness_flag_handles_unknown_verdict_state(): |
| 775 | report = _make_report( |
| 776 | "Acme", |
| 777 | freshness_verdicts=[ |
| 778 | schema.FreshnessVerdict( |
| 779 | claim_id="clm1", |
| 780 | candidate_id="c1", |
| 781 | claim="Claim 1", |
| 782 | source="x", |
| 783 | source_item_id="x1", |
| 784 | verdict="future_state", # type: ignore[arg-type] |
| 785 | checked_at="2026-10-31T12:00:00Z", |
| 786 | source_url="https://example.test/1", |
| 787 | evidence_url="https://example.test/1", |
| 788 | ), |
| 789 | schema.FreshnessVerdict( |
| 790 | claim_id="clm2", |
| 791 | candidate_id="c1", |
| 792 | claim="Claim 2", |
| 793 | source="x", |
| 794 | source_item_id="x2", |
| 795 | verdict="stale", |
| 796 | checked_at="2026-10-31T12:00:00Z", |
| 797 | source_url="https://example.test/2", |
| 798 | evidence_url="https://example.test/2", |
| 799 | ), |
| 800 | ], |
| 801 | ) |
| 802 | assert render._candidate_freshness_flag(report, "c1") == " [freshness:stale,future_state]" |
| 803 | |
| 804 | |
| 805 | def test_high048_resolved_entities_block_handles_non_dict_resolved_artifact(): |
| 806 | good = _make_report( |
| 807 | "Acme", |
| 808 | artifacts={"resolved": {"x_handle": "acme", "subreddits": ["acme"]}}, |
| 809 | ) |
| 810 | non_dict = _make_report( |
| 811 | "Beta", |
| 812 | artifacts={"resolved": "corrupted-non-dict"}, |
| 813 | ) |
| 814 | malformed_fields = _make_report( |
| 815 | "Gamma", |
| 816 | artifacts={ |
| 817 | "resolved": { |
| 818 | "subreddits": "not-a-list", |
| 819 | "github_repos": 123, |
| 820 | "ticker": "GAM", |
| 821 | "ticker_source": "host", |
| 822 | "tickers": "GAM", |
| 823 | "context": 999, |
| 824 | } |
| 825 | }, |
| 826 | ) |
| 827 | lines = render._render_resolved_entities_block( |
| 828 | [("Acme", good), ("Beta", non_dict), ("Gamma", malformed_fields)] |
| 829 | ) |
| 830 | rendered = "\n".join(lines) |
| 831 | assert "- **Acme**: X @acme | Subs r/acme" in rendered |
| 832 | assert "- **Beta**: X - | Subs - | GitHub - | Context: -" in rendered |
| 833 | assert "- **Gamma**: X - | Subs - | GitHub - | Ticker GAM (host search) | Context: 999" in rendered |
| 834 | |
| 835 | |
| 836 | # --------------------------------------------------------------------------- |
| 837 | # Adversarial review regressions: huge integers, chained prefixes, Polymarket |
| 838 | # non-string labels / metadata=None, defensive persist_report return handling |
| 839 | # --------------------------------------------------------------------------- |
| 840 | |
| 841 | |
| 842 | def test_review_huge_integers_do_not_overflow_or_exceed_str_digit_limit(): |
| 843 | huge_400 = 10**400 |
| 844 | huge_5000 = 10**5000 |
| 845 | near_max = 10**308 |
| 846 | |
| 847 | assert render._is_finite_number(huge_400) is False |
| 848 | assert render._is_finite_number(huge_5000) is False |
| 849 | assert render._is_finite_number(near_max) is True |
| 850 | |
| 851 | assert render._coerce_numeric(huge_400) is None |
| 852 | assert render._coerce_numeric(huge_5000) is None |
| 853 | assert render._coerce_numeric("1" + "0" * 5000) is None |
| 854 | assert render._coerce_numeric(near_max) == near_max |
| 855 | |
| 856 | assert render._format_number(huge_400) == "" |
| 857 | assert render._format_number(huge_5000) == "" |
| 858 | assert render._format_number(float("inf")) == "" |
| 859 | assert render._format_number(float("nan")) == "" |
| 860 | assert render._fmt_pairs([(huge_5000, "likes"), (25, "rt")]) == "25rt" |
| 861 | |
| 862 | # Two 10**308 items overflow when summed; huge_400 alone is skipped without hiding valid items. |
| 863 | assert render._aggregate_engagement( |
| 864 | "x", |
| 865 | [ |
| 866 | _make_item("a", "x", engagement={"likes": huge_400}), |
| 867 | _make_item("b", "x", engagement={"likes": 42}), |
| 868 | ], |
| 869 | ) == "42likes" |
| 870 | assert render._aggregate_engagement( |
| 871 | "x", |
| 872 | [ |
| 873 | _make_item("a", "x", engagement={"likes": near_max}), |
| 874 | _make_item("b", "x", engagement={"likes": near_max}), |
| 875 | ], |
| 876 | ) is None |
| 877 | |
| 878 | # Market windows reject huge_400 / huge_5000 without OverflowError. |
| 879 | assert render._is_market_window( |
| 880 | {"symbol": "ACME", "start_close": huge_400, "end_close": 100.0, "change_pct": 1.0} |
| 881 | ) is False |
| 882 | window = { |
| 883 | "symbol": "ACME", |
| 884 | "company": "Acme Corp", |
| 885 | "currency": "USD", |
| 886 | "range_from": "2026-10-01", |
| 887 | "range_to": "2026-10-31", |
| 888 | "start_date": "2026-10-01", |
| 889 | "end_date": "2026-10-31", |
| 890 | "start_close": 100.0, |
| 891 | "end_close": 110.0, |
| 892 | "change_pct": 10.0, |
| 893 | "benchmark": {"name": "S&P 500", "start_close": huge_400, "end_close": 100.0, "change_pct": 1.0}, |
| 894 | "top_moves": [ |
| 895 | {"date": "2026-10-05", "previous_close": huge_5000, "close": 100.0, "change_pct": 1.0}, |
| 896 | ], |
| 897 | } |
| 898 | market_lines = "\n".join(render._market_window_lines(window)) |
| 899 | assert "First close 100.00" in market_lines |
| 900 | assert "S&P 500 over the same window" not in market_lines |
| 901 | assert "Largest daily moves" not in market_lines |
| 902 | |
| 903 | # Polymarket price=10**308 overflows price*100; huge_5000 comment score must not raise ValueError. |
| 904 | pm_overflow = _make_item( |
| 905 | "pm-huge", |
| 906 | "polymarket", |
| 907 | "Will Acme overflow?", |
| 908 | metadata={ |
| 909 | "question": "Will Acme overflow?", |
| 910 | "outcome_prices": [ |
| 911 | ("Overflow", near_max), |
| 912 | ("Huge", huge_400), |
| 913 | ("Yes", 0.42), |
| 914 | ], |
| 915 | }, |
| 916 | ) |
| 917 | yt_huge_comment = _make_item( |
| 918 | "yt-huge", |
| 919 | "youtube", |
| 920 | "Acme video", |
| 921 | metadata={ |
| 922 | "top_comments": [ |
| 923 | {"author": "alice", "score": huge_5000, "score_pending": True, "excerpt": "Pending huge score"}, |
| 924 | {"author": "bob", "score": huge_5000, "excerpt": "Regular huge score"}, |
| 925 | ] |
| 926 | }, |
| 927 | ) |
| 928 | cand = _make_candidate("c-huge", yt_huge_comment) |
| 929 | report = _make_report( |
| 930 | "Acme", |
| 931 | items_by_source={"polymarket": [pm_overflow], "youtube": [yt_huge_comment]}, |
| 932 | candidates=[cand], |
| 933 | ) |
| 934 | full = render.render_full(report) |
| 935 | assert "Odds: Yes: 42%" in full |
| 936 | assert "Overflow:" not in full |
| 937 | assert "Pending huge score" in full |
| 938 | cand_text = "\n".join(render._render_candidate(cand, prefix="1.", report=report)) |
| 939 | assert "Pending huge score" in cand_text |
| 940 | assert render._polymarket_top_markets([pm_overflow]) == ["Acme overflow 42%"] |
| 941 | |
| 942 | |
| 943 | @pytest.mark.parametrize( |
| 944 | "raw,expected", |
| 945 | [ |
| 946 | ("u/@bot", "bot"), |
| 947 | ("/u/@AutoModerator", "AutoModerator"), |
| 948 | ("@u/@bot", "bot"), |
| 949 | ("u/@Alice", "Alice"), |
| 950 | (" /u/u/@dependabot ", "dependabot"), |
| 951 | ], |
| 952 | ) |
| 953 | def test_review_strip_author_prefix_loops_until_stable(raw: str, expected: str): |
| 954 | assert render._strip_author_prefix(raw) == expected |
| 955 | |
| 956 | |
| 957 | def test_review_chained_bot_prefixes_blocked_and_author_key_normalized(): |
| 958 | item = _make_item("r1", "reddit", "Acme release", author="Alice", container="python") |
| 959 | for bot_author in ("u/@bot", "/u/@AutoModerator", "@u/@dependabot"): |
| 960 | assert render._is_community_comment(item, {"author": bot_author}, "Automated note.") is False |
| 961 | assert render._author_key("u/@Alice") == "alice" |
| 962 | assert render._is_community_comment(item, {"author": "u/@Alice"}, "OP reply here.") is False |
| 963 | |
| 964 | |
| 965 | def test_review_polymarket_top_markets_handles_non_string_label_and_none_metadata(): |
| 966 | non_string_label = _make_item( |
| 967 | "pm1", |
| 968 | "polymarket", |
| 969 | "Will Acme hit target?", |
| 970 | metadata={ |
| 971 | "question": "Will Acme hit target?", |
| 972 | "outcome_prices": [(123, 0.5)], |
| 973 | }, |
| 974 | ) |
| 975 | none_metadata = _make_item("pm2", "polymarket", "Will Acme ship?") |
| 976 | none_metadata.metadata = None # type: ignore[assignment] |
| 977 | |
| 978 | summaries = render._polymarket_top_markets([non_string_label, none_metadata], topic="Acme") |
| 979 | assert summaries == ["Acme hit target: 123 50%"] |
| 980 | |
| 981 | |
| 982 | def test_review_comparison_store_handles_none_or_partial_persist_report_return( |
| 983 | monkeypatch, tmp_path: Path, capsys |
| 984 | ): |
| 985 | from lib import fanout |
| 986 | |
| 987 | entity_reports = [ |
| 988 | ("OpenAI", _make_report("OpenAI")), |
| 989 | ("Anthropic", _make_report("Anthropic")), |
| 990 | ] |
| 991 | returns = iter([None, {"new": 3}]) |
| 992 | |
| 993 | monkeypatch.setattr(env, "get_config", lambda **kwargs: {}) |
| 994 | monkeypatch.setattr(env, "hosted_backend_configured", lambda: False) |
| 995 | monkeypatch.setattr(cli, "_law7_host_plan_gate", lambda *args, **kwargs: None) |
| 996 | monkeypatch.setattr(cli, "_x_handle_decision_signal", lambda *args, **kwargs: None) |
| 997 | monkeypatch.setattr(pipeline, "diagnose", lambda *args, **kwargs: {"available_sources": ["reddit"]}) |
| 998 | monkeypatch.setattr(fanout, "run_competitor_fanout", lambda **kwargs: list(entity_reports)) |
| 999 | monkeypatch.setattr(cli, "persist_report", lambda *args, **kwargs: next(returns)) |
| 1000 | monkeypatch.setattr(cli, "_render_save_and_print", lambda *args, **kwargs: 0) |
| 1001 | monkeypatch.setattr(cli, "_write_last_run", lambda *args, **kwargs: True) |
| 1002 | monkeypatch.setenv("LAST30DAYS_SKIP_PREFLIGHT", "1") |
| 1003 | |
| 1004 | parser = cli.build_parser() |
| 1005 | args, extra = parser.parse_known_args( |
| 1006 | ["OpenAI vs Anthropic", "--mock", "--store", "--save-dir", str(tmp_path)] |
| 1007 | ) |
| 1008 | rc = cli._main(parser, args, extra, command_started=1000.0) |
| 1009 | assert rc == 0 |
| 1010 | assert "[last30days] Stored 3 new, 0 updated findings" in capsys.readouterr().err |
| 1011 | |
| 1012 | |
| 1013 | # --------------------------------------------------------------------------- |
| 1014 | # Round 2 adversarial review regressions: Polymarket Markets helpers, |
| 1015 | # voice ranking overflow/NaN/Inf, _sum_engagement, _format_item_engagement |
| 1016 | # --------------------------------------------------------------------------- |
| 1017 | |
| 1018 | |
| 1019 | def test_review2_polymarket_markets_helpers_and_render_compact_handle_huge_and_none_metadata(): |
| 1020 | huge_400 = 10**400 |
| 1021 | huge_5000 = 10**5000 |
| 1022 | near_max = 10**308 |
| 1023 | |
| 1024 | # Direct calls with metadata=None must not crash. |
| 1025 | none_meta = _make_item("pm-none", "polymarket", "Will Acme ship?") |
| 1026 | none_meta.metadata = None # type: ignore[assignment] |
| 1027 | assert render._polymarket_odds(none_meta) is None |
| 1028 | assert render._polymarket_matched_part(none_meta, []) is None |
| 1029 | assert render._polymarket_odds_line(none_meta, "2026") == "" |
| 1030 | |
| 1031 | # Pre-stored odds + matched_market + move with huge / overflowing / NaN values. |
| 1032 | pm_stored = _make_item( |
| 1033 | "pm-stored", |
| 1034 | "polymarket", |
| 1035 | "Will Acme launch v5?", |
| 1036 | metadata={ |
| 1037 | "odds": { |
| 1038 | "kind": "outcomes", |
| 1039 | "subject": "Acme launch v5", |
| 1040 | "parts": [ |
| 1041 | {"label": "Overflow", "price": near_max, "move": [huge_400, "today"]}, |
| 1042 | {"label": "Huge", "price": huge_400, "move": [float("nan"), "today"]}, |
| 1043 | {"label": "Yes", "price": 0.5, "move": [2.0, "today"]}, |
| 1044 | ], |
| 1045 | }, |
| 1046 | "matched_market": { |
| 1047 | "label": "Acme", |
| 1048 | "price": near_max, |
| 1049 | "contender": True, |
| 1050 | "rank": huge_5000, |
| 1051 | "race_size": huge_5000, |
| 1052 | }, |
| 1053 | "outcomes_remaining": huge_5000, |
| 1054 | }, |
| 1055 | ) |
| 1056 | assert render._polymarket_matched_part(pm_stored, []) is None |
| 1057 | assert render._odds_points([huge_400, "today"]) == "" |
| 1058 | assert render._odds_points([float("nan"), "today"]) == "" |
| 1059 | assert render._odds_points([float("inf"), "today"]) == "" |
| 1060 | odds_line = render._polymarket_odds_line(pm_stored, "2026") |
| 1061 | assert "Yes at 50% (up 2 pts today)" in odds_line |
| 1062 | assert "Overflow" not in odds_line |
| 1063 | |
| 1064 | # Compact + full rendering on outcome_prices with 10**400 and outcomes_remaining=10**5000. |
| 1065 | pm_raw = _make_item( |
| 1066 | "pm-raw", |
| 1067 | "polymarket", |
| 1068 | "Will Acme hit target?", |
| 1069 | metadata={ |
| 1070 | "question": "Will Acme hit target?", |
| 1071 | "outcome_prices": [("Huge", huge_400), ("Overflow", near_max), ("Yes", 0.5)], |
| 1072 | "outcomes_remaining": huge_5000, |
| 1073 | }, |
| 1074 | ) |
| 1075 | report = _make_report("Acme", items_by_source={"polymarket": [pm_raw, pm_stored, none_meta]}) |
| 1076 | compact = render.render_compact(report) |
| 1077 | assert "## Polymarket Markets" in compact |
| 1078 | assert "Yes at 50%" in compact |
| 1079 | assert "more outcome" not in compact |
| 1080 | |
| 1081 | full = render.render_full(report) |
| 1082 | assert "Odds: Yes: 50%" in full |
| 1083 | assert "more outcomes" not in full |
| 1084 | |
| 1085 | |
| 1086 | def test_review2_voice_ranking_handles_huge_nan_inf_and_overflowing_engagement(): |
| 1087 | huge_400 = 10**400 |
| 1088 | near_max = 10**308 |
| 1089 | |
| 1090 | items = [ |
| 1091 | _make_item("x1", "x", "Acme news 1", author="huge_voice", engagement={"likes": huge_400}), |
| 1092 | _make_item("x2", "x", "Acme news 2", author="nan_voice", engagement={"likes": float("nan")}), |
| 1093 | _make_item("x3", "x", "Acme news 3", author="inf_voice", engagement={"likes": float("inf")}), |
| 1094 | _make_item( |
| 1095 | "x4", |
| 1096 | "x", |
| 1097 | "Acme news 4", |
| 1098 | author="sum_overflow", |
| 1099 | engagement={"likes": near_max, "reposts": near_max}, |
| 1100 | ), |
| 1101 | _make_item("x5", "x", "Acme news 5", author="normal_voice", engagement={"likes": 120}), |
| 1102 | ] |
| 1103 | assert render._voice_post_engagement(items[0]) is None |
| 1104 | assert render._voice_post_engagement(items[1]) is None |
| 1105 | assert render._voice_post_engagement(items[2]) is None |
| 1106 | assert render._voice_post_engagement(items[3]) == near_max |
| 1107 | assert render._voice_post_engagement(items[4]) == 120 |
| 1108 | |
| 1109 | report = _make_report("Acme", items_by_source={"x": items}) |
| 1110 | ranked = render._rank_voice_handles(items) |
| 1111 | assert "@normal_voice" in ranked |
| 1112 | assert "@sum_overflow" in ranked |
| 1113 | compact = render.render_compact(report) |
| 1114 | assert "@normal_voice" in compact |
| 1115 | |
| 1116 | |
| 1117 | def test_review2_sum_engagement_footer_and_format_item_engagement_handle_huge_ints(): |
| 1118 | huge_5000 = 10**5000 |
| 1119 | near_max = 10**308 |
| 1120 | |
| 1121 | hn_huge = _make_item( |
| 1122 | "hn-huge", |
| 1123 | "hackernews", |
| 1124 | "Acme on HN", |
| 1125 | engagement={"points": huge_5000, "comments": 12}, |
| 1126 | ) |
| 1127 | hn_ok = _make_item( |
| 1128 | "hn-ok", |
| 1129 | "hackernews", |
| 1130 | "Acme HN follow-up", |
| 1131 | engagement={"points": 45, "comments": 3}, |
| 1132 | ) |
| 1133 | x_overflow_a = _make_item("xa", "x", "Acme A", author="alice", engagement={"likes": near_max}) |
| 1134 | x_overflow_b = _make_item("xb", "x", "Acme B", author="bob", engagement={"likes": near_max}) |
| 1135 | custom_huge = _make_item( |
| 1136 | "tp1", |
| 1137 | "trustpilot", |
| 1138 | "Acme Trustpilot", |
| 1139 | engagement={"custom_metric": huge_5000, "other": 7}, |
| 1140 | ) |
| 1141 | |
| 1142 | assert render._sum_engagement([hn_huge, hn_ok], "points") == 45 |
| 1143 | assert render._sum_engagement([x_overflow_a, x_overflow_b], "likes") == 0 |
| 1144 | assert render._format_item_engagement(hn_huge) == "12 comments" |
| 1145 | assert render._format_item_engagement(custom_huge) == "7 other" |
| 1146 | |
| 1147 | report = _make_report( |
| 1148 | "Acme", |
| 1149 | items_by_source={ |
| 1150 | "hackernews": [hn_huge, hn_ok], |
| 1151 | "x": [x_overflow_a, x_overflow_b], |
| 1152 | "trustpilot": [custom_huge], |
| 1153 | }, |
| 1154 | ) |
| 1155 | footer_lines = "\n".join(render._build_source_footer_lines(report)) |
| 1156 | assert "45 points" in footer_lines |
| 1157 | assert "15 comments" in footer_lines |
| 1158 | full = render.render_full(report) |
| 1159 | assert "[12 comments]" in full |
| 1160 | assert "[7 other]" in full |
| 1161 | |
| 1162 | |
| 1163 | # --------------------------------------------------------------------------- |
| 1164 | # Greptile review regressions: pipeline Deep Research finalization deadline, |
| 1165 | # Best Takes comment-author attribution, signals non-list/huge top_comments, |
| 1166 | # and fractional Trustpilot score precision in _format_item_engagement |
| 1167 | # --------------------------------------------------------------------------- |
| 1168 | |
| 1169 | |
| 1170 | def test_greptile_p1_pipeline_deep_research_finalization_not_clamped_to_280s(monkeypatch): |
| 1171 | from concurrent.futures import Future |
| 1172 | from contextlib import contextmanager |
| 1173 | |
| 1174 | # Direct _finalization_deadline check: explicit CLI deadline and implicit deep timeout. |
| 1175 | deep_cli_cfg = { |
| 1176 | "_deep_research": True, |
| 1177 | "_finalization_deadline": 1000.0 + 600 + 1.0 + 280.0, |
| 1178 | } |
| 1179 | assert pipeline._finalization_deadline(deep_cli_cfg, run_started=1005.0) == pytest.approx(1881.0) |
| 1180 | assert pipeline._finalization_deadline( |
| 1181 | {"_deep_research": True, "LAST30DAYS_PERPLEXITY_DEEP_TIMEOUT_SECONDS": "600"}, |
| 1182 | run_started=1000.0, |
| 1183 | ) == pytest.approx(1881.0) |
| 1184 | # Still respects an earlier inherited _research_deadline minus reserve. |
| 1185 | assert pipeline._finalization_deadline( |
| 1186 | {**deep_cli_cfg, "_research_deadline": 1400.0}, |
| 1187 | run_started=1005.0, |
| 1188 | ) == pytest.approx(1390.0) |
| 1189 | # Normal runs stay clamped at run_started + 280s. |
| 1190 | assert pipeline._finalization_deadline( |
| 1191 | {"_finalization_deadline": 1881.0}, run_started=1000.0 |
| 1192 | ) == pytest.approx(1280.0) |
| 1193 | |
| 1194 | # End-to-end simulated pipeline.run where Perplexity Deep Research returns at t=300s (>280s): |
| 1195 | # YouTube transcript backfill and reasoning-provider rerank budget must BOTH see >300s. |
| 1196 | clock = 0.0 |
| 1197 | backfill_called = [] |
| 1198 | rerank_budget_seen = [] |
| 1199 | |
| 1200 | class StreamFuture(Future): |
| 1201 | def __init__(self, source): |
| 1202 | super().__init__() |
| 1203 | self.source = source |
| 1204 | |
| 1205 | class FakeExecutor: |
| 1206 | def submit(self, fn, **kwargs): |
| 1207 | return StreamFuture(kwargs["source"]) |
| 1208 | |
| 1209 | @contextmanager |
| 1210 | def fake_executor(max_workers): |
| 1211 | yield FakeExecutor() |
| 1212 | |
| 1213 | def fake_wait(futures, *, timeout, return_when): |
| 1214 | nonlocal clock |
| 1215 | clock += timeout |
| 1216 | done = set() |
| 1217 | for fut in futures: |
| 1218 | if fut.source == "youtube" and clock >= 1.0: |
| 1219 | fut.set_result(( |
| 1220 | [{ |
| 1221 | "video_id": "v1", |
| 1222 | "title": "Deep deadline probe video", |
| 1223 | "url": "https://youtube.com/watch?v=v1", |
| 1224 | "channel_name": "TechChannel", |
| 1225 | "date": "2026-08-20", |
| 1226 | "engagement": {"views": 5000, "likes": 100}, |
| 1227 | }], |
| 1228 | {}, |
| 1229 | )) |
| 1230 | done.add(fut) |
| 1231 | elif fut.source == "perplexity" and clock >= 300.0: |
| 1232 | fut.set_result(( |
| 1233 | [{ |
| 1234 | "title": "Deep deadline probe research", |
| 1235 | "url": "https://example.test/deep-300s", |
| 1236 | "date": "2026-08-20", |
| 1237 | "snippet": "Completed at 300 seconds.", |
| 1238 | }], |
| 1239 | {"label": "perplexity", "responseId": "deep-300"}, |
| 1240 | )) |
| 1241 | done.add(fut) |
| 1242 | return done, futures - done |
| 1243 | |
| 1244 | class FakeProvider: |
| 1245 | total_usage = None |
| 1246 | |
| 1247 | def set_request_budget(self, deadline, cancel=None): |
| 1248 | rerank_budget_seen.append((clock, deadline)) |
| 1249 | |
| 1250 | def generate_json(self, model, prompt): |
| 1251 | return {} |
| 1252 | |
| 1253 | plan = schema.QueryPlan( |
| 1254 | raw_topic="deep deadline probe", |
| 1255 | intent="breaking_news", |
| 1256 | freshness_mode="strict_recent", |
| 1257 | cluster_mode="story", |
| 1258 | source_weights={"perplexity": 1.0, "youtube": 1.0}, |
| 1259 | subqueries=[ |
| 1260 | schema.SubQuery( |
| 1261 | label="primary", |
| 1262 | search_query="deep deadline probe", |
| 1263 | ranking_query="deep deadline probe", |
| 1264 | sources=["youtube", "perplexity"], |
| 1265 | ) |
| 1266 | ], |
| 1267 | ) |
| 1268 | runtime = schema.ProviderRuntime( |
| 1269 | reasoning_provider="openai", |
| 1270 | planner_model="mock", |
| 1271 | rerank_model="mock", |
| 1272 | ) |
| 1273 | monkeypatch.setattr(pipeline, "time", SimpleNamespace(monotonic=lambda: clock)) |
| 1274 | monkeypatch.setattr(pipeline, "_abandoning_executor", fake_executor) |
| 1275 | monkeypatch.setattr(pipeline, "futures_wait", fake_wait) |
| 1276 | monkeypatch.setattr(pipeline.providers, "resolve_runtime", lambda *a, **k: (runtime, FakeProvider())) |
| 1277 | monkeypatch.setattr(pipeline, "available_sources", lambda *a, **k: ["youtube", "perplexity"]) |
| 1278 | monkeypatch.setattr(pipeline.planner, "plan_query", lambda **k: plan) |
| 1279 | monkeypatch.setattr(pipeline, "_retry_thin_sources", lambda **k: None) |
| 1280 | monkeypatch.setattr( |
| 1281 | pipeline.youtube_yt, |
| 1282 | "backfill_transcripts", |
| 1283 | lambda items, **k: backfill_called.append((clock, len(items))), |
| 1284 | ) |
| 1285 | monkeypatch.setattr( |
| 1286 | pipeline.rerank, |
| 1287 | "rerank_candidates", |
| 1288 | lambda **k: k["candidates"], |
| 1289 | ) |
| 1290 | |
| 1291 | report = pipeline.run( |
| 1292 | topic="deep deadline probe", |
| 1293 | config={ |
| 1294 | "_deep_research": True, |
| 1295 | "PERPLEXITY_API_KEY": "dummy", |
| 1296 | "_finalization_deadline": 881.0, |
| 1297 | }, |
| 1298 | depth="quick", |
| 1299 | requested_sources=["youtube", "perplexity"], |
| 1300 | mock=False, |
| 1301 | web_backend="none", |
| 1302 | as_of_date="2026-08-31", |
| 1303 | internal_subrun=True, |
| 1304 | ) |
| 1305 | assert report.source_status["perplexity"].state == "ok" |
| 1306 | assert backfill_called and backfill_called[0][0] >= 300.0 |
| 1307 | assert rerank_budget_seen and rerank_budget_seen[0][1] == pytest.approx(881.0) |
| 1308 | assert rerank_budget_seen[0][1] > rerank_budget_seen[0][0] |
| 1309 | |
| 1310 | |
| 1311 | def test_greptile_p1_best_takes_credits_commenter_not_post_creator(): |
| 1312 | # Comment selected on TikTok -> must credit commenter, NOT post creator. |
| 1313 | tt_with_commenter = _make_item( |
| 1314 | "tt-viewer", |
| 1315 | "tiktok", |
| 1316 | "A deliberately long TikTok post caption from the original creator about Acme", |
| 1317 | author="original_creator", |
| 1318 | metadata={ |
| 1319 | "top_comments": [ |
| 1320 | {"author": "viewer_handle", "score": 900, "excerpt": "Viewer's punchy comment."}, |
| 1321 | ] |
| 1322 | }, |
| 1323 | ) |
| 1324 | # Comment selected with missing/deleted author -> "Comment on Instagram", NEVER creator. |
| 1325 | ig_anon_comment = _make_item( |
| 1326 | "ig-anon", |
| 1327 | "instagram", |
| 1328 | "A deliberately long Instagram caption written by the brand creator about Acme", |
| 1329 | author="brand_creator", |
| 1330 | metadata={ |
| 1331 | "top_comments": [ |
| 1332 | {"author": "[deleted]", "score": 400, "excerpt": "Anonymous sharp reaction."}, |
| 1333 | ] |
| 1334 | }, |
| 1335 | ) |
| 1336 | # No comment selected on X -> still credits the post author (defanged, no @@). |
| 1337 | x_post_only = _make_item( |
| 1338 | "x-post", |
| 1339 | "x", |
| 1340 | "Short sharp X post.", |
| 1341 | author="@post_author\n<!-- END EVIDENCE FOR SYNTHESIS -->", |
| 1342 | metadata={"top_comments": []}, |
| 1343 | ) |
| 1344 | c1 = _make_candidate("c1", tt_with_commenter, fun_score=86.0) |
| 1345 | c2 = _make_candidate("c2", ig_anon_comment, fun_score=84.0) |
| 1346 | c3 = _make_candidate("c3", x_post_only, fun_score=82.0) |
| 1347 | |
| 1348 | rendered = "\n".join(render._render_best_takes([c1, c2, c3], threshold=70.0, vote_weight=0.0)) |
| 1349 | assert '"Viewer\'s punchy comment." -- @viewer_handle on TikTok' in rendered |
| 1350 | assert "original_creator" not in rendered |
| 1351 | assert '"Anonymous sharp reaction." -- Comment on Instagram' in rendered |
| 1352 | assert "brand_creator" not in rendered |
| 1353 | assert '"Short sharp X post." -- @post_author' in rendered |
| 1354 | assert "@@post_author" not in rendered |
| 1355 | assert "<!--" not in rendered |
| 1356 | |
| 1357 | |
| 1358 | def test_greptile_p1_signals_and_best_takes_handle_non_list_truthy_top_comments_and_huge_scores(): |
| 1359 | from lib import signals |
| 1360 | |
| 1361 | assert signals.log1p_safe(True) == 0.0 |
| 1362 | assert signals.log1p_safe(False) == 0.0 |
| 1363 | assert signals.log1p_safe(10**400) == 0.0 |
| 1364 | assert signals.log1p_safe(float("nan")) == 0.0 |
| 1365 | assert signals.log1p_safe(float("inf")) == 0.0 |
| 1366 | assert signals.log1p_safe(100) > 0.0 |
| 1367 | |
| 1368 | bad_int = _make_item("b1", "reddit", "Acme thread with int top_comments", container="python", metadata={"top_comments": 42}) |
| 1369 | bad_dict = _make_item("b2", "x", "Acme post with dict top_comments", author="alice", metadata={"top_comments": {"a": 1}}) |
| 1370 | bad_str = _make_item("b3", "youtube", "Acme video with str top_comments", metadata={"top_comments": "not-a-list"}) |
| 1371 | none_meta = _make_item("b4", "tiktok", "Acme clip with None metadata", author="bob") |
| 1372 | none_meta.metadata = None # type: ignore[assignment] |
| 1373 | huge_score = _make_item( |
| 1374 | "b5", |
| 1375 | "reddit", |
| 1376 | "Acme thread with huge comment score", |
| 1377 | container="python", |
| 1378 | metadata={"top_comments": [{"author": "dev", "score": 10**400, "excerpt": "Valid comment text."}]}, |
| 1379 | ) |
| 1380 | |
| 1381 | cands = [ |
| 1382 | _make_candidate(f"c{i}", it, fun_score=85.0, cluster_id="cl1") |
| 1383 | for i, it in enumerate((bad_int, bad_dict, bad_str, none_meta, huge_score), start=1) |
| 1384 | ] |
| 1385 | for item in (bad_int, bad_dict, bad_str, none_meta, huge_score): |
| 1386 | assert signals._top_comment_score(item) == 0.0 |
| 1387 | for cand in cands: |
| 1388 | assert signals.top_comment_vote_signal(cand) == 0.0 |
| 1389 | |
| 1390 | best_takes = "\n".join(render._render_best_takes(cands, threshold=70.0)) |
| 1391 | assert "## Best Takes" in best_takes |
| 1392 | assert "Valid comment text." in best_takes |
| 1393 | |
| 1394 | cluster = schema.Cluster( |
| 1395 | cluster_id="cl1", |
| 1396 | title="Acme discussion", |
| 1397 | candidate_ids=[c.candidate_id for c in cands], |
| 1398 | representative_ids=["c1", "c5"], |
| 1399 | sources=["reddit", "x", "youtube", "tiktok"], |
| 1400 | score=85.0, |
| 1401 | ) |
| 1402 | report = _make_report( |
| 1403 | "Acme", |
| 1404 | items_by_source={ |
| 1405 | "reddit": [bad_int, huge_score], |
| 1406 | "x": [bad_dict], |
| 1407 | "youtube": [bad_str], |
| 1408 | "tiktok": [none_meta], |
| 1409 | }, |
| 1410 | candidates=cands, |
| 1411 | clusters=[cluster], |
| 1412 | ) |
| 1413 | assert "## Best Takes" in render.render_compact(report) |
| 1414 | assert "## All Items by Source" in render.render_full(report) |
| 1415 | |
| 1416 | |
| 1417 | def test_greptile_p2_format_item_engagement_preserves_fractional_scores_and_skips_bad_values(): |
| 1418 | tp_float = _make_item( |
| 1419 | "tp-float", |
| 1420 | "trustpilot", |
| 1421 | "Acme Trustpilot 4.24", |
| 1422 | engagement={"trustScore": 4.24, "reviews": 1200}, |
| 1423 | ) |
| 1424 | tp_str = _make_item( |
| 1425 | "tp-str", |
| 1426 | "trustpilot", |
| 1427 | "Acme Trustpilot string 4.24", |
| 1428 | engagement={"trustScore": "4.24", "bad_nan": "NaN", "bad_inf": "inf", "bad_huge": "1e500"}, |
| 1429 | ) |
| 1430 | tp_bad = _make_item( |
| 1431 | "tp-bad", |
| 1432 | "trustpilot", |
| 1433 | "Acme Trustpilot bad", |
| 1434 | engagement={ |
| 1435 | "huge": 10**5000, |
| 1436 | "nan": float("nan"), |
| 1437 | "inf": float("inf"), |
| 1438 | "flag": True, |
| 1439 | "trustScore": 4.24, |
| 1440 | }, |
| 1441 | ) |
| 1442 | |
| 1443 | assert render._format_item_engagement(tp_float) == "1200 reviews, 4.24 trustScore" |
| 1444 | assert render._format_item_engagement(tp_str) == "4.24 trustScore" |
| 1445 | assert render._format_item_engagement(tp_bad) == "4.24 trustScore" |
| 1446 | |
| 1447 | report = _make_report("Acme", items_by_source={"trustpilot": [tp_float, tp_str, tp_bad]}) |
| 1448 | full = render.render_full(report) |
| 1449 | assert "[1200 reviews, 4.24 trustScore]" in full |
| 1450 | assert "[4.24 trustScore]" in full |
| 1451 | assert "4.2 trustScore" not in full |
| 1452 |