fix: retry Agent Step2 once when first write attempt fails

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-03 16:40:05 +08:00
parent 64179820d7
commit db270013eb
2 changed files with 41 additions and 1 deletions

View File

@@ -53,3 +53,33 @@ def test_write_wecom_report_extracts_markdown_block(monkeypatch):
assert md is not None
assert md.startswith("📰")
assert "正文" in md
def test_run_agent_workflow_retries_step2(monkeypatch):
import daily.agent_workflow as agent
calls = {"n": 0}
def fake_llm(system, user):
if '"trends"' in user:
calls["n"] += 1
if calls["n"] == 1:
raise RuntimeError("Bridge request timed out")
return "📰 **早报 · 2026-07-03**\n\n重试成功"
return json.dumps(
{"headline": "h", "opening": "o", "themes": [], "top_picks": [], "signals": []},
ensure_ascii=False,
)
monkeypatch.setattr(agent, "llm_chat", fake_llm)
md = agent.run_agent_workflow(
{"date": "2026-07-03"},
date_str="2026-07-03",
time_str="09:30 (UTC+8)",
updated="2026-07-02",
)
assert md is not None
assert "重试成功" in md
assert calls["n"] == 2