From 1d6c1b43296e2bab76e227728eb7479901eddcd9 Mon Sep 17 00:00:00 2001 From: gahusb Date: Tue, 28 Apr 2026 09:09:05 +0900 Subject: [PATCH] fix(agent-office): bookmark field name + service_proxy contract + mktemp Co-Authored-By: Claude Sonnet 4.6 --- agent-office/app/service_proxy.py | 16 +++++++++------- agent-office/app/telegram/webhook.py | 6 +++--- agent-office/tests/test_realestate_agent.py | 4 +++- agent-office/tests/test_realestate_callback.py | 11 ++++++++--- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/agent-office/app/service_proxy.py b/agent-office/app/service_proxy.py index 51a5f7a..1a372c3 100644 --- a/agent-office/app/service_proxy.py +++ b/agent-office/app/service_proxy.py @@ -112,13 +112,15 @@ async def realestate_collect() -> Dict[str, Any]: async def realestate_matches(limit: int = 20) -> List[Dict[str, Any]]: - resp = await _client.get( - f"{REALESTATE_LAB_URL}/api/realestate/matches", - params={"limit": limit, "unread_only": True}, - ) - resp.raise_for_status() - data = resp.json() - return data if isinstance(data, list) else data.get("matches", []) + """realestate-lab의 GET /api/realestate/matches 호출.""" + async with httpx.AsyncClient(timeout=10) as client: + resp = await client.get( + f"{REALESTATE_LAB_URL}/api/realestate/matches", + params={"size": limit}, + ) + resp.raise_for_status() + data = resp.json() + return data.get("items", []) async def realestate_dashboard() -> Dict[str, Any]: diff --git a/agent-office/app/telegram/webhook.py b/agent-office/app/telegram/webhook.py index 6883b52..107d533 100644 --- a/agent-office/app/telegram/webhook.py +++ b/agent-office/app/telegram/webhook.py @@ -84,10 +84,10 @@ async def _handle_realestate_bookmark(callback_query: dict, callback_id: str) -> try: result = await service_proxy.realestate_bookmark_toggle(ann_id) - bookmarked = result.get("bookmarked", None) - if bookmarked is True: + is_on = result.get("is_bookmarked") + if is_on == 1: await send_raw(f"🔖 북마크 추가 완료 (#{ann_id})") - elif bookmarked is False: + elif is_on == 0: await send_raw(f"🔖 북마크 해제 완료 (#{ann_id})") else: await send_raw(f"🔖 북마크 토글 완료 (#{ann_id})") diff --git a/agent-office/tests/test_realestate_agent.py b/agent-office/tests/test_realestate_agent.py index 2e42f5b..7abc838 100644 --- a/agent-office/tests/test_realestate_agent.py +++ b/agent-office/tests/test_realestate_agent.py @@ -2,7 +2,9 @@ import os import sys import tempfile -_TMP = tempfile.mktemp(suffix=".db") +_fd, _TMP = tempfile.mkstemp(suffix=".db") +os.close(_fd) +os.unlink(_TMP) os.environ["AGENT_OFFICE_DB_PATH"] = _TMP sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) diff --git a/agent-office/tests/test_realestate_callback.py b/agent-office/tests/test_realestate_callback.py index b7b3364..e12e156 100644 --- a/agent-office/tests/test_realestate_callback.py +++ b/agent-office/tests/test_realestate_callback.py @@ -4,7 +4,9 @@ import tempfile import gc from unittest.mock import AsyncMock, patch -_TMP = tempfile.mktemp(suffix=".db") +_fd, _TMP = tempfile.mkstemp(suffix=".db") +os.close(_fd) +os.unlink(_TMP) os.environ["AGENT_OFFICE_DB_PATH"] = _TMP sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -26,11 +28,12 @@ def _init_db(): def test_callback_realestate_bookmark_calls_proxy(): - """callback_data 'realestate_bookmark_42' 가 service_proxy.realestate_bookmark_toggle(42) 를 호출.""" + """callback_data 'realestate_bookmark_42' 가 service_proxy.realestate_bookmark_toggle(42) 를 호출하고 + is_bookmarked=1 이면 '추가 완료' 메시지를 전송한다.""" from app import service_proxy from app.telegram import webhook - fake_toggle = AsyncMock(return_value={"bookmarked": True}) + fake_toggle = AsyncMock(return_value={"is_bookmarked": 1}) fake_send = AsyncMock(return_value={"ok": True}) fake_api_call = AsyncMock(return_value={"ok": True}) @@ -49,6 +52,8 @@ def test_callback_realestate_bookmark_calls_proxy(): fake_toggle.assert_awaited_once_with(42) assert result == {"ok": True, "announcement_id": 42} + args, _ = fake_send.call_args + assert "추가" in args[0] def test_callback_realestate_bookmark_invalid_id():