feat(agent-office): /agents/{id}/logs 엔드포인트가 service /logs/recent 와 merge
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
47
agent-office/tests/test_log_merge.py
Normal file
47
agent-office/tests/test_log_merge.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import pytest
|
||||
import respx
|
||||
import httpx
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
from app.db import add_log, _conn
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _clean_logs():
|
||||
with _conn() as conn:
|
||||
conn.execute("DELETE FROM agent_logs WHERE agent_id = 'lotto'")
|
||||
yield
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_agent_logs_endpoint_merges_db_and_service_logs():
|
||||
add_log("lotto", "큐레이션 완료: #1234 conf=0.78")
|
||||
respx.get("http://lotto:8000/logs/recent").mock(
|
||||
return_value=httpx.Response(200, json={
|
||||
"logs": [
|
||||
{"ts": "2026-05-28T10:00:00Z", "source": "access",
|
||||
"method": "GET", "path": "/api/lotto/latest",
|
||||
"status": 200, "ms": 8,
|
||||
"message": "GET /api/lotto/latest → 200 (8ms)"},
|
||||
{"ts": "2026-05-28T10:00:02Z", "source": "log",
|
||||
"logger": "lotto", "level": "info",
|
||||
"message": "성과 통계 캐시 갱신"},
|
||||
]
|
||||
})
|
||||
)
|
||||
|
||||
client = TestClient(app)
|
||||
resp = client.get("/api/agent-office/agents/lotto/logs?limit=20")
|
||||
assert resp.status_code == 200
|
||||
logs = resp.json()["logs"]
|
||||
|
||||
sources = {x["source"] for x in logs}
|
||||
assert "agent" in sources
|
||||
assert "access" in sources
|
||||
assert "log" in sources
|
||||
|
||||
messages = [x["message"] for x in logs]
|
||||
assert any("큐레이션 완료" in m for m in messages)
|
||||
assert any("성과 통계 캐시 갱신" in m for m in messages)
|
||||
assert any("/api/lotto/latest" in m for m in messages)
|
||||
Reference in New Issue
Block a user