import asyncio from B01_Dashboard import B01_Dashboard_Knowledge_Chat as chat def test_chat_excludes_practice_documents_from_gemini(monkeypatch, tmp_path): public = tmp_path / "법률" private = tmp_path / "실무문서" public.mkdir() private.mkdir() (public / "현행.md").write_text("# 임도 기준\n" + "임도 설치 기준 내용 " * 10, encoding="utf-8") (private / "사례.md").write_text("# 임도 기준\n비공개 사례 " * 10, encoding="utf-8") monkeypatch.setattr(chat, "ORIGINAL", tmp_path) monkeypatch.setenv("GEMINI_API_KEY", "test-key") chat._sections.cache_clear() sent = {} class Response: def raise_for_status(self): pass def json(self): return {"candidates": [{"content": {"parts": [{"text": "설명 [1]"}]}}]} class Client: def __init__(self, timeout): pass async def __aenter__(self): return self async def __aexit__(self, *_args): pass async def post(self, url, *, headers, json): sent["prompt"] = json["contents"][0]["parts"][0]["text"] return Response() monkeypatch.setattr(chat.httpx, "AsyncClient", Client) result = asyncio.run(chat.ask_knowledge_chat(chat.ChatRequest(question="임도 기준"), {})) assert result["answer"] == "설명 [1]" assert result["sources"][0]["path"] == "법률/현행.md" assert "실무문서" not in sent["prompt"] assert "비공개 사례" not in sent["prompt"] chat._sections.cache_clear()