diff --git a/tests/run_test.bat b/tests/run_test.bat index 8f35968..1af35dc 100644 --- a/tests/run_test.bat +++ b/tests/run_test.bat @@ -2,3 +2,6 @@ cd /d c:\Users\Certes\Desktop\variet-agent python tests/test_cli_tools.py 2>&1 type tests\cli_test_output.txt +echo. +echo === Wiki Client Tests === +python tests/test_wiki_client.py diff --git a/tests/test_wiki_client.py b/tests/test_wiki_client.py new file mode 100644 index 0000000..0de22df --- /dev/null +++ b/tests/test_wiki_client.py @@ -0,0 +1,122 @@ +"""Wiki.js GraphQL 클라이언트 테스트.""" + +import asyncio +import sys +import os +import io + +if sys.stdout.encoding != "utf-8": + sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace") + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + + +async def test_wiki_client(): + """WikiClient 전체 API 스트레스/기능 테스트.""" + print("=== Wiki.js Client Test ===") + from tools.wiki_client import WikiClient + + client = WikiClient(timeout=10.0) + test_path = "research/agent-test-sandbox" + + # 1. 목록 조회 + try: + pages = await client.list_pages() + print(f" [OK] 페이지 목록 조회: {len(pages)}건 반환됨") + except Exception as e: + print(f" [FAIL] 페이지 목록 조회 실패: {e}") + return + + # 2. 기존 샌드박스 정리 (존재 시) + existing = await client.find_page(test_path) + if existing: + print(f" [INFO] 잔여 테스트 페이지 삭제 중 (id: {existing.id})") + await client.delete_page(existing.id) + # 삭제 반영 대기 + await asyncio.sleep(1) + + # 3. 페이지 생성 + print(f" [ACT] 테스트 페이지 생성: /{test_path}") + test_content = "# Test\n이것은 자동화 테스트 페이지입니다." + try: + new_page = await client.create_page( + test_path, + "Test Sandbox", + test_content, + "테스트 요약", + ["test", "agent"] + ) + print(f" [OK] 페이지 생성 성공 (id: {new_page.id})") + except Exception as e: + print(f" [FAIL] 페이지 생성 실패: {e}") + return + + # 4. 페이지 조회 검증 + try: + fetched = await client.get_page(new_page.id) + assert fetched.path == test_path, "경로 불일치" + print(f" [OK] 생성된 페이지 조회 성공 (id: {fetched.id})") + except Exception as e: + print(f" [FAIL] 생성된 페이지 조회 실패: {e}") + + # 5. 페이지 수정 연산 + print(f" [ACT] 페이지 데이터 업데이트") + update_content = test_content + "\n\n업데이트된 내용입니다." + try: + ok = await client.update_page( + new_page.id, + update_content, + title="Updated Test Sandbox" + ) + assert ok is True, "업데이트 API 반환 결과 False" + print(f" [OK] 페이지 수정 성공") + except Exception as e: + print(f" [FAIL] 페이지 수정 실패: {e}") + + # 6. Upsert API 검증 (기존 문서 덮어쓰기) + print(f" [ACT] Upsert API 검증") + try: + upserted = await client.upsert_page( + test_path, + "Upserted Test Sandbox", + update_content + "\nUpsert 완료" + ) + assert upserted.id == new_page.id, "Upsert가 기존 ID를 재사용하지 않음" + print(f" [OK] Upsert (기존 수정) 성공") + except Exception as e: + print(f" [FAIL] Upsert (기존 수정) 실패: {e}") + + # 7. Dashboard 갱신 API 검증 + print(f" [ACT] Dashboard 갱신 테스트") + try: + dash = await client.update_dashboard([ + {"topic": "Dummy Topic 1", "status": "✅", "path": "research/dummy1"}, + {"topic": "Dummy Topic 2", "status": "진행중", "path": "research/dummy2"} + ]) + print(f" [OK] 대시보드 강제 갱신 API 호춣 성공 (id: {dash.id})") + + # 다시 원래 상태로 롤백 (엔트리 없이 호출하면 파일 시스템 스캔) + await client.update_dashboard() + print(f" [OK] 대시보드 자동 스캔 & 롤백 성공") + except Exception as e: + print(f" [FAIL] 대시보드 API 실패: {e}") + + # 8. 정리 (삭제) + print(f" [ACT] 테스트 페이지 삭제") + try: + ok = await client.delete_page(new_page.id) + assert ok is True, "삭제 API 반환 결과 False" + print(f" [OK] 정리 프러시저 (삭제) 성공") + except Exception as e: + print(f" [FAIL] 삭제 실패: {e}") + + print(" ✅ WikiClient All Tests Completed\n") + + +async def main(): + await test_wiki_client() + print("🎉 All tests completed!") + + +if __name__ == "__main__": + asyncio.run(main())