merge: fix/kakao-callback-fast-reply(카카오 콜백 대기 문구를 늦어질 때만) 을 main 에 병합

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5.5 committed 2026-10-21 14:15:22 +09:00
commit 9c107fa895
3 files changed
+89 -23

No files matched your search

+51 -11
View File
@@ -317,19 +317,55 @@ async def test_목록은_발행_여부를_같이_말한다(client, auth_headers,
# ── 콜백 (5초 벽 넘기) ───────────────────────────────────────────────────
async def test_콜백이_켜져_있으면_즉답하고_뒤에서_마저_만든다(client, auth_headers, db_engine, monkeypatch):
"""오픈빌더 스킬 타임아웃은 5초다."""
async def test_콜백이_켜져_있어도_빨리_끝나면_대기_문구_없이_바로_답한다(client, db_engine, monkeypatch):
"""1초면 끝나는 답에 "확인하고 있어요" 가 먼저 붙으면 사장님에게는 두 번 말하는 봇이다."""
import router.v1.agent.kakao_bot as bot
pushed = AsyncMock()
monkeypatch.setattr(bot, "_push", pushed)
payload = body("안녕", "콜백-빠른-발화자")
payload["userRequest"]["callbackUrl"] = "https://callback.example/one-shot"
res = await client.post(PATH, headers={"X-Agent-Secret": SECRET}, json=payload)
assert "useCallback" not in res.json()
assert "연결" in said(res)
pushed.assert_not_awaited() # 콜백 주소는 쓰지 않는다
async def test_콜백이_켜져_있고_늦어지면_즉답하고_같은_작업을_콜백으로_보낸다(client, monkeypatch):
"""오픈빌더 스킬 타임아웃은 5초다. 늦어진 작업은 취소하지 않고 끝난 결과를 콜백으로 보낸다."""
import asyncio
import router.v1.agent.kakao_bot as bot
runs = []
async def slow_handle(utterance, speaker, app_user_id=""):
runs.append(utterance)
await asyncio.sleep(0.2)
return channel._say("늦은 답")
monkeypatch.setattr(bot.channel, "handle", slow_handle)
monkeypatch.setattr(bot, "FAST_REPLY_SEC", 0.05)
sent = {}
async def fake_push(callback_url, utterance, speaker, app_user_id=""):
sent["url"] = callback_url
sent["payload"] = await bot._answer(utterance, speaker, 5.0)
class FakeClient:
async def __aenter__(self):
return self
monkeypatch.setattr(bot, "_push", fake_push)
async def __aexit__(self, *_):
return False
payload = body("안녕", "콜백-발화자")
async def post(self, url, json):
sent["url"], sent["payload"] = url, json
return SimpleNamespace(status_code=200)
# 테스트 클라이언트도 httpx 라 모듈 전체가 아니라 bot 이 보는 이름만 바꾼다.
monkeypatch.setattr(bot, "httpx", SimpleNamespace(AsyncClient=lambda **_kw: FakeClient()))
payload = body("휴무 바꿔줘", "콜백-느린-발화자")
payload["userRequest"]["callbackUrl"] = "https://callback.example/one-shot"
res = await client.post(PATH, headers={"X-Agent-Secret": SECRET}, json=payload)
@@ -338,9 +374,10 @@ async def test_콜백이_켜져_있으면_즉답하고_뒤에서_마저_만든
assert res.json()["data"]["text"]
assert "template" not in res.json()
# 실제 답은 콜백으로 간다.
# 실제 답은 콜백으로 가고, 작업은 한 번만 돌았다.
assert sent["url"] == "https://callback.example/one-shot"
assert "연결" in sent["payload"]["template"]["outputs"][0]["simpleText"]["text"]
assert sent["payload"]["template"]["outputs"][0]["simpleText"]["text"] == "늦은 답"
assert runs == ["휴무 바꿔줘"]
async def test_콜백이_없으면_예전처럼_동기로_답한다(client, db_engine):
@@ -353,7 +390,10 @@ async def test_콜백_전송이_실패해도_터지지_않는다(monkeypatch):
"""주소는 1분 · 1회다."""
import router.v1.agent.kakao_bot as bot
monkeypatch.setattr(bot, "_answer", AsyncMock(return_value=bot._reply("답")))
import asyncio
done = asyncio.get_running_loop().create_future()
done.set_result(channel._say("답"))
class Boom:
async def __aenter__(self):
@@ -363,7 +403,7 @@ async def test_콜백_전송이_실패해도_터지지_않는다(monkeypatch):
return False
monkeypatch.setattr(bot.httpx, "AsyncClient", lambda **_kw: Boom())
await bot._push("https://callback.example/x", "안녕", "누구") # 예외가 새 나오지 않는다
await bot._push("https://callback.example/x", done, 1.0) # 예외가 새 나오지 않는다
# ── 여러 가게 ────────────────────────────────────────────────────────────