"""Retro publish tests (AGENTIC-WP-0010 T02).""" import json import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from session_memory.retro.publish import ( # noqa: E402 publish_to_hub, render_markdown, write_local, ) def _report(): return { "window": {"since": "2026-06-01T00:00:00Z", "until": "2026-06-08T00:00:00Z", "days": 7}, "generated_at": "2026-06-08T19:00:00Z", "n_sessions": 12, "suggestions": [ {"repo": "state-hub", "title": "schema thrash", "recommendation": "front-load schemas", "priority": "high", "score": 632.0, "cross_flavor": False, "signal_type": "schema_thrash"}, ], "measure": {"infra_overhead_share_median": 0.117, "error_rate": 0.96, "schema_thrash_sessions": 8, "success_rate": 1.0, "tokens_p50": 250725}, } def test_render_markdown(): md = render_markdown(_report()) assert "Weekly Coding Retro" in md assert "**state-hub**" in md and "front-load schemas" in md assert "infra-overhead median: 0.117" in md def test_write_local_json_and_md(tmp_path): jp = str(tmp_path / "out" / "retro.json") mp = str(tmp_path / "out" / "retro.md") write_local(_report(), jp, mp) assert json.load(open(jp))["n_sessions"] == 12 assert "Weekly Coding Retro" in open(mp).read() def test_publish_calls_poster_with_coding_retro_event(): captured = {} def poster(url, payload): captured["url"] = url captured["payload"] = payload ok = publish_to_hub(_report(), base_url="http://hub", poster=poster) assert ok is True assert captured["url"] == "http://hub/progress/" assert captured["payload"]["event_type"] == "coding_retro" assert captured["payload"]["detail"]["n_sessions"] == 12 def test_publish_degrades_gracefully_on_failure(): def boom(url, payload): raise OSError("hub down") assert publish_to_hub(_report(), poster=boom) is False