test(agent-office): 하위호환(비자율 경로) + issue_regen 콜백 테스트

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-11 02:48:18 +09:00
parent 9d50aa4256
commit 28d489770a

View File

@@ -118,3 +118,52 @@ async def test_handle_insta_issue_invalid_data(monkeypatch):
)
assert result["ok"] is False
assert result["error"] == "invalid_callback_data"
@pytest.mark.asyncio
async def test_backward_compat_non_autonomous_uses_legacy_path(monkeypatch):
"""autonomous_issue=False, auto_select=False → insta_ranked 미호출, _push_keyword_candidates 호출."""
agent = InstaAgent()
agent.state = "idle"
monkeypatch.setattr("app.agents.insta.get_agent_config",
lambda aid: {"custom_config": {"autonomous_issue": False, "auto_select": False}})
monkeypatch.setattr(agent, "transition", AsyncMock())
monkeypatch.setattr(agent, "_run_collect_and_extract", AsyncMock())
# insta_get_preferences는 try/except 안에 있으므로 예외를 던져도 안전하지만 깔끔하게 mock
monkeypatch.setattr("app.agents.insta.service_proxy.insta_get_preferences",
AsyncMock(return_value={}))
# 비자율 경로에서 insta_ranked는 호출되면 안 된다
ranked = AsyncMock()
monkeypatch.setattr("app.agents.insta.service_proxy.insta_ranked", ranked)
# insta_list_keywords: 비자율 경로에서 반드시 호출
monkeypatch.setattr("app.agents.insta.service_proxy.insta_list_keywords",
AsyncMock(return_value=[]))
# auto_select=False → _push_keyword_candidates 경로
push = AsyncMock()
monkeypatch.setattr(agent, "_push_keyword_candidates", push)
gen = AsyncMock()
monkeypatch.setattr(agent, "_generate_and_preview", gen)
monkeypatch.setattr("app.agents.insta.create_task", lambda *a, **k: "t1")
monkeypatch.setattr("app.agents.insta.update_task_status", lambda *a, **k: None)
monkeypatch.setattr("app.agents.insta.add_log", lambda *a, **k: None)
await agent.on_schedule()
ranked.assert_not_awaited() # 자율 경로(insta_ranked) 미진입 확인
gen.assert_not_awaited() # _generate_and_preview 미호출 확인
push.assert_awaited_once() # 기존 candidate-push 경로 진입 확인
@pytest.mark.asyncio
async def test_callback_regen_rejects_old_and_regenerates(monkeypatch):
"""issue_regen: 기존 슬레이트 rejected 처리 후 같은 키워드로 _generate_and_preview 재호출."""
agent = InstaAgent()
monkeypatch.setattr("app.agents.insta.service_proxy.insta_get_slate",
AsyncMock(return_value={"keyword": "금리", "category": "economy"}))
dec = AsyncMock(return_value={"status": "rejected"})
monkeypatch.setattr("app.agents.insta.service_proxy.insta_decision", dec)
gen = AsyncMock()
monkeypatch.setattr(agent, "_generate_and_preview", gen)
res = await agent.on_callback("issue_regen", {"slate_id": 8})
assert res["ok"] is True
dec.assert_awaited_once_with(8, "rejected") # 이전 슬레이트 폐기
gen.assert_awaited_once() # 같은 키워드로 재생성
assert gen.await_args.args[0]["keyword"] == "금리"