Ver código fonte

chore(langgraph): Docker Compose + Phase 1 integration tests

iwt 4 meses atrás
pai
commit
7c4e975058

+ 22 - 0
cfc-langgraph/docker-compose.yml

@@ -0,0 +1,22 @@
+version: "3.8"
+
+services:
+  langgraph-svc:
+    build:
+      context: .
+      dockerfile: Dockerfile
+    ports:
+      - "9000:9000"
+    env_file:
+      - .env
+    environment:
+      - JAVA_BASE_URL=http://host.docker.internal:9082
+      - CHROMA_DB_PATH=/data/chroma_db
+    volumes:
+      - langgraph-data:/data
+      - ./app:/app/app  # 开发模式: 热重载
+    command: uvicorn app.main:app --host 0.0.0.0 --port 9000 --reload
+    restart: unless-stopped
+
+volumes:
+  langgraph-data:

+ 0 - 0
cfc-langgraph/tests/__init__.py


+ 16 - 0
cfc-langgraph/tests/conftest.py

@@ -0,0 +1,16 @@
+import pytest
+from httpx import AsyncClient, ASGITransport
+from app.main import app
+
+
+@pytest.fixture
+async def client():
+    transport = ASGITransport(app=app)
+    async with AsyncClient(transport=transport, base_url="http://test") as ac:
+        yield ac
+
+
+@pytest.fixture
+async def health_response(client):
+    resp = await client.get("/health")
+    return resp

+ 44 - 0
cfc-langgraph/tests/test_recommend.py

@@ -0,0 +1,44 @@
+import pytest
+from httpx import AsyncClient, ASGITransport
+from app.main import app
+
+
+@pytest.mark.asyncio
+async def test_health_check():
+    transport = ASGITransport(app=app)
+    async with AsyncClient(transport=transport, base_url="http://test") as client:
+        resp = await client.get("/health")
+        assert resp.status_code == 200
+        assert resp.json() == {"status": "ok"}
+
+
+@pytest.mark.asyncio
+async def test_recommend_empty_tags():
+    """空标签应返回空列表"""
+    transport = ASGITransport(app=app)
+    async with AsyncClient(transport=transport, base_url="http://test") as client:
+        resp = await client.post("/api/v1/recommend", json={
+            "user_id": 1,
+            "tags": [],
+            "query": "推荐一些适合孩子的活动",
+            "limit": 3,
+        })
+        assert resp.status_code == 200
+        data = resp.json()
+        assert "items" in data
+
+
+@pytest.mark.asyncio
+async def test_recommend_with_tags():
+    """带标签应返回推荐结果"""
+    transport = ASGITransport(app=app)
+    async with AsyncClient(transport=transport, base_url="http://test") as client:
+        resp = await client.post("/api/v1/recommend", json={
+            "user_id": 1,
+            "tags": ["益生菌", "肠胃"],
+            "limit": 3,
+        })
+        assert resp.status_code == 200
+        data = resp.json()
+        assert "items" in data
+        assert "source" in data