import asyncio from B01_Dashboard import B01_Dashboard_Knowledge_Chat as chat def test_chat_searches_all_knowledge_markdown_except_excluded_folders(monkeypatch, tmp_path): public = tmp_path / "original" / "법률" guide = tmp_path / "technical_info" private = tmp_path / "original" / "실무문서" stmate = tmp_path / "original" / "원가계산" / "STmate" dasan = tmp_path / "original" / "원가계산" / "다산소프트" public.mkdir(parents=True) guide.mkdir() private.mkdir() stmate.mkdir(parents=True) dasan.mkdir() (public / "현행.md").write_text("# 임도 기준\n" + "임도 설치 기준 내용 " * 10, encoding="utf-8") (guide / "_검토.md").write_text("# 임도 기준\n기술정보 안내 " * 10, encoding="utf-8") (private / "사례.md").write_text("# 임도 기준\n비공개 사례 " * 10, encoding="utf-8") (stmate / "자료.md").write_text("# 임도 기준\nSTmate 자료 " * 10, encoding="utf-8") (dasan / "자료.md").write_text("# 임도 기준\n다산소프트 자료 " * 10, encoding="utf-8") monkeypatch.setattr(chat, "KNOWLEDGE", 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]" paths = {source["path"] for source in result["sources"]} assert paths == {"original/법률/현행.md"} assert "실무문서" not in sent["prompt"] assert "비공개 사례" not in sent["prompt"] assert "STmate" not in sent["prompt"] assert "다산소프트" not in sent["prompt"] assert "기술정보 안내" not in sent["prompt"] chat._sections.cache_clear()